KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > environment > commandline > CommandLineContext


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.util.Enumeration JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.io.InputStream JavaDoc;
29
30 /**
31  *
32  * Implements the {@link org.apache.cocoon.environment.Context} interface
33  * @author ?
34  * @version CVS $Id: CommandLineContext.java 30932 2004-07-29 17:35:38Z vgritsenko $
35  */

36
37 public class CommandLineContext extends AbstractLogEnabled implements Context {
38
39     /** The context directory path*/
40     private String JavaDoc contextDir;
41
42     /** The context attributes */
43     private Map JavaDoc attributes;
44
45     /**
46      * Constructs a CommandlineContext object from a ServletContext object
47      */

48     public CommandLineContext (String JavaDoc contextDir) {
49         String JavaDoc contextDirPath = new File JavaDoc(contextDir).getAbsolutePath();
50         // store contextDirPath as is don't remove trailing /.
51
this.contextDir = contextDirPath;
52         this.attributes = new HashMap JavaDoc();
53     }
54
55     public Object JavaDoc getAttribute(String JavaDoc 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 JavaDoc name, Object JavaDoc 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 JavaDoc 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 JavaDoc getResource(String JavaDoc path) throws MalformedURLException JavaDoc {
84         if (getLogger().isDebugEnabled()) {
85             getLogger().debug("CommandlineContext: getResource=" + path);
86         }
87         // rely on File to build correct File and URL
88
File JavaDoc f = new File JavaDoc( contextDir, path );
89         if (!f.exists()) return null;
90         return f.toURL();
91     }
92
93     public String JavaDoc getRealPath(String JavaDoc path) {
94         if (getLogger().isDebugEnabled()) {
95             getLogger().debug("CommandlineContext: getRealPath=" + path);
96         }
97         // rely on File to build correct File and URL
98
File JavaDoc f = new File JavaDoc( this.contextDir, path );
99         return f.getAbsolutePath();
100     }
101
102     public String JavaDoc getMimeType(String JavaDoc file) {
103         if (getLogger().isDebugEnabled()) {
104             getLogger().debug("CommandlineContext: getMimeType=" + file);
105         }
106         //return servletContext.getMimeType(file);
107
return null;
108     }
109
110     public String JavaDoc getInitParameter(String JavaDoc name) {
111         getLogger().debug("CommandlineContext: getInitParameter=" + name);
112         return null;
113     }
114
115     public InputStream JavaDoc getResourceAsStream(String JavaDoc path){
116         getLogger().debug("CommandlineContext: getResourceAsStream "+path);
117     return null;
118     }
119 }
120
Popular Tags