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.

AFPResourceLevel.java 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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;
  19. /**
  20. * A resource level
  21. */
  22. public class AFPResourceLevel {
  23. /** directly in page **/
  24. public static final int INLINE = 0;
  25. /** page level **/
  26. public static final int PAGE = 1;
  27. /** page group level **/
  28. public static final int PAGE_GROUP = 2;
  29. /** document level **/
  30. public static final int DOCUMENT = 3;
  31. /** print file level **/
  32. public static final int PRINT_FILE = 4;
  33. /** external level **/
  34. public static final int EXTERNAL = 5;
  35. private static final String NAME_INLINE = "inline";
  36. private static final String NAME_PAGE = "page";
  37. private static final String NAME_PAGE_GROUP = "page-group";
  38. private static final String NAME_DOCUMENT = "document";
  39. private static final String NAME_PRINT_FILE = "print-file";
  40. private static final String NAME_EXTERNAL = "external";
  41. private static final String[] NAMES = new String[] {
  42. NAME_INLINE, NAME_PAGE, NAME_PAGE_GROUP, NAME_DOCUMENT, NAME_PRINT_FILE, NAME_EXTERNAL
  43. };
  44. /** where the resource will reside in the AFP output */
  45. private int level = PRINT_FILE; // default is print-file level (images)
  46. /** the external resource group file path */
  47. private String extFilePath = null;
  48. /**
  49. * Sets the resource placement level within the AFP output
  50. *
  51. * @param levelString the resource level (page, page-group, document, print-file or external)
  52. * @return true if the resource level was successfully set
  53. */
  54. public static AFPResourceLevel valueOf(String levelString) {
  55. if (levelString != null) {
  56. levelString = levelString.toLowerCase();
  57. AFPResourceLevel resourceLevel = null;
  58. for (int i = 0; i < NAMES.length; i++) {
  59. if (NAMES[i].equals(levelString)) {
  60. resourceLevel = new AFPResourceLevel(i);
  61. break;
  62. }
  63. }
  64. return resourceLevel;
  65. }
  66. return null;
  67. }
  68. /**
  69. * Main constructor
  70. *
  71. * @param level the resource level
  72. */
  73. public AFPResourceLevel(int level) {
  74. setLevel(level);
  75. }
  76. /**
  77. * Sets the resource level
  78. *
  79. * @param level the resource level
  80. */
  81. public void setLevel(int level) {
  82. this.level = level;
  83. }
  84. /**
  85. * Returns true if this is at page level
  86. *
  87. * @return true if this is at page level
  88. */
  89. public boolean isPage() {
  90. return level == PAGE;
  91. }
  92. /**
  93. * Returns true if this is at page group level
  94. *
  95. * @return true if this is at page group level
  96. */
  97. public boolean isPageGroup() {
  98. return level == PAGE_GROUP;
  99. }
  100. /**
  101. * Returns true if this is at document level
  102. *
  103. * @return true if this is at document level
  104. */
  105. public boolean isDocument() {
  106. return level == DOCUMENT;
  107. }
  108. /**
  109. * Returns true if this is at external level
  110. *
  111. * @return true if this is at external level
  112. */
  113. public boolean isExternal() {
  114. return level == EXTERNAL;
  115. }
  116. /**
  117. * Returns true if this is at print-file level
  118. *
  119. * @return true if this is at print-file level
  120. */
  121. public boolean isPrintFile() {
  122. return level == PRINT_FILE;
  123. }
  124. /**
  125. * Returns true if this resource level is inline
  126. *
  127. * @return true if this resource level is inline
  128. */
  129. public boolean isInline() {
  130. return level == INLINE;
  131. }
  132. /**
  133. * Returns the destination file path of the external resource group file
  134. *
  135. * @return the destination file path of the external resource group file
  136. */
  137. public String getExternalFilePath() {
  138. return this.extFilePath;
  139. }
  140. /**
  141. * Sets the external destination of the resource
  142. *
  143. * @param filePath the external resource group file
  144. */
  145. public void setExternalFilePath(String filePath) {
  146. this.extFilePath = filePath;
  147. }
  148. /** {@inheritDoc} */
  149. public String toString() {
  150. return NAMES[level] + (isExternal() ? ", file=" + extFilePath : "");
  151. }
  152. /** {@inheritDoc} */
  153. public boolean equals(Object obj) {
  154. if (this == obj) {
  155. return true;
  156. }
  157. if ((obj == null) || !(obj instanceof AFPResourceLevel)) {
  158. return false;
  159. }
  160. AFPResourceLevel rl = (AFPResourceLevel)obj;
  161. return (level == level)
  162. && (extFilePath == rl.extFilePath
  163. || extFilePath != null && extFilePath.equals(rl.extFilePath));
  164. }
  165. /** {@inheritDoc} */
  166. public int hashCode() {
  167. int hash = 7;
  168. hash = 31 * hash + level;
  169. hash = 31 * hash + (null == extFilePath ? 0 : extFilePath.hashCode());
  170. return hash;
  171. }
  172. }