1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2001, 2002,2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package com.sun.org.apache.xerces.internal.util; 22 23 import java.io.InputStream; 24 import java.io.IOException; 25 import java.io.Reader; 26 27 import com.sun.org.apache.xerces.internal.xni.XNIException; 28 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; 29 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; 30 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 31 32 import org.xml.sax.EntityResolver; 33 import org.xml.sax.InputSource; 34 import org.xml.sax.SAXException; 35 36 /** 37 * This class wraps a SAX entity resolver in an XNI entity resolver. 38 * 39 * @see EntityResolver 40 * 41 * @author Andy Clark, IBM 42 * 43 */ 44 public class EntityResolverWrapper 45 implements XMLEntityResolver { 46 47 // 48 // Data 49 // 50 114 String baseSystemId = resourceIdentifier.getBaseSystemId(); 115 InputStream byteStream = inputSource.getByteStream(); 116 Reader charStream = inputSource.getCharacterStream(); 117 String encoding = inputSource.getEncoding(); 118 XMLInputSource xmlInputSource = 119 new XMLInputSource(publicId, systemId, baseSystemId, true); 120 xmlInputSource.setByteStream(byteStream); 121 xmlInputSource.setCharacterStream(charStream); 122 xmlInputSource.setEncoding(encoding); 123 return xmlInputSource; 124 } 125 } 126 127 // error resolving entity 128 catch (SAXException e) { 129 Exception ex = e.getException(); 130 if (ex == null) { 131 ex = e; 132 } 133 throw new XNIException(ex); 134 } 135 } 136 137 // unable to resolve entity 138 return null; 139 140 } // resolveEntity(String,String,String):XMLInputSource 141 } | 1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 */ 4 /* 5 * Licensed to the Apache Software Foundation (ASF) under one or more 6 * contributor license agreements. See the NOTICE file distributed with 7 * this work for additional information regarding copyright ownership. 8 * The ASF licenses this file to You under the Apache License, Version 2.0 9 * (the "License"); you may not use this file except in compliance with 10 * the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package com.sun.org.apache.xerces.internal.util; 22 23 import java.io.InputStream; 24 import java.io.IOException; 25 import java.io.Reader; 26 27 import com.sun.org.apache.xerces.internal.xni.XNIException; 28 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; 29 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; 30 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 31 import javax.xml.catalog.CatalogException; 32 33 import org.xml.sax.EntityResolver; 34 import org.xml.sax.InputSource; 35 import org.xml.sax.SAXException; 36 37 /** 38 * This class wraps a SAX entity resolver in an XNI entity resolver. 39 * 40 * @see EntityResolver 41 * 42 * @author Andy Clark, IBM 43 * 44 */ 45 public class EntityResolverWrapper 46 implements XMLEntityResolver { 47 48 // 49 // Data 50 // 51 115 String baseSystemId = resourceIdentifier.getBaseSystemId(); 116 InputStream byteStream = inputSource.getByteStream(); 117 Reader charStream = inputSource.getCharacterStream(); 118 String encoding = inputSource.getEncoding(); 119 XMLInputSource xmlInputSource = 120 new XMLInputSource(publicId, systemId, baseSystemId, true); 121 xmlInputSource.setByteStream(byteStream); 122 xmlInputSource.setCharacterStream(charStream); 123 xmlInputSource.setEncoding(encoding); 124 return xmlInputSource; 125 } 126 } 127 128 // error resolving entity 129 catch (SAXException e) { 130 Exception ex = e.getException(); 131 if (ex == null) { 132 ex = e; 133 } 134 throw new XNIException(ex); 135 } 136 137 catch (CatalogException e) { 138 throw new XNIException(e); 139 } 140 } 141 142 // unable to resolve entity 143 return null; 144 145 } // resolveEntity(String,String,String):XMLInputSource 146 } |