1 5 6 package org.exoplatform.services.xml.resolving.impl.simple; 7 8 import java.io.IOException ; 9 import java.io.InputStream ; 10 11 import org.xml.sax.EntityResolver ; 12 import org.xml.sax.InputSource ; 13 14 import org.apache.commons.logging.Log; 15 import org.exoplatform.services.log.LogService; 16 import org.exoplatform.container.PortalContainer; 17 import org.exoplatform.container.RootContainer; 18 19 20 27 28 public class SimpleResolver implements EntityResolver { 29 private String localPath; 30 private Log log; 31 32 public SimpleResolver(String localPath) 33 { 34 this.localPath = localPath; 35 36 LogService logService = (LogService) RootContainer.getInstance(). 37 getComponentInstanceOfType(LogService.class); 38 log = logService.getLog(this.getClass()); 39 } 40 41 public InputSource resolveEntity (String publicId, String systemId) throws IOException 42 { 43 log.debug("query for resolve entity publicId["+publicId+" systemId["+systemId+"]"); 44 int fileIndex = systemId.lastIndexOf('/'); 45 if(fileIndex == -1) 46 return null; 47 48 String dtdPath = localPath+systemId.substring(fileIndex); 49 log.debug("local path is ["+dtdPath+"]"); 50 51 if(this.getClass().getResource(dtdPath) == null) { 52 log.warn("Local entity definitions of '"+dtdPath+" not found in catalog. Trying to load from "+systemId+".."); 53 return null; 54 } 55 InputSource source = new InputSource (this.getClass().getResourceAsStream(dtdPath)); 56 log.debug("Local entity definitions found in '" + dtdPath + "'"); 57 58 source.setSystemId(systemId); 59 return source; 60 } 61 } 62 63 | Popular Tags |