diff options
author | Glen Mazza <gmazza@apache.org> | 2004-08-18 03:26:37 +0000 |
---|---|---|
committer | Glen Mazza <gmazza@apache.org> | 2004-08-18 03:26:37 +0000 |
commit | 74ca9b8223ae7f3168ffc75f3b85c1b692af09b4 (patch) | |
tree | 12d220c455ed3d8a6585c418c3de98e8771f3e01 /src/java/org/apache/fop | |
parent | 98a82065accd4dfb081daa8429f03f0fed993dff (diff) | |
download | xmlgraphics-fop-74ca9b8223ae7f3168ffc75f3b85c1b692af09b4.tar.gz xmlgraphics-fop-74ca9b8223ae7f3168ffc75f3b85c1b692af09b4.zip |
1. Moved getNameId() from FObj to FONode.
2. Centralized determination of generatesInlineAreas() from multiple FObj subclasses into fo.PropertySets BitSet object.
3. validateChildNode() implemented for fo:list-item.
4. fo:initial-property-set now extending FObj instead of ToBeImplementedElement; burden of implementation on individual FOInputHandler subclasses.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197882 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop')
18 files changed, 122 insertions, 158 deletions
diff --git a/src/java/org/apache/fop/fo/Constants.java b/src/java/org/apache/fop/fo/Constants.java index 3c8638c16..584c84e34 100644 --- a/src/java/org/apache/fop/fo/Constants.java +++ b/src/java/org/apache/fop/fo/Constants.java @@ -56,7 +56,7 @@ public interface Constants { int RENDER_RTF = 10; // element constants - int FO_UNKNOWN = 0; // FObj base class + int FO_UNKNOWN_NODE = 0; // FObj base class int FO_BASIC_LINK = 1; int FO_BIDI_OVERRIDE = 2; int FO_BLOCK = 3; diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index 73204f27d..000539700 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -112,14 +112,23 @@ public abstract class FONode { } /** - * Returns the name of the object - * @return the name of this object + * Returns the name of the node + * @return the name of this node */ public String getName() { return null; } /** + * Returns the Constants class integer value of this node + * @return the integer enumeration of this FO (e.g., FO_ROOT) + * if a formatting object, FO_UNKNOWN_NODE otherwise + */ + public int getNameId() { + return Constants.FO_UNKNOWN_NODE; + } + + /** * Checks to make sure, during SAX processing of input document, that the * incoming node is valid for the this (parent) node (e.g., checking to * see that fo:table is not an immediate child of fo:root) diff --git a/src/java/org/apache/fop/fo/FOText.java b/src/java/org/apache/fop/fo/FOText.java index 70a7db4f8..5966928a2 100644 --- a/src/java/org/apache/fop/fo/FOText.java +++ b/src/java/org/apache/fop/fo/FOText.java @@ -488,6 +488,10 @@ public class FOText extends FObj { } + /** + * @todo rename somehow, there isn't an fo:text. + * @todo see if should still be a subclass of FObj + */ public String getName() { return "fo:text"; } diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java index f0e6f7461..cbff2af55 100644 --- a/src/java/org/apache/fop/fo/FObj.java +++ b/src/java/org/apache/fop/fo/FObj.java @@ -192,8 +192,8 @@ public class FObj extends FONode implements Constants { */ protected void addChildNode(FONode child) { if (PropertySets.canHaveMarkers(getNameId()) && - "fo:marker".equals(child.getName())) { - addMarker((Marker) child); + child.getNameId() == FO_MARKER) { + addMarker((Marker) child); } else { if (childNodes == null) { childNodes = new ArrayList(); @@ -333,15 +333,6 @@ public class FObj extends FONode implements Constants { } /** - * Check if this formatting object generates inline areas. - * - * @return true if generates inline areas - */ - public boolean generatesInlineAreas() { - return true; - } - - /** * Set writing mode for this FO. * Use that from the nearest ancestor, including self, which generates * reference areas, or from root FO if no ancestor found. @@ -386,7 +377,7 @@ public class FObj extends FONode implements Constants { * the first child. * @param marker Marker to add. */ - public void addMarker(Marker marker) { + protected void addMarker(Marker marker) { String mcname = marker.getMarkerClassName(); if (childNodes != null) { // check for empty childNodes @@ -541,21 +532,5 @@ public class FObj extends FONode implements Constants { } return -1; } - - /** - * Returns the name of this FO (e.g., "fo:root"); - * @return the name of the FO - */ - public String getName() { - return null; - } - - /** - * Returns the Constants class integer value of this formatting object - * @return the integer enumeration of this FO (e.g., FO_ROOT) - */ - public int getNameId() { - return FO_UNKNOWN; - } } diff --git a/src/java/org/apache/fop/fo/PropertyManager.java b/src/java/org/apache/fop/fo/PropertyManager.java index e241c3142..c3ab86847 100644 --- a/src/java/org/apache/fop/fo/PropertyManager.java +++ b/src/java/org/apache/fop/fo/PropertyManager.java @@ -19,7 +19,6 @@ package org.apache.fop.fo; // FOP -import org.apache.fop.apps.FOPException; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; import org.apache.fop.fo.properties.Property; diff --git a/src/java/org/apache/fop/fo/PropertySets.java b/src/java/org/apache/fop/fo/PropertySets.java index 0bb9f56f7..ebb340991 100644 --- a/src/java/org/apache/fop/fo/PropertySets.java +++ b/src/java/org/apache/fop/fo/PropertySets.java @@ -27,6 +27,7 @@ public class PropertySets { private static short[][] mapping = null; private static BitSet can_have_markers = null; private static BitSet can_have_id = null; + private static BitSet no_inline_areas = null; private Element[] elements = new Element[Constants.ELEMENT_COUNT+1]; private BitSet block_elems = new BitSet(); @@ -1086,6 +1087,30 @@ public class PropertySets { } /** + * Determines if the FO generates inline areas. Used only within flow.Block + * for whitespace handling + * @param elementId Constants enumeration ID of the FO (e.g., FO_ROOT) + * @return true if id property is applicable, false otherwise + * @todo see if more values need to be entered here (copied values over + * from legacy code, list of FO's below probably incomplete) + * @todo see if still needed (LM has a similar generatesInlineAreas() + * method) + */ + public static boolean generatesInlineAreas(int elementId) { + if (no_inline_areas == null) { + no_inline_areas = new BitSet(); + no_inline_areas.set(Constants.FO_UNKNOWN_NODE); + no_inline_areas.set(Constants.FO_BLOCK); + no_inline_areas.set(Constants.FO_BLOCK_CONTAINER); + no_inline_areas.set(Constants.FO_LIST_BLOCK); + no_inline_areas.set(Constants.FO_LIST_ITEM); + no_inline_areas.set(Constants.FO_TABLE); + no_inline_areas.set(Constants.FO_TABLE_AND_CAPTION); + } + return !(no_inline_areas.get(elementId)); + } + + /** * An object that represent the properties and contents of a fo element */ class Element { diff --git a/src/java/org/apache/fop/fo/flow/Block.java b/src/java/org/apache/fop/fo/flow/Block.java index 537a0f553..254864f6f 100644 --- a/src/java/org/apache/fop/fo/flow/Block.java +++ b/src/java/org/apache/fop/fo/flow/Block.java @@ -32,6 +32,7 @@ import org.apache.fop.fo.CharIterator; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; import org.apache.fop.fo.FObjMixed; +import org.apache.fop.fo.PropertySets; import org.apache.fop.fo.RecursiveCharIterator; import org.apache.fop.layoutmgr.BlockLayoutManager; import org.apache.fop.fo.Constants; @@ -91,6 +92,7 @@ public class Block extends FObjMixed { /** * @param parent FONode that is the parent of this object + * */ public Block(FONode parent) { super(parent); @@ -176,24 +178,18 @@ public class Block extends FObjMixed { } /** - * @return false (Block cannot generate inline areas) - */ - public boolean generatesInlineAreas() { - return false; - } - - /** * @see org.apache.fop.fo.FONode#addChildNode(FONode) */ public void addChildNode(FONode child) { // Handle whitespace based on values of properties // Handle a sequence of inline-producing child nodes in // one pass - if (child instanceof FObj && ((FObj) child).generatesInlineAreas()) { - if (firstInlineChild == null) { - firstInlineChild = child; - } - // lastInlineChild = childNodes.size(); + if (child instanceof FObj && ("fo:text".equals(child.getName()) + || PropertySets.generatesInlineAreas(child.getNameId()))) { + if (firstInlineChild == null) { + firstInlineChild = child; + } + // lastInlineChild = childNodes.size(); } else { // Handle whitespace in preceeding inline areas if any handleWhiteSpace(); diff --git a/src/java/org/apache/fop/fo/flow/BlockContainer.java b/src/java/org/apache/fop/fo/flow/BlockContainer.java index 2f2813db5..91214ad1b 100644 --- a/src/java/org/apache/fop/fo/flow/BlockContainer.java +++ b/src/java/org/apache/fop/fo/flow/BlockContainer.java @@ -76,13 +76,6 @@ public class BlockContainer extends FObj { } /** - * @return false (BlockContainer cannot generate inline areas) - */ - public boolean generatesInlineAreas() { - return false; - } - - /** * @return the span for this object */ public int getSpan() { @@ -98,6 +91,9 @@ public class BlockContainer extends FObj { list.add(blm); } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:block-container"; } diff --git a/src/java/org/apache/fop/fo/flow/ExternalGraphic.java b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java index 99bb8bedb..fd449e946 100644 --- a/src/java/org/apache/fop/fo/flow/ExternalGraphic.java +++ b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java @@ -59,6 +59,7 @@ public class ExternalGraphic extends FObj { /** * @see org.apache.fop.fo.FObj#addProperties + * @todo switch method from image() to startImage()? */ protected void addProperties(Attributes attlist) throws SAXParseException { super.addProperties(attlist); diff --git a/src/java/org/apache/fop/fo/flow/InitialPropertySet.java b/src/java/org/apache/fop/fo/flow/InitialPropertySet.java index 982d1b434..a3b39e0bb 100644 --- a/src/java/org/apache/fop/fo/flow/InitialPropertySet.java +++ b/src/java/org/apache/fop/fo/flow/InitialPropertySet.java @@ -14,7 +14,7 @@ * limitations under the License. */ -/* $Id$ */ +/* $Id:$ */ package org.apache.fop.fo.flow; @@ -25,13 +25,12 @@ import org.xml.sax.SAXParseException; // FOP import org.apache.fop.fo.FONode; -import org.apache.fop.fo.ToBeImplementedElement; +import org.apache.fop.fo.FObj; /** - * Class modelling the fo:initial-property-set object. See Sec. 6.6.4 of the - * XSL-FO Standard. + * Class modelling the fo:initial-property-set object. */ -public class InitialPropertySet extends ToBeImplementedElement { +public class InitialPropertySet extends FObj { /** * @param parent FONode that is the parent of this object @@ -49,6 +48,9 @@ public class InitialPropertySet extends ToBeImplementedElement { invalidChildError(loc, nsURI, localName); } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:initial-property-set"; } diff --git a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java index 8bd5a5f49..0da8d71ff 100644 --- a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java +++ b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -114,15 +114,6 @@ public class InstreamForeignObject extends FObj { } /** - * This flow object generates inline areas. - * @see org.apache.fop.fo.FObj#generatesInlineAreas() - * @return true - */ - public boolean generatesInlineAreas() { - return true; - } - - /** * @see org.apache.fop.fo.FObj#addLayoutManager(List) */ public void addLayoutManager(List list) { diff --git a/src/java/org/apache/fop/fo/flow/ListBlock.java b/src/java/org/apache/fop/fo/flow/ListBlock.java index 86d6b70e8..244095c25 100644 --- a/src/java/org/apache/fop/fo/flow/ListBlock.java +++ b/src/java/org/apache/fop/fo/flow/ListBlock.java @@ -38,18 +38,6 @@ import org.apache.fop.layoutmgr.list.ListBlockLayoutManager; */ public class ListBlock extends FObj { - private int align; - private int alignLast; - private int breakBefore; - private int breakAfter; - private int lineHeight; - private int startIndent; - private int endIndent; - private int spaceBefore; - private int spaceAfter; - private int spaceBetweenListRows = 0; - private ColorType backgroundColor; - // used for child node validation private boolean hasListItem = false; @@ -65,22 +53,6 @@ public class ListBlock extends FObj { */ protected void addProperties(Attributes attlist) throws SAXParseException { super.addProperties(attlist); - - this.align = this.propertyList.get(PR_TEXT_ALIGN).getEnum(); - this.alignLast = this.propertyList.get(PR_TEXT_ALIGN_LAST).getEnum(); - this.lineHeight = - this.propertyList.get(PR_LINE_HEIGHT).getLength().getValue(); - this.startIndent = - this.propertyList.get(PR_START_INDENT).getLength().getValue(); - this.endIndent = - this.propertyList.get(PR_END_INDENT).getLength().getValue(); - this.spaceBefore = - this.propertyList.get(PR_SPACE_BEFORE | CP_OPTIMUM).getLength().getValue(); - this.spaceAfter = - this.propertyList.get(PR_SPACE_AFTER | CP_OPTIMUM).getLength().getValue(); - this.spaceBetweenListRows = 0; // not used at present - this.backgroundColor = - this.propertyList.get(PR_BACKGROUND_COLOR).getColorType(); getFOInputHandler().startList(this); } @@ -114,13 +86,6 @@ public class ListBlock extends FObj { } /** - * @return false (ListBlock does not generate inline areas) - */ - public boolean generatesInlineAreas() { - return false; - } - - /** * @see org.apache.fop.fo.FObj#addLayoutManager(List) */ public void addLayoutManager(List list) { @@ -128,6 +93,9 @@ public class ListBlock extends FObj { list.add(lm); } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:list-block"; } diff --git a/src/java/org/apache/fop/fo/flow/ListItem.java b/src/java/org/apache/fop/fo/flow/ListItem.java index 49aaf4fe2..7fd8170b2 100644 --- a/src/java/org/apache/fop/fo/flow/ListItem.java +++ b/src/java/org/apache/fop/fo/flow/ListItem.java @@ -14,7 +14,7 @@ * limitations under the License. */ -/* $Id$ */ +/* $Id:$ */ package org.apache.fop.fo.flow; @@ -23,6 +23,7 @@ import java.util.List; // XML import org.xml.sax.Attributes; +import org.xml.sax.Locator; import org.xml.sax.SAXParseException; // FOP @@ -31,24 +32,13 @@ import org.apache.fop.fo.FObj; import org.apache.fop.layoutmgr.list.ListItemLayoutManager; /** - * Class modelling the fo:list-item object. See Sec. 6.8.3 of the XSL-FO - * Standard. + * Class modelling the fo:list-item object. */ public class ListItem extends FObj { private ListItemLabel label = null; private ListItemBody body = null; - private int align; - private int alignLast; - private int breakBefore; - private int breakAfter; - private int lineHeight; - private int startIndent; - private int endIndent; - private int spaceBefore; - private int spaceAfter; - /** * @param parent FONode that is the parent of this object */ @@ -62,49 +52,68 @@ public class ListItem extends FObj { protected void addProperties(Attributes attlist) throws SAXParseException { super.addProperties(attlist); getFOInputHandler().startListItem(this); - this.align = this.propertyList.get(PR_TEXT_ALIGN).getEnum(); - this.alignLast = this.propertyList.get(PR_TEXT_ALIGN_LAST).getEnum(); - this.lineHeight = - this.propertyList.get(PR_LINE_HEIGHT).getLength().getValue(); - this.spaceBefore = - this.propertyList.get(PR_SPACE_BEFORE | CP_OPTIMUM).getLength().getValue(); - this.spaceAfter = - this.propertyList.get(PR_SPACE_AFTER | CP_OPTIMUM).getLength().getValue(); + } + + /** + * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) + * XSL Content Model: marker* (list-item-label,list-item-body) + */ + protected void validateChildNode(Locator loc, String nsURI, String localName) + throws SAXParseException { + if (nsURI == FO_URI && localName.equals("marker")) { + if (label != null) { + nodesOutOfOrderError(loc, "fo:marker", "fo:list-item-label"); + } + } else if (nsURI == FO_URI && localName.equals("list-item-label")) { + if (label != null) { + tooManyNodesError(loc, "fo:list-item-label"); + } + } else if (nsURI == FO_URI && localName.equals("list-item-body")) { + if (label == null) { + nodesOutOfOrderError(loc, "fo:list-item-label", "fo:list-item-body"); + } else if (body != null) { + tooManyNodesError(loc, "fo:list-item-body"); + } + } else { + invalidChildError(loc, nsURI, localName); + } } /** * @see org.apache.fop.fo.FONode#addChildNode(FONode) + * @todo see if can/should rely on base class for this + * (i.e., add to childNodes instead) */ public void addChildNode(FONode child) { - if ("fo:list-item-label".equals(child.getName())) { - label = (ListItemLabel)child; - } else if ("fo:list-item-body".equals(child.getName())) { - body = (ListItemBody)child; - } else if ("fo:marker".equals(child.getName())) { - // marker - } else { - // error + int nameId = ((FObj)child).getNameId(); + + if (nameId == FO_LIST_ITEM_LABEL) { + label = (ListItemLabel) child; + } else if (nameId == FO_LIST_ITEM_BODY) { + body = (ListItemBody) child; + } else if (nameId == FO_MARKER) { + addMarker((Marker) child); } } /** - * @return false (ListItem cannot generate inline areas) + * Make sure content model satisfied, if so then tell the + * FOInputHandler that we are at the end of the flow. + * @see org.apache.fop.fo.FONode#end */ - public boolean generatesInlineAreas() { - return false; + protected void endOfNode() throws SAXParseException { + if (label == null || body == null) { + missingChildElementError("marker* (list-item-label,list-item-body)"); + } + getFOInputHandler().endListItem(this); } /** * @see org.apache.fop.fo.FObj#addLayoutManager(List) - * @todo remove checks for non-nulls after validateChildNode() added */ public void addLayoutManager(List list) { - if (label != null && body != null) { - ListItemLayoutManager blm = new ListItemLayoutManager(this); - list.add(blm); - } else { - getLogger().error("list-item requires list-item-label and list-item-body"); - } + ListItemLayoutManager blm = new ListItemLayoutManager(this); + list.add(blm); } public ListItemLabel getLabel() { @@ -115,11 +124,9 @@ public class ListItem extends FObj { return body; } - protected void endOfNode() throws SAXParseException { - super.endOfNode(); - getFOInputHandler().endListItem(this); - } - + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:list-item"; } diff --git a/src/java/org/apache/fop/fo/flow/Table.java b/src/java/org/apache/fop/fo/flow/Table.java index e6402ecda..57e380fb9 100644 --- a/src/java/org/apache/fop/fo/flow/Table.java +++ b/src/java/org/apache/fop/fo/flow/Table.java @@ -130,13 +130,6 @@ public class Table extends FObj { } } - /** - * @return false (Table does not generate inline areas) - */ - public boolean generatesInlineAreas() { - return false; - } - private ArrayList getColumns() { return columns; } diff --git a/src/java/org/apache/fop/fo/flow/TableAndCaption.java b/src/java/org/apache/fop/fo/flow/TableAndCaption.java index caa8ee189..cd79627f9 100644 --- a/src/java/org/apache/fop/fo/flow/TableAndCaption.java +++ b/src/java/org/apache/fop/fo/flow/TableAndCaption.java @@ -36,12 +36,8 @@ public class TableAndCaption extends ToBeImplementedElement { } /** - * @return false (TableAndCaption doesn't generate inline areas) + * @see org.apache.fop.fo.FObj#getName() */ - public boolean generatesInlineAreas() { - return false; - } - public String getName() { return "fo:table-and-caption"; } diff --git a/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java b/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java index 8793f957b..322d3df25 100644 --- a/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java +++ b/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java @@ -152,7 +152,7 @@ public class ConditionalPageMasterReference extends FObj { * Check that the parent is the right type of formatting object * repeatable-page-master-alternatives. * @param parent parent node - * @throws FOPException If the parent is invalid + * @throws SAXParseException If the parent is invalid */ protected void validateParent(FONode parent) throws SAXParseException { if (parent.getName().equals("fo:repeatable-page-master-alternatives")) { diff --git a/src/java/org/apache/fop/fo/pagination/StaticContent.java b/src/java/org/apache/fop/fo/pagination/StaticContent.java index 405e8d014..02f725676 100644 --- a/src/java/org/apache/fop/fo/pagination/StaticContent.java +++ b/src/java/org/apache/fop/fo/pagination/StaticContent.java @@ -68,7 +68,7 @@ public class StaticContent extends Flow { /** * flowname checking is more stringient for static content currently * @param name the flow-name to set - * @throws FOPException for a missing flow name + * @throws SAXParseException for a missing flow name */ protected void setFlowName(String name) throws SAXParseException { if (name == null || name.equals("")) { diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java index 422da40d9..fb6534577 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -85,6 +85,8 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { /** * @see org.apache.fop.layoutmgr.AbstractLayoutManager#initProperties() + * @todo need to take into account somewhere the effects of fo:initial-property-set, + * if defined for the block. */ protected void initProperties() { PropertyManager pm = fobj.getPropertyManager(); |