You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2005/03/22 17:18:57 UTC
svn commit: r158620 -
cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/jxpath/JXPathCocoonContexts.java
Author: vgritsenko
Date: Tue Mar 22 08:18:56 2005
New Revision: 158620
URL: http://svn.apache.org/viewcvs?view=rev&rev=158620
Log:
do not mess up jxpath introspection for Cocoon environment classes
Modified:
cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/jxpath/JXPathCocoonContexts.java
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/jxpath/JXPathCocoonContexts.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/jxpath/JXPathCocoonContexts.java?view=diff&r1=158619&r2=158620
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/jxpath/JXPathCocoonContexts.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/jxpath/JXPathCocoonContexts.java Tue Mar 22 08:18:56 2005
@@ -15,25 +15,31 @@
*/
package org.apache.cocoon.jxpath;
-import java.util.Map;
-
import org.apache.avalon.framework.component.Component;
-import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.thread.ThreadSafe;
+
import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.Context;
+import org.apache.cocoon.environment.Cookie;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
-import org.apache.cocoon.environment.http.HttpContext;
-import org.apache.cocoon.environment.http.HttpRequest;
-import org.apache.cocoon.environment.http.HttpSession;
+
import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.JXPathContextFactory;
import org.apache.commons.jxpath.JXPathIntrospector;
import org.apache.commons.jxpath.servlet.Constants;
import org.apache.commons.jxpath.servlet.KeywordVariables;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.Principal;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.Map;
+
/**
* Component that allocate and cache JXPathContexts bound to VariableContext,
* Cocoon Request, Cocoon Session and Cocoon Context.
@@ -71,16 +77,16 @@
private static final String VARCONTEXT = Constants.JXPATH_CONTEXT + "/VAR";
private static JXPathContextFactory factory;
- private Context context;
+ private org.apache.avalon.framework.context.Context context;
static {
factory = JXPathContextFactory.newInstance();
- JXPathIntrospector.registerDynamicClass(HttpRequest.class, CocoonRequestHandler.class);
- JXPathIntrospector.registerDynamicClass(HttpSession.class, CocoonSessionHandler.class);
- JXPathIntrospector.registerDynamicClass(HttpContext.class, CocoonContextHandler.class);
+ JXPathIntrospector.registerDynamicClass(RequestProxy.class, CocoonRequestHandler.class);
+ JXPathIntrospector.registerDynamicClass(SessionProxy.class, CocoonSessionHandler.class);
+ JXPathIntrospector.registerDynamicClass(ContextProxy.class, CocoonContextHandler.class);
}
- public void contextualize(Context context) {
+ public void contextualize(org.apache.avalon.framework.context.Context context) {
this.context = context;
}
@@ -97,8 +103,8 @@
}
/**
- * Returns a JXPathContext bound to the "request" scope. Caches that context
- * within the request itself.
+ * Returns a JXPathContext bound to the "request" scope.
+ * Caches that context within the request itself.
*/
public final JXPathContext getRequestContext() {
final Map objectModel = ContextHelper.getObjectModel(this.context);
@@ -106,19 +112,17 @@
Request request = ObjectModelHelper.getRequest(objectModel);
JXPathContext context = (JXPathContext) request.getAttribute(Constants.JXPATH_CONTEXT);
if (context == null) {
- org.apache.cocoon.environment.Context cocoonContext = ObjectModelHelper.getContext(objectModel);
+ Context envContext = ObjectModelHelper.getContext(objectModel);
JXPathContext parentContext = null;
Session session = request.getSession(false);
if (session != null) {
- parentContext = getSessionContext(session, cocoonContext);
+ parentContext = getSessionContext(session, envContext);
} else {
- parentContext = getApplicationContext(cocoonContext);
- }
- if (request.getClass() != HttpRequest.class) {
- JXPathIntrospector.registerDynamicClass(request.getClass(), CocoonRequestHandler.class);
+ parentContext = getApplicationContext(envContext);
}
+ request = new RequestProxy(request);
context = factory.newContext(parentContext, request);
context.setVariables(new KeywordVariables(Constants.REQUEST_SCOPE, request));
request.setAttribute(Constants.JXPATH_CONTEXT, context);
@@ -127,17 +131,14 @@
}
/**
- * Returns a JXPathContext bound to the "session" scope. Caches that context
- * within the session itself.
+ * Returns a JXPathContext bound to the "session" scope.
+ * Caches that context within the session itself.
*/
- public final JXPathContext getSessionContext(Session session, org.apache.cocoon.environment.Context cocoonContext) {
+ public final JXPathContext getSessionContext(Session session, Context envContext) {
JXPathContext context = (JXPathContext) session.getAttribute(Constants.JXPATH_CONTEXT);
if (context == null) {
- if (session.getClass() != HttpSession.class) {
- JXPathIntrospector.registerDynamicClass(session.getClass(), CocoonSessionHandler.class);
- }
-
- JXPathContext parentContext = getApplicationContext(cocoonContext);
+ JXPathContext parentContext = getApplicationContext(envContext);
+ session = new SessionProxy(session);
context = factory.newContext(parentContext, session);
context.setVariables(new KeywordVariables(Constants.SESSION_SCOPE, session));
session.setAttribute(Constants.JXPATH_CONTEXT, context);
@@ -149,18 +150,299 @@
* Returns a JXPathContext bound to the "application" scope. Caches that context
* within the servlet context itself.
*/
- public final JXPathContext getApplicationContext(org.apache.cocoon.environment.Context cocoonContext) {
- JXPathContext context = (JXPathContext) cocoonContext.getAttribute(Constants.JXPATH_CONTEXT);
+ public final JXPathContext getApplicationContext(Context envContext) {
+ JXPathContext context = (JXPathContext) envContext.getAttribute(Constants.JXPATH_CONTEXT);
if (context == null) {
- if (cocoonContext.getClass() != HttpContext.class) {
- JXPathIntrospector.registerDynamicClass(cocoonContext.getClass(), CocoonContextHandler.class);
- }
-
- context = factory.newContext(null, cocoonContext);
- context.setVariables(new KeywordVariables(Constants.APPLICATION_SCOPE, cocoonContext));
- cocoonContext.setAttribute(Constants.JXPATH_CONTEXT, context);
+ envContext = new ContextProxy(envContext);
+ context = factory.newContext(null, envContext);
+ context.setVariables(new KeywordVariables(Constants.APPLICATION_SCOPE, envContext));
+ envContext.setAttribute(Constants.JXPATH_CONTEXT, context);
}
return context;
}
+ public static final class RequestProxy implements Request {
+ private Request delegate;
+
+ public RequestProxy (Request delegate) {
+ this.delegate = delegate;
+ }
+
+ public Object get(String name) {
+ return this.delegate.get(name);
+ }
+
+ public Object getAttribute(String name) {
+ return this.delegate.getAttribute(name);
+ }
+
+ public Enumeration getAttributeNames() {
+ return this.delegate.getAttributeNames();
+ }
+
+ public String getCharacterEncoding() {
+ return this.delegate.getCharacterEncoding();
+ }
+
+ public void setCharacterEncoding(String enc)
+ throws java.io.UnsupportedEncodingException {
+ this.delegate.setCharacterEncoding(enc);
+ }
+
+ public int getContentLength() {
+ return this.delegate.getContentLength();
+ }
+
+ public String getContentType() {
+ return this.delegate.getContentType();
+ }
+
+ public String getParameter(String name) {
+ return this.delegate.getParameter(name);
+ }
+
+ public Enumeration getParameterNames() {
+ return this.delegate.getParameterNames();
+ }
+
+ public String[] getParameterValues(String name) {
+ return this.delegate.getParameterValues(name);
+ }
+
+ public String getProtocol() {
+ return this.delegate.getProtocol();
+ }
+
+ public String getScheme() {
+ return this.delegate.getScheme();
+ }
+
+ public String getServerName() {
+ return this.delegate.getServerName();
+ }
+
+ public int getServerPort() {
+ return this.delegate.getServerPort();
+ }
+
+ public String getRemoteAddr() {
+ return this.delegate.getRemoteAddr();
+ }
+
+ public String getRemoteHost() {
+ return this.delegate.getRemoteHost();
+ }
+
+ public void setAttribute(String name, Object o) {
+ this.delegate.setAttribute(name, o);
+ }
+
+ public void removeAttribute(String name) {
+ this.delegate.removeAttribute(name);
+ }
+
+ public Locale getLocale() {
+ return this.delegate.getLocale();
+ }
+
+ public Enumeration getLocales() {
+ return this.delegate.getLocales();
+ }
+
+ public boolean isSecure() {
+ return this.delegate.isSecure();
+ }
+
+ public Cookie[] getCookies() {
+ return this.delegate.getCookies();
+ }
+
+ public Map getCookieMap() {
+ return this.delegate.getCookieMap();
+ }
+
+ public long getDateHeader(String name) {
+ return this.delegate.getDateHeader(name);
+ }
+
+ public String getHeader(String name) {
+ return this.delegate.getHeader(name);
+ }
+
+ public Enumeration getHeaders(String name) {
+ return this.delegate.getHeaders(name);
+ }
+
+ public Enumeration getHeaderNames() {
+ return this.delegate.getHeaderNames();
+ }
+
+ public String getMethod() {
+ return this.delegate.getMethod();
+ }
+
+ public String getPathInfo() {
+ return this.delegate.getPathInfo();
+ }
+
+ public String getPathTranslated() {
+ return this.delegate.getPathTranslated();
+ }
+
+ public String getContextPath() {
+ return this.delegate.getContextPath();
+ }
+
+ public String getQueryString() {
+ return this.delegate.getQueryString();
+ }
+
+ public String getRemoteUser() {
+ return this.delegate.getRemoteUser();
+ }
+
+ public String getRequestedSessionId() {
+ return this.delegate.getRequestedSessionId();
+ }
+
+ public String getRequestURI() {
+ return this.delegate.getRequestURI();
+ }
+
+ public String getSitemapURI() {
+ return this.delegate.getSitemapURI();
+ }
+
+ public String getServletPath() {
+ return this.delegate.getServletPath();
+ }
+
+ public Session getSession(boolean create) {
+ return this.delegate.getSession(create);
+ }
+
+ public Session getSession() {
+ return this.delegate.getSession();
+ }
+
+ public boolean isRequestedSessionIdValid() {
+ return this.delegate.isRequestedSessionIdValid();
+ }
+
+ public boolean isRequestedSessionIdFromCookie() {
+ return this.delegate.isRequestedSessionIdFromCookie();
+ }
+
+ public boolean isRequestedSessionIdFromURL() {
+ return this.delegate.isRequestedSessionIdFromURL();
+ }
+
+ public Principal getUserPrincipal() {
+ return this.delegate.getUserPrincipal();
+ }
+
+ public boolean isUserInRole(String role) {
+ return this.delegate.isUserInRole(role);
+ }
+
+ public String getAuthType() {
+ return this.delegate.getAuthType();
+ }
+ }
+
+ public class SessionProxy implements Session {
+ private Session delegate;
+
+ public SessionProxy(Session delegate) {
+ this.delegate = delegate;
+ }
+
+ public long getCreationTime() {
+ return this.delegate.getCreationTime();
+ }
+
+ public String getId() {
+ return this.delegate.getId();
+ }
+
+ public long getLastAccessedTime() {
+ return this.delegate.getLastAccessedTime();
+ }
+
+ public void setMaxInactiveInterval(int interval) {
+ this.delegate.setMaxInactiveInterval(interval);
+ }
+
+ public int getMaxInactiveInterval() {
+ return this.delegate.getMaxInactiveInterval();
+ }
+
+ public Object getAttribute(String name) {
+ return this.delegate.getAttribute(name);
+ }
+
+ public Enumeration getAttributeNames() {
+ return this.delegate.getAttributeNames();
+ }
+
+ public void setAttribute(String name, Object value) {
+ this.delegate.setAttribute(name, value);
+ }
+
+ public void removeAttribute(String name) {
+ this.delegate.removeAttribute(name);
+ }
+
+ public void invalidate() {
+ this.delegate.invalidate();
+ }
+
+ public boolean isNew() {
+ return this.delegate.isNew();
+ }
+ }
+
+ public class ContextProxy implements Context {
+ private Context delegate;
+
+ public ContextProxy(org.apache.cocoon.environment.Context delegate) {
+ this.delegate = delegate;
+ }
+
+ public Object getAttribute(String name) {
+ return this.delegate.getAttribute(name);
+ }
+
+ public void setAttribute(String name, Object value) {
+ this.delegate.setAttribute(name, value);
+ }
+
+ public void removeAttribute(String name) {
+ this.delegate.removeAttribute(name);
+ }
+
+ public Enumeration getAttributeNames() {
+ return this.delegate.getAttributeNames();
+ }
+
+ public URL getResource(String path) throws MalformedURLException {
+ return this.delegate.getResource(path);
+ }
+
+ public String getRealPath(String path) {
+ return this.delegate.getRealPath(path);
+ }
+
+ public String getMimeType(String file) {
+ return this.delegate.getMimeType(file);
+ }
+
+ public String getInitParameter(String name) {
+ return this.delegate.getInitParameter(name);
+ }
+
+ public InputStream getResourceAsStream(String path) {
+ return this.delegate.getResourceAsStream(path);
+ }
+ }
}