1 /* |
1 /* |
2 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
55 * which are not required to be reported by conformant XML processors. |
55 * which are not required to be reported by conformant XML processors. |
56 * |
56 * |
57 * @author David Brownell |
57 * @author David Brownell |
58 * @author Janet Koenig |
58 * @author Janet Koenig |
59 * @author Kohsuke KAWAGUCHI |
59 * @author Kohsuke KAWAGUCHI |
60 * @version $Id: DTDParser.java,v 1.2 2009-04-16 15:25:49 snajper Exp $ |
60 * @version $Id: DTDParser.java,v 1.2 2009/04/16 15:25:49 snajper Exp $ |
61 */ |
61 */ |
62 public class DTDParser { |
62 public class DTDParser { |
63 public final static String TYPE_CDATA = "CDATA"; |
63 public final static String TYPE_CDATA = "CDATA"; |
64 public final static String TYPE_ID = "ID"; |
64 public final static String TYPE_ID = "ID"; |
65 public final static String TYPE_IDREF = "IDREF"; |
65 public final static String TYPE_IDREF = "IDREF"; |
213 /** |
213 /** |
214 * Parse a DTD. |
214 * Parse a DTD. |
215 */ |
215 */ |
216 public void parse(String uri) |
216 public void parse(String uri) |
217 throws IOException, SAXException { |
217 throws IOException, SAXException { |
218 InputSource inSource; |
218 InputSource in; |
219 |
219 |
220 init(); |
220 init(); |
221 // System.out.println ("parse (\"" + uri + "\")"); |
221 // System.out.println ("parse (\"" + uri + "\")"); |
222 inSource = resolver.resolveEntity(null, uri); |
222 in = resolver.resolveEntity(null, uri); |
223 |
223 |
224 // If custom resolver punts resolution to parser, handle it ... |
224 // If custom resolver punts resolution to parser, handle it ... |
225 if (inSource == null) { |
225 if (in == null) { |
226 inSource = Resolver.createInputSource(new java.net.URL(uri), false); |
226 in = Resolver.createInputSource(new java.net.URL(uri), false); |
227 |
227 |
228 // ... or if custom resolver doesn't correctly construct the |
228 // ... or if custom resolver doesn't correctly construct the |
229 // input entity, patch it up enough so relative URIs work, and |
229 // input entity, patch it up enough so relative URIs work, and |
230 // issue a warning to minimize later confusion. |
230 // issue a warning to minimize later confusion. |
231 } else if (inSource.getSystemId() == null) { |
231 } else if (in.getSystemId() == null) { |
232 warning("P-065", null); |
232 warning("P-065", null); |
233 inSource.setSystemId(uri); |
233 in.setSystemId(uri); |
234 } |
234 } |
235 |
235 |
236 parseInternal(inSource); |
236 parseInternal(in); |
237 } |
237 } |
238 |
238 |
239 // makes sure the parser is reset to "before a document" |
239 // makes sure the parser is reset to "before a document" |
240 private void init() { |
240 private void init() { |
241 in = null; |
241 in = null; |