KickJava   Java API By Example, From Geeks To Geeks.

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


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: TagLogicalElement.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
26 import org.apache.fop.render.afp.tools.BinaryUtils;
27
28 /**
29  * A Tag Logical Element structured field assigns an attribute name and an
30  * attribute value to a page or page group. The Tag Logical Element structured
31  * field may be embedded directly in the page or page group, or it may reference
32  * the page or page group from a document index. When a Tag Logical Element
33  * structured field references a page or is embedded in a page following the
34  * active environment group, it is associated with the page. When a Tag Logical
35  * Element structured field references a page group or is embedded in a page
36  * group following the Begin Named Page Group structured field, it is associated
37  * with the page group. When a Tag Logical Element structured field is associated
38  * with a page group, the parameters of the Tag Logical Element structured field
39  * are inherited by all pages in the page group and by all other page groups
40  * that are nested in the page group. The scope of a Tag Logical Element is
41  * determined by its position with respect to other TLEs that reference, or are
42  * embedded in, the same page or page group. The Tag Logical Element structured
43  * field does not provide any presentation specifications and therefore has no
44  * effect on the appearance of a document when it is presented.
45  * <p/>
46  */

47 public class TagLogicalElement extends AbstractAFPObject {
48
49     /**
50      * Name of the key, used within the TLE
51      */

52     private String JavaDoc _tleName = null;
53
54     /**
55      * Value returned by the key
56      */

57     private String JavaDoc _tleValue = null;
58
59     /**
60      * Byte representaion of the name
61      */

62     private byte[] _tleByteName = null;
63
64     /**
65      * Byte representaion of the value
66      */

67     private byte[] _tleByteValue = null;
68
69     /**
70      * Construct a tag logical element with the name and value specified.
71      * @param name the name of the tag logical element
72      * @param value the value of the tag logical element
73      */

74     public TagLogicalElement(String JavaDoc name, String JavaDoc value) {
75
76         _tleName = name;
77         _tleValue = value;
78
79         try {
80
81             _tleByteName = name.getBytes(AFPConstants.EBCIDIC_ENCODING);
82             _tleByteValue = value.getBytes(AFPConstants.EBCIDIC_ENCODING);
83
84         } catch (UnsupportedEncodingException JavaDoc usee) {
85
86             _tleByteName = name.getBytes();
87             _tleByteValue = value.getBytes();
88             log.warn(
89                 "Constructor:: UnsupportedEncodingException translating the name "
90                 + name);
91
92         }
93
94     }
95
96     /**
97      * Accessor method to obtain the byte array AFP datastream for the
98      * TagLogicalElement.
99      * @param os The outputsteam stream
100      * @throws java.io.IOException
101      */

102     public void writeDataStream(OutputStream JavaDoc os) throws IOException JavaDoc {
103
104         byte[] data = new byte[17 + _tleName.length() + _tleValue.length()];
105
106         data[0] = 0x5A;
107         // Set the total record length
108
byte[] rl1 =
109             BinaryUtils.convert(16 + _tleName.length() + _tleValue.length(), 2);
110         //Ignore first byte
111
data[1] = rl1[0];
112         data[2] = rl1[1];
113
114         // Structured field ID for a TLE
115
data[3] = (byte) 0xD3;
116         data[4] = (byte) 0xA0;
117         data[5] = (byte) 0x90;
118
119         data[6] = 0x00; // Reserved
120
data[7] = 0x00; // Reserved
121
data[8] = 0x00; // Reserved
122

123         //Use 2 triplets, attrubute name and value (the key for indexing)
124

125         byte[] rl2 = BinaryUtils.convert(_tleName.length() + 4, 1);
126         data[9] = rl2[0]; // length of the triplet, including this field
127
data[10] = 0x02; //Identifies it as a FQN triplet
128
data[11] = 0x0B; // GID format
129
data[12] = 0x00;
130
131         int pos = 13;
132         for (int i = 0; i < _tleByteName.length; i++) {
133             data[pos++] = _tleByteName[i];
134         }
135
136         byte[] rl3 = BinaryUtils.convert(_tleByteValue.length + 4, 1);
137         data[pos++] = rl3[0]; // length of the triplet, including this field
138
data[pos++] = 0x36; //Identifies the triplet, attribute value
139
data[pos++] = 0x00; // Reserved
140
data[pos++] = 0x00; // Reserved
141

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