package org.apache.fop.fo;
// Java
-import java.util.Iterator;
import java.util.ListIterator;
import java.util.Map;
import java.util.Stack;
* has been reached.
* The default implementation simply calls {@link #finalizeNode()}, without
* sending any event to the {@link FOEventHandler}.
- * <br/><i>Note: the recommended way to override this method in subclasses is</i>
- * <br/><br/><code>super.endOfNode(); // invoke finalizeNode()
- * <br/>getFOEventHandler().endXXX(); // send endOfNode() notification</code>
+ * <p><i>Note: the recommended way to override this method in subclasses is</i></p>
+ * <p><code>super.endOfNode(); // invoke finalizeNode()</code></p>
+ * <p><code>getFOEventHandler().endXXX(); // send endOfNode() notification</code></p>
*
* @throws FOPException if there's a problem during processing
*/
*
* @param propertyName the name of the property.
* @param propertyValue the value of the property.
- * * @param e optional property parsing exception.
+ * @param e optional property parsing exception.
* @throws ValidationException the validation error provoked by the method call
*/
protected void invalidPropertyValueError(String propertyName, String propertyValue, Exception e)
* @param ranges a stack of delimited text ranges
* @return the (possibly) updated stack of delimited text ranges
*/
- public Stack collectDelimitedTextRanges(Stack<DelimitedTextRange> ranges) {
+ public Stack<DelimitedTextRange> collectDelimitedTextRanges(Stack<DelimitedTextRange> ranges) {
// if boundary before, then push new range
if (isRangeBoundaryBefore()) {
maybeNewRange(ranges);
* @param currentRange the current range or null (if none)
* @return the (possibly) updated stack of delimited text ranges
*/
- protected Stack collectDelimitedTextRanges(Stack<DelimitedTextRange> ranges, DelimitedTextRange currentRange) {
- for (Iterator it = getChildNodes(); (it != null) && it.hasNext();) {
- ranges = ((FONode) it.next()).collectDelimitedTextRanges(ranges);
+ protected Stack<DelimitedTextRange> collectDelimitedTextRanges(
+ Stack<DelimitedTextRange> ranges, DelimitedTextRange currentRange) {
+
+ for (FONodeIterator it = getChildNodes(); (it != null) && it.hasNext();) {
+ ranges = it.next().collectDelimitedTextRanges(ranges);
}
return ranges;
}
}
/**
- * Base iterator interface over a FO's children
+ * Base iterator interface over a FO's children, offering three methods on top of the base interface
+ * methods {@see java.util.ListIterator}.
*/
- public interface FONodeIterator extends ListIterator {
+ public interface FONodeIterator extends ListIterator<FONode> {
/**
* Returns the parent node for this iterator's list
*
* @return the parent node
*/
- FObj parentNode();
-
- /**
- * Convenience method with return type of FONode
- * (semantically equivalent to: <code>(FONode) next();</code>)
- *
- * @return the next node (if any), as a type FONode
- */
- FONode nextNode();
-
- /**
- * Convenience method with return type of FONode
- * (semantically equivalent to: <code>(FONode) previous();</code>)
- *
- * @return the previous node (if any), as a type FONode
- */
- FONode previousNode();
+ FObj parent();
/**
* Returns the first node in the list, and decreases the index,
*
* @return the first node in the list
*/
- FONode firstNode();
+ FONode first();
/**
* Returns the last node in the list, and advances the
*
* @return the last node in the list
*/
- FONode lastNode();
+ FONode last();
}
*/
private void checkId(String id) throws ValidationException {
if (!inMarker() && !id.equals("")) {
- Set idrefs = getBuilderContext().getIDReferences();
+ Set<String> idrefs = getBuilderContext().getIDReferences();
if (!idrefs.contains(id)) {
idrefs.add(id);
} else {
if (firstChild != null) {
firstChild.siblings[0] = null;
}
- } else {
+ } else if (child.siblings != null) {
FONode prevChild = child.siblings[0];
prevChild.siblings[1] = nextChild;
if (nextChild != null) {
return it;
} else {
while (it.hasNext()
- && it.nextNode().siblings[1] != childNode) {
+ && it.next().siblings[1] != childNode) {
//nop
}
if (it.hasNext()) {
String mcname = marker.getMarkerClassName();
if (firstChild != null) {
// check for empty childNodes
- for (Iterator iter = getChildNodes(); iter.hasNext();) {
- FONode node = (FONode) iter.next();
+ for (Iterator<FONode> iter = getChildNodes(); iter.hasNext();) {
+ FONode node = iter.next();
if (node instanceof FObj
|| (node instanceof FOText
&& ((FOText) node).willCreateArea())) {
/** {@inheritDoc} */
protected String getContextInfoAlt() {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
if (getLocalName() != null) {
sb.append(getName());
sb.append(", ");
if (iter == null) {
return null;
}
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
while (iter.hasNext()) {
FONode node = (FONode) iter.next();
String s = node.gatherContextInfo();
/**
* Convenience method for validity checking. Checks if the
* incoming node is a member of the "%block;" parameter entity
- * as defined in Sect. 6.2 of the XSL 1.0 & 1.1 Recommendations
+ * as defined in Sect. 6.2 of the XSL 1.0 & 1.1 Recommendations
*
* @param nsURI namespace URI of incoming node
* @param lName local name (i.e., no prefix) of incoming node
/**
* Convenience method for validity checking. Checks if the
* incoming node is a member of the "%inline;" parameter entity
- * as defined in Sect. 6.2 of the XSL 1.0 & 1.1 Recommendations
+ * as defined in Sect. 6.2 of the XSL 1.0 & 1.1 Recommendations
*
* @param nsURI namespace URI of incoming node
* @param lName local name (i.e., no prefix) of incoming node
/**
* Convenience method for validity checking. Checks if the
* incoming node is a member of the neutral item list
- * as defined in Sect. 6.2 of the XSL 1.0 & 1.1 Recommendations
+ * as defined in Sect. 6.2 of the XSL 1.0 & 1.1 Recommendations
* @param nsURI namespace URI of incoming node
* @param lName local name (i.e., no prefix) of incoming node
* @return true if a member, false if not
* @param bidiLevel a non-negative bidi embedding level
*/
public void setBidiLevel(int bidiLevel) {
+
assert bidiLevel >= 0;
- if (bidiLevel >= 0) {
- if ((this.bidiLevel < 0) || (bidiLevel < this.bidiLevel)) {
- this.bidiLevel = bidiLevel;
- if ((parent != null) && !isBidiPropagationBoundary()) {
- FObj foParent = (FObj) parent;
- int parentBidiLevel = foParent.getBidiLevel();
- if ((parentBidiLevel < 0) || (bidiLevel < parentBidiLevel)) {
- foParent.setBidiLevel(bidiLevel);
- }
+
+ if ((this.bidiLevel < 0) || (bidiLevel < this.bidiLevel)) {
+ this.bidiLevel = bidiLevel;
+ if ((parent != null) && !isBidiPropagationBoundary()) {
+ FObj foParent = (FObj) parent;
+ int parentBidiLevel = foParent.getBidiLevel();
+ if ((parentBidiLevel < 0) || (bidiLevel < parentBidiLevel)) {
+ foParent.setBidiLevel(bidiLevel);
}
}
}
}
/** {@inheritDoc} */
- public FObj parentNode() {
+ public FObj parent() {
return parentNode;
}
/** {@inheritDoc} */
- public Object next() {
+ public FONode next() {
if (currentNode != null) {
if (currentIndex != 0) {
if (currentNode.siblings != null
}
/** {@inheritDoc} */
- public Object previous() {
+ public FONode previous() {
if (currentNode.siblings != null
&& currentNode.siblings[0] != null) {
currentIndex--;
}
/** {@inheritDoc} */
- public void set(Object o) {
+ public void set(FONode newNode) {
if ((flags & F_SET_ALLOWED) == F_SET_ALLOWED) {
- FONode newNode = (FONode) o;
if (currentNode == parentNode.firstChild) {
parentNode.firstChild = newNode;
} else {
}
/** {@inheritDoc} */
- public void add(Object o) {
- FONode newNode = (FONode) o;
+ public void add(FONode newNode) {
if (currentIndex == -1) {
if (currentNode != null) {
FONode.attachSiblings(newNode, currentNode);
} else {
if (currentNode.siblings != null
&& currentNode.siblings[1] != null) {
- FONode.attachSiblings((FONode) o, currentNode.siblings[1]);
+ FONode.attachSiblings(newNode, currentNode.siblings[1]);
}
- FONode.attachSiblings(currentNode, (FONode) o);
+ FONode.attachSiblings(currentNode, newNode);
if (currentNode == parentNode.lastChild) {
parentNode.lastChild = newNode;
}
}
/** {@inheritDoc} */
- public FONode lastNode() {
+ public FONode last() {
while (currentNode != null
&& currentNode.siblings != null
&& currentNode.siblings[1] != null) {
}
/** {@inheritDoc} */
- public FONode firstNode() {
+ public FONode first() {
currentNode = parentNode.firstChild;
currentIndex = 0;
return currentNode;
}
-
- /** {@inheritDoc} */
- public FONode nextNode() {
- return (FONode) next();
- }
-
- /** {@inheritDoc} */
- public FONode previousNode() {
- return (FONode) previous();
- }
}
}