Difference between revisions of "Renaissance:ODFToolkit"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Using the ODFTOOLKIT)
m (Categorizing)
Line 1: Line 1:
{{User Experience Community}}
=== Using the ODFTOOLKIT ===
=== Using the ODFTOOLKIT ===
* go to the [http://odftoolkit.org/ OdfToolkit] site and download the ODFDOM Java API
* go to the [http://odftoolkit.org/ OdfToolkit] site and download the ODFDOM Java API

Latest revision as of 22:46, 17 March 2010



Quick Navigation



  • 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);
            System.out.println("Loading ...");
            // The input of an ODF document is hard coded so far
            odfDoc = OdfDocument.loadDocument("d:\\scenarios.odt");
            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);
                        String n = sub.substring(m.start(), m.end());
        catch (Exception e)
Personal tools