| 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 as published by
5 * the Free Software Foundation. This program is distributed in the hope
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7 * 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 * Copyright: 2005
18 * The copyright to this program is held by it's authors.
19 *
20 * ID: $Id: XMLFeature.java 2145 2011-04-05 01:15:52Z dmsmith $
21 */
22 package org.crosswire.common.xml;
23
24
25 /**
26 * Wraps an XML Feature. The "known" set of XML Features is found in
27 * XMLFeatureSet.
28 *
29 * @see gnu.lgpl.License for license details.<br>
30 * The copyright to this program is held by it's authors.
31 * @author DM Smith [dmsmith555 at yahoo dot com]
32 */
33 public enum XMLFeature {
34 /** Namespaces feature id */
35 NAMESPACES("http://xml.org/sax/features/namespaces"),
36
37 /** Namespace prefixes feature id */
38 NAMESPACE_PREFIX("http://xml.org/sax/features/namespace-prefixes"),
39
40 /** Validation feature id */
41 VALIDATION("http://xml.org/sax/features/validation"),
42
43 /** Schema validation feature id */
44 SCHEMA_VALIDATION("http://apache.org/xml/features/validation/schema"),
45
46 /** Schema full checking feature id */
47 SCHEMA_FULL_CHECKING("http://apache.org/xml/features/validation/schema-full-checking"),
48
49 /** Validate schema annotations feature id */
50 VALIDATE_ANNOTATIONS("http://apache.org/xml/features/validate-annotations"),
51
52 /** Dynamic validation feature id */
53 DYNAMIC_VALIDATION("http://apache.org/xml/features/validation/dynamic"),
54
55 /** Load external DTD feature id */
56 LOAD_EXTERNAL_DTD("http://apache.org/xml/features/nonvalidating/load-external-dtd"),
57
58 /** XInclude feature id */
59 XINCLUDE("http://apache.org/xml/features/xinclude"),
60
61 /** XInclude fixup base URIs feature id */
62 XINCLUDE_FIXUP_BASE_URIS("http://apache.org/xml/features/xinclude/fixup-base-uris", true),
63
64 /** XInclude fixup language feature id */
65 XINCLUDE_FIXUP_LANGUAGE("http://apache.org/xml/features/xinclude/fixup-language", true);
66
67 /**
68 * Construct a feature for xml, setting the initial state
69 *
70 * @param control
71 * @param initialState
72 */
73 private XMLFeature(String control, boolean initialState) {
74 this.control = control;
75 this.state = initialState;
76 }
77
78 /**
79 * Construct a feature for xml, setting the initial state set to false.
80 *
81 * @param control
82 */
83 private XMLFeature(String control) {
84 this(control, false);
85 }
86
87 /**
88 * @return the control associated with this feature
89 */
90 public String getControl() {
91 return control;
92 }
93
94 /**
95 * What state should the feature be set to.
96 *
97 * @return the state of the feature
98 */
99 public boolean getState() {
100 return state;
101 }
102
103 /**
104 * Lookup method to convert from a String
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 @Override
118 public String toString() {
119 return (state ? "on " : "off ") + control;
120 }
121
122 private String control;
123 private boolean state;
124
125 }
126