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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* DomDocumentBuilder.java --
2
   Copyright (C) 2004,2006,2007 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.io.File;
41
import java.io.InputStream;
42
import java.io.IOException;
43
import java.io.Reader;
44
import java.net.MalformedURLException;
45
import java.net.URL;
46
import javax.xml.parsers.DocumentBuilder;
47
import org.w3c.dom.Document;
48
import org.w3c.dom.DOMConfiguration;
49
import org.w3c.dom.DOMImplementation;
50
import org.w3c.dom.ls.DOMImplementationLS;
51
import org.w3c.dom.ls.LSException;
52
import org.w3c.dom.ls.LSInput;
53
import org.w3c.dom.ls.LSParser;
54
import org.xml.sax.EntityResolver;
55
import org.xml.sax.ErrorHandler;
56
import org.xml.sax.InputSource;
57
import org.xml.sax.SAXException;
58
 
59
/**
60
 * Document builder using the GNU DOM Load & Save implementation.
61
 *
62
 * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
63
 */
64
class DomDocumentBuilder
65
  extends DocumentBuilder
66
{
67
 
68
  final DOMImplementation impl;
69
  final DOMImplementationLS ls;
70
  final LSParser parser;
71
 
72
  DomDocumentBuilder(DOMImplementation impl,
73
                     DOMImplementationLS ls,
74
                     LSParser parser)
75
  {
76
    this.impl = impl;
77
    this.ls = ls;
78
    this.parser = parser;
79
  }
80
 
81
  public boolean isNamespaceAware()
82
  {
83
    DOMConfiguration config = parser.getDomConfig();
84
    return ((Boolean) config.getParameter("namespaces")).booleanValue();
85
  }
86
 
87
  public boolean isValidating()
88
  {
89
    DOMConfiguration config = parser.getDomConfig();
90
    return ((Boolean) config.getParameter("validating")).booleanValue();
91
  }
92
 
93
  public boolean isXIncludeAware()
94
  {
95
    DOMConfiguration config = parser.getDomConfig();
96
    return ((Boolean) config.getParameter("xinclude-aware")).booleanValue();
97
  }
98
 
99
  public void setEntityResolver(EntityResolver resolver)
100
  {
101
    DOMConfiguration config = parser.getDomConfig();
102
    config.setParameter("entity-resolver", resolver);
103
  }
104
 
105
  public void setErrorHandler(ErrorHandler handler)
106
  {
107
    DOMConfiguration config = parser.getDomConfig();
108
    config.setParameter("error-handler", handler);
109
  }
110
 
111
  public DOMImplementation getDOMImplementation()
112
  {
113
    return impl;
114
  }
115
 
116
  public Document newDocument()
117
  {
118
    return impl.createDocument(null, null, null);
119
  }
120
 
121
  public Document parse(InputStream in)
122
    throws SAXException, IOException
123
  {
124
    LSInput input = ls.createLSInput();
125
    input.setByteStream(in);
126
    try
127
      {
128
        return parser.parse(input);
129
      }
130
    catch (LSException e)
131
      {
132
        Throwable e2 = e.getCause();
133
        if (e2 instanceof IOException)
134
          throw (IOException) e2;
135
        else
136
          throw e;
137
      }
138
  }
139
 
140
  public Document parse(InputStream in, String systemId)
141
    throws SAXException, IOException
142
  {
143
    LSInput input = ls.createLSInput();
144
    input.setByteStream(in);
145
    input.setSystemId(systemId);
146
    try
147
      {
148
        return parser.parse(input);
149
      }
150
    catch (LSException e)
151
      {
152
        Throwable e2 = e.getCause();
153
        if (e2 instanceof IOException)
154
          throw (IOException) e2;
155
        else
156
          throw e;
157
      }
158
  }
159
 
160
  public Document parse(String systemId)
161
    throws SAXException, IOException
162
  {
163
    try
164
      {
165
        return parser.parseURI(systemId);
166
      }
167
    catch (LSException e)
168
      {
169
        Throwable e2 = e.getCause();
170
        if (e2 instanceof IOException)
171
          throw (IOException) e2;
172
        else
173
          throw e;
174
      }
175
  }
176
 
177
  public Document parse(InputSource is)
178
    throws SAXException, IOException
179
  {
180
    LSInput input = ls.createLSInput();
181
    String systemId = is.getSystemId();
182
    InputStream in = is.getByteStream();
183
    if (in != null)
184
      {
185
        input.setByteStream(in);
186
      }
187
    else
188
      {
189
        Reader reader = is.getCharacterStream();
190
        if (reader != null)
191
          {
192
            input.setCharacterStream(reader);
193
          }
194
        else
195
          {
196
            try
197
              {
198
                URL url = new URL(systemId);
199
                input.setByteStream(url.openStream());
200
              }
201
            catch (MalformedURLException e)
202
              {
203
                // Maybe this is a relative file URL
204
                File cwd = new File(System.getProperty("user.dir"));
205
                URL url = new URL(cwd.toURL(), systemId);
206
                input.setByteStream(url.openStream());
207
              }
208
          }
209
      }
210
    input.setPublicId(is.getPublicId());
211
    input.setSystemId(systemId);
212
    input.setEncoding(is.getEncoding());
213
    try
214
      {
215
        return parser.parse(input);
216
      }
217
    catch (LSException e)
218
      {
219
        Throwable e2 = e.getCause();
220
        if (e2 instanceof IOException)
221
          throw (IOException) e2;
222
        else
223
          throw e;
224
      }
225
  }
226
 
227
}

powered by: WebSVN 2.1.0

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