1 16 package org.apache.cocoon.environment.commandline; 17 18 import org.apache.commons.collections.iterators.IteratorEnumeration; 19 import org.apache.avalon.framework.logger.AbstractLogEnabled; 20 import org.apache.cocoon.environment.Context; 21 22 import java.io.File ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import java.util.Enumeration ; 26 import java.util.Map ; 27 import java.util.HashMap ; 28 import java.io.InputStream ; 29 30 36 37 public class CommandLineContext extends AbstractLogEnabled implements Context { 38 39 40 private String contextDir; 41 42 43 private Map attributes; 44 45 48 public CommandLineContext (String contextDir) { 49 String contextDirPath = new File (contextDir).getAbsolutePath(); 50 this.contextDir = contextDirPath; 52 this.attributes = new HashMap (); 53 } 54 55 public Object getAttribute(String name) { 56 if (getLogger().isDebugEnabled()) { 57 getLogger().debug("CommandlineContext: getAttribute=" + name); 58 } 59 return this.attributes.get(name); 60 } 61 62 public void setAttribute(String name, Object value) { 63 if (getLogger().isDebugEnabled()) { 64 getLogger().debug("CommandlineContext: setAttribute=" + name); 65 } 66 this.attributes.put(name, value); 67 } 68 69 public void removeAttribute(String name) { 70 if (getLogger().isDebugEnabled()) { 71 getLogger().debug("CommandlineContext: removeAttribute=" + name); 72 } 73 this.attributes.remove(name); 74 } 75 76 public Enumeration getAttributeNames() { 77 if (getLogger().isDebugEnabled()) { 78 getLogger().debug("CommandlineContext: getAttributeNames"); 79 } 80 return new IteratorEnumeration(this.attributes.keySet().iterator()); 81 } 82 83 public URL getResource(String path) throws MalformedURLException { 84 if (getLogger().isDebugEnabled()) { 85 getLogger().debug("CommandlineContext: getResource=" + path); 86 } 87 File f = new File ( contextDir, path ); 89 if (!f.exists()) return null; 90 return f.toURL(); 91 } 92 93 public String getRealPath(String path) { 94 if (getLogger().isDebugEnabled()) { 95 getLogger().debug("CommandlineContext: getRealPath=" + path); 96 } 97 File f = new File ( this.contextDir, path ); 99 return f.getAbsolutePath(); 100 } 101 102 public String getMimeType(String file) { 103 if (getLogger().isDebugEnabled()) { 104 getLogger().debug("CommandlineContext: getMimeType=" + file); 105 } 106 return null; 108 } 109 110 public String getInitParameter(String name) { 111 getLogger().debug("CommandlineContext: getInitParameter=" + name); 112 return null; 113 } 114 115 public InputStream getResourceAsStream(String path){ 116 getLogger().debug("CommandlineContext: getResourceAsStream "+path); 117 return null; 118 } 119 } 120 | Popular Tags |