Java string sub matching and replacing, document template style

I have an application that involves a spreadsheet or direct entry where I map the columns to textual tokens and use those tokens and what they represent to fill in rows in multiple SQL tables. Kind of like document templates.

To give a example to explain better what I mean, Lets say I have a csv file with two columns “First Name” and “Last Name” and will will map those to tokens “++fname++” and “++lname++” and the app will map token “++domain++” to “example.com”. Here would be the example csv –

"First Name","Last Name
John,Doe
Jane,Smith

So then I would use a HashMap or SQL database or something similar to store the values so I would end up with the first row looking like this in memory.

"++fname++" = "John"
"++fnamei++" = "J"
"++lname++" = "Smith"
"++lnamei++" = "S"
"++domain++" = "example.com"

The SQl table for example would have columns fname, lname, name, email. A preperared statement would be like –

String col[] = new String[4](); 
col[0] = "++fname++";
col[1] = "++lname++";
col[2] = "++fname++ ++lname++";
col[3] = "++fnamei++.++lname++@++domain++";
for (int i = 0; i < col.length; i++ ) {
    p.setString(i + 1,TokenEval(col[i]));
}

The TokenEval() would then insert the proper information so the table would have this inserted –

+++++++++++++++++++++++++++++++++++++++++++++
| John | Doe | John Doe | [email protected] |

The first thing to mention is that I could create classes for each table and use static variables, but there are 50 or so tables that I may have to update at times, and the input is also variable. There also may be many tokens, 20, 30, or even 50+, by the time I am done. The goal is to make the application flexible to changes in the input and the SQL tables where instead of having static classes, get the columns from the SQL server and then map them to token values that are mapped to data so if the table changes or the input changes I can map those in software rather than having to build new versions. Also, a lot of the columns in the database tables are either duplicate information, default values, or system-wide values I can define or possibly change in real-time.

My questions are: first, what would have better performance or be cleaner, using a HashMap to map the tokens to the values and using the .get() to get the mapped value or implementing something like an H2 memory SQL table?

Second, doing the string substitution. I know I can easily match and do the single tokens for fname and lname, but when there are multiple tokens in the string or other characters, like for the name and email, I am not sure what would be the best approach. I could do a char by char over the string and extract the tokens used, get them and rebuild the string, or maybe use the indexOf() to find the tokens and use .replace() once I know what they are. With so many tokens, doing a .replace() for every one for each field would take a long time. Or could I pass the string to the H2 SQL server, and it sends back matches, and I do the substitution from the result? Or is there a library already existing for this application for doing templates/token matching in Java?

Thanks!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật