This commit was manufactured by cvs2svn to create branch 'gomp-branch'.
[official-gcc.git] / libjava / gnu / xml / dom / DomDocumentConfiguration.java
blob38d6e6d7bb36f39342df36f4e9bd539468e47b7d
1 /* DomDocumentConfiguration.java --
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package gnu.xml.dom;
40 import java.util.Arrays;
41 import java.util.List;
42 import org.w3c.dom.DOMConfiguration;
43 import org.w3c.dom.DOMErrorHandler;
44 import org.w3c.dom.DOMException;
45 import org.w3c.dom.DOMStringList;
47 /**
48 * Document configuration, used to store normalization and other parameters.
50 * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
52 class DomDocumentConfiguration
53 implements DOMConfiguration, DOMStringList
56 private static final List SUPPORTED_PARAMETERS =
57 Arrays.asList(new String[] { "cdata-sections",
58 "comments",
59 "element-content-whitespace",
60 "entities",
61 "error-handler",
62 "namespace-declarations",
63 "split-cdata-sections",
64 "infoset"});
66 boolean cdataSections = true;
67 boolean comments = true;
68 boolean elementContentWhitespace = true;
69 boolean entities = true;
70 DOMErrorHandler errorHandler;
71 boolean namespaceDeclarations = true;
72 boolean splitCdataSections = true;
74 public void setParameter(String name, Object value)
75 throws DOMException
77 name = name.toLowerCase();
78 if ("cdata-sections".equals(name))
80 cdataSections = "true".equals(value.toString());
82 else if ("comments".equals(name))
84 comments = "true".equals(value.toString());
86 else if ("element-content-whitespace".equals(name))
88 elementContentWhitespace = "true".equals(value.toString());
90 else if ("entities".equals(name))
92 entities = "true".equals(value.toString());
94 else if ("error-handler".equals(name))
96 try
98 errorHandler = (DOMErrorHandler) value;
100 catch (ClassCastException e)
102 throw new DomDOMException(DOMException.TYPE_MISMATCH_ERR,
103 value.getClass().getName(), null, 0);
106 else if ("namespace-declarations".equals(name))
108 namespaceDeclarations = "true".equals(value.toString());
110 else if ("split-cdata-sections".equals(name))
112 comments = "true".equals(value.toString());
114 else if ("infoset".equals(name))
116 if ("true".equals(value.toString()))
118 entities = false;
119 cdataSections = false;
120 namespaceDeclarations = true;
121 elementContentWhitespace = true;
122 comments = true;
125 else if (("canonical-form".equals(name) ||
126 "check-character-normalization".equals(name) ||
127 "datatype-normalization".equals(name) ||
128 "normalize-characters".equals(name) ||
129 "validate".equals(name) ||
130 "validate-if-schema".equals(name)) &&
131 "false".equals(value.toString()))
133 // NOOP
135 else if (("namespaces".equals(name) ||
136 "well-formed".equals(name)) &&
137 "true".equals(value.toString()))
139 // NOOP
141 else
143 throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR,
144 name, null, 0);
148 public Object getParameter(String name)
149 throws DOMException
151 name = name.toLowerCase();
152 if ("cdata-sections".equals(name))
154 return cdataSections ? Boolean.TRUE : Boolean.FALSE;
156 else if ("comments".equals(name))
158 return comments ? Boolean.TRUE : Boolean.FALSE;
160 else if ("element-content-whitespace".equals(name))
162 return elementContentWhitespace ? Boolean.TRUE : Boolean.FALSE;
164 else if ("entities".equals(name))
166 return entities ? Boolean.TRUE : Boolean.FALSE;
168 else if ("error-handler".equals(name))
170 return errorHandler;
172 else if ("namespace-declarations".equals(name))
174 return namespaceDeclarations ? Boolean.TRUE : Boolean.FALSE;
176 else if ("split-cdata-sections".equals(name))
178 return comments ? Boolean.TRUE : Boolean.FALSE;
180 else if ("canonical-form".equals(name) ||
181 "check-character-normalization".equals(name) ||
182 "datatype-normalization".equals(name) ||
183 "normalize-characters".equals(name) ||
184 "validate".equals(name) ||
185 "validate-if-schema".equals(name))
187 return Boolean.FALSE;
189 else if ("namespaces".equals(name) ||
190 "well-formed".equals(name))
192 return Boolean.TRUE;
194 else if ("infoset".equals(name))
196 return (entities == false &&
197 cdataSections == false &&
198 namespaceDeclarations == true &&
199 comments == true) ? Boolean.TRUE : Boolean.FALSE;
201 throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR, name, null, 0);
204 public boolean canSetParameter(String name, Object value)
206 name = name.toLowerCase();
207 if ("error-handler".equals(name))
209 return (value == null || value instanceof DOMErrorHandler);
211 else if (contains(name))
213 return true;
215 else if ("canonical-form".equals(name) ||
216 "check-character-normalization".equals(name) ||
217 "datatype-normalization".equals(name) ||
218 "normalize-characters".equals(name) ||
219 "validate".equals(name) ||
220 "validate-if-schema".equals(name))
222 return "false".equals(value.toString());
224 else if ("namespaces".equals(name) ||
225 "well-formed".equals(name))
227 return "true".equals(value.toString());
229 return false;
232 public DOMStringList getParameterNames()
234 return this;
237 public String item(int i)
241 return (String) SUPPORTED_PARAMETERS.get(i);
243 catch (IndexOutOfBoundsException e)
245 return null;
249 public int getLength()
251 return SUPPORTED_PARAMETERS.size();
254 public boolean contains(String str)
256 str = str.toLowerCase();
257 return SUPPORTED_PARAMETERS.contains(str);