001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: Flow.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.fo.pagination;
021:
022: import org.xml.sax.Locator;
023:
024: import org.apache.fop.apps.FOPException;
025: import org.apache.fop.fo.FONode;
026: import org.apache.fop.fo.FObj;
027: import org.apache.fop.fo.PropertyList;
028: import org.apache.fop.fo.ValidationException;
029:
030: /**
031: * Class modelling the fo:flow object.
032: */
033: public class Flow extends FObj {
034: // The value of properties relevant for fo:flow.
035: private String flowName;
036: // End of property values
037:
038: /** used for FO validation */
039: private boolean blockItemFound = false;
040:
041: /**
042: * @param parent FONode that is the parent of this object
043: */
044: public Flow(FONode parent) {
045: super (parent);
046: }
047:
048: /**
049: * @see org.apache.fop.fo.FObj#bind(PropertyList)
050: */
051: public void bind(PropertyList pList) throws FOPException {
052: flowName = pList.get(PR_FLOW_NAME).getString();
053: }
054:
055: /**
056: * @see org.apache.fop.fo.FONode#startOfNode
057: */
058: protected void startOfNode() throws FOPException {
059: if (flowName == null || flowName.equals("")) {
060: missingPropertyError("flow-name");
061: }
062:
063: // according to communication from Paul Grosso (XSL-List,
064: // 001228, Number 406), confusion in spec section 6.4.5 about
065: // multiplicity of fo:flow in XSL 1.0 is cleared up - one (1)
066: // fo:flow per fo:page-sequence only.
067:
068: /* if (pageSequence.isFlowSet()) {
069: if (this.name.equals("fo:flow")) {
070: throw new FOPException("Only a single fo:flow permitted"
071: + " per fo:page-sequence");
072: } else {
073: throw new FOPException(this.name
074: + " not allowed after fo:flow");
075: }
076: }
077: */
078: // Now done in addChild of page-sequence
079: //pageSequence.addFlow(this);
080: getFOEventHandler().startFlow(this );
081: }
082:
083: /**
084: * Make sure content model satisfied, if so then tell the
085: * FOEventHandler that we are at the end of the flow.
086: * @see org.apache.fop.fo.FONode#endOfNode
087: */
088: protected void endOfNode() throws FOPException {
089: if (!blockItemFound) {
090: missingChildElementError("marker* (%block;)+");
091: }
092: getFOEventHandler().endFlow(this );
093: }
094:
095: /**
096: * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
097: * XSL Content Model: marker* (%block;)+
098: */
099: protected void validateChildNode(Locator loc, String nsURI,
100: String localName) throws ValidationException {
101: if (FO_URI.equals(nsURI) && localName.equals("marker")) {
102: if (blockItemFound) {
103: nodesOutOfOrderError(loc, "fo:marker", "(%block;)");
104: }
105: } else if (!isBlockItem(nsURI, localName)) {
106: invalidChildError(loc, nsURI, localName);
107: } else {
108: blockItemFound = true;
109: }
110: }
111:
112: /**
113: * @return true (Flow can generate reference areas)
114: */
115: public boolean generatesReferenceAreas() {
116: return true;
117: }
118:
119: /** @return "flow-name" property. */
120: public String getFlowName() {
121: return flowName;
122: }
123:
124: /** @see org.apache.fop.fo.FONode#getLocalName() */
125: public String getLocalName() {
126: return "flow";
127: }
128:
129: /**
130: * @see org.apache.fop.fo.FObj#getNameId()
131: */
132: public int getNameId() {
133: return FO_FLOW;
134: }
135: }
|