1 17 package org.apache.cocoon.components.source.impl; 18 19 import java.io.IOException ; 20 import java.net.MalformedURLException ; 21 import java.util.Map ; 22 23 import org.apache.avalon.framework.logger.AbstractLogEnabled; 24 import org.apache.avalon.framework.service.ServiceException; 25 import org.apache.avalon.framework.service.ServiceManager; 26 import org.apache.avalon.framework.service.Serviceable; 27 import org.apache.avalon.framework.thread.ThreadSafe; 28 import org.apache.excalibur.source.Source; 29 import org.apache.excalibur.source.SourceException; 30 import org.apache.excalibur.source.SourceFactory; 31 import org.apache.excalibur.source.SourceResolver; 32 33 34 46 public class ZipSourceFactory extends AbstractLogEnabled 47 implements SourceFactory, ThreadSafe, Serviceable { 48 49 protected ServiceManager manager; 50 public static final String ZIP_SOURCE_SCHEME = "zip:"; 51 52 public Source getSource(String location, Map parameters) 53 throws IOException , MalformedURLException { 54 55 if ( this.getLogger().isDebugEnabled() ) { 56 this.getLogger().debug("Processing " + location); 57 } 58 59 int separatorPos = location.indexOf('@'); 61 if (separatorPos == -1) { 62 throw new MalformedURLException ("@ required in URI: " + location); 63 } 64 int protocolEnd = location.indexOf("://"); 65 if (protocolEnd == -1) { 66 throw new MalformedURLException ("URI does not contain '://' : " + location); 67 } 68 69 String documentName = location.substring(protocolEnd + 3, separatorPos); 72 Source archive; 73 SourceResolver resolver = null; 74 try { 75 resolver = (SourceResolver)this.manager.lookup( SourceResolver.ROLE ); 76 archive = resolver.resolveURI(location.substring(separatorPos + 1)); 77 } catch (ServiceException se) { 78 throw new SourceException("SourceResolver is not available.", se); 79 } finally { 80 this.manager.release(resolver); 81 } 82 return new ZipSource(archive, documentName); 83 } 84 85 86 public void release(Source source) { 87 } 89 90 public void service(ServiceManager manager) throws ServiceException { 91 this.manager = manager; 92 } 93 94 } 95 | Popular Tags |