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.

PDFAMode.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.pdf;
  19. /** Enum class for PDF/A modes. */
  20. public enum PDFAMode {
  21. /** PDF/A disabled. */
  22. DISABLED("PDF/A disabled"),
  23. /** PDF/A-1a enabled. */
  24. PDFA_1A(1, 'A'),
  25. /** PDF/A-1b enabled. */
  26. PDFA_1B(1, 'B'),
  27. /** PDF/A-2a enabled. */
  28. PDFA_2A(2, 'A'),
  29. /** PDF/A-2b enabled. */
  30. PDFA_2B(2, 'B'),
  31. /** PDF/A-2u enabled. */
  32. PDFA_2U(2, 'U'),
  33. PDFA_3A(3, 'A'),
  34. PDFA_3B(3, 'B'),
  35. PDFA_3U(3, 'U');
  36. private final String name;
  37. private final int part;
  38. private final char level;
  39. /**
  40. * Constructor to add a new named item.
  41. * @param name Name of the item.
  42. */
  43. private PDFAMode(String name) {
  44. this.name = name;
  45. this.part = 0;
  46. this.level = 0;
  47. }
  48. private PDFAMode(int part, char level) {
  49. this.name = "PDF/A-" + part + Character.toLowerCase(level);
  50. this.part = part;
  51. this.level = level;
  52. }
  53. /** @return the name of the enum */
  54. public String getName() {
  55. return this.name;
  56. }
  57. /**
  58. * Returns {@code true} if this enum corresponds to one of the available PDF/A modes.
  59. *
  60. * @return {@code true} if this is not DISABLED
  61. */
  62. public boolean isEnabled() {
  63. return this != DISABLED;
  64. }
  65. /**
  66. * Returns the part of the specification this enum corresponds to.
  67. *
  68. * @return 1 for PDF/A-1 (ISO 19005-1), 2 for PDF/A-2 (ISO 19005-2)
  69. */
  70. public int getPart() {
  71. return part;
  72. }
  73. /**
  74. * Returns {@code true} if this enum corresponds to PDF/A-1 (ISO 19005-1).
  75. */
  76. public boolean isPart1() {
  77. return part == 1;
  78. }
  79. /**
  80. * Returns {@code true} if this enum corresponds to PDF/A-2 (ISO 19005-2).
  81. */
  82. public boolean isPart2() {
  83. return part == 1 || part == 2;
  84. }
  85. /**
  86. * Returns the conformance level for this enum.
  87. *
  88. * @return 'A', 'B' or 'U'
  89. */
  90. public char getConformanceLevel() {
  91. return level;
  92. }
  93. /**
  94. * Returns {@code true} if this enum corresponds to conformance level A.
  95. */
  96. public boolean isLevelA() {
  97. return level == 'A';
  98. }
  99. /**
  100. * Returns the mode enum object given a String.
  101. * @param s the string
  102. * @return the PDFAMode enum object (DISABLED will be returned if no match is found)
  103. */
  104. public static PDFAMode getValueOf(String s) {
  105. for (PDFAMode mode : values()) {
  106. if (mode.name.equalsIgnoreCase(s)) {
  107. return mode;
  108. }
  109. }
  110. return DISABLED;
  111. }
  112. /** {@inheritDoc} */
  113. public String toString() {
  114. return name;
  115. }
  116. }