blob: af1f50e070bb144f47fcf4b5596da2fbcb8e9687 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/*-- $Id$ --
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources."
*/
package org.apache.fop.fo.pagination;
// FOP
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.apps.FOPException;
import org.apache.fop.layout.RegionArea;
/**
* This is an abstract base class for pagination regions
*/
public abstract class Region extends FObj
{
public static final String PROP_REGION_NAME = "region-name";
private SimplePageMaster _layoutMaster;
private String _regionName;
protected Region(FObj parent, PropertyList propertyList)
throws FOPException
{
super(parent, propertyList);
this.name = getElementName();
// regions may have name, or default
if (null == this.properties.get(PROP_REGION_NAME)) {
setRegionName(getDefaultRegionName());
}
else if (this.properties.get(PROP_REGION_NAME).getString().equals("")) {
setRegionName(getDefaultRegionName());
}
else {
setRegionName(this.properties.get(PROP_REGION_NAME).getString());
// check that name is OK. Not very pretty.
if (isReserved(getRegionName()) &&
!getRegionName().equals(getDefaultRegionName())) {
throw new FOPException(PROP_REGION_NAME+" '" + _regionName
+ "' for "+this.name+" not permitted.");
}
}
if (parent.getName().equals("fo:simple-page-master")) {
_layoutMaster = (SimplePageMaster) parent;
getPageMaster().addRegion(this);
} else {
throw new FOPException(getElementName()+" must be child "
+ "of simple-page-master, not "
+ parent.getName());
}
}
/**
* Creates a Region layout object for this pagination Region.
*/
abstract RegionArea makeRegionArea(int allocationRectangleXPosition,
int allocationRectangleYPosition,
int allocationRectangleWidth,
int allocationRectangleHeight);
/**
* Returns the default region name (xsl-region-before, xsl-region-start,
* etc.)
*/
protected abstract String getDefaultRegionName();
/**
* Returns the element name ("fo:region-body", "fo:region-start",
* etc.)
*/
protected abstract String getElementName();
public abstract String getRegionClass();
/**
* Returns the name of this region
*/
public String getRegionName()
{
return _regionName;
}
private void setRegionName(String name)
{
_regionName = name;
}
protected SimplePageMaster getPageMaster()
{
return _layoutMaster;
}
/**
* Checks to see if a given region name is one of the reserved names
*
* @param name a region name to check
* @return true if the name parameter is a reserved region name
*/
protected boolean isReserved(String name)
throws FOPException
{
return (name.equals( "xsl-region-before" ) ||
name.equals( "xsl-region-start" ) ||
name.equals( "xsl-region-end" ) ||
name.equals( "xsl-region-after" ) ||
name.equals( "xsl-before-float-separator" ) ||
name.equals( "xsl-footnote-separator" ));
}
public boolean generatesReferenceAreas() {
return true;
}
}
|