* 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
*/
/**
* Check if this formatting object generates reference areas.
- *
* @return true if generates reference areas
+ * @todo see if needed
*/
public boolean generatesReferenceAreas() {
return false;
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;
/**
* 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
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
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);
// XML
import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
+import org.xml.sax.Locator;
import org.xml.sax.SAXParseException;
// FOP
/**
* Class modelling the fo:table-cell object.
- * @todo implement validateChildNode()
+ * @todo check need for all instance variables stored here
*/
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.
*/
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?)
*/
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.
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";
}
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
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;)+
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 (??).
list.add(lm);
}
+ /**
+ * @see org.apache.fop.fo.FObj#getName()
+ */
public String getName() {
return "fo:flow";
}
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
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");
return pageMaster;
}
+ /**
+ * @see org.apache.fop.fo.FObj#getName()
+ */
public String getName() {
return "fo:page-sequence-master";
}
return foInputHandler;
}
+ /**
+ * @see org.apache.fop.fo.FObj#getName()
+ */
public String getName() {
return "fo:root";
}
super(parent);
}
- private void setup() {
- }
-
/**
* @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
* XSL Content Model: (%block;)+
}
/**
- * 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";
}
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() + "'");
}
*/
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;
}
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;
}
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);
}
}
/**
* 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();
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);
}
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) {
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;
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;
}
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) {