Author: alexsmirnov
Date: 2007-04-10 13:47:42 -0400 (Tue, 10 Apr 2007)
New Revision: 61
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextMap.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java
Log:
Continue work for portlet integration
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java 2007-04-10
17:43:39 UTC (rev 60)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java 2007-04-10
17:47:42 UTC (rev 61)
@@ -66,6 +66,7 @@
import java.security.Principal;
import java.util.Collections;
+import java.util.Enumeration;
import java.util.Enumeration;
@@ -188,202 +189,24 @@
*
*/
- public void dispatch(String path) throws IOException {
-
- // perform Generation in generator, do nothing in Action.
-
- // generator place special Dispatcher to objectModel ...
-
- // May be must set Dispatcher in special method in Context Component ???
-
- String jspPageURL = (String) getCocoonRequest().getAttribute(
-
- JSFGenerator.PAGE_URL_PARAM_NAME);
-
- RequestDispatcher dispatcher = getCocoonHttpContext()
-
- .getNamedDispatcher(getJspServletName());
-
- this.log("Dispatch for page: " + jspPageURL);
-
- // Dispatcher dispatch = getDispatcher();
-
- if (dispatcher == null) {
-
- throw new IOException("NamedDispatcher is null for servlet "
-
- + getJspServletName());
-
- }
-
- try {// Reset jsp Request/Response wrappers - for create on demand
-
- // with new Writer for current XML Consumer.
-
- this.jspRequest = null;
-
- this.jspResponse = null;
-
- dispatcher.include(new JSPServletRequest(getCocoonHttpRequest(),
-
- jspPageURL, null), (ServletResponse) this.getResponse());
-
- } catch (ServletException e) {
-
- //
-
- if (e.getMessage() != null) {
-
- throw new FacesException(e.getMessage(), e);
-
- } else {
-
- throw new FacesException(e);
-
- }
-
- }
-
- }
-
- /*
- *
- * (non-Javadoc)
- *
- *
- *
- * @see javax.faces.context.ExternalContext#encodeActionURL(java.lang.String)
- *
- */
-
- public String encodeActionURL(String url) {
-
- //
-
- return getCocoonResponse().encodeURL(url);
-
- }
-
- /*
- *
- * (non-Javadoc)
- *
- *
- *
- * @see javax.faces.context.ExternalContext#encodeNamespace(java.lang.String)
- *
- */
-
- public String encodeNamespace(String name) {
-
- // HACK - set namespace prefix in Action sitemap parameter.
-
- // return this.getCocoonRequest().getContextPath()+"/"+name;
-
- String namespace = (String) this.getCocoonRequest().getAttribute(
-
- FacesAction.ACT_NAMESPACE);
-
- if (null != namespace) {
-
- return namespace + name;
-
- }
-
- return name;
-
- }
-
- /*
- *
- * (non-Javadoc)
- *
- *
- *
- * @see javax.faces.context.ExternalContext#encodeResourceURL(java.lang.String)
- *
- */
-
- public String encodeResourceURL(String url) {
-
- //
-
- return this.getCocoonResponse().encodeURL(url);
-
- }
-
- /*
- *
- * (non-Javadoc)
- *
- *
- *
- * @see javax.faces.context.ExternalContext#getApplicationMap()
- *
- */
-
public Map getApplicationMap() {
-
- //
-
if (applicationMap == null) {
+ applicationMap = new ContextAttributesMap() {
- applicationMap = new ContextMap() {
- public Object get(Object key) {
-
- if (key == null) {
-
- throw new NullPointerException();
-
- }
-
- return getCocoonContext().getAttribute(key.toString());
-
+ protected Enumeration getEnumeration() {
+ return getContextAttributeNames();
}
- public Object put(Object key, Object value) {
- if (key == null) {
-
- throw new NullPointerException();
-
- }
-
- String keyString = key.toString();
-
- Object result = getCocoonContext().getAttribute(keyString);
-
- getCocoonContext().setAttribute(keyString, value);
-
- return (result);
-
+ protected Object getAttribute(String name) {
+ return getContextAttribute(name);
}
- public Object remove(Object key) {
-
- if (key == null) {
-
- return null;
-
- }
-
- String keyString = key.toString();
-
- Object result = getCocoonContext().getAttribute(keyString);
-
- getCocoonContext().removeAttribute(keyString);
-
- return (result);
-
+ protected void setAttribute(String name, Object value) {
+ setContextAttribute(name,value);
}
- protected Enumeration getEnumeration() {
-
- return getCocoonContext().getAttributeNames();
-
- }
-
};
}
@@ -392,122 +215,49 @@
}
+ protected abstract void setContextAttribute(String name, Object value);
+ protected abstract Object getContextAttribute(String name);
+ protected abstract Enumeration getContextAttributeNames();
+
/*
- *
* (non-Javadoc)
- *
- *
- *
* @see javax.faces.context.ExternalContext#getAuthType()
- *
*/
- public String getAuthType() {
-
- //
-
- return this.getCocoonRequest().getAuthType();
-
- }
-
- /*
- *
- * (non-Javadoc)
- *
- *
- *
- * @see javax.faces.context.ExternalContext#getContext()
- *
- */
-
public Object getContext() {
return this.context;
}
+ /**
+ * @param context
+ */
public void setContext(Object context) {
this.context = context;
}
- /*
- return servletContext; // .getContext(getRequestContextPath());
-
- // return getCocoonHttpContext();
-
- }
-
/*
- *
* (non-Javadoc)
- *
- *
- *
* @see javax.faces.context.ExternalContext#getInitParameter(java.lang.String)
- *
*/
- public String getInitParameter(String name) {
-
- // HACK - get init parameter from Action configuration instead of
-
- // servlet ...
-
- String ret = (String) getActionSettings().get(name);
-
- if (ret == null) {
-
- ret = this.getCocoonContext().getInitParameter(name);
-
- }
-
- return ret;
-
- }
-
- /*
- *
- * (non-Javadoc)
- *
- *
- *
- * @see javax.faces.context.ExternalContext#getInitParameterMap()
- *
- */
-
public Map getInitParameterMap() {
- // Combine Servlet InitParameters with Cocoon Action configuration
- // parameters ?
-
if (initParameterMap == null) {
- initParameterMap = new ContextConcatentedMap(this
+ initParameterMap = new ContextAttributesMap() {
- .getActionSettings()) {
+ protected Object getAttribute(String name) {
+ return getInitParameter(name);
+ }
- public Object getBase(Object key) {
-
- // HACK - return configuration parameter from Cocoon
-
- // FacesAction
-
- return getCocoonContext().getInitParameter(key.toString());
-
+ protected void setAttribute(String name, Object value) {
+ throw new UnsupportedOperationException();
}
protected Enumeration getEnumeration() {
-
- if (http) {
-
- return getCocoonHttpContext().getInitParameterNames();
-
- } else {
-
- return Collections.enumeration(Collections.EMPTY_SET);
-
- }
-
+ return getInitParametersNames();
}
};
@@ -518,70 +268,35 @@
}
- /*
- *
- * (non-Javadoc)
- *
- *
- *
- * @see javax.faces.context.ExternalContext#getRemoteUser()
- *
+
+ /**
+ * Hoock method for initialization parameters.
+ * @return
*/
+ protected abstract Enumeration getInitParametersNames();
- public String getRemoteUser() {
- //
- return getCocoonRequest().getRemoteUser();
- }
-
- /*
- *
- * (non-Javadoc)
- *
- *
- *
+ /* (non-Javadoc)
* @see javax.faces.context.ExternalContext#getRequest()
- *
*/
-
public Object getRequest() {
return request;
}
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#setRequest(java.lang.Object)
+ */
public void setRequest(Object request) {
this.request = request;
}
- public String getRequestContextPath() {
-
- // TODO return Cocoon sitemap-specific path ? or configure from sitemap
-
- // parameters of Action.
-
- return getCocoonRequest().getContextPath();
-
- }
-
- /*
- *
- * (non-Javadoc)
- *
- *
- *
- * @see javax.faces.context.ExternalContext#getRequestCookieMap()
- *
- */
-
public Map getRequestCookieMap() {
-
- //
-
- return getCocoonRequest().getCookieMap();
-
+ // Portlet environment don't have methods to use cookies.
+ return Collections.EMPTY_MAP;
}
/*
@@ -928,24 +643,6 @@
*
*/
- public String getRequestPathInfo() {
-
- //
-
- return (String) getCocoonRequest().getAttribute(FacesAction.ACT_SRC);
-
- }
-
- /*
- *
- * (non-Javadoc)
- *
- *
- *
- * @see javax.faces.context.ExternalContext#getRequestServletPath()
- *
- */
-
public String getRequestServletPath() {
// TODO return current sitemap path ??? For cocoon, always "/" !
@@ -1199,44 +896,4 @@
}
- // Private methods - for Cocoon Context Interaction.
-
- // TODO - rewrite as lazy creation, but need reset with change Context ?
-
- // private Map getObjectModel() {
-
- // return ContextHelper.getObjectModel(getCocoonContext());
-
- // }
-
- private class EnumerationIterator implements Iterator {
-
- public EnumerationIterator(Enumeration locales) {
-
- this.locales = locales;
-
- }
-
- private Enumeration locales;
-
- public boolean hasNext() {
-
- return locales.hasMoreElements();
-
- }
-
- public Object next() {
-
- return locales.nextElement();
-
- }
-
- public void remove() {
-
- throw new UnsupportedOperationException();
-
- }
-
- }
-
}
\ No newline at end of file
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextMap.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextMap.java 2007-04-10
17:43:39 UTC (rev 60)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextMap.java 2007-04-10
17:47:42 UTC (rev 61)
@@ -19,10 +19,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
package org.ajax4jsf.portlet.context;
import java.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.Enumeration;
@@ -48,6 +50,8 @@
abstract class ContextMap extends AbstractMap {
+ private transient volatile Set keySet;
+
/*
*
* (non-Javadoc)
@@ -74,6 +78,30 @@
}
+ public Set keySet() {
+ if (keySet == null) {
+ keySet = new AbstractSet(){
+
+ public Iterator iterator() {
+ return new EnumerationIterator(getEnumeration());
+ }
+ public int size() {
+ Enumeration enumeration = getEnumeration();
+ int size = 0;
+ while (enumeration.hasMoreElements()) {
+ size++;
+ };
+ return size;
+ }
+ };
+ }
+ return keySet;
+ }
+
+ public Collection values() {
+ return super.values();
+ }
+
/**
*
*
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java 2007-04-10
17:43:39 UTC (rev 60)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java 2007-04-10
17:47:42 UTC (rev 61)
@@ -6,8 +6,14 @@
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Enumeration;
+import java.util.Map;
import java.util.Set;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
/**
* @author asmirnov
*
@@ -22,29 +28,41 @@
public ServletContextImpl(Object context, Object request, Object response) {
super(context, request, response);
}
+
+ private HttpServletRequest getHttpRequest(){
+ return (HttpServletRequest) getRequest();
+ }
+
+ private ServletContext getServletContext(){
+ return (ServletContext) getContext();
+ }
+ private HttpServletResponse getHttpResponse(){
+ return (HttpServletResponse) getResponse();
+ }
/* (non-Javadoc)
* @see javax.faces.context.ExternalContext#getInitParameter(java.lang.String)
*/
public String getInitParameter(String name) {
- // TODO Auto-generated method stub
- return null;
+ return getServletContext().getInitParameter(name);
}
+
+ protected Enumeration getInitParametersNames() {
+ return getServletContext().getInitParameterNames();
+ }
/* (non-Javadoc)
* @see javax.faces.context.ExternalContext#getResource(java.lang.String)
*/
public URL getResource(String path) throws MalformedURLException {
- // TODO Auto-generated method stub
- return null;
+ return getServletContext().getResource(path);
}
/* (non-Javadoc)
* @see javax.faces.context.ExternalContext#getResourceAsStream(java.lang.String)
*/
public InputStream getResourceAsStream(String path) {
- // TODO Auto-generated method stub
- return null;
+ return getServletContext().getResourceAsStream(path);
}
/* (non-Javadoc)
@@ -52,7 +70,43 @@
*/
public Set getResourcePaths(String path) {
// TODO Auto-generated method stub
- return null;
+ return getServletContext().getResourcePaths(path);
}
+ protected Object getContextAttribute(String name) {
+ return getServletContext().getAttribute(name);
+ }
+
+ protected Enumeration getContextAttributeNames() {
+ return getServletContext().getAttributeNames();
+ }
+
+ protected void setContextAttribute(String name, Object value) {
+ getServletContext().setAttribute(name, value);
+ }
+
+ public String getAuthType() {
+ return getHttpRequest().getAuthType();
+ }
+
+ public String getRemoteUser() {
+ return getHttpRequest().getRemoteUser();
+ }
+
+ public String getRequestContextPath() {
+ return getHttpRequest().getContextPath();
+ }
+
+ public String getRequestPathInfo() {
+ return getHttpRequest().getPathInfo();
+ }
+
+ public String getRequestServletPath() {
+ return getHttpRequest().getServletPath();
+ }
+
+ public Map getRequestCookieMap() {
+ // TODO Auto-generated method stub
+ return getHttpRequest().;
+ }
}