Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also obtain a copy of the License at http://odftoolkit.org/docs/license.txt Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 package org.odftoolkit.simple.meta;
 
 import java.util.Date;
 import java.util.List;
 
Meta represent the meta data feature in the ODF document.

It provides convenient method to get meta data info.

 
 public class Meta {
 
Constructor of Meta feature.

Parameters:
metaDom the file DOM element of meta.xml
 
 	public Meta(OdfFileDom metaDom) {
 		OfficeDocumentMetaElement metaEle = OdfElement.findFirstChildNode(OfficeDocumentMetaElement.classmetaDom);
 		 = OdfElement.findFirstChildNode(OfficeMetaElement.classmetaEle);
 	}

Get the instance of OfficeMetaElement which represents this feature.

Returns:
the instance of OfficeMetaElement
 
 	}

Receives the value of the odf dom element representation MetaGeneratorElement.

Returns:
the generator info of the current document.

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.MetaGeneratorElement.
 
 	public String getGenerator() {
 		MetaGeneratorElement metaGenerator = OdfElement.findFirstChildNode(
 		if (metaGenerator != null) {
 			return metaGenerator.getTextContent();
 		}
 		return null;
 
 	}

Sets the value of the odf dom element representation MetaGeneratorElement.

Parameters:
generator set the specified document generator.
See also:
org.odftoolkit.odfdom.dom.element.meta.MetaGeneratorElement.
	public void setGenerator(String generator) {
		MetaGeneratorElement metaGenerator = OdfElement.findFirstChildNode(
		if (metaGenerator == null) {
		}
		metaGenerator.setTextContent(generator);
	}

Receives the value of the odf dom element representation DcTitleElement.

Returns:
the title of the current document.

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.DcTitleElement.
	public String getTitle() {
		DcTitleElement titleEle = OdfElement.findFirstChildNode(
		if (titleEle != null) {
			return titleEle.getTextContent();
		}
		return null;
	}

Sets the value of the odf dom element representation DcTitleElement.

Parameters:
title set the specified document title
See also:
org.odftoolkit.odfdom.dom.element.meta.DcTitleElement.
	public void setTitle(String title) {
		DcTitleElement titleEle = OdfElement.findFirstChildNode(
		if (titleEle == null) {
		}
		titleEle.setTextContent(title);
	}

Receives the value of the odf dom element representation DcDescriptionElement.

Returns:
the description of the current document;

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.DcDescriptionElement.
	public String getDescription() {
		if (descEle != null) {
			return descEle.getTextContent();
		}
		return null;
	}

Sets the value of the odf dom element representation DcDescriptionElement.

Parameters:
description set the specified document description
See also:
org.odftoolkit.odfdom.dom.element.meta.DcDescriptionElement.
	public void setDescription(String description) {
		if (descEle == null) {
		}
		descEle.setTextContent(description);
	}

Receives the value of the odf dom element representation DcSubjectElement.

Returns:
the subject of the current document.

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.DcSubjectElement.
	public String getSubject() {
		DcSubjectElement subjectEle = OdfElement.findFirstChildNode(
		if (subjectEle != null) {
			return subjectEle.getTextContent();
		}
		return null;
	}

Sets the value of the odf dom element representation DcSubjectElement.

Parameters:
subject set the specified document subject.
See also:
org.odftoolkit.odfdom.dom.element.meta.DcSubjectElement.
	public void setSubject(String subject) {
		DcSubjectElement subjectEle = OdfElement.findFirstChildNode(
		if (subjectEle == null) {
		}
		subjectEle.setTextContent(subject);
	}

Receives the list value of the odf dom element representation MetaKeywordElement.

Returns:
the keywords of the current document.

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.MetaKeywordElement.
	public List<StringgetKeywords() {
		List<Stringkeywords = new ArrayList<String>();
		MetaKeywordElement keywordEle = OdfElement.findFirstChildNode(
		if (keywordEle != null) {
			keywords.add(keywordEle.getTextContent());
			MetaKeywordElement keywordNext;
			while ((keywordNext = OdfElement.findNextChildNode(
					MetaKeywordElement.classkeywordEle)) != null) {
				keywords.add(keywordNext.getTextContent());
				keywordEle = keywordNext;
			}
			return keywords;
else {
			return null;
		}
	}

Sets the list value of the odf dom element representation MetaKeywordElement.

Parameters:
keyList set the specified list of keywords.
See also:
org.odftoolkit.odfdom.dom.element.meta.MetaKeywordElement.
	public void setKeywords(List<StringkeyList) {
		MetaKeywordElement keywordEle = OdfElement.findFirstChildNode(
		if (keywordEle != null) {
			MetaKeywordElement keywordTmp;
			toBeDeleted.add(keywordEle);
			while ((keywordTmp = OdfElement.findNextChildNode(
					MetaKeywordElement.classkeywordEle)) != null) {
				keywordEle = keywordTmp;
				toBeDeleted.add(keywordTmp);
			}
		}
		// remove the original
		for (MetaKeywordElement keyele : toBeDeleted) {
		}
		// add new
		for (int i = 0; i < keyList.size(); i++) {
			keywordElement.setTextContent(keyList.get(i));
		}
	}

Add the keyword to the current document. Create child element MetaKeywordElement.

Parameters:
keyword the value of child element MetaKeywordElement.
See also:
org.odftoolkit.odfdom.dom.element.meta.MetaKeywordElement.
	public void addKeyword(String keyword) {
		keywordElement.setTextContent(keyword);
	}

Receives the list value of the odf dom element representation MetaUserDefinedElement.

Returns:
get the list of user-defined metadata names;

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.MetaUserDefinedElement.
		List<StringdefinedNames = new ArrayList<String>();
		MetaUserDefinedElement definedEle = OdfElement.findFirstChildNode(
		if (definedEle != null) {
			definedNames.add(definedEle.getMetaNameAttribute());
			while ((definedNext = OdfElement.findNextChildNode(
					MetaUserDefinedElement.classdefinedEle)) != null) {
				definedNames.add(definedNext.getMetaNameAttribute());
				definedEle = definedNext;
			}
			return definedNames;
else {
			return null;
		}
	}

Receives the odf dom element representation MetaUserDefinedElement by attribute name.

Parameters:
name the name of the user-defined metadata
Returns:
the MetaUserDefinedElement which is identified by the specified name;

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.MetaUserDefinedElement.
			String name) {
		MetaUserDefinedElement definedEle = OdfElement.findFirstChildNode(
		if (definedEle != null) {
			if (definedEle.getMetaNameAttribute().equals(name)) {
				return definedEle;
			}
			while ((definedNext = OdfElement.findNextChildNode(
					MetaUserDefinedElement.classdefinedEle)) != null) {
				if (definedNext.getMetaNameAttribute().equals(name)) {
					return definedNext;
				}
				definedEle = definedNext;
			}
			return null;
else {
			return null;
		}
	}

Receives the value of the odf dom element representation MetaUserDefinedElement by attribute name.

Parameters:
name the name of the user-defined metadata
Returns:
the value of the user-defined metadata with the specified name;

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.MetaUserDefinedElement.
		if (definedElement != null) {
			return definedElement.getTextContent();
		}
		return null;
	}

Receives the data type of the odf dom element representation MetaUserDefinedElement by attribute name.

Parameters:
name the name of the user-defined metadata
Returns:
the data type of the user-defined metadata with the specified name;

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.MetaUserDefinedElement.
		if (definedElement != null) {
			return definedElement.getMetaValueTypeAttribute();
		}
		return null;
	}

Remove the odf dom element representation MetaUserDefinedElement by attribute name.

Parameters:
name the name of the user-defined metadata
See also:
org.odftoolkit.odfdom.dom.element.meta.MetaUserDefinedElement.
	public void removeUserDefinedDataByName(String name) {
		if (definedElement != null) {
		}
	}

Sets the value of the odf dom element representation MetaUserDefinedElement by attribute name.

Parameters:
name the name need to set for the user-defined metadata
value the value need to set for the user-defined metadata
See also:
org.odftoolkit.odfdom.dom.element.meta.MetaUserDefinedElement.
	public void setUserDefinedDataValue(String nameString value) {
		if (definedElement != null) {
			definedElement.setTextContent(value);
		}
	}

Sets the data type of the odf dom element representation MetaUserDefinedElement by attribute name.

Parameters:
name the name need to set for the user-defined metadata
value the value need to set for the user-defined metadata
See also:
org.odftoolkit.odfdom.dom.element.meta.MetaUserDefinedElement.
	public void setUserDefinedDataType(String nameString value) {
		if (definedElement != null) {
			definedElement.setMetaValueTypeAttribute(value);
		}
	}

Sets the odf dom element representation MetaUserDefinedElement, if the element with the attribute name exists,then update;or create a new element if type or value is null,the original will not be updated.

Parameters:
name the name need to set for the user-defined metadata
type the data type need to set for the user-defined metadata
value the value need to set for the user-defined metadata
See also:
org.odftoolkit.odfdom.dom.element.meta.MetaUserDefinedElement.
	public void setUserDefinedData(String nameString typeString value) {
		// test if name exists
		// if exists, then update,if parameter is null, then don't change
		if (definedElement != null) {
			if (type != null) {
				definedElement.setMetaValueTypeAttribute(type);
			}
			if (value != null) {
				definedElement.setTextContent(value);
			}
else {
			// if not exists, add
					type);
			definedElement.setTextContent(value);
		}
	}

Receives the value of the odf dom element representation MetaInitialCreatorElement.

Returns:
get the initial creator of the current document;

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.MetaInitialCreatorElement.
		if (iniCreatorEle != null) {
			return iniCreatorEle.getTextContent();
		}
		return null;
	}

Sets the value of the odf dom element representation MetaInitialCreatorElement.

Parameters:
initialCreator set the specified initial creator
See also:
org.odftoolkit.odfdom.dom.element.meta.MetaInitialCreatorElement.
	public void setInitialCreator(String initialCreator) {
		if (iniCreatorEle == null) {
		}
		iniCreatorEle.setTextContent(initialCreator);
	}

Receives the value of the odf dom element representation DcCreatorElement.

Returns:
the creator of the current document;

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.DcCreatorElement.
	public String getCreator() {
		DcCreatorElement creatorEle = OdfElement.findFirstChildNode(
		if (creatorEle != null) {
			return creatorEle.getTextContent();
		}
		return null;
	}

Sets the value of the odf dom element representation DcCreatorElement.

Parameters:
creator set the specified creator
See also:
org.odftoolkit.odfdom.dom.element.meta.DcCreatorElement.
	public void setCreator(String creator) {
		DcCreatorElement creatorEle = OdfElement.findFirstChildNode(
		if (creatorEle == null) {
		}
		creatorEle.setTextContent(creator);
	}

Receives the value of the odf dom element representation MetaPrintedByElement

Returns:
the name of the last person who printed the current document;

null, if element is not set

See also:
org.odftoolkit.odfdom.dom.element.meta.MetaPrintedByElement.
	public String getPrintedBy() {
		MetaPrintedByElement printedByEle = OdfElement.findFirstChildNode(
		if (printedByEle != null) {
			return printedByEle.getTextContent();
		}
		return null;
	}

Sets the value of the odf dom element representation MetaPrintedByElement.

Parameters:
printedBy the name need to set for the last person who printed the current document
See also:
org.odftoolkit.odfdom.dom.element.meta.MetaPrintedByElement.
	public void setPrintedBy(String printedBy) {
		MetaPrintedByElement printedByEle = OdfElement.findFirstChildNode(
		if (printedByEle == null) {
		}
		printedByEle.setTextContent(printedBy);
	}

Receives the value of the odf dom element representation MetaCreationDateElement

Returns:
the date and time when the document was created initially;

null, if element is not set

See also:
org.odftoolkit.odfdom.dom.element.meta.MetaCreationDateElement.
		if (creationDateEle != null) {
			return stringToCalendar(creationDateEle.getTextContent());
		}
		return null;
	}

Sets the value of the odf dom element representation MetaCreationDateElement .

Parameters:
creationDate the date and time need to set
See also:
org.odftoolkit.odfdom.dom.element.meta.MetaCreationDateElement.
	public void setCreationDate(Calendar creationDate) {
		if (creationDateEle == null) {
		}
		creationDateEle.setTextContent(calendarToString(creationDate));
	}

Receives the value of the odf dom element representation DcDateElement.

Returns:
the date and time when the document was last modified;

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.DcDateElement.
	public Calendar getDcdate() {
		DcDateElement dcDateEle = OdfElement.findFirstChildNode(
		if (dcDateEle != null) {
			return stringToCalendar(dcDateEle.getTextContent());
		}
		return null;
	}

Sets the value of the odf dom element representation DcDateElement.

Parameters:
dcdate the date and time need to set
See also:
org.odftoolkit.odfdom.dom.element.meta.DcDateElement.
	public void setDcdate(Calendar dcdate) {
		DcDateElement dcDateEle = OdfElement.findFirstChildNode(
		if (dcDateEle == null) {
		}
		dcDateEle.setTextContent(calendarToString(dcdate));
	}

Receives the value of the odf dom element representation MetaPrintDateElement.

Returns:
the date and time when the document was last printed;

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.MetaPrintDateElement
	public Calendar getPrintDate() {
		MetaPrintDateElement printDateEle = OdfElement.findFirstChildNode(
		if (printDateEle != null) {
			return stringToCalendar(printDateEle.getTextContent());
		}
		return null;
	}

Sets the value of the odf dom element representation MetaPrintDateElement.

Parameters:
printDate the date and time need to set
See also:
org.odftoolkit.odfdom.dom.element.meta.MetaPrintDateElement
	public void setPrintDate(Calendar printDate) {
		MetaPrintDateElement printDateEle = OdfElement.findFirstChildNode(
		if (printDateEle == null) {
		}
		printDateEle.setTextContent(calendarToString(printDate));
	}

Receives the value of the odf dom element representation DcLanguageElement.

Returns:
the default language of the document;

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.DcLanguageElement
	public String getLanguage() {
		DcLanguageElement languageEle = OdfElement.findFirstChildNode(
		if (languageEle != null) {
			return languageEle.getTextContent();
		}
		return null;
	}

Sets the value of the odf dom element representation DcLanguageElement.

Parameters:
language the default language need to set fo the current document
See also:
org.odftoolkit.odfdom.dom.element.meta.DcLanguageElement
	public void setLanguage(String language) {
		DcLanguageElement languageEle = OdfElement.findFirstChildNode(
		if (languageEle == null) {
		}
		languageEle.setTextContent(language);
	}

Receives the value of the odf dom element representation MetaEditingCyclesElement .

Returns:
the number of times that the document has been edited;

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.MetaEditingCyclesElement
		if (editingCyclesEle != null) {
			return Integer.valueOf(editingCyclesEle.getTextContent());
		}
		return null;
	}

Sets the value of the odf dom element representation MetaEditingCyclesElement .

Parameters:
editingCycles set the specified edit times
See also:
org.odftoolkit.odfdom.dom.element.meta.MetaEditingCyclesElement
	public void setEditingCycles(Integer editingCycles) {
		if (editingCyclesEle == null) {
		}
		editingCyclesEle.setTextContent(String.valueOf(editingCycles));
	}

Receives the value of the odf dom element representation MetaEditingDurationElement.

Returns:
the total time spent editing the document;

null, if the element is not set.

See also:
org.odftoolkit.odfdom.dom.element.meta.MetaEditingDurationElement
		if (editiingDurationEle != null) {
			return Duration.valueOf(editiingDurationEle.getTextContent());
		}
		return null;
	}

Sets the value of the odf dom element representation MetaEditingDurationElement.

Parameters:
editingDuration the time need to set
See also:
org.odftoolkit.odfdom.dom.element.meta.MetaEditingDurationElement
	public void setEditingDuration(Duration editingDuration) {
		if (editiingDurationEle == null) {
		}
		editiingDurationEle.setTextContent(editingDuration.toString());
	}

Receives the sub feature of DocumentStatistic.

Returns:
the statistics about the document which can be represented by DocumentStatistic feature;

null, if the feature is not exist.

See also:
org.odftoolkit.odfdom.dom.element.meta.DocumentStatistic
		if (element != null) {
			return new DocumentStatistic(element);
else {
			return null;
		}
	}
		return OdfElement.findFirstChildNode(
	}

Change valid string of calendar to Calendar type.

Parameters:
baseDate the string of a calender
Returns:
the object of Calender
	private Calendar stringToCalendar(String baseDate) {
		// Calendar calendar=new GregorianCalendar();
		Calendar calendar = Calendar.getInstance();
		Date d1 = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
		try {
			d1 = sdf.parse(baseDate);
catch (Exception e) {
			// invalid format or null value in meta.xml
			// d1=new Date();
		}
		calendar.setTime(d1);
		return calendar;
	}

Convert a Canlender object to String object.

Parameters:
calendar an instanceof Canlender
Returns:
the String format(yyyy-MM-dd'T'HH:mm:ss) of Calendar.
	private String calendarToString(Calendar calendar) {
		return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(calendar.getTime());
	}
New to GrepCode? Check out our FAQ X