1 16 package org.apache.cocoon.components.resolver; 17 18 import org.apache.excalibur.xml.EntityResolver; 19 import org.apache.avalon.framework.activity.Disposable; 20 import org.apache.avalon.framework.component.ComponentException; 21 import org.apache.avalon.framework.component.ComponentManager; 22 import org.apache.avalon.framework.component.Composable; 23 import org.apache.avalon.framework.context.Context; 24 import org.apache.avalon.framework.context.ContextException; 25 import org.apache.avalon.framework.context.Contextualizable; 26 import org.apache.avalon.framework.logger.AbstractLogEnabled; 27 import org.apache.avalon.framework.parameters.ParameterException; 28 import org.apache.avalon.framework.parameters.Parameterizable; 29 import org.apache.avalon.framework.parameters.Parameters; 30 import org.apache.avalon.framework.thread.ThreadSafe; 31 import org.apache.cocoon.Constants; 32 import org.apache.xml.resolver.CatalogManager; 33 import org.apache.xml.resolver.tools.CatalogResolver; 34 import org.xml.sax.InputSource ; 35 import org.xml.sax.SAXException ; 36 37 import java.io.IOException ; 38 39 40 59 public class ResolverImpl extends AbstractLogEnabled 60 implements EntityResolver, 61 Resolver, 62 Contextualizable, 63 Composable, 64 Parameterizable, 65 ThreadSafe, 66 Disposable { 67 68 69 protected CatalogManager catalogManager = new CatalogManager(); 70 71 72 protected CatalogResolver catalogResolver = new CatalogResolver(catalogManager); 73 74 75 protected ComponentManager manager = null; 76 77 78 protected org.apache.cocoon.environment.Context context; 79 80 81 public void contextualize(Context context) 82 throws ContextException { 83 this.context = (org.apache.cocoon.environment.Context) 84 context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); 85 } 86 87 88 94 public void parameterize(Parameters params) throws ParameterException { 95 96 97 String verbosity = params.getParameter("verbosity", ""); 98 if (verbosity != "") { 99 if (this.getLogger().isDebugEnabled()) { 100 this.getLogger().debug("Setting Catalog resolver " 101 + "verbosity level to " + verbosity); 102 } 103 int verbosityLevel = 0; 104 try { 105 verbosityLevel = Integer.parseInt(verbosity); 106 catalogManager.setVerbosity(verbosityLevel); 107 } catch (NumberFormatException ce1) { 108 this.getLogger().warn("Trouble setting Catalog verbosity", 109 ce1); 110 } 111 } 112 113 114 String catalogFile = params.getParameter("catalog", 115 "/WEB-INF/entities/catalog"); 116 try { 117 String catalogURL = null; 118 catalogURL = this.context.getRealPath(catalogFile); 119 if (catalogURL == null) { 120 catalogURL = 121 this.context.getResource(catalogFile).toExternalForm(); 122 } 123 if (this.getLogger().isDebugEnabled()) { 124 this.getLogger().debug("System OASIS Catalog URL is " 125 + catalogURL); 126 } 127 catalogResolver.getCatalog().parseCatalog(catalogURL); 128 } catch (Exception e) { 129 this.getLogger().warn("Could not get Catalog URL", e); 130 } 131 132 133 String localCatalogFile = params.getParameter("local-catalog", null); 134 if (localCatalogFile != null) { 135 try { 136 if (this.getLogger().isDebugEnabled()) { 137 this.getLogger().debug("Additional Catalog is " 138 + localCatalogFile); 139 } 140 catalogResolver.getCatalog().parseCatalog(localCatalogFile); 141 } catch (Exception e) { 142 this.getLogger().warn("Could not get local Catalog file", e); 143 } 144 } 145 } 146 147 152 public void compose(ComponentManager manager) throws ComponentException { 153 if ((this.manager == null) && (manager != null)) { 154 this.manager = manager; 155 } 156 } 157 158 192 public InputSource resolveEntity(String publicId, String systemId) 193 throws SAXException , IOException { 194 200 InputSource altInputSource = catalogResolver.resolveEntity(publicId, 201 systemId); 202 if (altInputSource != null) { 203 if (this.getLogger().isDebugEnabled()) { 204 this.getLogger().debug("Resolved catalog entity: " 205 + publicId + " " + altInputSource.getSystemId()); 206 } 207 } 208 215 return altInputSource; 216 } 217 218 221 public void dispose() { 222 } 223 } 224 | Popular Tags |