gmazza 2004/09/04 12:53:07 Modified: src/java/org/apache/fop/fo FObj.java src/java/org/apache/fop/fo/flow PageNumberCitation.java TableCell.java src/java/org/apache/fop/fo/pagination Flow.java PageSequence.java PageSequenceMaster.java Root.java StaticContent.java src/java/org/apache/fop/layoutmgr PageLayoutManager.java PageNumberCitationLayoutManager.java src/java/org/apache/fop/render/rtf RTFHandler.java Log: 1.) validateChildNode() implemented for fo:table-cell. 2.) various code cleanups throughout the FO's. Revision Changes Path 1.72 +3 -1 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.71 retrieving revision 1.72 diff -u -r1.71 -r1.72 --- FObj.java 30 Aug 2004 12:00:51 -0000 1.71 +++ FObj.java 4 Sep 2004 19:53:06 -0000 1.72 @@ -202,6 +202,8 @@ * Convenience method to quickly obtain the length value of a property * for this FO, without querying for the propertyList first. * Meaningful only for properties having a length representation + * Note: getValue() only correct after resolution completed, therefore + * should be called only in layout manager code. * @param propId - the Constants ID of the desired property to obtain * @return the length value of the property value */ @@ -358,8 +360,8 @@ /** * Check if this formatting object generates reference areas. - * * @return true if generates reference areas + * @todo see if needed */ public boolean generatesReferenceAreas() { return false; 1.36 +11 -50 xml-fop/src/java/org/apache/fop/fo/flow/PageNumberCitation.java Index: PageNumberCitation.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/PageNumberCitation.java,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- PageNumberCitation.java 30 Aug 2004 12:00:52 -0000 1.35 +++ PageNumberCitation.java 4 Sep 2004 19:53:06 -0000 1.36 @@ -27,10 +27,8 @@ import org.xml.sax.SAXParseException; // FOP -import org.apache.fop.datatypes.ColorType; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; -import org.apache.fop.fonts.Font; import org.apache.fop.layoutmgr.PageNumberCitationLayoutManager; /** @@ -40,16 +38,6 @@ * block referenced with the ref-id attribute. */ public class PageNumberCitation extends FObj { - /** Fontstate for this object **/ - protected Font fontState; - - private float red; - private float green; - private float blue; - private int wrapOption; - private String pageNumber; - private String refId; - private boolean unresolved = false; /** * @param parent FONode that is the parent of this object @@ -59,6 +47,17 @@ } /** + * @see org.apache.fop.fo.FObj#addProperties + */ + protected void addProperties(Attributes attlist) throws SAXParseException { + super.addProperties(attlist); + + if (getPropString(PR_REF_ID) == null || getPropString(PR_REF_ID).equals("")) { + missingPropertyError("ref-id"); + } + } + + /** * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) * XSL Content Model: empty */ @@ -68,47 +67,9 @@ } /** - * @todo switch this method to addProperties() - */ - private void setup() { - // Common Font Properties - this.fontState = propMgr.getFontState(getFOInputHandler().getFontInfo()); - - ColorType c = this.propertyList.get(PR_COLOR).getColorType(); - this.red = c.getRed(); - this.green = c.getGreen(); - this.blue = c.getBlue(); - - this.wrapOption = getPropEnum(PR_WRAP_OPTION); - this.refId = getPropString(PR_REF_ID); - - if (this.refId.equals("")) { - //throw new FOPException("page-number-citation must contain \"ref-id\""); - } - - } - - public String getRefId() { - return refId; - } - - public boolean getUnresolved() { - return unresolved; - } - - public void setUnresolved(boolean isUnresolved) { - unresolved = isUnresolved; - } - - public Font getFontState() { - return fontState; - } - - /** * @see org.apache.fop.fo.FObj#addLayoutManager(List) */ public void addLayoutManager(List list) { - setup(); PageNumberCitationLayoutManager lm = new PageNumberCitationLayoutManager(this); list.add(lm); 1.30 +71 -48 xml-fop/src/java/org/apache/fop/fo/flow/TableCell.java Index: TableCell.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/TableCell.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- TableCell.java 30 Aug 2004 12:00:52 -0000 1.29 +++ TableCell.java 4 Sep 2004 19:53:06 -0000 1.30 @@ -23,7 +23,7 @@ // XML import org.xml.sax.Attributes; -import org.xml.sax.SAXException; +import org.xml.sax.Locator; import org.xml.sax.SAXParseException; // FOP @@ -35,7 +35,7 @@ /** * Class modelling the fo:table-cell object. - * @todo implement validateChildNode() + * @todo check need for all instance variables stored here */ public class TableCell extends FObj { @@ -47,6 +47,9 @@ private int numRowsSpanned; private int iColNumber = -1; // uninitialized + /** used for FO validation */ + private boolean blockItemFound = false; + /** * Offset of content rectangle in inline-progression-direction, * relative to table. @@ -121,11 +124,73 @@ */ protected void addProperties(Attributes attlist) throws SAXParseException { super.addProperties(attlist); - doSetup(); // init some basic property values + this.iColNumber = + propertyList.get(PR_COLUMN_NUMBER).getNumber().intValue(); + if (iColNumber < 0) { + iColNumber = 0; + } + this.numColumnsSpanned = + this.propertyList.get(PR_NUMBER_COLUMNS_SPANNED).getNumber().intValue(); + if (numColumnsSpanned < 1) { + numColumnsSpanned = 1; + } + this.numRowsSpanned = + this.propertyList.get(PR_NUMBER_ROWS_SPANNED).getNumber().intValue(); + if (numRowsSpanned < 1) { + numRowsSpanned = 1; + } + + this.backgroundColor = + this.propertyList.get(PR_BACKGROUND_COLOR).getColorType(); + + bSepBorders = (getPropEnum(PR_BORDER_COLLAPSE) == BorderCollapse.SEPARATE); + + calcBorders(propMgr.getBorderAndPadding()); + + // Vertical cell alignment + verticalAlign = getPropEnum(PR_DISPLAY_ALIGN); + if (verticalAlign == DisplayAlign.AUTO) { + // Depends on all cells starting in row + bRelativeAlign = true; + verticalAlign = getPropEnum(PR_RELATIVE_ALIGN); + } else { + bRelativeAlign = false; // Align on a per-cell basis + } + + this.minCellHeight = getPropLength(PR_HEIGHT); getFOInputHandler().startCell(this); } /** + * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) + * XSL Content Model: marker* (%block;)+ + */ + protected void validateChildNode(Locator loc, String nsURI, String localName) + throws SAXParseException { + if (nsURI == FO_URI && localName.equals("marker")) { + if (blockItemFound) { + nodesOutOfOrderError(loc, "fo:marker", "(%block;)"); + } + } else if (!isBlockItem(nsURI, localName)) { + invalidChildError(loc, nsURI, localName); + } else { + blockItemFound = true; + } + } + + /** + * 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 + */ + protected void endOfNode() throws SAXParseException { + if (!blockItemFound) { + missingChildElementError("marker* (%block;)+"); + } + getFOInputHandler().endCell(this); + } + + /** * Set position relative to table (set by body?) */ public void setStartOffset(int offset) { @@ -164,47 +229,6 @@ } /** - * @todo convert to addProperties() - */ - private void doSetup() { - - this.iColNumber = - propertyList.get(PR_COLUMN_NUMBER).getNumber().intValue(); - if (iColNumber < 0) { - iColNumber = 0; - } - this.numColumnsSpanned = - this.propertyList.get(PR_NUMBER_COLUMNS_SPANNED).getNumber().intValue(); - if (numColumnsSpanned < 1) { - numColumnsSpanned = 1; - } - this.numRowsSpanned = - this.propertyList.get(PR_NUMBER_ROWS_SPANNED).getNumber().intValue(); - if (numRowsSpanned < 1) { - numRowsSpanned = 1; - } - - this.backgroundColor = - this.propertyList.get(PR_BACKGROUND_COLOR).getColorType(); - - bSepBorders = (getPropEnum(PR_BORDER_COLLAPSE) == BorderCollapse.SEPARATE); - - calcBorders(propMgr.getBorderAndPadding()); - - // Vertical cell alignment - verticalAlign = getPropEnum(PR_DISPLAY_ALIGN); - if (verticalAlign == DisplayAlign.AUTO) { - // Depends on all cells starting in row - bRelativeAlign = true; - verticalAlign = getPropEnum(PR_RELATIVE_ALIGN); - } else { - bRelativeAlign = false; // Align on a per-cell basis - } - - this.minCellHeight = getPropLength(PR_HEIGHT); - } - - /** * Calculate cell border and padding, including offset of content * rectangle from the theoretical grid position. */ @@ -307,11 +331,10 @@ Cell clm = new Cell(this); list.add(clm); } - - protected void endOfNode() throws SAXParseException { - getFOInputHandler().endCell(this); - } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:table-cell"; } 1.29 +27 -56 xml-fop/src/java/org/apache/fop/fo/pagination/Flow.java Index: Flow.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/Flow.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- Flow.java 25 Aug 2004 05:03:06 -0000 1.28 +++ Flow.java 4 Sep 2004 19:53:07 -0000 1.29 @@ -48,9 +48,10 @@ private ArrayList markerSnapshot; /** - * flow-name attribute + * flow-name attribute: indicates the region the content of this + * flow should go to. */ - private String flowName; + protected String flowName; /** * Content-width of current column area during layout @@ -68,6 +69,25 @@ } /** + * @see org.apache.fop.fo.FObj#addProperties + */ + protected void addProperties(Attributes attlist) throws SAXParseException { + super.addProperties(attlist); + + this.pageSequence = (PageSequence) parent; + + flowName = getPropString(PR_FLOW_NAME); + + if (flowName == null || flowName.equals("")) { + missingPropertyError("flow-name"); + } + + // Now done in addChild of page-sequence + //pageSequence.addFlow(this); + getFOInputHandler().startFlow(this); + } + + /** * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) * XSL Content Model: marker* (%block;)+ */ @@ -97,64 +117,12 @@ } /** - * @see org.apache.fop.fo.FObj#addProperties - */ - protected void addProperties(Attributes attlist) throws SAXParseException { - super.addProperties(attlist); - if (parent.getName().equals("fo:page-sequence")) { - this.pageSequence = (PageSequence) parent; - } else { - throw new SAXParseException("flow must be child of " - + "page-sequence, not " + parent.getName(), locator); - } - // according to communication from Paul Grosso (XSL-List, - // 001228, Number 406), confusion in spec section 6.4.5 about - // multiplicity of fo:flow in XSL 1.0 is cleared up - one (1) - // fo:flow per fo:page-sequence only. - - /* if (pageSequence.isFlowSet()) { - if (this.name.equals("fo:flow")) { - throw new FOPException("Only a single fo:flow permitted" - + " per fo:page-sequence"); - } else { - throw new FOPException(this.name - + " not allowed after fo:flow"); - } - } - */ - setFlowName(getProperty(PR_FLOW_NAME).getString()); - // Now done in addChild of page-sequence - //pageSequence.addFlow(this); - - getFOInputHandler().startFlow(this); - } - - /** - * @param name the name of the flow to set - * @throws FOPException for an empty name - */ - protected void setFlowName(String name) throws SAXParseException { - if (name == null || name.equals("")) { - throw new SAXParseException("A 'flow-name' is required for " - + getName(), locator); - } else { - flowName = name; - } - } - - /** - * @return the name of this flow - */ - public String getFlowName() { - return flowName; - } - - /** * @param contentWidth content width of this flow, in millipoints (??) */ protected void setContentWidth(int contentWidth) { this.contentWidth = contentWidth; } + /** * @return the content width of this flow (really of the region * in which it is flowing), in millipoints (??). @@ -178,6 +146,9 @@ list.add(lm); } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:flow"; } 1.42 +2 -2 xml-fop/src/java/org/apache/fop/fo/pagination/PageSequence.java Index: PageSequence.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/PageSequence.java,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- PageSequence.java 30 Aug 2004 12:00:52 -0000 1.41 +++ PageSequence.java 4 Sep 2004 19:53:07 -0000 1.42 @@ -189,7 +189,7 @@ this.titleFO = (Title)child; } else if (childName.equals("fo:flow")) { this.mainFlow = (Flow)child; - String flowName = this.mainFlow.getFlowName(); + String flowName = this.mainFlow.getPropString(PR_FLOW_NAME); if (flowMap.containsKey(flowName)) { throw new FOPException("flow-name " + flowName @@ -205,7 +205,7 @@ startStructuredPageSequence(); super.addChildNode(child); // For getChildren } else if (childName.equals("fo:static-content")) { - String flowName = ((StaticContent)child).getFlowName(); + String flowName = ((StaticContent)child).getPropString(PR_FLOW_NAME); if (flowMap.containsKey(flowName)) { throw new FOPException("flow-name " + flowName + " is not unique within an fo:page-sequence"); 1.21 +3 -0 xml-fop/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java Index: PageSequenceMaster.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- PageSequenceMaster.java 25 Aug 2004 05:03:06 -0000 1.20 +++ PageSequenceMaster.java 4 Sep 2004 19:53:07 -0000 1.21 @@ -193,6 +193,9 @@ return pageMaster; } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:page-sequence-master"; } 1.24 +3 -0 xml-fop/src/java/org/apache/fop/fo/pagination/Root.java Index: Root.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/Root.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- Root.java 16 Aug 2004 11:59:52 -0000 1.23 +++ Root.java 4 Sep 2004 19:53:07 -0000 1.24 @@ -222,6 +222,9 @@ return foInputHandler; } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:root"; } 1.24 +2 -17 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.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- StaticContent.java 25 Aug 2004 05:03:06 -0000 1.23 +++ StaticContent.java 4 Sep 2004 19:53:07 -0000 1.24 @@ -38,9 +38,6 @@ super(parent); } - private void setup() { - } - /** * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) * XSL Content Model: (%block;)+ @@ -65,20 +62,8 @@ } /** - * flowname checking is more stringient for static content currently - * @param name the flow-name to set - * @throws SAXParseException for a missing flow name + * @see org.apache.fop.fo.FObj#getName() */ - protected void setFlowName(String name) throws SAXParseException { - if (name == null || name.equals("")) { - throw new SAXParseException("A 'flow-name' is required for " - + getName() + ".", locator); - } else { - super.setFlowName(name); - } - - } - public String getName() { return "fo:static-content"; } 1.46 +4 -4 xml-fop/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java Index: PageLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java,v retrieving revision 1.45 retrieving revision 1.46 diff -u -r1.45 -r1.46 --- PageLayoutManager.java 29 Aug 2004 20:58:20 -0000 1.45 +++ PageLayoutManager.java 4 Sep 2004 19:53:07 -0000 1.46 @@ -709,8 +709,8 @@ throws FOPException { currentSimplePageMaster = getSimplePageMasterToUse(bIsBlank); Region body = currentSimplePageMaster.getRegion(FO_REGION_BODY); - if (!pageSequence.getMainFlow().getFlowName().equals(body.getRegionName())) { - throw new FOPException("Flow '" + pageSequence.getMainFlow().getFlowName() + if (!pageSequence.getMainFlow().getPropString(PR_FLOW_NAME).equals(body.getRegionName())) { + throw new FOPException("Flow '" + pageSequence.getMainFlow().getPropString(PR_FLOW_NAME) + "' does not map to the region-body in page-master '" + currentSimplePageMaster.getMasterName() + "'"); } @@ -884,13 +884,13 @@ */ private StaticContentLayoutManager getStaticContentLayoutManager(StaticContent sc) { StaticContentLayoutManager lm = - (StaticContentLayoutManager)staticContentLMs.get(sc.getFlowName()); + (StaticContentLayoutManager)staticContentLMs.get(sc.getPropString(PR_FLOW_NAME)); if (lm != null) { return lm; } lm = new StaticContentLayoutManager(); lm.setFObj(sc); - staticContentLMs.put(sc.getFlowName(), lm); + staticContentLMs.put(sc.getPropString(PR_FLOW_NAME), lm); return lm; } 1.4 +12 -14 xml-fop/src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java Index: PageNumberCitationLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PageNumberCitationLayoutManager.java 16 Aug 2004 04:11:42 -0000 1.3 +++ PageNumberCitationLayoutManager.java 4 Sep 2004 19:53:07 -0000 1.4 @@ -35,15 +35,18 @@ PageNumberCitation pncNode; Font font = null; + // whether the page referred to by the citation has been resolved yet + private boolean resolved = false; + /** * Constructor * * @param node the formatting object that creates this area - * @todo better null checking of font object + * @todo better retrieval of font info */ public PageNumberCitationLayoutManager(PageNumberCitation node) { super(node); - font = node.getFontState(); + font = node.getPropertyManager().getFontState(node.getFOInputHandler().getFontInfo()); pncNode = node; } @@ -54,8 +57,8 @@ public void addAreas(PositionIterator posIter, LayoutContext context) { super.addAreas(posIter, context); - if (pncNode.getUnresolved()) { - parentLM.addUnresolvedArea(pncNode.getRefId(), + if (!resolved) { + parentLM.addUnresolvedArea(pncNode.getPropString(PR_REF_ID), (Resolveable) curArea); } } @@ -67,14 +70,9 @@ /** * if id can be resolved then simply return a word, otherwise * return a resolveable area - * @todo move ref-id validation check to the FO class' addProperties(). */ private InlineArea getPageNumberCitationInlineArea(LayoutManager parentLM) { - if (pncNode.getRefId().equals("")) { - fobj.getLogger().error("page-number-citation must contain \"ref-id\""); - return null; - } - PageViewport page = parentLM.resolveRefID(pncNode.getRefId()); + PageViewport page = parentLM.resolveRefID(pncNode.getPropString(PR_REF_ID)); InlineArea inline = null; if (page != null) { String str = page.getPageNumber(); @@ -90,10 +88,10 @@ inline.addTrait(Trait.FONT_NAME, font.getFontName()); inline.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize())); - pncNode.setUnresolved(false); + resolved = true; } else { - pncNode.setUnresolved(true); - inline = new UnresolvedPageNumber(pncNode.getRefId()); + resolved = false; + inline = new UnresolvedPageNumber(pncNode.getPropString(PR_REF_ID)); String str = "MMM"; // reserve three spaces for page number int width = getStringWidth(str); inline.setIPD(width); 1.30 +7 -7 xml-fop/src/java/org/apache/fop/render/rtf/RTFHandler.java Index: RTFHandler.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/RTFHandler.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- RTFHandler.java 24 Jul 2004 22:56:31 -0000 1.29 +++ RTFHandler.java 4 Sep 2004 19:53:07 -0000 1.30 @@ -219,7 +219,7 @@ } try { - if (fl.getFlowName().equals("xsl-region-body")) { + if (fl.getPropString(Constants.PR_FLOW_NAME).equals("xsl-region-body")) { // if there is no header in current page-sequence but there has been // a header in a previous page-sequence, insert an empty header. if (bPrevHeaderSpecified && !bHeaderSpecified) { @@ -244,7 +244,7 @@ contAfter.newAfter(attr); } - } else if (fl.getFlowName().equals("xsl-region-before")) { + } else if (fl.getPropString(Constants.PR_FLOW_NAME).equals("xsl-region-before")) { bHeaderSpecified = true; bPrevHeaderSpecified = true; @@ -261,7 +261,7 @@ RtfBefore before = c.newBefore(beforeAttributes); builderContext.pushContainer(before); - } else if (fl.getFlowName().equals("xsl-region-after")) { + } else if (fl.getPropString(Constants.PR_FLOW_NAME).equals("xsl-region-after")) { bFooterSpecified = true; bPrevFooterSpecified = true; @@ -298,11 +298,11 @@ } try { - if (fl.getFlowName().equals("xsl-region-body")) { + if (fl.getPropString(Constants.PR_FLOW_NAME).equals("xsl-region-body")) { //just do nothing - } else if (fl.getFlowName().equals("xsl-region-before")) { + } else if (fl.getPropString(Constants.PR_FLOW_NAME).equals("xsl-region-before")) { builderContext.popContainer(); - } else if (fl.getFlowName().equals("xsl-region-after")) { + } else if (fl.getPropString(Constants.PR_FLOW_NAME).equals("xsl-region-after")) { builderContext.popContainer(); } } catch (Exception e) {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]