[jopendocument] RhinoFileTemplate.setField( String name, String data ) do not put in text as expected

2012-07-23 Thread Brumle
I'd have tried out the demo in 
http://www.jopendocument.org/start_text_2.html , excerpt for a few 
problems  this example now works ok with using the embedded template 
test.ott.
When I'd tries to use an template I'd have made myself, no data is filled 
in, and the file that is produced are still an template. test.ott are made 
with OpenOffice 2.4, I'd think those problems are due to version conflicts 
as the way input fields are threated may have been altered, and 
jopedocument cannot handle it. I'd have been looking for OpenOffice 2.4 but 
it looks like there are only current versions out on the net. It's just an 
hypotesis cause I'd haven't tested it through, only with the test.ott 
template.

I'd have made myself an mysql database with a Java front end to keep record 
of adresses, and I'd like to start an new letter just by looking up an 
address and klick new letter. 
Is there anybody in the group who have done this or something alike? 

Enclosing my test program: This is the version for my own template.

package opendocumenttest;

import java.io.File;
import java.util.*;
import javax.script.ScriptEngineManager;
import org.jopendocument.dom.ODSingleXMLDocument;
import org.jopendocument.dom.OOUtils;
import org.jopendocument.dom.template.JavaScriptFileTemplate;
import org.jopendocument.dom.template.RhinoFileTemplate;

public class OpenDocumentTest3 {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws Exception {

File templateFile = new File(brevmal.ott);

// Let's make a temp file, so I don't mess up the directory
// filer alle veier
File tempDir = new File(/home/sigmund/tmp);
File tempFile = File.createTempFile(test, odt, tempDir);


// Load the template.
// Java 5 users will have to use RhinoFileTemplate instead
RhinoFileTemplate template = new RhinoFileTemplate(templateFile);

// Fill with sample values.

Calendar cal = new GregorianCalendar(); // dags dato
int date = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH) + 1; // januar = 0
int year = cal.get(Calendar.YEAR);
String datoStr = String.format(%02d.%02d.%d, date, month, year );
template.setField(dato, datoStr );

template.setField(adressat, Svipp AS);
template.setField(adresse, Larsamyrå);
template.setField(post, 4500 SANDNES);



// Make a new document, and save it.
ODSingleXMLDocument doc = template.createDocument();
tempFile = doc.saveAs(tempFile);

// Open the document with OpenOffice.org !
OOUtils.open(tempFile);
}

// Missing function
private static MapString, String createMap(String n, String min, 
String max) {
final MapString, String res = new HashMapString, String();
res.put(name, n);
res.put(min, min);
res.put(max, max);
return res;
}

}

Happy coding! Brumle.


[jopendocument] Re: RhinoFileTemplate.setField( String name, String data ) do not put in text as expected

2012-07-25 Thread Brumle
Now, I'd got the data into the document, JOpendocument addon to LibreOffice 
writer were missing. You might find a link to it at the very end of the 
JOpendocument website. 

Furthermore what's template here, is not what LibreOffice treat as a 
template, test.odt is a writer file, and not a template. Renaming it to 
.ott do not make it an LibreOffice template. template.createDocument 
creates a ODSingleXMLDocument, yes, but note that this function do not 
create an document from a template. If template is a template, it will 
create a template, or if template is a writer document, it will create a 
writer document.

I'd have done some research for if possible to generate a doc from a 
template, like LibreOffice do, but that seems like it is not straight 
forward, JOpendocument do'nt support it by now. Now, I'd need to determine 
the name of the resulting doc, but if that's not important, it's just to 
load an template into template object, do whatever you like, save it to an 
temporary file, and open int in LibreOffice. The user may then select a 
filename for it. 

Until JOpenDocument are supporting creation of a document from an template, 
I'd just make an doc from the actual template, and that will do fine. I'd 
has to remember to make a new one if the template is altered, however.

Happy coding!


[jopendocument] Re: receive field in a template

2012-08-25 Thread Brumle
If I'd have understood your request correctly, you'd entered someting into 
an opened template, and saved it. That file could be decompressed and infor 
extracted as any xml file. Haven't done that in java, but I'd had 
decompressed the file and looked into it by an text editor. I'd had 
attemted to alter the file as well, but then opendocument says the file 
have been tampered with, and strip it of all text.

Sigmund

kl. 11:02:04 UTC+2 torsdag 23. august 2012 skrev jepse følgende:

 Hi there,

 how can i receive the added jopendocument-fields/sections etc. in a 
 template? 

 Thanks for your help!

 Jepse