1 17 18 19 20 package org.apache.lenya.cms.cocoon.acting; 21 22 import java.io.File ; 23 import java.net.URL ; 24 import java.util.Map ; 25 26 import org.apache.avalon.framework.parameters.Parameters; 27 import org.apache.avalon.framework.thread.ThreadSafe; 28 import org.apache.cocoon.acting.ServiceableAction; 29 import org.apache.cocoon.environment.Redirector; 30 import org.apache.cocoon.environment.SourceResolver; 31 import org.apache.excalibur.source.Source; 32 33 34 48 public class ResourceExistsAction extends ServiceableAction implements ThreadSafe { 49 52 public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, 53 Parameters parameters) throws Exception { 54 String urlstring = parameters.getParameter("url", source); 55 String typestring = parameters.getParameter("type", "resource"); 56 Source src = null; 57 58 try { 59 src = resolver.resolveURI(urlstring); 60 61 File resource = new File (new URL (src.getURI()).getFile()); 62 63 if (typestring.equals("resource") && src.exists()) { 64 getLogger().debug(".act(): Resource (file or directory) exists: " + src.getURI()); 65 66 return EMPTY_MAP; 67 } else if (typestring.equals("file") && resource.isFile()) { 68 getLogger().debug(".act(): File exists: " + resource); 69 70 return EMPTY_MAP; 71 } else if (typestring.equals("directory") && resource.isDirectory()) { 72 getLogger().debug(".act(): Directory exists: " + resource); 73 74 return EMPTY_MAP; 75 } else { 76 getLogger().debug(".act(): Resource " + resource + " as type \"" + typestring + 77 "\" does not exist"); 78 } 79 } catch (Exception e) { 80 getLogger().warn(".act(): Exception", e); 81 } finally { 82 resolver.release(src); 83 } 84 85 return null; 86 } 87 } 88 | Popular Tags |