Renaissance:ODFToolkit
From Apache OpenOffice Wiki
|
---|
Quick Navigation
Team |
Using the ODFTOOLKIT
- go to the OdfToolkit site and download the ODFDOM Java API
- follow the instructions in the wiki and install apps that are required
- download Netbeans, open the ODFDOM project and start coding :-)
Loading an ODF file and processing meta.xml
- this is just a really dirty version I hacked
- no XML parsing required so far, just using a regular expression
- it loads an ODT file and displays entries in meta:document-statistic that I considered interesting
- go on and improve!
package loadodf; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.openoffice.odf.doc.OdfDocument; /** * * @author Andreas Bartel * @version 0.1 */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here OdfDocument odfDoc; String s = null; String regex = "\"\\d*\""; Pattern p = Pattern.compile(regex); try { System.out.println("Loading ..."); // The input of an ODF document is hard coded so far odfDoc = OdfDocument.loadDocument("d:\\scenarios.odt"); System.out.println("Done!"); BufferedReader meta = new BufferedReader(new InputStreamReader(odfDoc.getMetaStream())); while ((s = meta.readLine()) != null) { if (s.contains("meta:document-statistic")) { int i = s.indexOf("meta:table-count"); int j = s.indexOf("</office:meta"); String sub = s.substring(i, j-1); Matcher m = p.matcher(sub); while(m.find()) { String n = sub.substring(m.start(), m.end()); System.out.println(n); } } } } catch (Exception e) { System.err.println(e); } } }