KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > afp > modca > PageObject


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: PageObject.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.afp.modca;
21 import java.io.IOException JavaDoc;
22 import java.io.OutputStream JavaDoc;
23
24
25
26 /**
27  * Pages contain the data objects that comprise a presentation document. Each
28  * page has a set of data objects associated with it. Each page within a
29  * document is independent from any other page, and each must establish its own
30  * environment parameters.
31  *
32  * The page is the level in the document component hierarchy that is used for
33  * printing or displaying a document's content. The data objects contained in
34  * the page envelope in the data stream are presented when the page is
35  * presented. Each data object has layout information associated with it that
36  * directs the placement and orientation of the data on the page. In addition,
37  * each page contains layout information that specifies the measurement units,
38  * page width, and page depth.
39  *
40  * A page is initiated by a begin page structured field and terminated by an end
41  * page structured field. Structured fields that define objects and active
42  * environment groups or that specify attributes of the page may be encountered
43  * in page state.
44  *
45  */

46 public class PageObject extends AbstractPageObject {
47
48     /**
49      * The resource group object
50      */

51     private ResourceGroup _resourceGroup = null;
52
53     /**
54      * Construct a new page object for the specified name argument, the page
55      * name should be an 8 character identifier.
56      *
57      * @param name
58      * the name of the page.
59      * @param width
60      * the width of the page.
61      * @param height
62      * the height of the page.
63      * @param rotation
64      * the rotation of the page.
65      */

66     public PageObject(String JavaDoc name, int width, int height, int rotation) {
67
68         super(name, width, height, rotation);
69
70     }
71
72     /**
73      * Adds an overlay to the page resources
74      * @param overlay the overlay to add
75      */

76     public void addOverlay(Overlay overlay) {
77         if (_resourceGroup == null) {
78             _resourceGroup = new ResourceGroup();
79         }
80         _resourceGroup.addOverlay(overlay);
81     }
82
83     /**
84      * Creates an IncludePageOverlay on the page.
85      *
86      * @param name
87      * the name of the overlay
88      * @param x
89      * the x position of the overlay
90      * @param y
91      * the y position of the overlay
92      * @param orientation
93      * the orientation required for the overlay
94      */

95     public void createIncludePageOverlay(String JavaDoc name, int x, int y, int orientation) {
96
97         IncludePageOverlay ipo = new IncludePageOverlay(name, x, y, orientation);
98         _objects.add(ipo);
99
100     }
101
102     /**
103      * Accessor method to write the AFP datastream for the page.
104      * @param os The stream to write to
105      * @throws java.io.IOException
106      */

107     public void writeDataStream(OutputStream JavaDoc os)
108         throws IOException JavaDoc {
109
110         writeStart(os);
111
112         if (_resourceGroup != null) {
113             _resourceGroup.writeDataStream(os);
114         }
115
116         _activeEnvironmentGroup.writeDataStream(os);
117
118         writeObjectList(_segments, os);
119
120         writeObjectList(_tagLogicalElements, os);
121
122         writeObjectList(_objects, os);
123
124         writeEnd(os);
125
126     }
127
128     /**
129      * Helper method to write the start of the page.
130      * @param os The stream to write to
131      */

132     private void writeStart(OutputStream JavaDoc os)
133         throws IOException JavaDoc {
134
135         byte[] data = new byte[17];
136
137         data[0] = 0x5A; // Structured field identifier
138
data[1] = 0x00; // Length byte 1
139
data[2] = 0x10; // Length byte 2
140
data[3] = (byte) 0xD3; // Structured field id byte 1
141
data[4] = (byte) 0xA8; // Structured field id byte 2
142
data[5] = (byte) 0xAF; // Structured field id byte 3
143
data[6] = 0x00; // Flags
144
data[7] = 0x00; // Reserved
145
data[8] = 0x00; // Reserved
146

147         for (int i = 0; i < _nameBytes.length; i++) {
148
149             data[9 + i] = _nameBytes[i];
150
151         }
152
153         os.write(data);
154
155     }
156
157     /**
158      * Helper method to write the end of the page.
159      * @param os The stream to write to
160      */

161     private void writeEnd(OutputStream JavaDoc os)
162         throws IOException JavaDoc {
163
164         byte[] data = new byte[17];
165
166         data[0] = 0x5A; // Structured field identifier
167
data[1] = 0x00; // Length byte 1
168
data[2] = 0x10; // Length byte 2
169
data[3] = (byte) 0xD3; // Structured field id byte 1
170
data[4] = (byte) 0xA9; // Structured field id byte 2
171
data[5] = (byte) 0xAF; // Structured field id byte 3
172
data[6] = 0x00; // Flags
173
data[7] = 0x00; // Reserved
174
data[8] = 0x00; // Reserved
175

176         for (int i = 0; i < _nameBytes.length; i++) {
177
178             data[9 + i] = _nameBytes[i];
179
180         }
181
182         os.write(data);
183
184     }
185
186 }
Popular Tags