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.

FullyQualifiedNameTriplet.java 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 java.io.UnsupportedEncodingException;
  22. import org.apache.fop.afp.AFPConstants;
  23. /**
  24. * A Fully Qualified Name triplet enable the identification and referencing of
  25. * objects using Gloabl Identifiers (GIDs).
  26. */
  27. public class FullyQualifiedNameTriplet extends AbstractTriplet {
  28. // Specifies how the GID will be used
  29. /** This GID replaces the first parameter in the structured field that contains a GID name. */
  30. public static final byte TYPE_REPLACE_FIRST_GID_NAME = 0x01;
  31. /** This triplet contains the name of a font family. */
  32. public static final byte TYPE_FONT_FAMILY_NAME = 0x07;
  33. /** This triplet contains the name of a font typeface. */
  34. public static final byte TYPE_FONT_TYPEFACE_NAME = 0x08;
  35. /** This triplet specifies a reference to the MO:DCA resource hierarchy. */
  36. public static final byte TYPE_MODCA_RESOURCE_HIERARCHY_REF = 0x09;
  37. /** The triplet contains a GID reference to a begin resource group structured field. */
  38. public static final byte TYPE_BEGIN_RESOURCE_GROUP_REF = 0x0A;
  39. /** The triplet contains a GID reference to a document attribute. */
  40. public static final byte TYPE_ATTRIBUTE_GID = 0x0B;
  41. /** The triplet contains the GID of a process element. */
  42. public static final byte TYPE_PROCESS_ELEMENT_GID = 0x0C;
  43. /** The triplet contains a reference to a begin page group structured field. */
  44. public static final byte TYPE_BEGIN_PAGE_GROUP_REF = 0x0D;
  45. /** The triplet contains a reference to a media type. */
  46. public static final byte TYPE_MEDIA_TYPE_REF = 0x11;
  47. /** The triplet contains a reference to a color management resource. */
  48. public static final byte TYPE_COLOR_MANAGEMENT_RESOURCE_REF = 0x41;
  49. /** The triplet contains a reference to a data-object font file that defines a base font. */
  50. public static final byte TYPE_DATA_OBJECT_FONT_BASE_FONT_ID = 0x6E;
  51. /** The triplet contains a reference to a data-object font file that defines a linked font. */
  52. public static final byte TYPE_DATA_OBJECT_FONT_LINKED_FONT_ID = 0x7E;
  53. /** The triplet contains a reference to a begin document structured field. */
  54. public static final byte TYPE_BEGIN_DOCUMENT_REF = (byte)0x83;
  55. /**
  56. * The triplet contains a reference to a begin structured field associated with a resource;
  57. * or contains a GID reference to a coded font.
  58. */
  59. public static final byte TYPE_BEGIN_RESOURCE_OBJECT_REF = (byte)0x84;
  60. /**
  61. * The triplet contains a GID reference to a code page that specifies the code points and
  62. * graphic character names for a coded font.
  63. */
  64. public static final byte TYPE_CODE_PAGE_NAME_REF = (byte)0x85;
  65. /**
  66. * The triplet contains a GID name reference to a font character set that specifies
  67. * a set of graphics characters.
  68. */
  69. public static final byte TYPE_FONT_CHARSET_NAME_REF = (byte)0x86;
  70. /** The triplet contains a GID reference to a begin page structured field. */
  71. public static final byte TYPE_BEGIN_PAGE_REF = (byte)0x87;
  72. /** The triplet contains a GID reference to a begin medium map structured field. */
  73. public static final byte TYPE_BEGIN_MEDIUM_MAP_REF = (byte)0x8D;
  74. /**
  75. * The triplet contains a GID reference to a coded font, which identifies a specific
  76. * code page and a specific font character set.
  77. */
  78. public static final byte TYPE_CODED_FONT_NAME_REF = (byte)0x8E;
  79. /** The triplet contains a GID reference to a begin document index structured field. */
  80. public static final byte TYPE_BEGIN_DOCUMENT_INDEX_REF = (byte)0x98;
  81. /** The triplet contains a GID reference to a begin overlay structured field. */
  82. public static final byte TYPE_BEGIN_OVERLAY_REF = (byte)0xB0;
  83. /** The triplet contains a GID reference to a resource used by a data object. */
  84. public static final byte TYPE_DATA_OBJECT_INTERNAL_RESOURCE_REF = (byte)0xBE;
  85. /** The triplet contains a GID reference to an index element structured field. */
  86. public static final byte TYPE_INDEX_ELEMENT_GID = (byte)0xCA;
  87. /**
  88. * The triplet contains a reference to other object data which may or may
  89. * not be defined by an IBM presentation architecture.
  90. */
  91. public static final byte TYPE_OTHER_OBJECT_DATA_REF = (byte)0xCE;
  92. /**
  93. * The triplet contains a reference to a resource used by a data object.
  94. * The GID may be a filename or any other identifier associated with the
  95. * resource and is used to located the resource object in the resource hierarchy.
  96. * The data object that uses the resource may or may not be defined by an
  97. * IBM presentation architecture.
  98. */
  99. public static final byte TYPE_DATA_OBJECT_EXTERNAL_RESOURCE_REF = (byte)0xDE;
  100. // GID Format
  101. /** The GID is a character encoded name. */
  102. public static final byte FORMAT_CHARSTR = (byte)0x00;
  103. /** the GID is a ASN.1 object identifier (OID). */
  104. public static final byte FORMAT_OID = (byte)0x10;
  105. /** the GID is a uniform resource locator (URL). */
  106. public static final byte FORMAT_URL = (byte)0x20;
  107. /** the fully qualified name type */
  108. private final byte type;
  109. /** the fully qualified name format */
  110. private final byte format;
  111. /** the actual fully qualified name */
  112. private final String fqName;
  113. /**
  114. * Main constructor
  115. *
  116. * @param type the fully qualified name type
  117. * @param format the fully qualified name format
  118. * @param fqName the fully qualified name
  119. */
  120. public FullyQualifiedNameTriplet(byte type, byte format, String fqName) {
  121. super(FULLY_QUALIFIED_NAME);
  122. this.type = type;
  123. this.format = format;
  124. this.fqName = fqName;
  125. }
  126. /**
  127. * Returns the actual fully qualified name
  128. *
  129. * @return the actual fully qualified name
  130. */
  131. public String getFullyQualifiedName() {
  132. return fqName;
  133. }
  134. /** {@inheritDoc} */
  135. public String toString() {
  136. return this.fqName;
  137. }
  138. /** {@inheritDoc} */
  139. public int getDataLength() {
  140. return 4 + fqName.length();
  141. }
  142. /** {@inheritDoc} */
  143. public void writeToStream(OutputStream os) throws IOException {
  144. byte[] data = getData();
  145. data[2] = type;
  146. data[3] = format;
  147. // FQName
  148. byte[] fqNameBytes;
  149. String encoding = AFPConstants.EBCIDIC_ENCODING;
  150. if (format == FORMAT_URL) {
  151. encoding = AFPConstants.US_ASCII_ENCODING;
  152. }
  153. try {
  154. fqNameBytes = fqName.getBytes(encoding);
  155. } catch (UnsupportedEncodingException e) {
  156. throw new IllegalArgumentException(
  157. encoding + " encoding failed");
  158. }
  159. System.arraycopy(fqNameBytes, 0, data, 4, fqNameBytes.length);
  160. os.write(data);
  161. }
  162. }