Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append StringReader For Multiple Entries

I'm creating a program in Java that reads a string of XSL-FO code, populates the empty fields with app data, and adds it to a StringReader, to eventually be set as an InputSource for a web dispatcher.

I already have the code to find and populate the blank template, and now I need to loop through the template X number of times to create X instances of the same document, put together all as a single document.

Psuedocode:

StringReader reader = new StringReader();

for (Iterator i = Object.iterator(); i.hasNext();
{
Object o = (Object) i.next();
reader.append(populateObject(o);
}
InputSource isource = new InputSource(reader);

StringReader, however, doesn't have an append function, and probably isn't meant to have one either. So, how can I create an InputSource that will satisfy the need to have a full, accurate reference to my XML code, that can be read by an InputSource object?

like image 375
Zibbobz Avatar asked Mar 26 '26 19:03

Zibbobz


1 Answers

You could try doing all the appending before-hand:

StringBuilder sb = new StringBuilder();

for (...)
    sb.append(populateObject(obj));

StringReader reader = new StringReader(sb.toString());

Use StringBuffer if you're using a Java version below 5.

like image 185
arshajii Avatar answered Mar 28 '26 08:03

arshajii



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!