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: Region.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.fo.pagination;
021:
022: import java.awt.Rectangle;
023:
024: import org.xml.sax.Locator;
025:
026: import org.apache.fop.apps.FOPException;
027: import org.apache.fop.datatypes.FODimension;
028: import org.apache.fop.datatypes.Numeric;
029: import org.apache.fop.fo.FONode;
030: import org.apache.fop.fo.FObj;
031: import org.apache.fop.fo.PropertyList;
032: import org.apache.fop.fo.ValidationException;
033: import org.apache.fop.fo.expr.PropertyException;
034: import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
035:
036: /**
037: * This is an abstract base class for pagination regions
038: */
039: public abstract class Region extends FObj {
040: // The value of properties relevant for fo:region
041: private CommonBorderPaddingBackground commonBorderPaddingBackground;
042: // private ToBeImplementedProperty clip
043: private int displayAlign;
044: private int overflow;
045: private String regionName;
046: private Numeric referenceOrientation;
047: private int writingMode;
048: // End of property values
049:
050: private SimplePageMaster layoutMaster;
051:
052: /**
053: * @see org.apache.fop.fo.FONode#FONode(FONode)
054: */
055: protected Region(FONode parent) {
056: super (parent);
057: layoutMaster = (SimplePageMaster) parent;
058: }
059:
060: /**
061: * @see org.apache.fop.fo.FObj#bind(PropertyList)
062: */
063: public void bind(PropertyList pList) throws FOPException {
064: commonBorderPaddingBackground = pList
065: .getBorderPaddingBackgroundProps();
066: // clip = pList.get(PR_CLIP);
067: displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum();
068: overflow = pList.get(PR_OVERFLOW).getEnum();
069: regionName = pList.get(PR_REGION_NAME).getString();
070: referenceOrientation = pList.get(PR_REFERENCE_ORIENTATION)
071: .getNumeric();
072: writingMode = pList.getWritingMode();
073:
074: // regions may have name, or default
075: if (regionName.equals("")) {
076: regionName = getDefaultRegionName();
077: } else {
078: // check that name is OK. Not very pretty.
079: if (isReserved(getRegionName())
080: && !getRegionName().equals(getDefaultRegionName())) {
081: throw new ValidationException("region-name '"
082: + regionName + "' for " + this .getName()
083: + " is not permitted.", locator);
084: }
085: }
086:
087: //TODO do we need context for getBPPaddingAndBorder() and getIPPaddingAndBorder()?
088: if (getUserAgent().validateStrictly()
089: && (getCommonBorderPaddingBackground()
090: .getBPPaddingAndBorder(false, null) != 0 || getCommonBorderPaddingBackground()
091: .getIPPaddingAndBorder(false, null) != 0)) {
092: throw new PropertyException(
093: "Border and padding for region \"" + regionName
094: + "\" must be '0' (See 6.4.13 in XSL 1.0).");
095: }
096: }
097:
098: /**
099: * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
100: * XSL Content Model: empty
101: */
102: protected void validateChildNode(Locator loc, String nsURI,
103: String localName) throws ValidationException {
104: invalidChildError(loc, nsURI, localName);
105: }
106:
107: /**
108: * @param pageRefRect reference dimension of the page area.
109: * @param spm the simple page master this region belongs to.
110: * @return the rectangle for the viewport area
111: */
112: public abstract Rectangle getViewportRectangle(
113: FODimension pageRefRect, SimplePageMaster spm);
114:
115: /**
116: * Returns the default region name (xsl-region-before, xsl-region-start,
117: * etc.)
118: * @return the default region name
119: */
120: protected abstract String getDefaultRegionName();
121:
122: /**
123: * Checks to see if a given region name is one of the reserved names
124: *
125: * @param name a region name to check
126: * @return true if the name parameter is a reserved region name
127: */
128: protected boolean isReserved(String name) /*throws FOPException*/{
129: return (name.equals("xsl-region-before")
130: || name.equals("xsl-region-start")
131: || name.equals("xsl-region-end")
132: || name.equals("xsl-region-after")
133: || name.equals("xsl-before-float-separator") || name
134: .equals("xsl-footnote-separator"));
135: }
136:
137: /**
138: * @see org.apache.fop.fo.FObj#generatesReferenceAreas()
139: */
140: public boolean generatesReferenceAreas() {
141: return true;
142: }
143:
144: /**
145: * Returns a sibling region for this region.
146: * @param regionId the Constants ID of the FO representing the region
147: * @return the requested region
148: */
149: protected Region getSiblingRegion(int regionId) {
150: // Ask parent for region
151: return layoutMaster.getRegion(regionId);
152: }
153:
154: /**
155: * @return the Background Properties (border and padding are not used here).
156: */
157: public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
158: return commonBorderPaddingBackground;
159: }
160:
161: /** @return the "region-name" property. */
162: public String getRegionName() {
163: return regionName;
164: }
165:
166: /** @return the "writing-mode" property. */
167: public int getWritingMode() {
168: return writingMode;
169: }
170:
171: /** @return the "overflow" property. */
172: public int getOverflow() {
173: return overflow;
174: }
175:
176: /** @return the display-align property. */
177: public int getDisplayAlign() {
178: return displayAlign;
179: }
180:
181: /** @return the "reference-orientation" property. */
182: public int getReferenceOrientation() {
183: return referenceOrientation.getValue();
184: }
185: }
|