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.

ResourceObject.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.ResourceObjectTypeTriplet;
  22. import org.apache.fop.afp.util.BinaryUtils;
  23. /**
  24. * This resource structured field begins an envelope that is used to carry
  25. * resource objects in print-file-level (external) resource groups.
  26. */
  27. public class ResourceObject extends AbstractNamedAFPObject {
  28. /** graphics object type */
  29. public static final byte TYPE_GRAPHIC = 0x03;
  30. /** barcode object type */
  31. public static final byte TYPE_BARCODE = 0x05;
  32. /** image object type */
  33. public static final byte TYPE_IMAGE = 0x06;
  34. /** font character set type */
  35. public static final byte TYPE_FONT_CHARACTER_SET = 0x40;
  36. /** code page type */
  37. public static final byte TYPE_CODE_PAGE = 0x41;
  38. /** coded font type */
  39. public static final byte TYPE_CODED_FONT = 0x42;
  40. /** object container type */
  41. public static final byte TYPE_OBJECT_CONTAINER = (byte) 0x92;
  42. /** document object type */
  43. public static final byte TYPE_DOCUMENT = (byte) 0xA8;
  44. /** page segment object type */
  45. public static final byte TYPE_PAGE_SEGMENT = (byte) 0xFB;
  46. /** overlay object type */
  47. public static final byte TYPE_OVERLAY_OBJECT = (byte) 0xFC;
  48. /** page def type */
  49. public static final byte TYPE_PAGEDEF = (byte) 0xFD;
  50. /** form def type */
  51. public static final byte TYPE_FORMDEF = (byte) 0xFE;
  52. private AbstractNamedAFPObject namedObject;
  53. /**
  54. * Default constructor
  55. *
  56. * @param name the name of this resource (reference id)
  57. */
  58. public ResourceObject(String name) {
  59. super(name);
  60. }
  61. /**
  62. * Sets the data object referenced by this resource object
  63. *
  64. * @param namedObject the named data object
  65. */
  66. public void setDataObject(AbstractNamedAFPObject namedObject) {
  67. this.namedObject = namedObject;
  68. }
  69. /**
  70. * Returns the data object referenced by this resource object
  71. *
  72. * @return the data object referenced by this resource object
  73. */
  74. public AbstractNamedAFPObject getDataObject() {
  75. return namedObject;
  76. }
  77. /** {@inheritDoc} */
  78. protected void writeStart(OutputStream os) throws IOException {
  79. super.writeStart(os);
  80. byte[] data = new byte[19];
  81. copySF(data, Type.BEGIN, Category.NAME_RESOURCE);
  82. // Set the total record length
  83. int tripletDataLength = getTripletDataLength();
  84. byte[] len = BinaryUtils.convert(18 + tripletDataLength, 2);
  85. data[1] = len[0]; // Length byte 1
  86. data[2] = len[1]; // Length byte 2
  87. // Set reserved bits
  88. data[17] = 0x00; // Reserved
  89. data[18] = 0x00; // Reserved
  90. os.write(data);
  91. // Write triplets
  92. writeTriplets(os);
  93. }
  94. /** {@inheritDoc} */
  95. protected void writeContent(OutputStream os) throws IOException {
  96. if (namedObject != null) {
  97. namedObject.writeToStream(os);
  98. }
  99. }
  100. /** {@inheritDoc} */
  101. protected void writeEnd(OutputStream os) throws IOException {
  102. byte[] data = new byte[17];
  103. copySF(data, Type.END, Category.NAME_RESOURCE);
  104. os.write(data);
  105. }
  106. /** {@inheritDoc} */
  107. public String toString() {
  108. return this.getName();
  109. }
  110. /**
  111. * Sets Resource Object Type triplet
  112. *
  113. * @param type the resource object type
  114. */
  115. public void setType(byte type) {
  116. getTriplets().add(new ResourceObjectTypeTriplet(type));
  117. }
  118. }