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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. /* $Id$ */
  18. package org.apache.fop.afp.modca;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.apache.fop.afp.modca.triplets.AttributeQualifierTriplet;
  22. import org.apache.fop.afp.modca.triplets.AttributeValueTriplet;
  23. import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet;
  24. import org.apache.fop.afp.util.BinaryUtils;
  25. /**
  26. * A Tag Logical Element structured field assigns an attribute name and an
  27. * attribute value to a page or page group. The Tag Logical Element structured
  28. * field may be embedded directly in the page or page group, or it may reference
  29. * the page or page group from a document index. When a Tag Logical Element
  30. * structured field references a page or is embedded in a page following the
  31. * active environment group, it is associated with the page. When a Tag Logical
  32. * Element structured field references a page group or is embedded in a page
  33. * group following the Begin Named Page Group structured field, it is associated
  34. * with the page group. When a Tag Logical Element structured field is associated
  35. * with a page group, the parameters of the Tag Logical Element structured field
  36. * are inherited by all pages in the page group and by all other page groups
  37. * that are nested in the page group. The scope of a Tag Logical Element is
  38. * determined by its position with respect to other TLEs that reference, or are
  39. * embedded in, the same page or page group. The Tag Logical Element structured
  40. * field does not provide any presentation specifications and therefore has no
  41. * effect on the appearance of a document when it is presented.
  42. * <p/>
  43. */
  44. public class TagLogicalElement extends AbstractTripletStructuredObject {
  45. /**
  46. * Name of the key, used within the TLE
  47. */
  48. private String name = null;
  49. /**
  50. * Value returned by the key
  51. */
  52. private String value = null;
  53. /**
  54. * Sequence of TLE within document
  55. */
  56. private int tleID;
  57. /**
  58. * Construct a tag logical element with the name and value specified.
  59. *
  60. * @param name the name of the tag logical element
  61. * @param value the value of the tag logical element
  62. * @param tleID unique identifier for TLE within AFP stream
  63. */
  64. public TagLogicalElement(String name, String value, int tleID) {
  65. this.name = name;
  66. this.value = value;
  67. this.tleID = tleID;
  68. }
  69. /**
  70. * Sets the attribute value of this structured field
  71. *
  72. * @param value the attribute value
  73. */
  74. public void setAttributeValue(String value) {
  75. addTriplet(new AttributeValueTriplet(value));
  76. }
  77. /**
  78. * Sets the attribute qualifier of this structured field
  79. *
  80. * @param seqNumber the attribute sequence number
  81. * @param levNumber the attribute level number
  82. */
  83. public void setAttributeQualifier(int seqNumber, int levNumber) {
  84. addTriplet(new AttributeQualifierTriplet(seqNumber, levNumber));
  85. }
  86. /** {@inheritDoc} */
  87. public void writeToStream(OutputStream os) throws IOException {
  88. setFullyQualifiedName(
  89. FullyQualifiedNameTriplet.TYPE_ATTRIBUTE_GID,
  90. FullyQualifiedNameTriplet.FORMAT_CHARSTR,
  91. name);
  92. setAttributeValue(value);
  93. setAttributeQualifier(tleID, 1);
  94. byte[] data = new byte[SF_HEADER.length];
  95. copySF(data, Type.ATTRIBUTE, Category.PROCESS_ELEMENT);
  96. int tripletDataLength = getTripletDataLength();
  97. byte[] l = BinaryUtils.convert(data.length + tripletDataLength - 1, 2);
  98. data[1] = l[0];
  99. data[2] = l[1];
  100. os.write(data);
  101. writeTriplets(os);
  102. }
  103. }