You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TagLogicalElement.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright 2006 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.render.afp.modca;
  18. import java.io.IOException;
  19. import java.io.OutputStream;
  20. import java.io.UnsupportedEncodingException;
  21. import org.apache.fop.render.afp.tools.BinaryUtils;
  22. /**
  23. * A Tag Logical Element structured field assigns an attribute name and an
  24. * attribute value to a page or page group. The Tag Logical Element structured
  25. * field may be embedded directly in the page or page group, or it may reference
  26. * the page or page group from a document index. When a Tag Logical Element
  27. * structured field references a page or is embedded in a page following the
  28. * active environment group, it is associated with the page. When a Tag Logical
  29. * Element structured field references a page group or is embedded in a page
  30. * group following the Begin Named Page Group structured field, it is associated
  31. * with the page group. When a Tag Logical Element structured field is associated
  32. * with a page group, the parameters of the Tag Logical Element structured field
  33. * are inherited by all pages in the page group and by all other page groups
  34. * that are nested in the page group. The scope of a Tag Logical Element is
  35. * determined by its position with respect to other TLEs that reference, or are
  36. * embedded in, the same page or page group. The Tag Logical Element structured
  37. * field does not provide any presentation specifications and therefore has no
  38. * effect on the appearance of a document when it is presented.
  39. * <p/>
  40. */
  41. public class TagLogicalElement extends AbstractAFPObject {
  42. /**
  43. * Name of the key, used within the TLE
  44. */
  45. private String _tleName = null;
  46. /**
  47. * Value returned by the key
  48. */
  49. private String _tleValue = null;
  50. /**
  51. * Byte representaion of the name
  52. */
  53. private byte[] _tleByteName = null;
  54. /**
  55. * Byte representaion of the value
  56. */
  57. private byte[] _tleByteValue = null;
  58. /**
  59. * Construct a tag logical element with the name and value specified.
  60. * @param name the name of the tag logical element
  61. * @param value the value of the tag logical element
  62. */
  63. public TagLogicalElement(String name, String value) {
  64. _tleName = name;
  65. _tleValue = value;
  66. try {
  67. _tleByteName = name.getBytes(AFPConstants.EBCIDIC_ENCODING);
  68. _tleByteValue = value.getBytes(AFPConstants.EBCIDIC_ENCODING);
  69. } catch (UnsupportedEncodingException usee) {
  70. _tleByteName = name.getBytes();
  71. _tleByteValue = value.getBytes();
  72. log.warn(
  73. "Constructor:: UnsupportedEncodingException translating the name "
  74. + name);
  75. }
  76. }
  77. /**
  78. * Accessor method to obtain the byte array AFP datastream for the
  79. * TagLogicalElement.
  80. * @param os The outputsteam stream
  81. * @throws java.io.IOException
  82. */
  83. public void writeDataStream(OutputStream os) throws IOException {
  84. byte[] data = new byte[17 + _tleName.length() + _tleValue.length()];
  85. data[0] = 0x5A;
  86. // Set the total record length
  87. byte[] rl1 =
  88. BinaryUtils.convert(16 + _tleName.length() + _tleValue.length(), 2);
  89. //Ignore first byte
  90. data[1] = rl1[0];
  91. data[2] = rl1[1];
  92. // Structured field ID for a TLE
  93. data[3] = (byte) 0xD3;
  94. data[4] = (byte) 0xA0;
  95. data[5] = (byte) 0x90;
  96. data[6] = 0x00; // Reserved
  97. data[7] = 0x00; // Reserved
  98. data[8] = 0x00; // Reserved
  99. //Use 2 triplets, attrubute name and value (the key for indexing)
  100. byte[] rl2 = BinaryUtils.convert(_tleName.length() + 4, 1);
  101. data[9] = rl2[0]; // length of the triplet, including this field
  102. data[10] = 0x02; //Identifies it as a FQN triplet
  103. data[11] = 0x0B; // GID format
  104. data[12] = 0x00;
  105. int pos = 13;
  106. for (int i = 0; i < _tleByteName.length; i++) {
  107. data[pos++] = _tleByteName[i];
  108. }
  109. byte[] rl3 = BinaryUtils.convert(_tleByteValue.length + 4, 1);
  110. data[pos++] = rl3[0]; // length of the triplet, including this field
  111. data[pos++] = 0x36; //Identifies the triplet, attribute value
  112. data[pos++] = 0x00; // Reserved
  113. data[pos++] = 0x00; // Reserved
  114. for (int i = 0; i < _tleByteValue.length; i++) {
  115. data[pos++] = _tleByteValue[i];
  116. }
  117. os.write(data);
  118. }
  119. }