Difference between revisions of "Renaissance:ODFToolkit"

From Apache OpenOffice Wiki
Jump to: navigation, search
(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....)
 
Line 1: Line 1:
 +
=== 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 :-)
 +
 +
 
<source lang=java>
 
<source lang=java>
 
package loadodf;
 
package loadodf;

Revision as of 19:24, 10 December 2008

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 :-)


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);
        }
    }
}
Personal tools