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.

ObjectClassificationTriplet.java 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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.triplets;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.apache.fop.afp.AFPConstants;
  22. import org.apache.fop.afp.modca.Registry.ObjectType;
  23. import org.apache.fop.afp.util.StringUtils;
  24. /**
  25. * The Object Classification is used to classify and identify object data.
  26. * The object data may or may not be defined by an IBM presentation architecture
  27. */
  28. public class ObjectClassificationTriplet extends AbstractTriplet {
  29. /**
  30. * The scope of this object is the including page or overlay
  31. */
  32. public static final byte CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT = 0x01;
  33. /**
  34. * The scope of this object is not defined
  35. */
  36. public static final byte CLASS_TIME_VARIANT_PRESENTATION_OBJECT = 0x10;
  37. /**
  38. * This is not a presentation object, the scope of this object is not defined
  39. */
  40. public static final byte CLASS_EXECUTABLE_PROGRAM = 0x20;
  41. /**
  42. * Setup information file, document level. This is not a presentation object,
  43. */
  44. public static final byte CLASS_SETUP_FILE = 0x30;
  45. /**
  46. * This is a resource used by a presentation object that may itself be a resource.
  47. * The scope of the resource is the object that uses the resource.
  48. */
  49. public static final byte CLASS_SECONDARY_RESOURCE = 0x40;
  50. /**
  51. * Data object font. This is a non-FOCA font resource used to present
  52. * text in a data object. The scope of the resource is the object that
  53. * uses the resource.
  54. */
  55. public static final byte CLASS_DATA_OBJECT_FONT = 0x41;
  56. /** the object class */
  57. private final byte objectClass;
  58. /** the object type */
  59. private final ObjectType objectType;
  60. /** whether the container has an object environment group */
  61. private final boolean containerHasOEG;
  62. /** whether the data resides within the container */
  63. private final boolean dataInContainer;
  64. /** whether the data resides within the object container data */
  65. private final boolean dataInOCD;
  66. /** the object level (version) */
  67. private final String objectLevel;
  68. /** the company/organization name */
  69. private final String companyName;
  70. /**
  71. * Main constructor
  72. *
  73. * @param objectClass the object class type
  74. * @param objectType the object type registry entry
  75. * @param dataInContainer whether the data resides in the container
  76. * @param containerHasOEG whether the container has an object environment group
  77. * @param dataInOCD whether the data resides in a object container data structured field
  78. */
  79. public ObjectClassificationTriplet(byte objectClass, ObjectType objectType,
  80. boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD) {
  81. // no object level or company name specified
  82. this(objectClass, objectType, dataInContainer, containerHasOEG, dataInOCD, null, null);
  83. }
  84. /**
  85. * Fully parameterized constructor
  86. *
  87. * @param objectClass the object class type
  88. * @param objectType the object type registry entry
  89. * @param dataInContainer whether the data resides in the container
  90. * @param containerHasOEG whether the container has an object environment group
  91. * @param dataInOCD whether the data resides in a object container data structured field
  92. * @param objLev the release level or version number of the object type
  93. * @param compName the name of the company or organization that owns the object definition
  94. */
  95. public ObjectClassificationTriplet(byte objectClass, ObjectType objectType,
  96. boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD,
  97. String objLev, String compName) {
  98. super(OBJECT_CLASSIFICATION);
  99. this.objectClass = objectClass;
  100. if (objectType == null) {
  101. throw new IllegalArgumentException("MO:DCA Registry object type is null");
  102. }
  103. this.objectType = objectType;
  104. this.dataInContainer = dataInContainer;
  105. this.containerHasOEG = containerHasOEG;
  106. this.dataInOCD = dataInOCD;
  107. this.objectLevel = objLev;
  108. this.companyName = compName;
  109. }
  110. /**
  111. * Returns the structured field flags
  112. *
  113. * @param dataInContainer true if the object data in carried in the object container
  114. * @param containerHasOEG true if the object container has an object environment group
  115. * @param dataInOCD true if the object container data carries the object data
  116. *
  117. * @return the byte value of this structure
  118. */
  119. public byte[] getStructureFlagsAsBytes(boolean dataInContainer, boolean containerHasOEG,
  120. boolean dataInOCD) {
  121. byte[] strucFlgs = new byte[2];
  122. // Object Container (BOC/EOC)
  123. if (dataInContainer) {
  124. strucFlgs[0] |= 3 << 6;
  125. } else {
  126. strucFlgs[0] |= 1 << 6;
  127. }
  128. // Object Environment Group (OEG)
  129. if (containerHasOEG) {
  130. strucFlgs[0] |= 3 << 4;
  131. } else {
  132. strucFlgs[0] |= 1 << 4;
  133. }
  134. // Object Container Data (OCD) structured fields
  135. if (dataInOCD) {
  136. strucFlgs[0] |= 3 << 2;
  137. } else {
  138. strucFlgs[0] |= 1 << 2;
  139. }
  140. strucFlgs[1] = 0x00;
  141. return strucFlgs;
  142. }
  143. /** {@inheritDoc} */
  144. public int getDataLength() {
  145. return 96;
  146. }
  147. private static final int OBJECT_LEVEL_LEN = 8;
  148. private static final int OBJECT_TYPE_NAME_LEN = 32;
  149. private static final int COMPANY_NAME_LEN = 32;
  150. /** {@inheritDoc} */
  151. public void writeToStream(OutputStream os) throws IOException {
  152. byte[] data = getData();
  153. data[2] = 0x00; // reserved (must be zero)
  154. data[3] = objectClass; // ObjClass
  155. data[4] = 0x00; // reserved (must be zero)
  156. data[5] = 0x00; // reserved (must be zero)
  157. // StrucFlgs - Information on the structure of the object container
  158. byte[] structureFlagsBytes
  159. = getStructureFlagsAsBytes(dataInContainer, containerHasOEG, dataInOCD);
  160. data[6] = structureFlagsBytes[0];
  161. data[7] = structureFlagsBytes[1];
  162. byte[] objectIdBytes = objectType.getOID();
  163. // RegObjId - MOD:CA-registered ASN.1 OID for object type (8-23)
  164. System.arraycopy(objectIdBytes, 0, data, 8, objectIdBytes.length);
  165. // ObjTpName - name of object type (24-55)
  166. byte[] objectTypeNameBytes;
  167. objectTypeNameBytes
  168. = StringUtils.rpad(objectType.getName(), ' ', OBJECT_TYPE_NAME_LEN).getBytes(
  169. AFPConstants.EBCIDIC_ENCODING);
  170. System.arraycopy(objectTypeNameBytes, 0, data, 24, objectTypeNameBytes.length);
  171. // ObjLev - release level or version number of object type (56-63)
  172. byte[] objectLevelBytes;
  173. objectLevelBytes = StringUtils.rpad(objectLevel, ' ', OBJECT_LEVEL_LEN).getBytes(
  174. AFPConstants.EBCIDIC_ENCODING);
  175. System.arraycopy(objectLevelBytes, 0, data, 56, objectLevelBytes.length);
  176. // CompName - name of company or organization that owns object definition (64-95)
  177. byte[] companyNameBytes;
  178. companyNameBytes = StringUtils.rpad(companyName, ' ', COMPANY_NAME_LEN).getBytes(
  179. AFPConstants.EBCIDIC_ENCODING);
  180. System.arraycopy(companyNameBytes, 0, data, 64, companyNameBytes.length);
  181. os.write(data);
  182. }
  183. }