| XMLFeature.java |
1 /**
2 * Distribution License:
3 * JSword is free software; you can redistribute it and/or modify it under
4 * the terms of the GNU Lesser General Public License, version 2.1 or later
5 * as published by the Free Software Foundation. This program is distributed
6 * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
7 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 * See the GNU Lesser General Public License for more details.
9 *
10 * The License is available on the internet at:
11 * http://www.gnu.org/copyleft/lgpl.html
12 * or by writing to:
13 * Free Software Foundation, Inc.
14 * 59 Temple Place - Suite 330
15 * Boston, MA 02111-1307, USA
16 *
17 * © CrossWire Bible Society, 2005 - 2016
18 *
19 */
20 package org.crosswire.common.xml;
21
22
23 /**
24 * Wraps an XML Feature. The "known" set of XML Features is found in
25 * XMLFeatureSet.
26 *
27 * @see gnu.lgpl.License The GNU Lesser General Public License for details.
28 * @author DM Smith
29 */
30 public enum XMLFeature {
31 /** Namespaces feature id */
32 NAMESPACES("http://xml.org/sax/features/namespaces"),
33
34 /** Namespace prefixes feature id */
35 NAMESPACE_PREFIX("http://xml.org/sax/features/namespace-prefixes"),
36
37 /** Validation feature id */
38 VALIDATION("http://xml.org/sax/features/validation"),
39
40 /** Schema validation feature id */
41 SCHEMA_VALIDATION("http://apache.org/xml/features/validation/schema"),
42
43 /** Schema full checking feature id */
44 SCHEMA_FULL_CHECKING("http://apache.org/xml/features/validation/schema-full-checking"),
45
46 /** Validate schema annotations feature id */
47 VALIDATE_ANNOTATIONS("http://apache.org/xml/features/validate-annotations"),
48
49 /** Dynamic validation feature id */
50 DYNAMIC_VALIDATION("http://apache.org/xml/features/validation/dynamic"),
51
52 /** Load external DTD feature id */
53 LOAD_EXTERNAL_DTD("http://apache.org/xml/features/nonvalidating/load-external-dtd"),
54
55 /** XInclude feature id */
56 XINCLUDE("http://apache.org/xml/features/xinclude"),
57
58 /** XInclude fixup base URIs feature id */
59 XINCLUDE_FIXUP_BASE_URIS("http://apache.org/xml/features/xinclude/fixup-base-uris", true),
60
61 /** XInclude fixup language feature id */
62 XINCLUDE_FIXUP_LANGUAGE("http://apache.org/xml/features/xinclude/fixup-language", true);
63
64 /**
65 * Construct a feature for xml, setting the initial state
66 *
67 * @param control the identifier for an XML feature
68 * @param initialState whether that feature defaults to on or off
69 */
70 XMLFeature(String control, boolean initialState) {
71 this.control = control;
72 this.state = initialState;
73 }
74
75 /**
76 * Construct a feature for xml, setting the initial state set to false.
77 *
78 * @param control the identifier for an XML feature that is initially off
79 */
80 XMLFeature(String control) {
81 this(control, false);
82 }
83
84 /**
85 * @return the control associated with this feature
86 */
87 public String getControl() {
88 return control;
89 }
90
91 /**
92 * What state should the feature be set to.
93 *
94 * @return the state of the feature
95 */
96 public boolean getState() {
97 return state;
98 }
99
100 /**
101 * Lookup method to convert from a String
102 *
103 * @param name the name of the control feature
104 * @return the XML Feature
105 */
106 public static XMLFeature fromString(String name) {
107 for (XMLFeature o : XMLFeature.values()) {
108 if (o.control.equalsIgnoreCase(name)) {
109 return o;
110 }
111 }
112 // cannot get here
113 assert false;
114 return null;
115 }
116
117 /* (non-Javadoc)
118 * @see java.lang.Enum#toString()
119 */
120 @Override
121 public String toString() {
122 return (state ? "on " : "off ") + control;
123 }
124
125 private String control;
126 private boolean state;
127
128 }
129