Author: kentam
Date: Mon Apr 25 16:57:41 2005
New Revision: 164694
URL: http://svn.apache.org/viewcvs?rev=164694&view=rev
Log:
BEEHIVE-121: ServletBeanContext should expose ServletContext resources directly.
Implemented getResource() and getResourceAsStream() on ServletBeanContext to
delegate to the appropriate ServletContext APIs.
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/servlet/ServletBeanContext.java
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/servlet/ServletBeanContext.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/servlet/ServletBeanContext.java?rev=164694&r1=164693&r2=164694&view=diff
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/servlet/ServletBeanContext.java
(original)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/servlet/ServletBeanContext.java
Mon Apr 25 16:57:41 2005
@@ -18,6 +18,10 @@
*/
import java.util.Stack;
+import java.io.InputStream;
+import java.beans.beancontext.BeanContextChild;
+import java.net.URL;
+import java.net.MalformedURLException;
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
@@ -172,6 +176,54 @@
public void setWrappers(boolean useWrappers)
{
_useWrappers = useWrappers;
+ }
+
+ /**
+ * Override BeanContext.getResourceAsStream() so it delegates to the
current ServletContext.
+ *
+ * @param name the resource name
+ * @param bcc the specified child
+ * @return an <code>InputStream</code> for reading the resource,
+ * or <code>null</code> if the resource could not
+ * be found.
+ * @throws <code>IllegalArgumentException</code> if
+ * the resource is not valid
+ */
+ public InputStream getResourceAsStream(String name, BeanContextChild bcc)
throws IllegalArgumentException
+ {
+ ServletContext sc = getServletContext();
+ if ( sc != null )
+ return sc.getResourceAsStream( name );
+
+ return null;
+ }
+
+ /**
+ * Override BeanContext.getResource() so it delegates to the current
ServletContext.
+ *
+ * @param name the resource name
+ * @param bcc the specified child
+ * @return a <code>URL</code> for the named
+ * resource for the specified child
+ * @throws <code>IllegalArgumentException</code>
+ * if the resource is not valid
+ */
+ public URL getResource(String name, BeanContextChild bcc) throws
IllegalArgumentException
+ {
+ ServletContext sc = getServletContext();
+ if ( sc != null )
+ {
+ try
+ {
+ return sc.getResource( name );
+ }
+ catch ( MalformedURLException mue )
+ {
+ throw new IllegalArgumentException( mue.getMessage() );
+ }
+ }
+
+ return null;
}
protected boolean useWrappers() { return _useWrappers; }