Documents > Cookbook >Manipulate Metadata

This Meta API supports to access and set document metadata. It covers the metadata definitions in ODF Specification 1.2 Committee Draft05

Get Meta object
First you load an ODF text document(for example),then get the meta file DOM and then use the meta DOM to create an instance of the Meta. Use Meta you can access all the supported elements.

    TextDocument doc = (TextDocument) TextDocument.loadDocument("testtable.odt");
OdfFileDom metadom = doc.getMetaDom();
Meta metadata = new Meta(metadom);

Access metadata
After creating the Meta instance,you can use it to manipulate the metadata: for example, you can set a value for the <meta:generator> like this:

    metadata.setGenerator("$Win32 OpenOffice.org_project/300m15$Build-9379");

The <meta:keyword> may contain many keywords, you can set the whole list of keywords and add one keyword as you want. the api currently do not provide the direct method for deleting one keyword ,you can get the keyword list first,and then delete the keyword,finally set the list to the element.

List<String> keywords=metadata.getKeywords();

Access the user defined element
To manipulate the user defined data,you should get the list of their names,and then use the names to update the data or its datatype or delete the whole user defined data. you can use the setUserDefinedData(String name, String type, String value) method to update data,if the name not exists in the document,the method will add the new user defined data.

      List<String> names=metadata.getUserDefinedDataNames();
for (String name : names) {
String key="newId";
//org.odftoolkit.odfdom.dom.attribute.meta.MetaValueTypeAttribute.Value metadata.setUserDefinedData(key, Value.STRING.toString(), "new001");
//update the datatype metadata.setUserDefinedDataType(key, Value.BOOLEAN.toString());
//update the data value metadata.setUserDefinedDataValue(key, "false");

//get the datatype String dataType=metadata.getUserDefinedDataType(key);
//get the data value String dataValue=metadata.getUserDefinedDataValue(key);

Access the document statistics
if you want to access the document statistics,you should get a DocumentStatistic instance, if the return is null,it means that this ODF document doesn't have any document statistic information,you should create a document statistics object.

    DocumentStatistic stat = metadata.getDocumentStatistic();
if(stat==null) {
stat=new DocumentStatistic(metadata.getOfficeMetaElement().newMetaDocumentStatisticElement());

Integer cellCount=stat.getCellCount();

Powered by the Apache CMS.

Apache "ODF Toolkit" is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.

Copyright © 2011 The Apache Software Foundation Licensed under the Apache License, Version 2.0. Contact Us
Apache and the Apache feather logos are trademarks of The Apache Software Foundation.
Other names appearing on the site may be trademarks of their respective owners.