1 /* |
1 /* |
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2013, 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 |
68 * @return |
68 * @return |
69 * It's OK to return a relative URL. |
69 * It's OK to return a relative URL. |
70 */ |
70 */ |
71 protected abstract String findExternalResource( String nsURI, String localName, Attributes atts); |
71 protected abstract String findExternalResource( String nsURI, String localName, Attributes atts); |
72 |
72 |
|
73 @Override |
73 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) |
74 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) |
74 throws SAXException { |
75 throws SAXException { |
75 super.startElement(namespaceURI, localName, qName, atts); |
76 super.startElement(namespaceURI, localName, qName, atts); |
76 |
77 |
77 String relativeRef = findExternalResource(namespaceURI,localName,atts); |
78 String relativeRef = findExternalResource(namespaceURI,localName,atts); |
78 if(relativeRef==null) return; // non found |
79 if(relativeRef==null) return; // non found |
79 |
80 |
80 try { |
81 try { |
81 // absolutize URL. |
82 // absolutize URL. |
82 String lsi = locator.getSystemId(); |
83 assert locator != null; |
83 String ref; |
84 String lsi = locator.getSystemId(); |
84 if (lsi.startsWith("jar:")) { |
85 String ref; |
85 int bangIdx = lsi.indexOf('!'); |
86 if (lsi.startsWith("jar:")) { |
86 if (bangIdx > 0) { |
87 int bangIdx = lsi.indexOf('!'); |
87 ref = new URL(new URL(lsi), relativeRef).toString(); |
88 if (bangIdx > 0) { |
88 } else |
89 ref = new URL(new URL(lsi), relativeRef).toString(); |
89 ref = relativeRef; |
90 } else |
90 } else |
91 ref = relativeRef; |
91 ref = new URI(lsi).resolve(new URI(relativeRef)).toString(); |
92 } else |
|
93 ref = new URI(lsi).resolve(new URI(relativeRef)).toString(); |
92 |
94 |
93 // then parse this schema as well, |
95 // then parse this schema as well, |
94 // but don't mark this document as a root. |
96 // but don't mark this document as a root. |
95 parent.parse(ref,false); |
97 parent.parse(ref,false); |
96 } catch( URISyntaxException e ) { |
98 } catch( URISyntaxException e ) { |