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 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.EncodingTriplet;
  24. import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet;
  25. import org.apache.fop.afp.util.BinaryUtils;
  26. /**
  27. * A Tag Logical Element structured field assigns an attribute name and an
  28. * attribute value to a page or page group. The Tag Logical Element structured
  29. * field may be embedded directly in the page or page group, or it may reference
  30. * the page or page group from a document index. When a Tag Logical Element
  31. * structured field references a page or is embedded in a page following the
  32. * active environment group, it is associated with the page. When a Tag Logical
  33. * Element structured field references a page group or is embedded in a page
  34. * group following the Begin Named Page Group structured field, it is associated
  35. * with the page group. When a Tag Logical Element structured field is associated
  36. * with a page group, the parameters of the Tag Logical Element structured field
  37. * are inherited by all pages in the page group and by all other page groups
  38. * that are nested in the page group. The scope of a Tag Logical Element is
  39. * determined by its position with respect to other TLEs that reference, or are
  40. * embedded in, the same page or page group. The Tag Logical Element structured
  41. * field does not provide any presentation specifications and therefore has no
  42. * effect on the appearance of a document when it is presented.
  43. * <p/>
  44. */
  45. public class TagLogicalElement extends AbstractTripletStructuredObject {
  46. /**
  47. * the params of the TLE
  48. */
  49. private State state;
  50. /**
  51. * Construct a tag logical element with the name and value specified.
  52. *
  53. * @param state the state of the tag logical element
  54. */
  55. public TagLogicalElement(State state) {
  56. this.state = state;
  57. }
  58. private void setAttributeValue(String value) {
  59. addTriplet(new AttributeValueTriplet(value));
  60. }
  61. private void setEncoding(int encoding) {
  62. if (encoding != State.ENCODING_NONE) {
  63. addTriplet(new EncodingTriplet(encoding));
  64. }
  65. }
  66. /**
  67. * Sets the attribute qualifier of this structured field
  68. *
  69. * @param seqNumber the attribute sequence number
  70. * @param levNumber the attribute level number
  71. */
  72. public void setAttributeQualifier(int seqNumber, int levNumber) {
  73. addTriplet(new AttributeQualifierTriplet(seqNumber, levNumber));
  74. }
  75. /** {@inheritDoc} */
  76. public void writeToStream(OutputStream os) throws IOException {
  77. setFullyQualifiedName(
  78. FullyQualifiedNameTriplet.TYPE_ATTRIBUTE_GID,
  79. FullyQualifiedNameTriplet.FORMAT_CHARSTR,
  80. state.key);
  81. setAttributeValue(state.value);
  82. setEncoding(state.encoding);
  83. byte[] data = new byte[SF_HEADER_LENGTH];
  84. copySF(data, Type.ATTRIBUTE, Category.PROCESS_ELEMENT);
  85. int tripletDataLength = getTripletDataLength();
  86. byte[] l = BinaryUtils.convert(data.length + tripletDataLength - 1, 2);
  87. data[1] = l[0];
  88. data[2] = l[1];
  89. os.write(data);
  90. writeTriplets(os);
  91. }
  92. /**
  93. *
  94. * Holds the attribute state of a TLE
  95. *
  96. */
  97. public static class State {
  98. /**
  99. * value interpreted as no encoding
  100. */
  101. public static final int ENCODING_NONE = -1;
  102. /** The key attribute */
  103. private String key;
  104. /** The value attribute */
  105. private String value;
  106. /** The CCSID character et encoding attribute */
  107. private int encoding = ENCODING_NONE;
  108. /**
  109. * Constructor
  110. *
  111. * @param key the key attribute
  112. * @param value the value attribute
  113. */
  114. public State(String key, String value) {
  115. this.key = key;
  116. this.value = value;
  117. }
  118. /**
  119. *
  120. * @param key the key attribute
  121. * @param value the value attribute
  122. * @param encoding the CCSID character set encoding attribute
  123. */
  124. public State(String key, String value, int encoding) {
  125. this.key = key;
  126. this.value = value;
  127. this.encoding = encoding;
  128. }
  129. }
  130. }