Author: vgritsenko Date: Sat Nov 13 15:00:29 2004 New Revision: 65531 Modified: cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/CocoonContextHandler.java cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/CocoonRequestHandler.java cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/CocoonSessionHandler.java cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/JXPathCocoonContexts.java Log: whitespaces
Modified: cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/CocoonContextHandler.java ============================================================================== --- cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/CocoonContextHandler.java (original) +++ cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/CocoonContextHandler.java Sat Nov 13 15:00:29 2004 @@ -1,19 +1,18 @@ /* * Copyright 1999-2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.cocoon.jxpath; import java.util.Enumeration; @@ -31,16 +30,16 @@ */ public class CocoonContextHandler implements DynamicPropertyHandler { - public String[] getPropertyNames(Object context){ - Enumeration e = ((Context)context).getAttributeNames(); - return (String [])EnumerationUtils.toList(e).toArray(); + public String[] getPropertyNames(Object context) { + final Enumeration e = ((Context) context).getAttributeNames(); + return (String[]) EnumerationUtils.toList(e).toArray(); } - public Object getProperty(Object context, String property){ - return ((Context)context).getAttribute(property); + public Object getProperty(Object context, String property) { + return ((Context) context).getAttribute(property); } - public void setProperty(Object context, String property, Object value){ - ((Context)context).setAttribute(property, value); + public void setProperty(Object context, String property, Object value) { + ((Context) context).setAttribute(property, value); } } Modified: cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/CocoonRequestHandler.java ============================================================================== --- cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/CocoonRequestHandler.java (original) +++ cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/CocoonRequestHandler.java Sat Nov 13 15:00:29 2004 @@ -1,19 +1,18 @@ /* * Copyright 1999-2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.cocoon.jxpath; import java.util.Enumeration; @@ -31,16 +30,16 @@ */ public class CocoonRequestHandler implements DynamicPropertyHandler { - public String[] getPropertyNames(Object request){ - Enumeration e = ((Request)request).getAttributeNames(); - return (String [])EnumerationUtils.toList(e).toArray(); + public String[] getPropertyNames(Object request) { + final Enumeration e = ((Request) request).getAttributeNames(); + return (String[]) EnumerationUtils.toList(e).toArray(); } - public Object getProperty(Object request, String property){ - return ((Request)request).getAttribute(property); + public Object getProperty(Object request, String property) { + return ((Request) request).getAttribute(property); } - public void setProperty(Object request, String property, Object value){ - ((Request)request).setAttribute(property, value); + public void setProperty(Object request, String property, Object value) { + ((Request) request).setAttribute(property, value); } } Modified: cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/CocoonSessionHandler.java ============================================================================== --- cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/CocoonSessionHandler.java (original) +++ cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/CocoonSessionHandler.java Sat Nov 13 15:00:29 2004 @@ -1,19 +1,18 @@ /* * Copyright 1999-2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.cocoon.jxpath; import java.util.Enumeration; @@ -31,16 +30,16 @@ */ public class CocoonSessionHandler implements DynamicPropertyHandler { - public String[] getPropertyNames(Object session){ - Enumeration e = ((Session)session).getAttributeNames(); - return (String [])EnumerationUtils.toList(e).toArray(); + public String[] getPropertyNames(Object session) { + final Enumeration e = ((Session) session).getAttributeNames(); + return (String[]) EnumerationUtils.toList(e).toArray(); } - public Object getProperty(Object session, String property){ - return ((Session)session).getAttribute(property); + public Object getProperty(Object session, String property) { + return ((Session) session).getAttribute(property); } - public void setProperty(Object session, String property, Object value){ - ((Session)session).setAttribute(property, value); + public void setProperty(Object session, String property, Object value) { + ((Session) session).setAttribute(property, value); } } Modified: cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/JXPathCocoonContexts.java ============================================================================== --- cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/JXPathCocoonContexts.java (original) +++ cocoon/trunk/src/blocks/taglib/java/org/apache/cocoon/jxpath/JXPathCocoonContexts.java Sat Nov 13 15:00:29 2004 @@ -1,19 +1,18 @@ /* * Copyright 1999-2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.cocoon.jxpath; import java.util.Map; @@ -38,55 +37,55 @@ /** * Component that allocate and cache JXPathContexts bound to VariableContext, * Cocoon Request, Cocoon Session and Cocoon Context. + * * <p> * If you need to limit the attibute lookup to just one scope, you can use the * pre-definded variables "request", "session" and "application". * For example, the expression "$session/foo" extracts the value of the - * session attribute named "foo". + * session attribute named "foo".</p> + * * <p> * Following are some implementation details. * There is a separate JXPathContext for each of the four scopes. These contexts are chained * according to the nesting of the scopes. So, the parent of the "variable" * JXPathContext is a "request" JXPathContext, whose parent is a "session" * JXPathContext (that is if there is a session), whose parent is an "application" - * context. + * context.</p> + * * <p> * Since JXPath chains lookups for variables and extension functions, variables * and extension function declared in the outer scopes are also available in - * the inner scopes. + * the inner scopes.</p> + * * <p> * The "session" variable will be undefined if there is no session for this servlet. - * JXPath does not automatically create sessions. + * JXPath does not automatically create sessions.</p> * * @author <a href="mailto:[EMAIL PROTECTED]">Volker Schmitt</a> * @version CVS $Id$ */ public final class JXPathCocoonContexts implements Contextualizable, Recyclable { - + public static final String ROLE = JXPathCocoonContexts.class.getName(); + private static JXPathContextFactory factory; private JXPathContext variableContext; private Context context; - + static { factory = JXPathContextFactory.newInstance(); JXPathIntrospector.registerDynamicClass(HttpRequest.class, CocoonRequestHandler.class); JXPathIntrospector.registerDynamicClass(HttpSession.class, CocoonSessionHandler.class); JXPathIntrospector.registerDynamicClass(HttpContext.class, CocoonContextHandler.class); } - - /* (non-Javadoc) - * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context) - */ - public void contextualize(Context context) - throws ContextException { + + public void contextualize(Context context) { this.context = context; } public final JXPathContext getVariableContext() { if (variableContext == null) { - JXPathContext parentContext = getRequestContext(); - variableContext = factory.newContext(parentContext, null); + variableContext = factory.newContext(getRequestContext(), null); } return variableContext; } @@ -96,20 +95,24 @@ * within the request itself. */ public final JXPathContext getRequestContext() { - Map objectModel = ContextHelper.getObjectModel(this.context); + final Map objectModel = ContextHelper.getObjectModel(this.context); + 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); JXPathContext parentContext = null; + Session session = request.getSession(false); if (session != null) { parentContext = getSessionContext(session, cocoonContext); } else { parentContext = getApplicationContext(cocoonContext); } - if (request.getClass() != HttpRequest.class) + if (request.getClass() != HttpRequest.class) { JXPathIntrospector.registerDynamicClass(request.getClass(), CocoonRequestHandler.class); + } + context = factory.newContext(parentContext, request); context.setVariables(new KeywordVariables(Constants.REQUEST_SCOPE, request)); request.setAttribute(Constants.JXPATH_CONTEXT, context); @@ -124,8 +127,10 @@ public final JXPathContext getSessionContext(Session session, org.apache.cocoon.environment.Context cocoonContext) { JXPathContext context = (JXPathContext) session.getAttribute(Constants.JXPATH_CONTEXT); if (context == null) { - if (session.getClass() != HttpSession.class) + if (session.getClass() != HttpSession.class) { JXPathIntrospector.registerDynamicClass(session.getClass(), CocoonSessionHandler.class); + } + JXPathContext parentContext = getApplicationContext(cocoonContext); context = factory.newContext(parentContext, session); context.setVariables(new KeywordVariables(Constants.SESSION_SCOPE, session)); @@ -141,15 +146,17 @@ public final JXPathContext getApplicationContext(org.apache.cocoon.environment.Context cocoonContext) { JXPathContext context = (JXPathContext) cocoonContext.getAttribute(Constants.JXPATH_CONTEXT); if (context == null) { - if (cocoonContext.getClass() != HttpContext.class) + 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); } return context; } - + /* * @see Recyclable#recycle() */