OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [gnu/] [xml/] [dom/] [DomDocumentConfiguration.java] - Blame information for rev 769

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* DomDocumentConfiguration.java --
2
   Copyright (C) 2004 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
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.
10
 
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.
15
 
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., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
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.
25
 
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. */
37
 
38
package gnu.xml.dom;
39
 
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;
46
 
47
/**
48
 * Document configuration, used to store normalization and other parameters.
49
 *
50
 * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
51
 */
52
class DomDocumentConfiguration
53
  implements DOMConfiguration, DOMStringList
54
{
55
 
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"});
65
 
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;
73
 
74
  public void setParameter(String name, Object value)
75
    throws DOMException
76
  {
77
    name = name.toLowerCase();
78
    if ("cdata-sections".equals(name))
79
      {
80
        cdataSections = "true".equals(value.toString());
81
      }
82
    else if ("comments".equals(name))
83
      {
84
        comments = "true".equals(value.toString());
85
      }
86
    else if ("element-content-whitespace".equals(name))
87
      {
88
        elementContentWhitespace = "true".equals(value.toString());
89
      }
90
    else if ("entities".equals(name))
91
      {
92
        entities = "true".equals(value.toString());
93
      }
94
    else if ("error-handler".equals(name))
95
      {
96
        try
97
          {
98
            errorHandler = (DOMErrorHandler) value;
99
          }
100
        catch (ClassCastException e)
101
          {
102
            throw new DomDOMException(DOMException.TYPE_MISMATCH_ERR,
103
                                      value.getClass().getName(), null, 0);
104
          }
105
      }
106
    else if ("namespace-declarations".equals(name))
107
      {
108
        namespaceDeclarations = "true".equals(value.toString());
109
      }
110
    else if ("split-cdata-sections".equals(name))
111
      {
112
        comments = "true".equals(value.toString());
113
      }
114
    else if ("infoset".equals(name))
115
      {
116
        if ("true".equals(value.toString()))
117
          {
118
            entities = false;
119
            cdataSections = false;
120
            namespaceDeclarations = true;
121
            elementContentWhitespace = true;
122
            comments = true;
123
          }
124
      }
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()))
132
      {
133
        // NOOP
134
      }
135
    else if (("namespaces".equals(name) ||
136
              "well-formed".equals(name)) &&
137
             "true".equals(value.toString()))
138
      {
139
        // NOOP
140
      }
141
    else
142
      {
143
        throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR,
144
                                  name, null, 0);
145
      }
146
  }
147
 
148
  public Object getParameter(String name)
149
    throws DOMException
150
  {
151
    name = name.toLowerCase();
152
    if ("cdata-sections".equals(name))
153
      {
154
        return cdataSections ? Boolean.TRUE : Boolean.FALSE;
155
      }
156
    else if ("comments".equals(name))
157
      {
158
        return comments ? Boolean.TRUE : Boolean.FALSE;
159
      }
160
    else if ("element-content-whitespace".equals(name))
161
      {
162
        return elementContentWhitespace ? Boolean.TRUE : Boolean.FALSE;
163
      }
164
    else if ("entities".equals(name))
165
      {
166
        return entities ? Boolean.TRUE : Boolean.FALSE;
167
      }
168
    else if ("error-handler".equals(name))
169
      {
170
        return errorHandler;
171
      }
172
    else if ("namespace-declarations".equals(name))
173
      {
174
        return namespaceDeclarations ? Boolean.TRUE : Boolean.FALSE;
175
      }
176
    else if ("split-cdata-sections".equals(name))
177
      {
178
        return comments ? Boolean.TRUE : Boolean.FALSE;
179
      }
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))
186
      {
187
        return Boolean.FALSE;
188
      }
189
    else if ("namespaces".equals(name) ||
190
             "well-formed".equals(name))
191
      {
192
        return Boolean.TRUE;
193
      }
194
    else if ("infoset".equals(name))
195
      {
196
        return (entities == false &&
197
            cdataSections == false &&
198
            namespaceDeclarations == true &&
199
            comments == true) ? Boolean.TRUE : Boolean.FALSE;
200
      }
201
    throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR, name, null, 0);
202
  }
203
 
204
  public boolean canSetParameter(String name, Object value)
205
  {
206
    name = name.toLowerCase();
207
    if ("error-handler".equals(name))
208
      {
209
        return (value == null || value instanceof DOMErrorHandler);
210
      }
211
    else if (contains(name))
212
      {
213
        return true;
214
      }
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))
221
      {
222
        return "false".equals(value.toString());
223
      }
224
    else if ("namespaces".equals(name) ||
225
             "well-formed".equals(name))
226
      {
227
        return "true".equals(value.toString());
228
      }
229
    return false;
230
  }
231
 
232
  public DOMStringList getParameterNames()
233
  {
234
    return this;
235
  }
236
 
237
  public String item(int i)
238
  {
239
    try
240
      {
241
        return (String) SUPPORTED_PARAMETERS.get(i);
242
      }
243
    catch (IndexOutOfBoundsException e)
244
      {
245
        return null;
246
      }
247
  }
248
 
249
  public int getLength()
250
  {
251
    return SUPPORTED_PARAMETERS.size();
252
  }
253
 
254
  public boolean contains(String str)
255
  {
256
    str = str.toLowerCase();
257
    return SUPPORTED_PARAMETERS.contains(str);
258
  }
259
 
260
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.