vgritsenko 2004/06/18 09:45:57
Modified: . status.xml
src/blocks/portal/java/org/apache/cocoon/environment/portlet
PortletEnvironment.java PortletRequest.java
PortletSession.java
src/blocks/portal/java/org/apache/cocoon/portlet
CocoonPortlet.java
Log:
Add default-session-scope parameter to the CocoonPortlet.
Cleanup portlet env - remove unused stuff.
Revision Changes Path
1.369 +5 -1 cocoon-2.1/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/status.xml,v
retrieving revision 1.368
retrieving revision 1.369
diff -u -r1.368 -r1.369
--- status.xml 18 Jun 2004 07:10:45 -0000 1.368
+++ status.xml 18 Jun 2004 16:45:57 -0000 1.369
@@ -204,6 +204,10 @@
<changes>
<release version="@version@" date="@date@">
+ <action dev="VG" type="update">
+ Portal: CocoonPortlet has new configuration parameter,
+ default-session-scope.
+ </action>
<action dev="AG" type="update">
Updated commons-logging to 1.0.4
</action>
1.6 +31 -12
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletEnvironment.java
Index: PortletEnvironment.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletEnvironment.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PortletEnvironment.java 26 May 2004 01:31:06 -0000 1.5
+++ PortletEnvironment.java 18 Jun 2004 16:45:57 -0000 1.6
@@ -1,12 +1,12 @@
/*
* 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.
@@ -20,10 +20,8 @@
import org.apache.cocoon.environment.ObjectModelHelper;
import javax.portlet.PortletContext;
-
import java.io.IOException;
import java.io.OutputStream;
-import java.net.MalformedURLException;
/**
* Implements [EMAIL PROTECTED] org.apache.cocoon.environment.Environment}
interface for the JSR-168
@@ -64,6 +62,11 @@
*/
public static final String SESSION_APPLICATION_SCOPE =
"portlet-application-";
+ /**
+ * This is the prefix for portlet scope session attributes.
+ */
+ public static final String SESSION_PORTLET_SCOPE = "portlet-portlet-";
+
/**
* The PortletRequest
@@ -88,19 +91,24 @@
private String contentType;
/**
+ * @see #getDefaultSessionScope()
+ */
+ private int defaultSessionScope;
+
+ /**
* Constructs a PortletEnvironment object from a PortletRequest
* and PortletResponse objects
*/
public PortletEnvironment(String servletPath,
String uri,
- String root,
javax.portlet.ActionRequest request,
javax.portlet.ActionResponse response,
PortletContext portletContext,
Context context,
String containerEncoding,
- String defaultFormEncoding)
- throws MalformedURLException, IOException {
+ String defaultFormEncoding,
+ int defaultSessionScope)
+ throws IOException {
super(uri, null, null);
String pathInfo = request.getParameter(PARAMETER_PATH_INFO);
@@ -110,6 +118,7 @@
this.request.setContainerEncoding(containerEncoding);
this.response = new ActionResponse(response,
request.getPreferences(), (ActionRequest) this.request, uri);
this.context = context;
+ this.defaultSessionScope = defaultSessionScope;
setView(extractView(this.request));
setAction(extractAction(this.request));
@@ -123,14 +132,14 @@
*/
public PortletEnvironment(String servletPath,
String uri,
- String root,
javax.portlet.RenderRequest request,
javax.portlet.RenderResponse response,
PortletContext portletContext,
Context context,
String containerEncoding,
- String defaultFormEncoding)
- throws MalformedURLException, IOException {
+ String defaultFormEncoding,
+ int defaultSessionScope)
+ throws IOException {
super(uri, null, null);
String pathInfo = request.getParameter(PARAMETER_PATH_INFO);
@@ -140,6 +149,7 @@
this.request.setContainerEncoding(containerEncoding);
this.response = new RenderResponse(response,
request.getPreferences());
this.context = context;
+ this.defaultSessionScope = defaultSessionScope;
setView(extractView(this.request));
setAction(extractAction(this.request));
@@ -264,5 +274,14 @@
*/
public boolean isExternal() {
return true;
+ }
+
+ /**
+ * Default scope for the session attributes, either
+ * [EMAIL PROTECTED] javax.portlet.PortletSession#PORTLET_SCOPE} or
+ * [EMAIL PROTECTED] javax.portlet.PortletSession#APPLICATION_SCOPE}.
+ */
+ int getDefaultSessionScope() {
+ return this.defaultSessionScope;
}
}
1.3 +8 -7
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletRequest.java
Index: PortletRequest.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletRequest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PortletRequest.java 5 Mar 2004 13:02:08 -0000 1.2
+++ PortletRequest.java 18 Jun 2004 16:45:57 -0000 1.3
@@ -1,12 +1,12 @@
/*
* 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.
@@ -65,8 +65,8 @@
/** The current session */
private PortletSession session;
- private Cookie[] wrappedCookies = null;
- private Map wrappedCookieMap = null;
+ private Cookie[] wrappedCookies;
+ private Map wrappedCookieMap;
protected String portletRequestURI;
@@ -267,7 +267,8 @@
}
} else {
// new wrapper
- this.session = new PortletSession(serverSession);
+ this.session = new PortletSession(serverSession,
+
this.environment.getDefaultSessionScope());
}
} else {
// invalidate
1.4 +70 -46
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletSession.java
Index: PortletSession.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletSession.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PortletSession.java 1 May 2004 00:05:44 -0000 1.3
+++ PortletSession.java 18 Jun 2004 16:45:57 -0000 1.4
@@ -1,12 +1,12 @@
/*
* 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.
@@ -23,7 +23,7 @@
/**
* Provides access to the JSR-168 (Portlet) environment session.
*
- * Portlet scope and application scope session attributes are differentiated
+ * <p>Portlet scope and application scope session attributes are
differentiated
* using attribute name prefix, [EMAIL PROTECTED]
PortletEnvironment#SESSION_APPLICATION_SCOPE}.
*
* @see javax.portlet.PortletSession
@@ -34,13 +34,22 @@
public final class PortletSession implements Session {
private static final String APP_SCOPE =
PortletEnvironment.SESSION_APPLICATION_SCOPE;
+ private static final String PORTLET_SCOPE =
PortletEnvironment.SESSION_PORTLET_SCOPE;
javax.portlet.PortletSession session;
/**
+ * Default session scope. One of
+ * [EMAIL PROTECTED] javax.portlet.PortletSession.APPLICATION_SCOPE},
+ * [EMAIL PROTECTED] javax.portlet.PortletSession.PORTLET_SCOPE}.
+ */
+ private int scope;
+
+ /**
* Construct a new session from an PortletSession
*/
- public PortletSession(javax.portlet.PortletSession session) {
+ public PortletSession(javax.portlet.PortletSession session, int scope) {
+ this.scope = scope;
this.session = session;
}
@@ -48,13 +57,13 @@
* Returns the time when this session was created, measured
* in milliseconds since midnight January 1, 1970 GMT.
*
- * @return a <code>long</code> specifying
- * when this session was created,
- * expressed in
- * milliseconds since 1/1/1970 GMT
+ * @return a <code>long</code> specifying
+ * when this session was created,
+ * expressed in
+ * milliseconds since 1/1/1970 GMT
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an
+ * invalidated session
*/
public long getCreationTime() {
return this.session.getCreationTime();
@@ -65,11 +74,11 @@
* to this session. The identifier is assigned
* by the context container and is implementation dependent.
*
- * @return a string specifying the
identifier
- * assigned to this session
+ * @return a string specifying the identifier
+ * assigned to this session
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an
+ * invalidated session
*/
public String getId() {
return this.session.getId();
@@ -84,14 +93,14 @@
* a value associated with the session, do not affect the access
* time.
*
- * @return a <code>long</code>
- * representing the last time
- * the client sent a request
associated
- * with this session, expressed in
- * milliseconds since 1/1/1970 GMT
+ * @return a <code>long</code>
+ * representing the last time
+ * the client sent a request
associated
+ * with this session, expressed in
+ * milliseconds since 1/1/1970 GMT
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an
+ * invalidated session
*/
public long getLastAccessedTime() {
return this.session.getLastAccessedTime();
@@ -136,31 +145,39 @@
*
* @return the object with the specified name
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an
+ * invalidated session
*/
public Object getAttribute(String name) {
if (name.startsWith(APP_SCOPE)) {
return
this.session.getAttribute(name.substring(APP_SCOPE.length()),
javax.portlet.PortletSession.APPLICATION_SCOPE);
+ } else if (name.startsWith(PORTLET_SCOPE)) {
+ return
this.session.getAttribute(name.substring(PORTLET_SCOPE.length()),
+
javax.portlet.PortletSession.PORTLET_SCOPE);
+ } else {
+ return this.session.getAttribute(name, this.scope);
}
- return this.session.getAttribute(name);
}
/**
* Returns an <code>Enumeration</code> of <code>String</code> objects
* containing the names of all the objects bound to this session.
*
+ * <p>Objects' names in portlet session scope will be prefixed with
+ * [EMAIL PROTECTED] #PORTLET_SCOPE}, and names in application scope
will be prefixed
+ * with [EMAIL PROTECTED] #APP_SCOPE}.
+ *
* @return an <code>Enumeration</code> of
* <code>String</code> objects specifying
the
* names of all the objects bound to
* this session
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an
+ * invalidated session
*/
public Enumeration getAttributeNames() {
- final Enumeration names1 = this.session.getAttributeNames();
+ final Enumeration names1 =
this.session.getAttributeNames(javax.portlet.PortletSession.PORTLET_SCOPE);
final Enumeration names2 =
this.session.getAttributeNames(javax.portlet.PortletSession.APPLICATION_SCOPE);
return new Enumeration() {
@@ -170,9 +187,9 @@
public Object nextElement() throws NoSuchElementException {
if (names1.hasMoreElements()) {
- return names1.nextElement();
+ return PORTLET_SCOPE + names1.nextElement();
} else if (names2.hasMoreElements()) {
- return names2.nextElement();
+ return APP_SCOPE + names2.nextElement();
}
throw new NoSuchElementException();
@@ -191,16 +208,20 @@
*
* @param value the object to be bound; cannot be
null
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an
+ * invalidated session
*/
public void setAttribute(String name, Object value) {
if (name.startsWith(APP_SCOPE)) {
this.session.setAttribute(name.substring(APP_SCOPE.length()),
value,
javax.portlet.PortletSession.APPLICATION_SCOPE);
+ } else if (name.startsWith(PORTLET_SCOPE)) {
+ this.session.setAttribute(name.substring(PORTLET_SCOPE.length()),
+ value,
+
javax.portlet.PortletSession.PORTLET_SCOPE);
} else {
- this.session.setAttribute(name, value);
+ this.session.setAttribute(name, value, this.scope);
}
}
@@ -210,26 +231,29 @@
* bound with the specified name, this method does nothing.
*
*
- * @param name the name of the object to
- * remove from this session
+ * @param name the name of the object to
+ * remove from this session
*
- * @exception IllegalStateException if this method is called on an
- * invalidated session
+ * @exception IllegalStateException if this method is called on an
+ * invalidated session
*/
public void removeAttribute(String name) {
if (name.startsWith(APP_SCOPE)) {
this.session.removeAttribute(name.substring(APP_SCOPE.length()),
javax.portlet.PortletSession.APPLICATION_SCOPE);
+ } else if (name.startsWith(PORTLET_SCOPE)) {
+
this.session.removeAttribute(name.substring(PORTLET_SCOPE.length()),
+
javax.portlet.PortletSession.PORTLET_SCOPE);
} else {
- this.session.removeAttribute(name);
+ this.session.removeAttribute(name, this.scope);
}
}
/**
* Invalidates this session to it.
*
- * @exception IllegalStateException if this method is called on an
- * already invalidated session
+ * @exception IllegalStateException if this method is called on an
+ * already invalidated session
*/
public void invalidate() {
this.session.invalidate();
@@ -242,12 +266,12 @@
* the client had disabled the use of cookies, then a session would
* be new on each request.
*
- * @return <code>true</code> if the
- * server has created a session,
- * but the client has not yet
joined
+ * @return <code>true</code> if the
+ * server has created a session,
+ * but the client has not yet joined
*
- * @exception IllegalStateException if this method is called on an
- * already invalidated session
+ * @exception IllegalStateException if this method is called on an
+ * already invalidated session
*/
public boolean isNew() {
return this.session.isNew();
1.6 +23 -30
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
Index: CocoonPortlet.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CocoonPortlet.java 23 Apr 2004 15:50:34 -0000 1.5
+++ CocoonPortlet.java 18 Jun 2004 16:45:57 -0000 1.6
@@ -212,11 +212,6 @@
protected String portletContextPath;
/**
- * This is the url to the portlet context directory
- */
- protected String portletContextURL;
-
- /**
* The RequestFactory is responsible for wrapping multipart-encoded
* forms and for handing the file payload of incoming requests
*/
@@ -230,6 +225,17 @@
protected String servletPath;
/**
+ * Default scope for the session attributes, either
+ * [EMAIL PROTECTED] javax.portlet.PortletSession#PORTLET_SCOPE} or
+ * [EMAIL PROTECTED] javax.portlet.PortletSession#APPLICATION_SCOPE}.
+ * This corresponds to <code>default-session-scope</code>
+ * parameter, with default value <code>portlet</code>.
+ *
+ * @see org.apache.cocoon.environment.portlet.PortletSession
+ */
+ protected int defaultSessionScope;
+
+ /**
* Initialize this <code>CocoonPortlet</code> instance.
*
* @param conf The PortletConfig object from the portlet container.
@@ -319,26 +325,6 @@
}
}
- try {
- if (path.indexOf(':') > 1) {
- this.portletContextURL = path;
- } else {
- this.portletContextURL = new
File(path).toURL().toExternalForm();
- }
- } catch (MalformedURLException me) {
- // VG: Novell has absolute file names starting with the
- // volume name which is easily more then one letter.
- // Examples: sys:/apache/cocoon or sys:\apache\cocoon
- try {
- this.portletContextURL = new
File(path).toURL().toExternalForm();
- } catch (MalformedURLException ignored) {
- throw new PortletException("Unable to determine portlet
context URL.", me);
- }
- }
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("URL for Root: " + this.portletContextURL);
- }
-
this.forceLoadParameter = getInitParameter("load-class", null);
this.forceSystemProperty = getInitParameter("force-property", null);
@@ -482,6 +468,13 @@
}
}
+ final String sessionScopeParam =
getInitParameter("default-session-scope", "portlet");
+ if ("application".equalsIgnoreCase(sessionScopeParam)) {
+ this.defaultSessionScope =
javax.portlet.PortletSession.APPLICATION_SCOPE;
+ } else {
+ this.defaultSessionScope =
javax.portlet.PortletSession.PORTLET_SCOPE;
+ }
+
// Add the portlet configuration
this.appContext.put(CONTEXT_PORTLET_CONFIG, conf);
this.createCocoon();
@@ -1380,13 +1373,13 @@
}
env = new PortletEnvironment(servletPath,
uri,
- this.portletContextURL,
req,
res,
this.portletContext,
(PortletContext)
this.appContext.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT),
this.containerEncoding,
- formEncoding);
+ formEncoding,
+ this.defaultSessionScope);
env.enableLogging(getLogger());
return env;
}
@@ -1407,13 +1400,13 @@
}
env = new PortletEnvironment(servletPath,
uri,
- this.portletContextURL,
req,
res,
this.portletContext,
(PortletContext)
this.appContext.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT),
this.containerEncoding,
- formEncoding);
+ formEncoding,
+ this.defaultSessionScope);
env.enableLogging(getLogger());
return env;
}