From: Glen Mazza Date: Sat, 4 Sep 2004 19:53:07 +0000 (+0000) Subject: 1.) validateChildNode() implemented for fo:table-cell. X-Git-Tag: Root_Temp_KnuthStylePageBreaking~590 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ce6918191d4a085815a977aa394c8516609e3f91;p=xmlgraphics-fop.git 1.) validateChildNode() implemented for fo:table-cell. 2.) various code cleanups throughout the FO's. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197901 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java index 9aefe68ab..a1a25e8b7 100644 --- a/src/java/org/apache/fop/fo/FObj.java +++ b/src/java/org/apache/fop/fo/FObj.java @@ -202,6 +202,8 @@ public class FObj extends FONode implements Constants { * 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 @@ public class FObj extends FONode implements Constants { /** * Check if this formatting object generates reference areas. - * * @return true if generates reference areas + * @todo see if needed */ public boolean generatesReferenceAreas() { return false; diff --git a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java index c8e25eeda..456b96a50 100644 --- a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java +++ b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java @@ -27,10 +27,8 @@ import org.xml.sax.Locator; 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 @@ import org.apache.fop.layoutmgr.PageNumberCitationLayoutManager; * 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 @@ -58,6 +46,17 @@ public class PageNumberCitation extends FObj { super(parent); } + /** + * @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 @@ -67,48 +66,10 @@ public class PageNumberCitation extends FObj { invalidChildError(loc, nsURI, localName); } - /** - * @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); diff --git a/src/java/org/apache/fop/fo/flow/TableCell.java b/src/java/org/apache/fop/fo/flow/TableCell.java index ed2caa557..944e943c5 100644 --- a/src/java/org/apache/fop/fo/flow/TableCell.java +++ b/src/java/org/apache/fop/fo/flow/TableCell.java @@ -23,7 +23,7 @@ import java.util.List; // 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 @@ import org.apache.fop.fo.properties.CommonBorderAndPadding; /** * 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 @@ public class TableCell extends FObj { 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,10 +124,72 @@ public class TableCell extends FObj { */ 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?) */ @@ -163,47 +228,6 @@ public class TableCell extends FObj { return numRowsSpanned; } - /** - * @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 @@ public class TableCell extends FObj { 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"; } diff --git a/src/java/org/apache/fop/fo/pagination/Flow.java b/src/java/org/apache/fop/fo/pagination/Flow.java index c756749ca..723911c42 100644 --- a/src/java/org/apache/fop/fo/pagination/Flow.java +++ b/src/java/org/apache/fop/fo/pagination/Flow.java @@ -48,9 +48,10 @@ public class Flow extends FObj { 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 @@ -67,6 +68,25 @@ public class Flow extends FObj { super(parent); } + /** + * @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;)+ @@ -96,65 +116,13 @@ public class Flow extends FObj { getFOInputHandler().endFlow(this); } - /** - * @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 @@ public class Flow extends FObj { list.add(lm); } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:flow"; } diff --git a/src/java/org/apache/fop/fo/pagination/PageSequence.java b/src/java/org/apache/fop/fo/pagination/PageSequence.java index 57eff5ccd..7a025097f 100644 --- a/src/java/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/java/org/apache/fop/fo/pagination/PageSequence.java @@ -189,7 +189,7 @@ public class PageSequence extends FObj { 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 @@ public class PageSequence extends FObj { 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"); diff --git a/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java b/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java index 173e0be84..631187e4f 100644 --- a/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java +++ b/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java @@ -193,6 +193,9 @@ public class PageSequenceMaster extends FObj { return pageMaster; } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:page-sequence-master"; } diff --git a/src/java/org/apache/fop/fo/pagination/Root.java b/src/java/org/apache/fop/fo/pagination/Root.java index 0f8189092..a879f9469 100644 --- a/src/java/org/apache/fop/fo/pagination/Root.java +++ b/src/java/org/apache/fop/fo/pagination/Root.java @@ -222,6 +222,9 @@ public class Root extends FObj { return foInputHandler; } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:root"; } diff --git a/src/java/org/apache/fop/fo/pagination/StaticContent.java b/src/java/org/apache/fop/fo/pagination/StaticContent.java index 81b8e67af..6e9441afb 100644 --- a/src/java/org/apache/fop/fo/pagination/StaticContent.java +++ b/src/java/org/apache/fop/fo/pagination/StaticContent.java @@ -38,9 +38,6 @@ public class StaticContent extends Flow { super(parent); } - private void setup() { - } - /** * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) * XSL Content Model: (%block;)+ @@ -65,20 +62,8 @@ public class StaticContent extends Flow { } /** - * 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"; } diff --git a/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java index 6952b508f..6d701958e 100644 --- a/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java @@ -709,8 +709,8 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable 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 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable */ 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; } diff --git a/src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java index 9d1163520..acd674b94 100644 --- a/src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java @@ -35,15 +35,18 @@ public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager { 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 class PageNumberCitationLayoutManager extends LeafNodeLayoutManager { 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 @@ public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager { /** * 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 @@ public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager { 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); diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index cef51ee01..fe8a26b9a 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -219,7 +219,7 @@ public class RTFHandler extends FOInputHandler { } 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 @@ public class RTFHandler extends FOInputHandler { 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 @@ public class RTFHandler extends FOInputHandler { 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 @@ public class RTFHandler extends FOInputHandler { } 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) {