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: ResourceGroup.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.render.afp.modca;
021:
022: import java.io.IOException;
023: import java.io.OutputStream;
024: import java.io.UnsupportedEncodingException;
025: import java.util.ArrayList;
026: import java.util.List;
027:
028: /**
029: * A Resource Group contains a set of overlays.
030: */
031: public final class ResourceGroup extends AbstractNamedAFPObject {
032:
033: /**
034: * Default name for the resource group
035: */
036: private static final String DEFAULT_NAME = "RG000001";
037:
038: /**
039: * The overlays contained in this resource group
040: */
041: private List _overlays = new ArrayList();
042:
043: public ResourceGroup() {
044:
045: this (DEFAULT_NAME);
046:
047: }
048:
049: /**
050: * Constructor for the ResourceGroup, this takes a
051: * name parameter which must be 8 characters long.
052: * @param name the resource group name
053: */
054: public ResourceGroup(String name) {
055:
056: super (name);
057:
058: }
059:
060: /**
061: * Adds an overlay to the resource group
062: * @param overlay the overlay to add
063: */
064: public void addOverlay(Overlay overlay) {
065: _overlays.add(overlay);
066: }
067:
068: /**
069: * Returns the list of overlays
070: * @return the list of overlays
071: */
072: public List getOverlays() {
073: return _overlays;
074: }
075:
076: /**
077: * Accessor method to obtain write the AFP datastream for
078: * the resource group.
079: * @param os The stream to write to
080: * @throws java.io.IOException
081: */
082: public void writeDataStream(OutputStream os) throws IOException {
083:
084: writeStart(os);
085:
086: writeObjectList(_overlays, os);
087:
088: writeEnd(os);
089:
090: }
091:
092: /**
093: * Helper method to write the start of the resource group.
094: * @param os The stream to write to
095: */
096: private void writeStart(OutputStream os) throws IOException {
097:
098: byte[] data = new byte[17];
099:
100: data[0] = 0x5A; // Structured field identifier
101: data[1] = 0x00; // Length byte 1
102: data[2] = 0x10; // Length byte 2
103: data[3] = (byte) 0xD3; // Structured field id byte 1
104: data[4] = (byte) 0xA8; // Structured field id byte 2
105: data[5] = (byte) 0xC6; // Structured field id byte 3
106: data[6] = 0x00; // Flags
107: data[7] = 0x00; // Reserved
108: data[8] = 0x00; // Reserved
109:
110: for (int i = 0; i < _nameBytes.length; i++) {
111:
112: data[9 + i] = _nameBytes[i];
113:
114: }
115:
116: os.write(data);
117:
118: }
119:
120: /**
121: * Helper method to write the end of the resource group.
122: * @param os The stream to write to
123: */
124: private void writeEnd(OutputStream os) throws IOException {
125:
126: byte[] data = new byte[17];
127:
128: data[0] = 0x5A; // Structured field identifier
129: data[1] = 0x00; // Length byte 1
130: data[2] = 0x10; // Length byte 2
131: data[3] = (byte) 0xD3; // Structured field id byte 1
132: data[4] = (byte) 0xA9; // Structured field id byte 2
133: data[5] = (byte) 0xC6; // Structured field id byte 3
134: data[6] = 0x00; // Flags
135: data[7] = 0x00; // Reserved
136: data[8] = 0x00; // Reserved
137:
138: for (int i = 0; i < _nameBytes.length; i++) {
139:
140: data[9 + i] = _nameBytes[i];
141:
142: }
143:
144: os.write(data);
145:
146: }
147:
148: }
|