jOpenDocument


A pure Java library for OASIS Open Document files manipulation

Metadata

jOpenDocument provides an API to get and set properties of your ODF documents.

You can specify metadata values (creator, description, subject, date...) and user defined metadata.

 


As you can see in the sample code , we provide getters and setters for standard properties.

User definied properties are created by the getUserMeta method if you specify the second parameter to true.

The data type of a metadata is set automatically or can be specified if you need.


 


  // Load our document
  final File file = new File("template/tables.odt");
  final ODPackage pkg = new ODPackage(file);
  final ODMeta meta = pkg.getMeta();

  // Set some meta values
  meta.setTitle("jOpenDocument library sample");
  if (meta.getDescription().length() == 0) {
      meta.setDescription("A simple table");
  }

  // Get or create our meta if not exists
  ODUserDefinedMeta myMeta = meta.getUserMeta("Info 1"true);

  System.out.println("Old value: " + myMeta.getValue());
  System.out.println("Old type: " + myMeta.getValueType().getName());
        
  // set the value to Hello
  myMeta.setValue("Hello");

  System.out.println("New value: " + myMeta.getValue());
  System.out.println("New type: " + myMeta.getValueType().getName());   
      
  // Save the document
  pkg.saveAs(new File("template/meta_out.odt"));

Java2html