123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- /*
- * Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- /* $Id$ */
-
- package org.apache.fop.render.afp.modca;
-
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.UnsupportedEncodingException;
-
- import org.apache.fop.render.afp.tools.BinaryUtils;
-
- /**
- * A Tag Logical Element structured field assigns an attribute name and an
- * attribute value to a page or page group. The Tag Logical Element structured
- * field may be embedded directly in the page or page group, or it may reference
- * the page or page group from a document index. When a Tag Logical Element
- * structured field references a page or is embedded in a page following the
- * active environment group, it is associated with the page. When a Tag Logical
- * Element structured field references a page group or is embedded in a page
- * group following the Begin Named Page Group structured field, it is associated
- * with the page group. When a Tag Logical Element structured field is associated
- * with a page group, the parameters of the Tag Logical Element structured field
- * are inherited by all pages in the page group and by all other page groups
- * that are nested in the page group. The scope of a Tag Logical Element is
- * determined by its position with respect to other TLEs that reference, or are
- * embedded in, the same page or page group. The Tag Logical Element structured
- * field does not provide any presentation specifications and therefore has no
- * effect on the appearance of a document when it is presented.
- * <p/>
- */
- public class TagLogicalElement extends AbstractAFPObject {
-
- /**
- * Name of the key, used within the TLE
- */
- private String _tleName = null;
-
- /**
- * Value returned by the key
- */
- private String _tleValue = null;
-
- /**
- * Byte representaion of the name
- */
- private byte[] _tleByteName = null;
-
- /**
- * Byte representaion of the value
- */
- private byte[] _tleByteValue = null;
-
- /**
- * Construct a tag logical element with the name and value specified.
- * @param name the name of the tag logical element
- * @param value the value of the tag logical element
- */
- public TagLogicalElement(String name, String value) {
-
- _tleName = name;
- _tleValue = value;
-
- try {
-
- _tleByteName = name.getBytes(AFPConstants.EBCIDIC_ENCODING);
- _tleByteValue = value.getBytes(AFPConstants.EBCIDIC_ENCODING);
-
- } catch (UnsupportedEncodingException usee) {
-
- _tleByteName = name.getBytes();
- _tleByteValue = value.getBytes();
- log.warn(
- "Constructor:: UnsupportedEncodingException translating the name "
- + name);
-
- }
-
- }
-
- /**
- * Accessor method to obtain the byte array AFP datastream for the
- * TagLogicalElement.
- * @param os The outputsteam stream
- * @throws java.io.IOException
- */
- public void writeDataStream(OutputStream os) throws IOException {
-
- byte[] data = new byte[17 + _tleName.length() + _tleValue.length()];
-
- data[0] = 0x5A;
- // Set the total record length
- byte[] rl1 =
- BinaryUtils.convert(16 + _tleName.length() + _tleValue.length(), 2);
- //Ignore first byte
- data[1] = rl1[0];
- data[2] = rl1[1];
-
- // Structured field ID for a TLE
- data[3] = (byte) 0xD3;
- data[4] = (byte) 0xA0;
- data[5] = (byte) 0x90;
-
- data[6] = 0x00; // Reserved
- data[7] = 0x00; // Reserved
- data[8] = 0x00; // Reserved
-
- //Use 2 triplets, attrubute name and value (the key for indexing)
-
- byte[] rl2 = BinaryUtils.convert(_tleName.length() + 4, 1);
- data[9] = rl2[0]; // length of the triplet, including this field
- data[10] = 0x02; //Identifies it as a FQN triplet
- data[11] = 0x0B; // GID format
- data[12] = 0x00;
-
- int pos = 13;
- for (int i = 0; i < _tleByteName.length; i++) {
- data[pos++] = _tleByteName[i];
- }
-
- byte[] rl3 = BinaryUtils.convert(_tleByteValue.length + 4, 1);
- data[pos++] = rl3[0]; // length of the triplet, including this field
- data[pos++] = 0x36; //Identifies the triplet, attribute value
- data[pos++] = 0x00; // Reserved
- data[pos++] = 0x00; // Reserved
-
- for (int i = 0; i < _tleByteValue.length; i++) {
- data[pos++] = _tleByteValue[i];
- }
- os.write(data);
-
- }
-
- }
|