gmazza 2004/08/17 20:26:38 Modified: src/java/org/apache/fop/fo Constants.java FONode.java FOText.java FObj.java PropertyManager.java PropertySets.java src/java/org/apache/fop/fo/flow Block.java BlockContainer.java ExternalGraphic.java InitialPropertySet.java InstreamForeignObject.java ListBlock.java ListItem.java Table.java TableAndCaption.java src/java/org/apache/fop/fo/pagination ConditionalPageMasterReference.java StaticContent.java src/java/org/apache/fop/layoutmgr BlockLayoutManager.java Log: 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. Revision Changes Path 1.11 +2 -2 xml-fop/src/java/org/apache/fop/fo/Constants.java Index: Constants.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/Constants.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- Constants.java 8 Aug 2004 18:39:22 -0000 1.10 +++ Constants.java 18 Aug 2004 03:26:35 -0000 1.11 @@ -56,7 +56,7 @@ 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; 1.39 +11 -2 xml-fop/src/java/org/apache/fop/fo/FONode.java Index: FONode.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FONode.java,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- FONode.java 7 Aug 2004 13:01:15 -0000 1.38 +++ FONode.java 18 Aug 2004 03:26:35 -0000 1.39 @@ -112,11 +112,20 @@ } /** - * 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; } /** 1.24 +4 -0 xml-fop/src/java/org/apache/fop/fo/FOText.java Index: FOText.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOText.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- FOText.java 6 Aug 2004 15:41:10 -0000 1.23 +++ FOText.java 18 Aug 2004 03:26:35 -0000 1.24 @@ -488,6 +488,10 @@ } + /** + * @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"; } 1.68 +3 -28 xml-fop/src/java/org/apache/fop/fo/FObj.java Index: FObj.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FObj.java,v retrieving revision 1.67 retrieving revision 1.68 diff -u -r1.67 -r1.68 --- FObj.java 16 Aug 2004 11:59:51 -0000 1.67 +++ FObj.java 18 Aug 2004 03:26:35 -0000 1.68 @@ -192,8 +192,8 @@ */ 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 @@ } /** - * 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 @@ * 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 @@ -540,22 +531,6 @@ temp = temp.getParent(); } 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; } } 1.33 +0 -1 xml-fop/src/java/org/apache/fop/fo/PropertyManager.java Index: PropertyManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/PropertyManager.java,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- PropertyManager.java 13 Aug 2004 09:05:15 -0000 1.32 +++ PropertyManager.java 18 Aug 2004 03:26:35 -0000 1.33 @@ -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; 1.11 +26 -1 xml-fop/src/java/org/apache/fop/fo/PropertySets.java Index: PropertySets.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/PropertySets.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- PropertySets.java 11 Aug 2004 04:15:25 -0000 1.10 +++ PropertySets.java 18 Aug 2004 03:26:35 -0000 1.11 @@ -27,6 +27,7 @@ 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(); @@ -1083,6 +1084,30 @@ can_have_id.set(Constants.FO_WRAPPER); } return can_have_id.get(elementId); + } + + /** + * 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)); } /** 1.34 +8 -12 xml-fop/src/java/org/apache/fop/fo/flow/Block.java Index: Block.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/Block.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- Block.java 11 Aug 2004 04:15:25 -0000 1.33 +++ Block.java 18 Aug 2004 03:26:36 -0000 1.34 @@ -32,6 +32,7 @@ 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 @@ /** * @param parent FONode that is the parent of this object + * */ public Block(FONode parent) { super(parent); @@ -176,24 +178,18 @@ } /** - * @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(); 1.19 +3 -7 xml-fop/src/java/org/apache/fop/fo/flow/BlockContainer.java Index: BlockContainer.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/BlockContainer.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- BlockContainer.java 11 Aug 2004 04:15:25 -0000 1.18 +++ BlockContainer.java 18 Aug 2004 03:26:36 -0000 1.19 @@ -76,13 +76,6 @@ } /** - * @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 @@ list.add(blm); } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:block-container"; } 1.39 +1 -0 xml-fop/src/java/org/apache/fop/fo/flow/ExternalGraphic.java Index: ExternalGraphic.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/ExternalGraphic.java,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- ExternalGraphic.java 16 Aug 2004 04:11:41 -0000 1.38 +++ ExternalGraphic.java 18 Aug 2004 03:26:36 -0000 1.39 @@ -59,6 +59,7 @@ /** * @see org.apache.fop.fo.FObj#addProperties + * @todo switch method from image() to startImage()? */ protected void addProperties(Attributes attlist) throws SAXParseException { super.addProperties(attlist); 1.14 +7 -5 xml-fop/src/java/org/apache/fop/fo/flow/InitialPropertySet.java Index: InitialPropertySet.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/InitialPropertySet.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- InitialPropertySet.java 11 Aug 2004 04:15:25 -0000 1.13 +++ InitialPropertySet.java 18 Aug 2004 03:26:36 -0000 1.14 @@ -25,13 +25,12 @@ // 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 @@ invalidChildError(loc, nsURI, localName); } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:initial-property-set"; } 1.22 +0 -9 xml-fop/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java Index: InstreamForeignObject.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- InstreamForeignObject.java 16 Aug 2004 04:11:41 -0000 1.21 +++ InstreamForeignObject.java 18 Aug 2004 03:26:36 -0000 1.22 @@ -114,15 +114,6 @@ } /** - * 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) { 1.25 +3 -35 xml-fop/src/java/org/apache/fop/fo/flow/ListBlock.java Index: ListBlock.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/ListBlock.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- ListBlock.java 16 Aug 2004 04:11:41 -0000 1.24 +++ ListBlock.java 18 Aug 2004 03:26:36 -0000 1.25 @@ -38,18 +38,6 @@ */ 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 @@ */ 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 @@ } /** - * @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 @@ list.add(lm); } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:list-block"; } 1.26 +51 -44 xml-fop/src/java/org/apache/fop/fo/flow/ListItem.java Index: ListItem.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/ListItem.java,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- ListItem.java 11 Aug 2004 04:15:25 -0000 1.25 +++ ListItem.java 18 Aug 2004 03:26:36 -0000 1.26 @@ -23,6 +23,7 @@ // 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.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 @@ 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 @@ 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"; } 1.29 +0 -7 xml-fop/src/java/org/apache/fop/fo/flow/Table.java Index: Table.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/Table.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- Table.java 13 Aug 2004 00:03:49 -0000 1.28 +++ Table.java 18 Aug 2004 03:26:36 -0000 1.29 @@ -130,13 +130,6 @@ } } - /** - * @return false (Table does not generate inline areas) - */ - public boolean generatesInlineAreas() { - return false; - } - private ArrayList getColumns() { return columns; } 1.14 +1 -5 xml-fop/src/java/org/apache/fop/fo/flow/TableAndCaption.java Index: TableAndCaption.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/TableAndCaption.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- TableAndCaption.java 11 Aug 2004 04:15:26 -0000 1.13 +++ TableAndCaption.java 18 Aug 2004 03:26:36 -0000 1.14 @@ -36,12 +36,8 @@ } /** - * @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"; } 1.18 +1 -1 xml-fop/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java Index: ConditionalPageMasterReference.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- ConditionalPageMasterReference.java 8 Aug 2004 18:39:25 -0000 1.17 +++ ConditionalPageMasterReference.java 18 Aug 2004 03:26:37 -0000 1.18 @@ -152,7 +152,7 @@ * 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")) { 1.22 +2 -2 xml-fop/src/java/org/apache/fop/fo/pagination/StaticContent.java Index: StaticContent.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/StaticContent.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- StaticContent.java 16 Aug 2004 04:11:42 -0000 1.21 +++ StaticContent.java 18 Aug 2004 03:26:37 -0000 1.22 @@ -68,7 +68,7 @@ /** * 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("")) { 1.24 +2 -0 xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java Index: BlockLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- BlockLayoutManager.java 18 Jun 2004 04:13:53 -0000 1.23 +++ BlockLayoutManager.java 18 Aug 2004 03:26:37 -0000 1.24 @@ -85,6 +85,8 @@ /** * @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();
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]