ovidiu 02/01/29 10:49:48
Modified: src/java/org/apache/cocoon/environment Context.java
src/java/org/apache/cocoon/environment/commandline
CommandlineContext.java
src/java/org/apache/cocoon/environment/http HttpContext.java
Log:
Added getResourceAsStream(). Submitted by Mark Butler <[EMAIL PROTECTED]>.
Revision Changes Path
1.2 +43 -40 xml-cocoon2/src/java/org/apache/cocoon/environment/Context.java
Index: Context.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/Context.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Context.java 3 Jan 2002 12:31:15 -0000 1.1
+++ Context.java 29 Jan 2002 18:49:48 -0000 1.2
@@ -1,40 +1,43 @@
-/*****************************************************************************
- * Copyright (C) The Apache Software Foundation. All rights reserved. *
- * ------------------------------------------------------------------------- *
- * This software is published under the terms of the Apache Software License *
- * version 1.1, a copy of which has been included with this distribution in *
- * the LICENSE file. *
- *****************************************************************************/
-
-package org.apache.cocoon.environment;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Enumeration;
-
-/**
- * Defines an interface to provide client context information .
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
- * @version CVS $Revision: 1.1 $ $Date: 2002/01/03 12:31:15 $
- *
- */
-
-public interface Context {
-
- Object getAttribute(String name);
-
- void setAttribute(String name, Object value);
-
- void removeAttribute(String name);
-
- Enumeration getAttributeNames();
-
- URL getResource(String path) throws MalformedURLException;
-
- String getRealPath(String path);
-
- String getMimeType(String file);
-
- String getInitParameter(String name);
-}
+/*****************************************************************************
+ * Copyright (C) The Apache Software Foundation. All rights reserved. *
+ * ------------------------------------------------------------------------- *
+ * This software is published under the terms of the Apache Software License *
+ * version 1.1, a copy of which has been included with this distribution in *
+ * the LICENSE file. *
+ *****************************************************************************/
+
+package org.apache.cocoon.environment;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.io.InputStream;
+
+/**
+ * Defines an interface to provide client context information .
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
+ * @version CVS $Revision: 1.2 $ $Date: 2002/01/29 18:49:48 $
+ *
+ */
+
+public interface Context {
+
+ Object getAttribute(String name);
+
+ void setAttribute(String name, Object value);
+
+ void removeAttribute(String name);
+
+ Enumeration getAttributeNames();
+
+ URL getResource(String path) throws MalformedURLException;
+
+ String getRealPath(String path);
+
+ String getMimeType(String file);
+
+ String getInitParameter(String name);
+
+ InputStream getResourceAsStream(String path);
+}
1.3 +108 -102
xml-cocoon2/src/java/org/apache/cocoon/environment/commandline/CommandlineContext.java
Index: CommandlineContext.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/commandline/CommandlineContext.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CommandlineContext.java 9 Jan 2002 08:06:17 -0000 1.2
+++ CommandlineContext.java 29 Jan 2002 18:49:48 -0000 1.3
@@ -1,102 +1,108 @@
-/*****************************************************************************
- * Copyright (C) The Apache Software Foundation. All rights reserved. *
- * ------------------------------------------------------------------------- *
- * This software is published under the terms of the Apache Software License *
- * version 1.1, a copy of which has been included with this distribution in *
- * the LICENSE file. *
- *****************************************************************************/
-package org.apache.cocoon.environment.commandline;
-
-import org.apache.avalon.excalibur.collections.IteratorEnumeration;
-import org.apache.avalon.framework.logger.AbstractLoggable;
-import org.apache.cocoon.environment.Context;
-
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- *
- * Implements the {@link org.apache.cocoon.environment.Context} interface
- */
-
-public class CommandlineContext extends AbstractLoggable implements Context {
-
- /** The context directory path*/
- private String contextDir;
-
- /** The context attributes */
- private Map attributes;
-
- /**
- * Constructs a CommandlineContext object from a ServletContext object
- */
- public CommandlineContext (String contextDir) {
- String contextDirPath = new File(contextDir).getAbsolutePath();
- // store contextDirPath as is don't remove trailing /.
- this.contextDir = contextDirPath;
- this.attributes = new HashMap();
- }
-
- public Object getAttribute(String name) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("CommandlineContext: getAttribute=" + name);
- }
- return this.attributes.get(name);
- }
-
- public void setAttribute(String name, Object value) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("CommandlineContext: setAttribute=" + name);
- }
- this.attributes.put(name, value);
- }
-
- public void removeAttribute(String name) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("CommandlineContext: removeAttribute=" + name);
- }
- this.attributes.remove(name);
- }
-
- public Enumeration getAttributeNames() {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("CommandlineContext: getAttributeNames");
- }
- return new IteratorEnumeration(this.attributes.keySet().iterator());
- }
-
- public URL getResource(String path) throws MalformedURLException {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("CommandlineContext: getResource=" + path);
- }
- // rely on File to build correct File and URL
- File f = new File( contextDir, path );
- return f.toURL();
- }
-
- public String getRealPath(String path) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("CommandlineContext: getRealPath=" + path);
- }
- // rely on File to build correct File and URL
- File f = new File( this.contextDir, path );
- return f.getAbsolutePath();
- }
-
- public String getMimeType(String file) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("CommandlineContext: getMimeType=" + file);
- }
- //return servletContext.getMimeType(file);
- return null;
- }
-
- public String getInitParameter(String name) {
- getLogger().debug("CommandlineContext: getInitParameter=" + name);
- return null;
- }
-}
+/*****************************************************************************
+ * Copyright (C) The Apache Software Foundation. All rights reserved. *
+ * ------------------------------------------------------------------------- *
+ * This software is published under the terms of the Apache Software License *
+ * version 1.1, a copy of which has been included with this distribution in *
+ * the LICENSE file. *
+ *****************************************************************************/
+package org.apache.cocoon.environment.commandline;
+
+import org.apache.avalon.excalibur.collections.IteratorEnumeration;
+import org.apache.avalon.framework.logger.AbstractLoggable;
+import org.apache.cocoon.environment.Context;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.HashMap;
+import java.io.InputStream;
+
+/**
+ *
+ * Implements the {@link org.apache.cocoon.environment.Context} interface
+ */
+
+public class CommandlineContext extends AbstractLoggable implements Context {
+
+ /** The context directory path*/
+ private String contextDir;
+
+ /** The context attributes */
+ private Map attributes;
+
+ /**
+ * Constructs a CommandlineContext object from a ServletContext object
+ */
+ public CommandlineContext (String contextDir) {
+ String contextDirPath = new File(contextDir).getAbsolutePath();
+ // store contextDirPath as is don't remove trailing /.
+ this.contextDir = contextDirPath;
+ this.attributes = new HashMap();
+ }
+
+ public Object getAttribute(String name) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("CommandlineContext: getAttribute=" + name);
+ }
+ return this.attributes.get(name);
+ }
+
+ public void setAttribute(String name, Object value) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("CommandlineContext: setAttribute=" + name);
+ }
+ this.attributes.put(name, value);
+ }
+
+ public void removeAttribute(String name) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("CommandlineContext: removeAttribute=" + name);
+ }
+ this.attributes.remove(name);
+ }
+
+ public Enumeration getAttributeNames() {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("CommandlineContext: getAttributeNames");
+ }
+ return new IteratorEnumeration(this.attributes.keySet().iterator());
+ }
+
+ public URL getResource(String path) throws MalformedURLException {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("CommandlineContext: getResource=" + path);
+ }
+ // rely on File to build correct File and URL
+ File f = new File( contextDir, path );
+ return f.toURL();
+ }
+
+ public String getRealPath(String path) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("CommandlineContext: getRealPath=" + path);
+ }
+ // rely on File to build correct File and URL
+ File f = new File( this.contextDir, path );
+ return f.getAbsolutePath();
+ }
+
+ public String getMimeType(String file) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("CommandlineContext: getMimeType=" + file);
+ }
+ //return servletContext.getMimeType(file);
+ return null;
+ }
+
+ public String getInitParameter(String name) {
+ getLogger().debug("CommandlineContext: getInitParameter=" + name);
+ return null;
+ }
+
+ public InputStream getResourceAsStream(String path){
+ getLogger().debug("CommandlineContext: getResourceAsStream "+path);
+ return null;
+ }
+}
1.3 +84 -79
xml-cocoon2/src/java/org/apache/cocoon/environment/http/HttpContext.java
Index: HttpContext.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/http/HttpContext.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HttpContext.java 22 Jan 2002 00:17:13 -0000 1.2
+++ HttpContext.java 29 Jan 2002 18:49:48 -0000 1.3
@@ -1,79 +1,84 @@
-/*****************************************************************************
- * Copyright (C) The Apache Software Foundation. All rights reserved. *
- * ------------------------------------------------------------------------- *
- * This software is published under the terms of the Apache Software License *
- * version 1.1, a copy of which has been included with this distribution in *
- * the LICENSE file. *
- *****************************************************************************/
-package org.apache.cocoon.environment.http;
-
-import org.apache.cocoon.environment.Context;
-
-import javax.servlet.ServletContext;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Enumeration;
-
-/**
- *
- * Implements the {@link org.apache.cocoon.environment.Context} interface
- */
-
-public class HttpContext implements Context {
-
- /** The ServletContext */
- private ServletContext servletContext = null;
-
- /**
- * Constructs a HttpContext object from a ServletContext object
- */
- public HttpContext (ServletContext servletContext) {
- this.servletContext = servletContext;
- }
-
- public Object getAttribute(String name) {
- return servletContext.getAttribute(name);
- }
-
- public void setAttribute(String name, Object value) {
- servletContext.setAttribute(name, value);
- }
-
- public void removeAttribute(String name) {
- servletContext.removeAttribute(name);
- }
-
- public Enumeration getAttributeNames() {
- return servletContext.getAttributeNames();
- }
-
- public URL getResource(String path)
- throws MalformedURLException {
- return servletContext.getResource(path);
- }
-
- public String getRealPath(String path) {
- if (path.equals("/")) {
- String value = servletContext.getRealPath(path);
- if (value == null) {
- // Try to figure out the path of the root from that of WEB-INF
- try {
- value = this.servletContext.getResource("/WEB-INF").toString();
- } catch (MalformedURLException mue) {
- throw new RuntimeException("Cannot determine the base URL");
- }
- value = value.substring(0,value.length()-"WEB-INF".length());
- }
- return value;
- }
- return servletContext.getRealPath(path);
- }
-
- public String getMimeType(String file) {
- return servletContext.getMimeType(file);
- }
-
- public String getInitParameter(String name) {
- return servletContext.getInitParameter(name);
- }
-}
+/*****************************************************************************
+ * Copyright (C) The Apache Software Foundation. All rights reserved. *
+ * ------------------------------------------------------------------------- *
+ * This software is published under the terms of the Apache Software License *
+ * version 1.1, a copy of which has been included with this distribution in *
+ * the LICENSE file. *
+ *****************************************************************************/
+package org.apache.cocoon.environment.http;
+
+import org.apache.cocoon.environment.Context;
+
+import javax.servlet.ServletContext;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.io.InputStream;
+
+/**
+ *
+ * Implements the {@link org.apache.cocoon.environment.Context} interface
+ */
+
+public class HttpContext implements Context {
+
+ /** The ServletContext */
+ private ServletContext servletContext = null;
+
+ /**
+ * Constructs a HttpContext object from a ServletContext object
+ */
+ public HttpContext (ServletContext servletContext) {
+ this.servletContext = servletContext;
+ }
+
+ public Object getAttribute(String name) {
+ return servletContext.getAttribute(name);
+ }
+
+ public void setAttribute(String name, Object value) {
+ servletContext.setAttribute(name, value);
+ }
+
+ public void removeAttribute(String name) {
+ servletContext.removeAttribute(name);
+ }
+
+ public Enumeration getAttributeNames() {
+ return servletContext.getAttributeNames();
+ }
+
+ public URL getResource(String path)
+ throws MalformedURLException {
+ return servletContext.getResource(path);
+ }
+
+ public InputStream getResourceAsStream(String path) {
+ return servletContext.getResourceAsStream(path);
+ }
+
+ public String getRealPath(String path) {
+ if (path.equals("/")) {
+ String value = servletContext.getRealPath(path);
+ if (value == null) {
+ // Try to figure out the path of the root from that of WEB-INF
+ try {
+ value = this.servletContext.getResource("/WEB-INF").toString();
+ } catch (MalformedURLException mue) {
+ throw new RuntimeException("Cannot determine the base URL");
+ }
+ value = value.substring(0,value.length()-"WEB-INF".length());
+ }
+ return value;
+ }
+ return servletContext.getRealPath(path);
+ }
+
+ public String getMimeType(String file) {
+ return servletContext.getMimeType(file);
+ }
+
+ public String getInitParameter(String name) {
+ return servletContext.getInitParameter(name);
+ }
+}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]