1 57 58 package com.sun.org.apache.xerces.internal.util; 59 60 import java.io.InputStream ; 61 import java.io.IOException ; 62 import java.io.Reader ; 63 64 import com.sun.org.apache.xerces.internal.xni.XNIException; 65 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; 66 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; 67 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 68 69 import org.xml.sax.EntityResolver ; 70 import org.xml.sax.InputSource ; 71 import org.xml.sax.SAXException ; 72 73 82 public class EntityResolverWrapper 83 implements XMLEntityResolver { 84 85 89 90 protected EntityResolver fEntityResolver; 91 92 96 97 public EntityResolverWrapper() {} 98 99 100 public EntityResolverWrapper(EntityResolver entityResolver) { 101 setEntityResolver(entityResolver); 102 } 104 108 109 public void setEntityResolver(EntityResolver entityResolver) { 110 fEntityResolver = entityResolver; 111 } 113 114 public EntityResolver getEntityResolver() { 115 return fEntityResolver; 116 } 118 122 132 public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) 133 throws XNIException, IOException { 134 135 String pubId = resourceIdentifier.getPublicId(); 141 String sysId = resourceIdentifier.getExpandedSystemId(); 142 if (pubId == null && sysId == null) 143 return null; 144 145 if (fEntityResolver != null && resourceIdentifier != null) { 147 try { 148 InputSource inputSource = fEntityResolver.resolveEntity(pubId, sysId); 149 if (inputSource != null) { 150 String publicId = inputSource.getPublicId(); 151 String systemId = inputSource.getSystemId(); 152 String baseSystemId = resourceIdentifier.getBaseSystemId(); 153 InputStream byteStream = inputSource.getByteStream(); 154 Reader charStream = inputSource.getCharacterStream(); 155 String encoding = inputSource.getEncoding(); 156 XMLInputSource xmlInputSource = 157 new XMLInputSource(publicId, systemId, baseSystemId); 158 xmlInputSource.setByteStream(byteStream); 159 xmlInputSource.setCharacterStream(charStream); 160 xmlInputSource.setEncoding(encoding); 161 return xmlInputSource; 162 } 163 } 164 165 catch (SAXException e) { 167 Exception ex = e.getException(); 168 if (ex == null) { 169 ex = e; 170 } 171 throw new XNIException(ex); 172 } 173 } 174 175 return null; 177 178 } } 180 | Popular Tags |