1 17 package org.apache.forrest.sourceexists; 18 19 import java.net.MalformedURLException ; 20 import java.util.Map ; 21 22 import java.io.IOException ; 23 24 import org.apache.cocoon.selection.Selector; 25 26 import org.apache.avalon.framework.service.ServiceException; 27 import org.apache.avalon.framework.service.ServiceManager; 28 import org.apache.avalon.framework.service.Serviceable; 29 30 import org.apache.avalon.framework.logger.AbstractLogEnabled; 31 import org.apache.avalon.framework.parameters.Parameters; 32 import org.apache.avalon.framework.thread.ThreadSafe; 33 34 import org.apache.excalibur.source.Source; 35 import org.apache.excalibur.source.SourceResolver; 36 37 62 public class SourceExistsSelector extends AbstractLogEnabled 63 implements ThreadSafe, Selector, Serviceable { 64 65 SourceResolver resolver = null; 66 67 71 public void service(ServiceManager manager) throws ServiceException { 72 this.resolver = (SourceResolver)manager.lookup(SourceResolver.ROLE); 73 } 74 75 76 public boolean select(String uri, Map objectModel, Parameters parameters) { 77 Source src = null; 78 try { 79 src = resolver.resolveURI(uri); 80 if (src.exists()) { 81 return true; 82 } else { 83 return false; 84 } 85 } catch (MalformedURLException e) { 86 getLogger().warn("Selector URL '"+uri+"' is not a valid Source URL"); 87 return false; 88 } catch (IOException e) { 89 getLogger().warn("Error reading from source '"+uri+"': "+e.getMessage()); 90 return false; 91 } finally { 92 resolver.release(src); 93 } 94 } 95 } 96 | Popular Tags |