Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER Copyright 2011 IBM. 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.common.field;
 
A ReferenceField refers to a field that appears in another location in a document.

The advantage of entering a reference as a field is that you do not have to adjust the references manually every time you change the document. Just update the fields and the references in the document are updated too.

NOTE: Before the document is opened in any editor, the value of this field maybe invalid.

Since:
0.5
 
 public class ReferenceField extends Field {
 
 	private String name;
A DisplayType specifies the information that a reference field should display.
  • CHAPTER: displays the number of the chapter in which the referenced item appears.
  • DIRECTION: displays whether the referenced item is above or below the reference field.
  • PAGE: displays the number of the page on which the referenced item appears.
  • TEXT: displays the text of the referenced item.

Since:
0.5
 
 	public static enum DisplayType {
 
 		CHAPTER("chapter"), DIRECTION("direction"), PAGE("page"), TEXT("text");
 
 		private final String displayType;
 
 		DisplayType(String type) {
 			 = type;
 		}
 
 		public String toString() {
 			return ;
 		}
 	}
 
 	// package constructor, only called by Fields
 	ReferenceField(OdfElement odfElementString referenceName) {
 		OdfElement parentEle = (OdfElementodfElement.getParentNode();
 		if (parentEle instanceof TextAElement || parentEle instanceof TextHElement
 				|| parentEle instanceof TextMetaElement || parentEle instanceof TextMetaFieldElement
 				|| parentEle instanceof TextPElement || parentEle instanceof TextSpanElement) {
 			 = odfElement;
 			 = referenceName;
 			// insert start target element
			parentEle.insertBefore(odfElement);
			// insert end target element
			OdfElement nextSiblingEle = (OdfElementodfElement.getNextSibling();
			if (nextSiblingEle == null) {
else {
				parentEle.insertBefore(nextSiblingEle);
			}
else {
			throw new IllegalArgumentException("The specific odf element can't own a reference field.");
		}
	}

Set the name of this reference field.

Parameters:
referenceName the name of this content.
	public void setName(String referenceName) {
		 = referenceName;
	}

Get the name of this reference field.

Returns:
the name of this reference field.
	public String getName() {
	}

Append this reference field after the specifics OdfElement.

Parameters:
odfEle the reference of odf element.
type the display type.
	public void appendReferenceTo(OdfElement odfEleDisplayType type) {
		// create reference ref element.
		TextReferenceRefElement referenceRefElement = spanElement.newTextReferenceRefElement();
		referenceRefElement.setTextRefNameAttribute();
		referenceRefElement.setTextReferenceFormatAttribute(type.toString());
		// insert
		if (odfEle instanceof TextPElement) {
			odfEle.appendChild(spanElement);
else {
			OdfElement parentEle = (OdfElementodfEle.getParentNode();
			Node nextSiblingEle =  odfEle.getNextSibling();
			pElement.appendChild(spanElement);
			if (nextSiblingEle == null) {
				parentEle.appendChild(pElement);
else {
				parentEle.insertBefore(pElementnextSiblingEle);
			}
		}
	}
	}
	public FieldType getFieldType() {
	}
New to GrepCode? Check out our FAQ X