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 Map<String, String> createMap(String n, String min, 
String max) {
        final Map<String, String> res = new HashMap<String, String>();
        res.put("name", n);
        res.put("min", min);
        res.put("max", max);
        return res;
    }

}

Happy coding! Brumle.

Reply via email to