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.text.list;
 
 
ListItem represents an item in a list. ListItem can have text content or sub List.

Since:
0.4
 
 public class ListItem implements ListContainer {
 
 	// <text:list-item>
Constructor with list item element only.

Parameters:
element the list item odf element
 
 		this(elementnull);
 	}

Constructor with item content set

Parameters:
element the list item odf element
content item text content
 
 	ListItem(TextListItemElement elementString content) {
 		 = element;
 		setTextContent(content);
 	}

Get the instance of TextListItemElement which represents this list item.

Returns:
the instance of TextListItemElement
 
 		return ;
 	}

Get item text content. If this item has a List, its content is not included.

Returns:
the text content of this item
 
 	public String getTextContent() {
 		while (child != null) {
 			if (child instanceof TextPElement) {
 				return child.getTextContent();
 			}
 			child = child.getNextSibling();
 		}
 		return null;
 	}

Set item text content.

Parameters:
content item text content.
	public void setTextContent(String content) {
		if (content != null) {
			Node positionNode = null;
			TextPElement pElement = null;
			while (child != null) {
				if (child instanceof TextNumberElement) {
					positionNode = child.getNextSibling();
					child = child.getNextSibling();
else if ((child instanceof TextPElement) && (pElement == null)) {
					pElement = (TextPElementchild;
					child = child.getNextSibling();
else if ((child instanceof TextListElement) && (positionNode == null)) {
					positionNode = child;
					child = child.getNextSibling();
else {
					Node tmp = child;
					child = child.getNextSibling();
				}
			}
			if (pElement == null) {
				if (positionNode == null) {
else {
					.insertBefore(pElementpositionNode);
				}
			}
			pElement.setTextContent(content);
			if ( != null) {
else {
				// paragraphDecorator is null when the owner List is constructed
				// by List(TextListElement).
				Node previousSibling = .getPreviousSibling();
				String pElementStyleName = null;
				while (previousSibling != null) {
					if (previousSibling instanceof TextListItemElement) {
						Node previousChild = previousSibling.getFirstChild();
						while (previousChild != null) {
							if (previousChild instanceof TextPElement) {
								TextPElement previousPElement = (TextPElementpreviousChild;
								pElementStyleName = previousPElement.getTextStyleNameAttribute();
								break;
							}
							previousChild = previousChild.getNextSibling();
						}
						break;
					}
					previousSibling = previousSibling.getPreviousSibling();
				}
				if (pElementStyleName != null) {
					pElement.setTextStyleNameAttribute(pElementStyleName);
				}
			}
		}
	}

Remove this item from its owner list.
	public void remove() {
		Node parentElement = .getParentNode();
		Document doc = (DocumentownerDocument.getDocument();
	}

Get the start number of this item.

A value can be specified that restarts numbering of a list at the current item. This feature can only be applied to items in a list with a numbering list style.

Returns:
the start number of this item. If there is no start number setting on this item or the owner list is not a numbering list, null will be returned.
	public Integer getStartNumber() {
		}
		return null;
	}

Set the start number of this item.

A value can be specified that restarts numbering of a list at the current item. This feature can only be applied to items in a list with a numbering list style.

Parameters:
number the start number to be set.
Throws:
java.lang.IllegalArgumentException if number < 0.
	public void setStartNumber(Integer number) {
		if (number < 0) {
			throw new IllegalArgumentException("start number should be a non-negative integer.");
		}
		}
	}

Get the number format of this item.

List item can contain the text of a formatted number which is present when a list style is applied to an element whose corresponding list level style specifies that the list label is a number. This text may be used by consumers that do not support the automatic generation of numbering but should be ignored by consumers that do support it.

	public String getNumberFormat() {
		String format = null;
			if ((child != null) && (child instanceof TextNumberElement)) {
				format = ((TextNumberElementchild).getTextContent();
			}
		}
		return format;
	}

Set the number format of this item.

List item can contain the text of a formatted number which is present when a list style is applied to an element whose corresponding list level style specifies that the list label is a number. This text may be used by consumers that do not support the automatic generation of numbering but should be ignored by consumers that do support it.

Parameters:
format the number format to be set.
	public void setNumberFormat(String format) {
			TextNumberElement textNumberElement = null;
			if (child == null) {
				textNumberElement = .newTextNumberElement();
else {
				if (child instanceof TextNumberElement) {
					textNumberElement = (TextNumberElementchild;
else {
					textNumberElement = ((OdfFileDom.getOwnerDocument())
					.insertBefore(textNumberElementchild);
				}
			}
			textNumberElement.setTextContent(format);
		}
	}

Answers the index of the item in its owner list.

Returns:
index of the item.
	public int getIndex() {
		int i = 0;
		while (firstNode != null) {
			if (firstNode instanceof TextListItemElement) {
				if (firstNode == ) {
					break;
else {
					i++;
				}
			}
			firstNode = firstNode.getNextSibling();
		}
		return i;
	}

Get the List which contains this ListItem.
	public List getOwnerList() {
		if (parent instanceof TextListElement) {
			return new List((TextListElementparent);
		}
		return null;
	}
	public String toString() {
		StringBuilder strBuilder = new StringBuilder();
		String numberFormat = getNumberFormat();
		String splitStr = "";
		if (numberFormat != null) {
			strBuilder.append(numberFormat);
			strBuilder.append(" ");
			splitStr = "\n";
		}
		String textContent = getTextContent();
		if (textContent != null) {
			strBuilder.append(textContent);
			splitStr = "\n";
		}
		while (lists.hasNext()) {
			strBuilder.append(splitStr);
			strBuilder.append(lists.next().toString());
		}
		return strBuilder.toString();
	}
	}
	public List addList() {
	}
	public List addList(ListDecorator decorator) {
		return .addList(decorator);
	}
	public void clearList() {
	}
	}
	public boolean removeList(List list) {
	}
	private class ListContainerImpl extends AbstractListContainer {
		}
	}
	// set ListDecorator for decorating item, only used by List.
		 = decorator;
	}
New to GrepCode? Check out our FAQ X