1 /*
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.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
98 protected final EntityResolver entityResolver;
99 /**
100 * Stores all the outer-most <jaxb:bindings> customizations.
101 */
102 public final Set<Element> outerMostBindings = new HashSet<Element>();
103
104 /**
105 * Schema language dependent part of the processing.
106 */
107 protected final InternalizationLogic logic;
108 protected final WsimportOptions options;
109
110 public DOMForest(InternalizationLogic logic, @NotNull EntityResolver entityResolver, WsimportOptions options, ErrorReceiver errReceiver) {
111 this.options = options;
112 this.entityResolver = entityResolver;
113 this.errorReceiver = errReceiver;
114 this.logic = logic;
115 try {
116 // secure xml processing can be switched off if input requires it
117 boolean secureProcessingEnabled = options == null || !options.disableXmlSecurity;
118 DocumentBuilderFactory dbf = XmlUtil.newDocumentBuilderFactory(secureProcessingEnabled);
119 dbf.setNamespaceAware(true);
120 this.documentBuilder = dbf.newDocumentBuilder();
121
122 this.parserFactory = XmlUtil.newSAXParserFactory(secureProcessingEnabled);
123 this.parserFactory.setNamespaceAware(true);
124 } catch (ParserConfigurationException e) {
125 throw new AssertionError(e);
126 }
127 }
128
129 public List<Element> getInlinedSchemaElement() {
130 return inlinedSchemaElements;
131 }
132
133 public @NotNull Document parse(InputSource source, boolean root) throws SAXException, IOException {
134 if (source.getSystemId() == null)
135 throw new IllegalArgumentException();
136 return parse(source.getSystemId(), source, root);
137 }
138
139 /**
140 * Parses an XML at the given location (
141 * and XMLs referenced by it) into DOM trees
142 * and stores them to this forest.
143 *
|
1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
98 protected final EntityResolver entityResolver;
99 /**
100 * Stores all the outer-most <jaxb:bindings> customizations.
101 */
102 public final Set<Element> outerMostBindings = new HashSet<Element>();
103
104 /**
105 * Schema language dependent part of the processing.
106 */
107 protected final InternalizationLogic logic;
108 protected final WsimportOptions options;
109
110 public DOMForest(InternalizationLogic logic, @NotNull EntityResolver entityResolver, WsimportOptions options, ErrorReceiver errReceiver) {
111 this.options = options;
112 this.entityResolver = entityResolver;
113 this.errorReceiver = errReceiver;
114 this.logic = logic;
115 try {
116 // secure xml processing can be switched off if input requires it
117 boolean secureProcessingEnabled = options == null || !options.disableXmlSecurity;
118 DocumentBuilderFactory dbf = XmlUtil.newDocumentBuilderFactory(!secureProcessingEnabled);
119 dbf.setNamespaceAware(true);
120 this.documentBuilder = dbf.newDocumentBuilder();
121
122 this.parserFactory = XmlUtil.newSAXParserFactory(secureProcessingEnabled);
123 this.parserFactory.setNamespaceAware(true);
124
125 if(secureProcessingEnabled){
126 dbf.setExpandEntityReferences(false);
127 try {
128 parserFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
129 parserFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
130 parserFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
131 } catch (SAXNotRecognizedException e){
132 throw new ParserConfigurationException(e.getMessage());
133 } catch (SAXNotSupportedException e) {
134 throw new ParserConfigurationException(e.getMessage());
135 }
136 }
137
138 } catch (ParserConfigurationException e) {
139 throw new AssertionError(e);
140 }
141 }
142
143 public List<Element> getInlinedSchemaElement() {
144 return inlinedSchemaElements;
145 }
146
147 public @NotNull Document parse(InputSource source, boolean root) throws SAXException, IOException {
148 if (source.getSystemId() == null)
149 throw new IllegalArgumentException();
150 return parse(source.getSystemId(), source, root);
151 }
152
153 /**
154 * Parses an XML at the given location (
155 * and XMLs referenced by it) into DOM trees
156 * and stores them to this forest.
157 *
|