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