Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

AFPResourceLevel.java 5.4KB

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