KickJava   Java API By Example, From Geeks To Geeks.

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


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: ResourceGroup.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.afp.modca;
21
22 import java.io.IOException JavaDoc;
23 import java.io.OutputStream JavaDoc;
24 import java.io.UnsupportedEncodingException JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27
28 /**
29  * A Resource Group contains a set of overlays.
30  */

31 public final class ResourceGroup extends AbstractNamedAFPObject {
32
33     /**
34      * Default name for the resource group
35      */

36     private static final String JavaDoc DEFAULT_NAME = "RG000001";
37
38
39     /**
40      * The overlays contained in this resource group
41      */

42     private List JavaDoc _overlays = new ArrayList JavaDoc();
43
44     public ResourceGroup() {
45
46         this(DEFAULT_NAME);
47
48     }
49
50     /**
51      * Constructor for the ResourceGroup, this takes a
52      * name parameter which must be 8 characters long.
53      * @param name the resource group name
54      */

55     public ResourceGroup(String JavaDoc name) {
56
57         super(name);
58
59     }
60
61     /**
62      * Adds an overlay to the resource group
63      * @param overlay the overlay to add
64      */

65     public void addOverlay(Overlay overlay) {
66         _overlays.add(overlay);
67     }
68
69     /**
70      * Returns the list of overlays
71      * @return the list of overlays
72      */

73     public List JavaDoc getOverlays() {
74         return _overlays;
75     }
76
77     /**
78      * Accessor method to obtain write the AFP datastream for
79      * the resource group.
80      * @param os The stream to write to
81      * @throws java.io.IOException
82      */

83     public void writeDataStream(OutputStream JavaDoc os)
84         throws IOException JavaDoc {
85
86         writeStart(os);
87
88         writeObjectList(_overlays, os);
89
90         writeEnd(os);
91
92     }
93
94     /**
95      * Helper method to write the start of the resource group.
96      * @param os The stream to write to
97      */

98     private void writeStart(OutputStream JavaDoc os)
99         throws IOException JavaDoc {
100
101         byte[] data = new byte[17];
102
103         data[0] = 0x5A; // Structured field identifier
104
data[1] = 0x00; // Length byte 1
105
data[2] = 0x10; // Length byte 2
106
data[3] = (byte) 0xD3; // Structured field id byte 1
107
data[4] = (byte) 0xA8; // Structured field id byte 2
108
data[5] = (byte) 0xC6; // Structured field id byte 3
109
data[6] = 0x00; // Flags
110
data[7] = 0x00; // Reserved
111
data[8] = 0x00; // Reserved
112

113         for (int i = 0; i < _nameBytes.length; i++) {
114
115             data[9 + i] = _nameBytes[i];
116
117         }
118
119         os.write(data);
120
121     }
122
123     /**
124      * Helper method to write the end of the resource group.
125      * @param os The stream to write to
126      */

127     private void writeEnd(OutputStream JavaDoc os)
128         throws IOException JavaDoc {
129
130         byte[] data = new byte[17];
131
132         data[0] = 0x5A; // Structured field identifier
133
data[1] = 0x00; // Length byte 1
134
data[2] = 0x10; // Length byte 2
135
data[3] = (byte) 0xD3; // Structured field id byte 1
136
data[4] = (byte) 0xA9; // Structured field id byte 2
137
data[5] = (byte) 0xC6; // Structured field id byte 3
138
data[6] = 0x00; // Flags
139
data[7] = 0x00; // Reserved
140
data[8] = 0x00; // Reserved
141

142         for (int i = 0; i < _nameBytes.length; i++) {
143
144             data[9 + i] = _nameBytes[i];
145
146         }
147
148         os.write(data);
149
150     }
151
152 }
Popular Tags