Difference between revisions of "Renaissance:ODFToolkit"
From Apache OpenOffice Wiki
(New page: <source lang=java> package loadodf; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.openoffice....) |
m (Categorizing) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | {{User Experience Community}} | ||
+ | === Using the ODFTOOLKIT === | ||
+ | * go to the [http://odftoolkit.org/ OdfToolkit] site and download the ODFDOM Java API | ||
+ | * follow the instructions in the wiki and install apps that are required | ||
+ | * download [http://www.netbeans.org/ 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! | ||
+ | |||
+ | |||
<source lang=java> | <source lang=java> | ||
package loadodf; | package loadodf; |
Latest revision as of 22:46, 17 March 2010
|
---|
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); } } }