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.

Registry.java 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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.util.Collections;
  20. import java.util.HashMap;
  21. import org.apache.xmlgraphics.util.MimeConstants;
  22. /**
  23. * MOD:CA Registry of object types
  24. */
  25. public final class Registry {
  26. /** IOB supported object types */
  27. private static final byte COMPID_IOCA_FS10 = 5;
  28. private static final byte COMPID_IOCA_FS11 = 11;
  29. private static final byte COMPID_IOCA_FS40 = 55;
  30. private static final byte COMPID_IOCA_FS45 = 12;
  31. private static final byte COMPID_EPS = 13;
  32. private static final byte COMPID_TIFF = 14;
  33. private static final byte COMPID_GIF = 22;
  34. private static final byte COMPID_JFIF = 23; // jpeg file interchange format
  35. private static final byte COMPID_PDF_SINGLE_PAGE = 25;
  36. private static final byte COMPID_PCL_PAGE_OBJECT = 34;
  37. private static final byte COMPID_TRUETYPE_OPENTYPE_FONT_RESOURCE_OBJECT = 51;
  38. private static final byte COMPID_TRUETYPE_OPENTYPE_FONT_COLLECTION_RESOURCE_OBJECT = 53;
  39. /** mime type entry mapping */
  40. private final java.util.Map<String, ObjectType> mimeObjectTypeMap
  41. = Collections.synchronizedMap(new HashMap<String, ObjectType>());
  42. /** singleton instance */
  43. private static Registry instance;
  44. /**
  45. * Returns a single instance of a MO:DCA Registry
  46. *
  47. * @return a single instance of an MO:DCA Registry
  48. */
  49. public static Registry getInstance() {
  50. synchronized (Registry.class) {
  51. if (instance == null) {
  52. instance = new Registry();
  53. }
  54. }
  55. return instance;
  56. }
  57. /**
  58. * private constructor
  59. */
  60. private Registry() {
  61. init();
  62. }
  63. /**
  64. * Initializes the mimetype map
  65. */
  66. private void init() {
  67. mimeObjectTypeMap.put(
  68. MimeConstants.MIME_AFP_IOCA_FS10,
  69. new ObjectType(
  70. COMPID_IOCA_FS10,
  71. new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x05},
  72. "IOCA FS10",
  73. true,
  74. MimeConstants.MIME_AFP_IOCA_FS10
  75. )
  76. );
  77. mimeObjectTypeMap.put(
  78. MimeConstants.MIME_AFP_IOCA_FS11,
  79. new ObjectType(
  80. COMPID_IOCA_FS11,
  81. new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x11},
  82. "IOCA FS11",
  83. true,
  84. MimeConstants.MIME_AFP_IOCA_FS11
  85. )
  86. );
  87. // mimeObjectTypeMap.put(
  88. // MimeConstants.MIME_AFP_IOCA_FS40,
  89. // new ObjectType(
  90. // COMPID_IOCA_FS40,
  91. // new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x37},
  92. // "IOCA FS40",
  93. // true,
  94. // MimeConstants.MIME_AFP_IOCA_FS40
  95. // )
  96. //);
  97. mimeObjectTypeMap.put(
  98. MimeConstants.MIME_AFP_IOCA_FS45,
  99. new ObjectType(
  100. COMPID_IOCA_FS45,
  101. new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x12},
  102. "IOCA FS45",
  103. true,
  104. MimeConstants.MIME_AFP_IOCA_FS45
  105. )
  106. );
  107. mimeObjectTypeMap.put(
  108. MimeConstants.MIME_EPS,
  109. new ObjectType(
  110. COMPID_EPS,
  111. new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x0D},
  112. "Encapsulated Postscript",
  113. true,
  114. MimeConstants.MIME_EPS
  115. )
  116. );
  117. mimeObjectTypeMap.put(
  118. MimeConstants.MIME_TIFF,
  119. new ObjectType(
  120. COMPID_TIFF,
  121. new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x0E},
  122. "TIFF",
  123. true,
  124. MimeConstants.MIME_TIFF
  125. )
  126. );
  127. mimeObjectTypeMap.put(
  128. MimeConstants.MIME_GIF,
  129. new ObjectType(
  130. COMPID_GIF,
  131. new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x16},
  132. "GIF",
  133. true,
  134. MimeConstants.MIME_GIF
  135. )
  136. );
  137. mimeObjectTypeMap.put(
  138. MimeConstants.MIME_JPEG,
  139. new ObjectType(
  140. COMPID_JFIF,
  141. new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x17},
  142. "JFIF",
  143. true,
  144. MimeConstants.MIME_JPEG
  145. )
  146. );
  147. mimeObjectTypeMap.put(MimeConstants.MIME_PDF,
  148. new ObjectType(
  149. COMPID_PDF_SINGLE_PAGE,
  150. new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x19},
  151. "PDF Single-page Object",
  152. true,
  153. MimeConstants.MIME_PDF
  154. )
  155. );
  156. mimeObjectTypeMap.put(
  157. MimeConstants.MIME_PCL,
  158. new ObjectType(
  159. COMPID_PCL_PAGE_OBJECT,
  160. new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x22},
  161. "PCL Page Object",
  162. true,
  163. MimeConstants.MIME_PCL
  164. )
  165. );
  166. // mimeObjectTypeMap.put(
  167. // null,
  168. // new ObjectType(
  169. // COMPID_TRUETYPE_OPENTYPE_FONT_RESOURCE_OBJECT,
  170. // new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x33},
  171. // "TrueType/OpenType Font Resource Object",
  172. // true,
  173. // null
  174. // )
  175. // );
  176. // mimeObjectTypeMap.put(
  177. // null,
  178. // new ObjectType(
  179. // COMPID_TRUETYPE_OPENTYPE_FONT_COLLECTION_RESOURCE_OBJECT,
  180. // new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x35},
  181. // "TrueType/OpenType Font Collection Resource Object",
  182. // true,
  183. // null
  184. // )
  185. // );
  186. }
  187. /**
  188. * Returns the MOD:CA object type given a mimetype
  189. *
  190. * @param mimeType the object mimetype
  191. * @return the MOD:CA object type
  192. */
  193. public ObjectType getObjectType(String mimeType) {
  194. return mimeObjectTypeMap.get(mimeType);
  195. }
  196. /**
  197. * Encapsulates a MOD:CA Registry Object Type entry
  198. */
  199. public class ObjectType {
  200. private final byte componentId;
  201. private final byte[] oid;
  202. private final String name;
  203. private final boolean includable;
  204. private final String mimeType;
  205. /**
  206. * Main constructor
  207. *
  208. * @param componentId the component id of this object type
  209. * @param oid the object id of this object type
  210. * @param name the object type name
  211. * @param includable true if this object can be included with an IOB structured field
  212. * @param mimeType the mime type associated with this object type
  213. */
  214. public ObjectType(byte componentId, byte[] oid, String name,
  215. boolean includable, String mimeType) {
  216. this.componentId = componentId;
  217. this.oid = oid;
  218. this.name = name;
  219. this.includable = includable;
  220. this.mimeType = mimeType;
  221. }
  222. /**
  223. * Returns a MOD:CA object type OID from a given a componentId
  224. *
  225. * @return the corresponding object type id for a given component id
  226. * or null if the component id is unknown and the object type OID was not found.
  227. */
  228. public byte[] getOID() {
  229. return this.oid;
  230. }
  231. /**
  232. * Returns the object type name for the given componentId
  233. *
  234. * @return the object type name for the given componentId
  235. */
  236. public String getName() {
  237. return this.name;
  238. }
  239. /**
  240. * Returns the compontentId for this entry
  241. *
  242. * @return the compontentId for this entry
  243. */
  244. public byte getComponentId() {
  245. return this.componentId;
  246. }
  247. /**
  248. * Returns true if this component can be included with an IOB structured field
  249. *
  250. * @return true if this component can be included with an IOB structured field
  251. */
  252. public boolean isIncludable() {
  253. return this.includable;
  254. }
  255. /**
  256. * Returns the mime type associated with this object type
  257. *
  258. * @return the mime type associated with this object type
  259. */
  260. public String getMimeType() {
  261. return this.mimeType;
  262. }
  263. /** {@inheritDoc} */
  264. public String toString() {
  265. return this.getName();
  266. }
  267. }
  268. }