KickJava   Java API By Example, From Geeks To Geeks.

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


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: PageGroup.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 import java.io.UnsupportedEncodingException JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26
27 /**
28  * A page group is used in the data stream to define a named, logical grouping
29  * of sequential pages. Page groups are delimited by begin-end structured fields
30  * that carry the name of the page group. Page groups are defined so that the
31  * pages that comprise the group can be referenced or processed as a single
32  * entity. Page groups are often processed in stand-alone fashion; that is, they
33  * are indexed, retrieved, and presented outside the context of the containing
34  * document.
35  *
36  * @author <a HREF="mailto:pete@townsend.uk.com">Pete Townsend </a>
37  */

38 public class PageGroup extends AbstractNamedAFPObject {
39
40     /**
41      * The pages contained within this group
42      */

43     private List JavaDoc _objects = new ArrayList JavaDoc();
44
45     /**
46      * The tag logical elements contained within this group
47      */

48     private List JavaDoc _tagLogicalElements = new ArrayList JavaDoc();
49
50     /**
51      * The page state
52      */

53     private boolean _complete = false;
54
55     /**
56      * Constructor for the PageGroup.
57      *
58      * @param name
59      * the name of the page group
60      */

61     public PageGroup(String JavaDoc name) {
62
63         super(name);
64
65     }
66
67     /**
68      * Adds a page object to the group.
69      *
70      * @param page
71      * the page object to add
72      */

73     public void addPage(PageObject page) {
74
75         if (!_objects.contains(page)) {
76             _objects.add(page);
77         }
78
79     }
80
81     /**
82      * @return the name of the page group
83      */

84     public String JavaDoc getName() {
85         return _name;
86     }
87
88     /**
89      * Creates a TagLogicalElement on the page.
90      *
91      * @param name
92      * the name of the tag
93      * @param value
94      * the value of the tag
95      */

96     public void createTagLogicalElement(String JavaDoc name, String JavaDoc value) {
97
98         TagLogicalElement tle = new TagLogicalElement(name, value);
99         _tagLogicalElements.add(tle);
100
101     }
102
103     /**
104      * Creates an InvokeMediaMap on the page.
105      *
106      * @param name
107      * the name of the media map
108      */

109     public void createInvokeMediumMap(String JavaDoc name) {
110
111         InvokeMediumMap imm = new InvokeMediumMap(name);
112         _objects.add(imm);
113
114     }
115
116     /**
117      * Method to mark the end of the page group.
118      */

119     public void endPageGroup() {
120
121         _complete = true;
122
123     }
124
125     /**
126      * Returns an indication if the page group is complete
127      */

128     public boolean isComplete() {
129         return _complete;
130     }
131
132    /**
133      * Accessor method to write the AFP datastream for the page group.
134      * @param os The stream to write to
135      * @throws java.io.IOException
136      */

137     public void writeDataStream(OutputStream JavaDoc os)
138         throws IOException JavaDoc {
139
140         writeStart(os);
141
142         writeObjectList(_tagLogicalElements, os);
143
144         writeObjectList(_objects, os);
145
146         writeEnd(os);
147
148     }
149
150     /**
151      * Helper method to write the start of the page group.
152      * @param os The stream to write to
153      */

154     private void writeStart(OutputStream JavaDoc os)
155         throws IOException JavaDoc {
156
157         byte[] data = new byte[17];
158
159         data[0] = 0x5A; // Structured field identifier
160
data[1] = 0x00; // Length byte 1
161
data[2] = 0x10; // Length byte 2
162
data[3] = (byte) 0xD3; // Structured field id byte 1
163
data[4] = (byte) 0xA8; // Structured field id byte 2
164
data[5] = (byte) 0xAD; // Structured field id byte 3
165
data[6] = 0x00; // Flags
166
data[7] = 0x00; // Reserved
167
data[8] = 0x00; // Reserved
168

169         for (int i = 0; i < _nameBytes.length; i++) {
170
171             data[9 + i] = _nameBytes[i];
172
173         }
174
175         os.write(data);
176
177     }
178
179     /**
180      * Helper method to write the end of the page group.
181      * @param os The stream to write to
182      */

183     private void writeEnd(OutputStream JavaDoc os)
184         throws IOException JavaDoc {
185
186         byte[] data = new byte[17];
187
188         data[0] = 0x5A; // Structured field identifier
189
data[1] = 0x00; // Length byte 1
190
data[2] = 0x10; // Length byte 2
191
data[3] = (byte) 0xD3; // Structured field id byte 1
192
data[4] = (byte) 0xA9; // Structured field id byte 2
193
data[5] = (byte) 0xAD; // Structured field id byte 3
194
data[6] = 0x00; // Flags
195
data[7] = 0x00; // Reserved
196
data[8] = 0x00; // Reserved
197

198         for (int i = 0; i < _nameBytes.length; i++) {
199
200             data[9 + i] = _nameBytes[i];
201
202         }
203
204         os.write(data);
205
206     }
207
208 }
Popular Tags