You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by mr...@apache.org on 2005/08/26 07:46:58 UTC
svn commit: r240168 [16/30] - in /struts/sandbox/trunk/ti: ./
core/src/java/org/apache/ti/ core/src/java/org/apache/ti/config/
core/src/java/org/apache/ti/config/mapper/
core/src/java/org/apache/ti/core/ core/src/java/org/apache/ti/core/factory/
core/s...
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/scoping/internal/ScopedResponseImpl.java.disabled
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/scoping/internal/ScopedResponseImpl.java.disabled?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/scoping/internal/ScopedResponseImpl.java.disabled (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/scoping/internal/ScopedResponseImpl.java.disabled Thu Aug 25 22:46:03 2005
@@ -0,0 +1,1276 @@
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.scoping.internal;
+
+import org.apache.ti.pageflow.scoping.ScopedResponse;
+import org.apache.ti.util.logging.Logger;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+import javax.servlet.http.Cookie;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Date;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * A wrapper around HttpServletResponse, associated with a given scope-key. Delegates to the wrapped
+ * response object for some functionality, but prevents output or error codes or forwards from actually
+ * happening.
+ */
+public class ScopedResponseImpl
+ extends HttpServletResponseWrapper
+ implements ScopedResponse
+{
+ private static final Cookie[] NO_COOKIES = new Cookie[0];
+
+ private boolean _isError = false;
+ private int _statusCode = -1;
+ private String _redirectURI = null;
+ private String _statusMessage = null;
+
+ /** Map of name (String) -> headers (List). There can be more than one for each name. **/
+ private HashMap _headers = new HashMap();
+
+ private static final String SET_COOKIE = "Set-Cookie";
+ private static final Logger logger = Logger.getInstance( ScopedResponseImpl.class );
+
+
+ public ScopedResponseImpl( HttpServletResponse servletResponse )
+ {
+ super( servletResponse );
+ }
+
+ public void sendError( int i, String s ) throws IOException
+ {
+ _isError = true;
+ _statusCode = i;
+ _statusMessage = s;
+
+ if ( logger.isInfoEnabled() )
+ {
+ StringBuffer msg = new StringBuffer( "ScopedResponse error " ).append( i );
+ logger.info( msg.append( ": " ).append( s ) );
+ }
+ }
+
+ public void sendError( int i ) throws IOException
+ {
+ sendError( i, "" );
+ }
+
+ public void setStatus( int i )
+ {
+ setStatus( i, "" );
+ }
+
+ public void setStatus( int i, String s )
+ {
+ _statusCode = i;
+ _statusMessage = s;
+ }
+
+ public void setContentLength( int i )
+ {
+ // don't do anything
+ }
+
+ public void setContentType( String s )
+ {
+ // don't do anything
+ }
+
+ public void setBufferSize( int i )
+ {
+ // don't do anything
+ }
+
+ public void resetBuffer()
+ {
+ // don't do anything
+ }
+
+ public void reset()
+ {
+ // don't do anything
+ }
+
+ //
+ // Headers: We need some special handling for headers. Since we're
+ // *including* portlets, the response received from WLS will have
+ // no-op methods for all headers. So, this implementation collects
+ // headers explicitly, to avoid losing them.
+ //
+
+ /**
+ * Add a cookie to the response.
+ */
+ public void addCookie( Cookie cookie )
+ {
+ addObjectHeader(SET_COOKIE, cookie);
+ }
+
+ /**
+ * Gets a cookie that was added to the response.
+ */
+ public Cookie getCookie( String cookieName )
+ {
+ List cookies = getHeaders(SET_COOKIE);
+ if(cookies != null){
+ // start looking from the back (ie. the last cookie set)
+ for(int i = cookies.size(); --i > -1;) {
+ Cookie cookie = (Cookie)cookies.get(i);
+ if(cookie.getName().equals(cookieName)) {
+ return cookie;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Gets all Cookies that were added to the response.
+ */
+ public Cookie[] getCookies()
+ {
+ List cookies = (List)_headers.get(SET_COOKIE);
+ return cookies != null ? ( Cookie[] ) cookies.toArray( new Cookie[cookies.size()] ) : NO_COOKIES;
+ }
+
+ /**
+ * Returns <code>true</code> if this response containes the given header.
+ */
+ public boolean containsHeader( String name )
+ {
+ return _headers.containsKey( name );
+ }
+
+ /**
+ * Sets a response header with the given name and date-value.
+ */
+ public void setDateHeader( String name, long date )
+ {
+ setObjectHeader( name, new Date( date ) );
+ }
+
+ /**
+ * Adds a response header with the given name and date-value.
+ */
+ public void addDateHeader( String name, long date )
+ {
+ addObjectHeader( name, new Date( date ) );
+ }
+
+ /**
+ * Sets a response header with the given name and value.
+ */
+ public void setHeader( String name, String value )
+ {
+ setObjectHeader( name, value );
+ }
+
+ /**
+ * Adds a response header with the given name and value.
+ */
+ public void addHeader( String name, String value )
+ {
+ addObjectHeader( name, value );
+ }
+
+ /**
+ * Sets a response header with the given name and integer value.
+ */
+ public void setIntHeader( String name, int value )
+ {
+ setObjectHeader( name, new Integer( value ) );
+ }
+
+ /**
+ * Adds a response header with the given name and integer value.
+ */
+ public void addIntHeader( String name, int value )
+ {
+ addObjectHeader( name, new Integer( value ) );
+ }
+
+ /**
+ * Gets all headers.
+ *
+ * @return a Map of header-name (String) -> headers (List).
+ */
+ public Map getHeaders()
+ {
+ return _headers;
+ }
+
+ /**
+ * Gets all headers with the given name.
+ *
+ * @return a List of headers (String, Integer, Date, Cookie), or <code>null</code> if none are found.
+ */
+ public List getHeaders( String name )
+ {
+ return ( List ) _headers.get( name );
+ }
+
+ /**
+ * Gets the first header with the given name.
+ * @return an Object (String, Integer, Date, Cookie) that is the first header with the given name,
+ * or <code>null</code> if none is found.
+ */
+ public Object getFirstHeader( String name )
+ {
+ List foundHeaders = ( List ) _headers.get( name );
+ return ! foundHeaders.isEmpty() ? foundHeaders.get( 0 ) : null;
+ }
+
+ protected void addObjectHeader( String name, Object val )
+ {
+ List vals = ( List ) _headers.get( name );
+
+ if ( vals == null )
+ {
+ vals = new ArrayList();
+ _headers.put( name, vals );
+ }
+
+ vals.add( val );
+ }
+
+ protected void setObjectHeader( String name, Object val )
+ {
+ ArrayList vals = new ArrayList();
+ vals.add( val );
+ _headers.put( name, vals );
+ }
+
+ public HttpServletResponse getOuterResponse()
+ {
+ return (HttpServletResponse) getResponse();
+ }
+
+ public boolean isError()
+ {
+ return _isError;
+ }
+
+ public int getStatusCode()
+ {
+ return _statusCode;
+ }
+
+ public String getStatusMessage()
+ {
+ return _statusMessage;
+ }
+
+ public void sendRedirect( String redirectURI )
+ throws IOException
+ {
+ _redirectURI = redirectURI;
+ }
+
+ /**
+ * Actually send the redirect that was suggested by {@link #sendRedirect}.
+ *
+ * @throws IllegalStateException if {@link #sendRedirect} was not called.
+ */
+ public void applyRedirect()
+ throws IOException
+ {
+ if ( _redirectURI != null )
+ {
+ super.sendRedirect( _redirectURI );
+ }
+ else
+ {
+ throw new IllegalStateException( "No redirect to apply." );
+ }
+ }
+
+ public boolean didRedirect()
+ {
+ return _redirectURI != null;
+ }
+
+ public String getRedirectURI()
+ {
+ return _redirectURI;
+ }
+}
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.scoping.internal;
+
+import org.apache.ti.pageflow.scoping.ScopedResponse;
+import org.apache.ti.util.logging.Logger;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+import javax.servlet.http.Cookie;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Date;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * A wrapper around HttpServletResponse, associated with a given scope-key. Delegates to the wrapped
+ * response object for some functionality, but prevents output or error codes or forwards from actually
+ * happening.
+ */
+public class ScopedResponseImpl
+ extends HttpServletResponseWrapper
+ implements ScopedResponse
+{
+ private static final Cookie[] NO_COOKIES = new Cookie[0];
+
+ private boolean _isError = false;
+ private int _statusCode = -1;
+ private String _redirectURI = null;
+ private String _statusMessage = null;
+
+ /** Map of name (String) -> headers (List). There can be more than one for each name. **/
+ private HashMap _headers = new HashMap();
+
+ private static final String SET_COOKIE = "Set-Cookie";
+ private static final Logger logger = Logger.getInstance( ScopedResponseImpl.class );
+
+
+ public ScopedResponseImpl( HttpServletResponse servletResponse )
+ {
+ super( servletResponse );
+ }
+
+ public void sendError( int i, String s ) throws IOException
+ {
+ _isError = true;
+ _statusCode = i;
+ _statusMessage = s;
+
+ if ( logger.isInfoEnabled() )
+ {
+ StringBuffer msg = new StringBuffer( "ScopedResponse error " ).append( i );
+ logger.info( msg.append( ": " ).append( s ) );
+ }
+ }
+
+ public void sendError( int i ) throws IOException
+ {
+ sendError( i, "" );
+ }
+
+ public void setStatus( int i )
+ {
+ setStatus( i, "" );
+ }
+
+ public void setStatus( int i, String s )
+ {
+ _statusCode = i;
+ _statusMessage = s;
+ }
+
+ public void setContentLength( int i )
+ {
+ // don't do anything
+ }
+
+ public void setContentType( String s )
+ {
+ // don't do anything
+ }
+
+ public void setBufferSize( int i )
+ {
+ // don't do anything
+ }
+
+ public void resetBuffer()
+ {
+ // don't do anything
+ }
+
+ public void reset()
+ {
+ // don't do anything
+ }
+
+ //
+ // Headers: We need some special handling for headers. Since we're
+ // *including* portlets, the response received from WLS will have
+ // no-op methods for all headers. So, this implementation collects
+ // headers explicitly, to avoid losing them.
+ //
+
+ /**
+ * Add a cookie to the response.
+ */
+ public void addCookie( Cookie cookie )
+ {
+ addObjectHeader(SET_COOKIE, cookie);
+ }
+
+ /**
+ * Gets a cookie that was added to the response.
+ */
+ public Cookie getCookie( String cookieName )
+ {
+ List cookies = getHeaders(SET_COOKIE);
+ if(cookies != null){
+ // start looking from the back (ie. the last cookie set)
+ for(int i = cookies.size(); --i > -1;) {
+ Cookie cookie = (Cookie)cookies.get(i);
+ if(cookie.getName().equals(cookieName)) {
+ return cookie;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Gets all Cookies that were added to the response.
+ */
+ public Cookie[] getCookies()
+ {
+ List cookies = (List)_headers.get(SET_COOKIE);
+ return cookies != null ? ( Cookie[] ) cookies.toArray( new Cookie[cookies.size()] ) : NO_COOKIES;
+ }
+
+ /**
+ * Returns <code>true</code> if this response containes the given header.
+ */
+ public boolean containsHeader( String name )
+ {
+ return _headers.containsKey( name );
+ }
+
+ /**
+ * Sets a response header with the given name and date-value.
+ */
+ public void setDateHeader( String name, long date )
+ {
+ setObjectHeader( name, new Date( date ) );
+ }
+
+ /**
+ * Adds a response header with the given name and date-value.
+ */
+ public void addDateHeader( String name, long date )
+ {
+ addObjectHeader( name, new Date( date ) );
+ }
+
+ /**
+ * Sets a response header with the given name and value.
+ */
+ public void setHeader( String name, String value )
+ {
+ setObjectHeader( name, value );
+ }
+
+ /**
+ * Adds a response header with the given name and value.
+ */
+ public void addHeader( String name, String value )
+ {
+ addObjectHeader( name, value );
+ }
+
+ /**
+ * Sets a response header with the given name and integer value.
+ */
+ public void setIntHeader( String name, int value )
+ {
+ setObjectHeader( name, new Integer( value ) );
+ }
+
+ /**
+ * Adds a response header with the given name and integer value.
+ */
+ public void addIntHeader( String name, int value )
+ {
+ addObjectHeader( name, new Integer( value ) );
+ }
+
+ /**
+ * Gets all headers.
+ *
+ * @return a Map of header-name (String) -> headers (List).
+ */
+ public Map getHeaders()
+ {
+ return _headers;
+ }
+
+ /**
+ * Gets all headers with the given name.
+ *
+ * @return a List of headers (String, Integer, Date, Cookie), or <code>null</code> if none are found.
+ */
+ public List getHeaders( String name )
+ {
+ return ( List ) _headers.get( name );
+ }
+
+ /**
+ * Gets the first header with the given name.
+ * @return an Object (String, Integer, Date, Cookie) that is the first header with the given name,
+ * or <code>null</code> if none is found.
+ */
+ public Object getFirstHeader( String name )
+ {
+ List foundHeaders = ( List ) _headers.get( name );
+ return ! foundHeaders.isEmpty() ? foundHeaders.get( 0 ) : null;
+ }
+
+ protected void addObjectHeader( String name, Object val )
+ {
+ List vals = ( List ) _headers.get( name );
+
+ if ( vals == null )
+ {
+ vals = new ArrayList();
+ _headers.put( name, vals );
+ }
+
+ vals.add( val );
+ }
+
+ protected void setObjectHeader( String name, Object val )
+ {
+ ArrayList vals = new ArrayList();
+ vals.add( val );
+ _headers.put( name, vals );
+ }
+
+ public HttpServletResponse getOuterResponse()
+ {
+ return (HttpServletResponse) getResponse();
+ }
+
+ public boolean isError()
+ {
+ return _isError;
+ }
+
+ public int getStatusCode()
+ {
+ return _statusCode;
+ }
+
+ public String getStatusMessage()
+ {
+ return _statusMessage;
+ }
+
+ public void sendRedirect( String redirectURI )
+ throws IOException
+ {
+ _redirectURI = redirectURI;
+ }
+
+ /**
+ * Actually send the redirect that was suggested by {@link #sendRedirect}.
+ *
+ * @throws IllegalStateException if {@link #sendRedirect} was not called.
+ */
+ public void applyRedirect()
+ throws IOException
+ {
+ if ( _redirectURI != null )
+ {
+ super.sendRedirect( _redirectURI );
+ }
+ else
+ {
+ throw new IllegalStateException( "No redirect to apply." );
+ }
+ }
+
+ public boolean didRedirect()
+ {
+ return _redirectURI != null;
+ }
+
+ public String getRedirectURI()
+ {
+ return _redirectURI;
+ }
+}
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.scoping.internal;
+
+import org.apache.ti.pageflow.scoping.ScopedResponse;
+import org.apache.ti.util.logging.Logger;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+import javax.servlet.http.Cookie;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Date;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * A wrapper around HttpServletResponse, associated with a given scope-key. Delegates to the wrapped
+ * response object for some functionality, but prevents output or error codes or forwards from actually
+ * happening.
+ */
+public class ScopedResponseImpl
+ extends HttpServletResponseWrapper
+ implements ScopedResponse
+{
+ private static final Cookie[] NO_COOKIES = new Cookie[0];
+
+ private boolean _isError = false;
+ private int _statusCode = -1;
+ private String _redirectURI = null;
+ private String _statusMessage = null;
+
+ /** Map of name (String) -> headers (List). There can be more than one for each name. **/
+ private HashMap _headers = new HashMap();
+
+ private static final String SET_COOKIE = "Set-Cookie";
+ private static final Logger logger = Logger.getInstance( ScopedResponseImpl.class );
+
+
+ public ScopedResponseImpl( HttpServletResponse servletResponse )
+ {
+ super( servletResponse );
+ }
+
+ public void sendError( int i, String s ) throws IOException
+ {
+ _isError = true;
+ _statusCode = i;
+ _statusMessage = s;
+
+ if ( logger.isInfoEnabled() )
+ {
+ StringBuffer msg = new StringBuffer( "ScopedResponse error " ).append( i );
+ logger.info( msg.append( ": " ).append( s ) );
+ }
+ }
+
+ public void sendError( int i ) throws IOException
+ {
+ sendError( i, "" );
+ }
+
+ public void setStatus( int i )
+ {
+ setStatus( i, "" );
+ }
+
+ public void setStatus( int i, String s )
+ {
+ _statusCode = i;
+ _statusMessage = s;
+ }
+
+ public void setContentLength( int i )
+ {
+ // don't do anything
+ }
+
+ public void setContentType( String s )
+ {
+ // don't do anything
+ }
+
+ public void setBufferSize( int i )
+ {
+ // don't do anything
+ }
+
+ public void resetBuffer()
+ {
+ // don't do anything
+ }
+
+ public void reset()
+ {
+ // don't do anything
+ }
+
+ //
+ // Headers: We need some special handling for headers. Since we're
+ // *including* portlets, the response received from WLS will have
+ // no-op methods for all headers. So, this implementation collects
+ // headers explicitly, to avoid losing them.
+ //
+
+ /**
+ * Add a cookie to the response.
+ */
+ public void addCookie( Cookie cookie )
+ {
+ addObjectHeader(SET_COOKIE, cookie);
+ }
+
+ /**
+ * Gets a cookie that was added to the response.
+ */
+ public Cookie getCookie( String cookieName )
+ {
+ List cookies = getHeaders(SET_COOKIE);
+ if(cookies != null){
+ // start looking from the back (ie. the last cookie set)
+ for(int i = cookies.size(); --i > -1;) {
+ Cookie cookie = (Cookie)cookies.get(i);
+ if(cookie.getName().equals(cookieName)) {
+ return cookie;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Gets all Cookies that were added to the response.
+ */
+ public Cookie[] getCookies()
+ {
+ List cookies = (List)_headers.get(SET_COOKIE);
+ return cookies != null ? ( Cookie[] ) cookies.toArray( new Cookie[cookies.size()] ) : NO_COOKIES;
+ }
+
+ /**
+ * Returns <code>true</code> if this response containes the given header.
+ */
+ public boolean containsHeader( String name )
+ {
+ return _headers.containsKey( name );
+ }
+
+ /**
+ * Sets a response header with the given name and date-value.
+ */
+ public void setDateHeader( String name, long date )
+ {
+ setObjectHeader( name, new Date( date ) );
+ }
+
+ /**
+ * Adds a response header with the given name and date-value.
+ */
+ public void addDateHeader( String name, long date )
+ {
+ addObjectHeader( name, new Date( date ) );
+ }
+
+ /**
+ * Sets a response header with the given name and value.
+ */
+ public void setHeader( String name, String value )
+ {
+ setObjectHeader( name, value );
+ }
+
+ /**
+ * Adds a response header with the given name and value.
+ */
+ public void addHeader( String name, String value )
+ {
+ addObjectHeader( name, value );
+ }
+
+ /**
+ * Sets a response header with the given name and integer value.
+ */
+ public void setIntHeader( String name, int value )
+ {
+ setObjectHeader( name, new Integer( value ) );
+ }
+
+ /**
+ * Adds a response header with the given name and integer value.
+ */
+ public void addIntHeader( String name, int value )
+ {
+ addObjectHeader( name, new Integer( value ) );
+ }
+
+ /**
+ * Gets all headers.
+ *
+ * @return a Map of header-name (String) -> headers (List).
+ */
+ public Map getHeaders()
+ {
+ return _headers;
+ }
+
+ /**
+ * Gets all headers with the given name.
+ *
+ * @return a List of headers (String, Integer, Date, Cookie), or <code>null</code> if none are found.
+ */
+ public List getHeaders( String name )
+ {
+ return ( List ) _headers.get( name );
+ }
+
+ /**
+ * Gets the first header with the given name.
+ * @return an Object (String, Integer, Date, Cookie) that is the first header with the given name,
+ * or <code>null</code> if none is found.
+ */
+ public Object getFirstHeader( String name )
+ {
+ List foundHeaders = ( List ) _headers.get( name );
+ return ! foundHeaders.isEmpty() ? foundHeaders.get( 0 ) : null;
+ }
+
+ protected void addObjectHeader( String name, Object val )
+ {
+ List vals = ( List ) _headers.get( name );
+
+ if ( vals == null )
+ {
+ vals = new ArrayList();
+ _headers.put( name, vals );
+ }
+
+ vals.add( val );
+ }
+
+ protected void setObjectHeader( String name, Object val )
+ {
+ ArrayList vals = new ArrayList();
+ vals.add( val );
+ _headers.put( name, vals );
+ }
+
+ public HttpServletResponse getOuterResponse()
+ {
+ return (HttpServletResponse) getResponse();
+ }
+
+ public boolean isError()
+ {
+ return _isError;
+ }
+
+ public int getStatusCode()
+ {
+ return _statusCode;
+ }
+
+ public String getStatusMessage()
+ {
+ return _statusMessage;
+ }
+
+ public void sendRedirect( String redirectURI )
+ throws IOException
+ {
+ _redirectURI = redirectURI;
+ }
+
+ /**
+ * Actually send the redirect that was suggested by {@link #sendRedirect}.
+ *
+ * @throws IllegalStateException if {@link #sendRedirect} was not called.
+ */
+ public void applyRedirect()
+ throws IOException
+ {
+ if ( _redirectURI != null )
+ {
+ super.sendRedirect( _redirectURI );
+ }
+ else
+ {
+ throw new IllegalStateException( "No redirect to apply." );
+ }
+ }
+
+ public boolean didRedirect()
+ {
+ return _redirectURI != null;
+ }
+
+ public String getRedirectURI()
+ {
+ return _redirectURI;
+ }
+}
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.scoping.internal;
+
+import org.apache.ti.pageflow.scoping.ScopedResponse;
+import org.apache.ti.util.logging.Logger;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+import javax.servlet.http.Cookie;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Date;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * A wrapper around HttpServletResponse, associated with a given scope-key. Delegates to the wrapped
+ * response object for some functionality, but prevents output or error codes or forwards from actually
+ * happening.
+ */
+public class ScopedResponseImpl
+ extends HttpServletResponseWrapper
+ implements ScopedResponse
+{
+ private static final Cookie[] NO_COOKIES = new Cookie[0];
+
+ private boolean _isError = false;
+ private int _statusCode = -1;
+ private String _redirectURI = null;
+ private String _statusMessage = null;
+
+ /** Map of name (String) -> headers (List). There can be more than one for each name. **/
+ private HashMap _headers = new HashMap();
+
+ private static final String SET_COOKIE = "Set-Cookie";
+ private static final Logger logger = Logger.getInstance( ScopedResponseImpl.class );
+
+
+ public ScopedResponseImpl( HttpServletResponse servletResponse )
+ {
+ super( servletResponse );
+ }
+
+ public void sendError( int i, String s ) throws IOException
+ {
+ _isError = true;
+ _statusCode = i;
+ _statusMessage = s;
+
+ if ( logger.isInfoEnabled() )
+ {
+ StringBuffer msg = new StringBuffer( "ScopedResponse error " ).append( i );
+ logger.info( msg.append( ": " ).append( s ) );
+ }
+ }
+
+ public void sendError( int i ) throws IOException
+ {
+ sendError( i, "" );
+ }
+
+ public void setStatus( int i )
+ {
+ setStatus( i, "" );
+ }
+
+ public void setStatus( int i, String s )
+ {
+ _statusCode = i;
+ _statusMessage = s;
+ }
+
+ public void setContentLength( int i )
+ {
+ // don't do anything
+ }
+
+ public void setContentType( String s )
+ {
+ // don't do anything
+ }
+
+ public void setBufferSize( int i )
+ {
+ // don't do anything
+ }
+
+ public void resetBuffer()
+ {
+ // don't do anything
+ }
+
+ public void reset()
+ {
+ // don't do anything
+ }
+
+ //
+ // Headers: We need some special handling for headers. Since we're
+ // *including* portlets, the response received from WLS will have
+ // no-op methods for all headers. So, this implementation collects
+ // headers explicitly, to avoid losing them.
+ //
+
+ /**
+ * Add a cookie to the response.
+ */
+ public void addCookie( Cookie cookie )
+ {
+ addObjectHeader(SET_COOKIE, cookie);
+ }
+
+ /**
+ * Gets a cookie that was added to the response.
+ */
+ public Cookie getCookie( String cookieName )
+ {
+ List cookies = getHeaders(SET_COOKIE);
+ if(cookies != null){
+ // start looking from the back (ie. the last cookie set)
+ for(int i = cookies.size(); --i > -1;) {
+ Cookie cookie = (Cookie)cookies.get(i);
+ if(cookie.getName().equals(cookieName)) {
+ return cookie;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Gets all Cookies that were added to the response.
+ */
+ public Cookie[] getCookies()
+ {
+ List cookies = (List)_headers.get(SET_COOKIE);
+ return cookies != null ? ( Cookie[] ) cookies.toArray( new Cookie[cookies.size()] ) : NO_COOKIES;
+ }
+
+ /**
+ * Returns <code>true</code> if this response containes the given header.
+ */
+ public boolean containsHeader( String name )
+ {
+ return _headers.containsKey( name );
+ }
+
+ /**
+ * Sets a response header with the given name and date-value.
+ */
+ public void setDateHeader( String name, long date )
+ {
+ setObjectHeader( name, new Date( date ) );
+ }
+
+ /**
+ * Adds a response header with the given name and date-value.
+ */
+ public void addDateHeader( String name, long date )
+ {
+ addObjectHeader( name, new Date( date ) );
+ }
+
+ /**
+ * Sets a response header with the given name and value.
+ */
+ public void setHeader( String name, String value )
+ {
+ setObjectHeader( name, value );
+ }
+
+ /**
+ * Adds a response header with the given name and value.
+ */
+ public void addHeader( String name, String value )
+ {
+ addObjectHeader( name, value );
+ }
+
+ /**
+ * Sets a response header with the given name and integer value.
+ */
+ public void setIntHeader( String name, int value )
+ {
+ setObjectHeader( name, new Integer( value ) );
+ }
+
+ /**
+ * Adds a response header with the given name and integer value.
+ */
+ public void addIntHeader( String name, int value )
+ {
+ addObjectHeader( name, new Integer( value ) );
+ }
+
+ /**
+ * Gets all headers.
+ *
+ * @return a Map of header-name (String) -> headers (List).
+ */
+ public Map getHeaders()
+ {
+ return _headers;
+ }
+
+ /**
+ * Gets all headers with the given name.
+ *
+ * @return a List of headers (String, Integer, Date, Cookie), or <code>null</code> if none are found.
+ */
+ public List getHeaders( String name )
+ {
+ return ( List ) _headers.get( name );
+ }
+
+ /**
+ * Gets the first header with the given name.
+ * @return an Object (String, Integer, Date, Cookie) that is the first header with the given name,
+ * or <code>null</code> if none is found.
+ */
+ public Object getFirstHeader( String name )
+ {
+ List foundHeaders = ( List ) _headers.get( name );
+ return ! foundHeaders.isEmpty() ? foundHeaders.get( 0 ) : null;
+ }
+
+ protected void addObjectHeader( String name, Object val )
+ {
+ List vals = ( List ) _headers.get( name );
+
+ if ( vals == null )
+ {
+ vals = new ArrayList();
+ _headers.put( name, vals );
+ }
+
+ vals.add( val );
+ }
+
+ protected void setObjectHeader( String name, Object val )
+ {
+ ArrayList vals = new ArrayList();
+ vals.add( val );
+ _headers.put( name, vals );
+ }
+
+ public HttpServletResponse getOuterResponse()
+ {
+ return (HttpServletResponse) getResponse();
+ }
+
+ public boolean isError()
+ {
+ return _isError;
+ }
+
+ public int getStatusCode()
+ {
+ return _statusCode;
+ }
+
+ public String getStatusMessage()
+ {
+ return _statusMessage;
+ }
+
+ public void sendRedirect( String redirectURI )
+ throws IOException
+ {
+ _redirectURI = redirectURI;
+ }
+
+ /**
+ * Actually send the redirect that was suggested by {@link #sendRedirect}.
+ *
+ * @throws IllegalStateException if {@link #sendRedirect} was not called.
+ */
+ public void applyRedirect()
+ throws IOException
+ {
+ if ( _redirectURI != null )
+ {
+ super.sendRedirect( _redirectURI );
+ }
+ else
+ {
+ throw new IllegalStateException( "No redirect to apply." );
+ }
+ }
+
+ public boolean didRedirect()
+ {
+ return _redirectURI != null;
+ }
+
+ public String getRedirectURI()
+ {
+ return _redirectURI;
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/scoping/internal/ScopedServletConfig.java.disabled
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/scoping/internal/ScopedServletConfig.java.disabled?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/scoping/internal/ScopedServletConfig.java.disabled (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/scoping/internal/ScopedServletConfig.java.disabled Thu Aug 25 22:46:03 2005
@@ -0,0 +1,268 @@
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.scoping.internal;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import java.util.Enumeration;
+
+
+/**
+ * A wrapper around ServletConfig, associated with a given scope-key.
+ */
+public class ScopedServletConfig
+ extends AttributeContainer
+ implements ServletConfig
+{
+ private ServletContext _context;
+ private String _servletName;
+
+ public ScopedServletConfig( ServletContext context, ServletConfig baseServletConfig )
+ {
+ _context = context;
+
+ for ( Enumeration e = baseServletConfig.getInitParameterNames(); e.hasMoreElements(); )
+ {
+ String paramName = ( String ) e.nextElement();
+ setAttribute( paramName, baseServletConfig.getInitParameter( paramName ) );
+ }
+
+ _servletName = baseServletConfig.getServletName();
+ }
+
+ public String getServletName()
+ {
+ return _servletName;
+ }
+
+ public ServletContext getServletContext()
+ {
+ return _context;
+ }
+
+ public String getInitParameter( String s )
+ {
+ return ( String ) getAttribute( s );
+ }
+
+ public Enumeration getInitParameterNames()
+ {
+ return getAttributeNames();
+ }
+}
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.scoping.internal;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import java.util.Enumeration;
+
+
+/**
+ * A wrapper around ServletConfig, associated with a given scope-key.
+ */
+public class ScopedServletConfig
+ extends AttributeContainer
+ implements ServletConfig
+{
+ private ServletContext _context;
+ private String _servletName;
+
+ public ScopedServletConfig( ServletContext context, ServletConfig baseServletConfig )
+ {
+ _context = context;
+
+ for ( Enumeration e = baseServletConfig.getInitParameterNames(); e.hasMoreElements(); )
+ {
+ String paramName = ( String ) e.nextElement();
+ setAttribute( paramName, baseServletConfig.getInitParameter( paramName ) );
+ }
+
+ _servletName = baseServletConfig.getServletName();
+ }
+
+ public String getServletName()
+ {
+ return _servletName;
+ }
+
+ public ServletContext getServletContext()
+ {
+ return _context;
+ }
+
+ public String getInitParameter( String s )
+ {
+ return ( String ) getAttribute( s );
+ }
+
+ public Enumeration getInitParameterNames()
+ {
+ return getAttributeNames();
+ }
+}
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.scoping.internal;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import java.util.Enumeration;
+
+
+/**
+ * A wrapper around ServletConfig, associated with a given scope-key.
+ */
+public class ScopedServletConfig
+ extends AttributeContainer
+ implements ServletConfig
+{
+ private ServletContext _context;
+ private String _servletName;
+
+ public ScopedServletConfig( ServletContext context, ServletConfig baseServletConfig )
+ {
+ _context = context;
+
+ for ( Enumeration e = baseServletConfig.getInitParameterNames(); e.hasMoreElements(); )
+ {
+ String paramName = ( String ) e.nextElement();
+ setAttribute( paramName, baseServletConfig.getInitParameter( paramName ) );
+ }
+
+ _servletName = baseServletConfig.getServletName();
+ }
+
+ public String getServletName()
+ {
+ return _servletName;
+ }
+
+ public ServletContext getServletContext()
+ {
+ return _context;
+ }
+
+ public String getInitParameter( String s )
+ {
+ return ( String ) getAttribute( s );
+ }
+
+ public Enumeration getInitParameterNames()
+ {
+ return getAttributeNames();
+ }
+}
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.scoping.internal;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import java.util.Enumeration;
+
+
+/**
+ * A wrapper around ServletConfig, associated with a given scope-key.
+ */
+public class ScopedServletConfig
+ extends AttributeContainer
+ implements ServletConfig
+{
+ private ServletContext _context;
+ private String _servletName;
+
+ public ScopedServletConfig( ServletContext context, ServletConfig baseServletConfig )
+ {
+ _context = context;
+
+ for ( Enumeration e = baseServletConfig.getInitParameterNames(); e.hasMoreElements(); )
+ {
+ String paramName = ( String ) e.nextElement();
+ setAttribute( paramName, baseServletConfig.getInitParameter( paramName ) );
+ }
+
+ _servletName = baseServletConfig.getServletName();
+ }
+
+ public String getServletName()
+ {
+ return _servletName;
+ }
+
+ public ServletContext getServletContext()
+ {
+ return _context;
+ }
+
+ public String getInitParameter( String s )
+ {
+ return ( String ) getAttribute( s );
+ }
+
+ public Enumeration getInitParameterNames()
+ {
+ return getAttributeNames();
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/scoping/internal/ScopedSession.java.disabled
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/scoping/internal/ScopedSession.java.disabled?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/scoping/internal/ScopedSession.java.disabled (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/scoping/internal/ScopedSession.java.disabled Thu Aug 25 22:46:03 2005
@@ -0,0 +1,540 @@
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.scoping.internal;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionContext;
+import javax.servlet.ServletContext;
+import java.io.Serializable;
+
+
+/**
+ * A wrapper around HttpSession, associated with a given scope-key. All calls to setAttribute,
+ * getAttribute, removeAttribute, etc. are scoped to this object, while most other functionality
+ * delegates to the wrapped HttpSession.
+ */
+public class ScopedSession
+ extends ScopedAttributeContainer
+ implements HttpSession, Serializable
+{
+ private transient HttpSession _session;
+ private transient ServletContext _servletContext;
+
+ /**
+ * This constructor exists only for deserialization.
+ */
+ public ScopedSession()
+ {
+ super( null );
+ }
+
+ public ScopedSession( HttpSession session, ServletContext cxt, Object scopeKey )
+ {
+ super( scopeKey );
+ _session = session;
+ _servletContext = cxt;
+ }
+
+ public long getCreationTime()
+ {
+ return _session.getCreationTime();
+ }
+
+ public String getId()
+ {
+ return getScopedName( _session.getId() );
+ }
+
+ public long getLastAccessedTime()
+ {
+ return _session.getLastAccessedTime();
+ }
+
+ public ServletContext getServletContext()
+ {
+ return _servletContext;
+ }
+
+ public void setMaxInactiveInterval( int i )
+ {
+ _session.setMaxInactiveInterval( i );
+ }
+
+ public int getMaxInactiveInterval()
+ {
+ return _session.getMaxInactiveInterval();
+ }
+
+ public HttpSessionContext getSessionContext()
+ {
+ return _session.getSessionContext();
+ }
+
+ public Object getValue( String s )
+ {
+ return getAttribute( s );
+ }
+
+ public String[] getValueNames()
+ {
+ return getAttributeNamesArray();
+ }
+
+ public void putValue( String s, Object o )
+ {
+ setAttribute( s, o );
+ }
+
+ public void removeValue( String s )
+ {
+ removeAttribute( s );
+ }
+
+ public void invalidate()
+ {
+ removeAllAttributes();
+ }
+
+ public boolean isNew()
+ {
+ return _session.isNew();
+ }
+
+ /**
+ * Since _session is transient, this method is called by {@link ScopedRequestImpl#getSession}
+ * to reinitialize it each time.
+ */
+ void setSession( HttpSession session, ServletContext cxt )
+ {
+ _session = session;
+ _servletContext = cxt;
+ }
+
+ /**
+ * Returns the real (outer) HttpSession.
+ */
+ public HttpSession getOuterSession()
+ {
+ return _session;
+ }
+}
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.scoping.internal;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionContext;
+import javax.servlet.ServletContext;
+import java.io.Serializable;
+
+
+/**
+ * A wrapper around HttpSession, associated with a given scope-key. All calls to setAttribute,
+ * getAttribute, removeAttribute, etc. are scoped to this object, while most other functionality
+ * delegates to the wrapped HttpSession.
+ */
+public class ScopedSession
+ extends ScopedAttributeContainer
+ implements HttpSession, Serializable
+{
+ private transient HttpSession _session;
+ private transient ServletContext _servletContext;
+
+ /**
+ * This constructor exists only for deserialization.
+ */
+ public ScopedSession()
+ {
+ super( null );
+ }
+
+ public ScopedSession( HttpSession session, ServletContext cxt, Object scopeKey )
+ {
+ super( scopeKey );
+ _session = session;
+ _servletContext = cxt;
+ }
+
+ public long getCreationTime()
+ {
+ return _session.getCreationTime();
+ }
+
+ public String getId()
+ {
+ return getScopedName( _session.getId() );
+ }
+
+ public long getLastAccessedTime()
+ {
+ return _session.getLastAccessedTime();
+ }
+
+ public ServletContext getServletContext()
+ {
+ return _servletContext;
+ }
+
+ public void setMaxInactiveInterval( int i )
+ {
+ _session.setMaxInactiveInterval( i );
+ }
+
+ public int getMaxInactiveInterval()
+ {
+ return _session.getMaxInactiveInterval();
+ }
+
+ public HttpSessionContext getSessionContext()
+ {
+ return _session.getSessionContext();
+ }
+
+ public Object getValue( String s )
+ {
+ return getAttribute( s );
+ }
+
+ public String[] getValueNames()
+ {
+ return getAttributeNamesArray();
+ }
+
+ public void putValue( String s, Object o )
+ {
+ setAttribute( s, o );
+ }
+
+ public void removeValue( String s )
+ {
+ removeAttribute( s );
+ }
+
+ public void invalidate()
+ {
+ removeAllAttributes();
+ }
+
+ public boolean isNew()
+ {
+ return _session.isNew();
+ }
+
+ /**
+ * Since _session is transient, this method is called by {@link ScopedRequestImpl#getSession}
+ * to reinitialize it each time.
+ */
+ void setSession( HttpSession session, ServletContext cxt )
+ {
+ _session = session;
+ _servletContext = cxt;
+ }
+
+ /**
+ * Returns the real (outer) HttpSession.
+ */
+ public HttpSession getOuterSession()
+ {
+ return _session;
+ }
+}
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.scoping.internal;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionContext;
+import javax.servlet.ServletContext;
+import java.io.Serializable;
+
+
+/**
+ * A wrapper around HttpSession, associated with a given scope-key. All calls to setAttribute,
+ * getAttribute, removeAttribute, etc. are scoped to this object, while most other functionality
+ * delegates to the wrapped HttpSession.
+ */
+public class ScopedSession
+ extends ScopedAttributeContainer
+ implements HttpSession, Serializable
+{
+ private transient HttpSession _session;
+ private transient ServletContext _servletContext;
+
+ /**
+ * This constructor exists only for deserialization.
+ */
+ public ScopedSession()
+ {
+ super( null );
+ }
+
+ public ScopedSession( HttpSession session, ServletContext cxt, Object scopeKey )
+ {
+ super( scopeKey );
+ _session = session;
+ _servletContext = cxt;
+ }
+
+ public long getCreationTime()
+ {
+ return _session.getCreationTime();
+ }
+
+ public String getId()
+ {
+ return getScopedName( _session.getId() );
+ }
+
+ public long getLastAccessedTime()
+ {
+ return _session.getLastAccessedTime();
+ }
+
+ public ServletContext getServletContext()
+ {
+ return _servletContext;
+ }
+
+ public void setMaxInactiveInterval( int i )
+ {
+ _session.setMaxInactiveInterval( i );
+ }
+
+ public int getMaxInactiveInterval()
+ {
+ return _session.getMaxInactiveInterval();
+ }
+
+ public HttpSessionContext getSessionContext()
+ {
+ return _session.getSessionContext();
+ }
+
+ public Object getValue( String s )
+ {
+ return getAttribute( s );
+ }
+
+ public String[] getValueNames()
+ {
+ return getAttributeNamesArray();
+ }
+
+ public void putValue( String s, Object o )
+ {
+ setAttribute( s, o );
+ }
+
+ public void removeValue( String s )
+ {
+ removeAttribute( s );
+ }
+
+ public void invalidate()
+ {
+ removeAllAttributes();
+ }
+
+ public boolean isNew()
+ {
+ return _session.isNew();
+ }
+
+ /**
+ * Since _session is transient, this method is called by {@link ScopedRequestImpl#getSession}
+ * to reinitialize it each time.
+ */
+ void setSession( HttpSession session, ServletContext cxt )
+ {
+ _session = session;
+ _servletContext = cxt;
+ }
+
+ /**
+ * Returns the real (outer) HttpSession.
+ */
+ public HttpSession getOuterSession()
+ {
+ return _session;
+ }
+}
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.scoping.internal;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionContext;
+import javax.servlet.ServletContext;
+import java.io.Serializable;
+
+
+/**
+ * A wrapper around HttpSession, associated with a given scope-key. All calls to setAttribute,
+ * getAttribute, removeAttribute, etc. are scoped to this object, while most other functionality
+ * delegates to the wrapped HttpSession.
+ */
+public class ScopedSession
+ extends ScopedAttributeContainer
+ implements HttpSession, Serializable
+{
+ private transient HttpSession _session;
+ private transient ServletContext _servletContext;
+
+ /**
+ * This constructor exists only for deserialization.
+ */
+ public ScopedSession()
+ {
+ super( null );
+ }
+
+ public ScopedSession( HttpSession session, ServletContext cxt, Object scopeKey )
+ {
+ super( scopeKey );
+ _session = session;
+ _servletContext = cxt;
+ }
+
+ public long getCreationTime()
+ {
+ return _session.getCreationTime();
+ }
+
+ public String getId()
+ {
+ return getScopedName( _session.getId() );
+ }
+
+ public long getLastAccessedTime()
+ {
+ return _session.getLastAccessedTime();
+ }
+
+ public ServletContext getServletContext()
+ {
+ return _servletContext;
+ }
+
+ public void setMaxInactiveInterval( int i )
+ {
+ _session.setMaxInactiveInterval( i );
+ }
+
+ public int getMaxInactiveInterval()
+ {
+ return _session.getMaxInactiveInterval();
+ }
+
+ public HttpSessionContext getSessionContext()
+ {
+ return _session.getSessionContext();
+ }
+
+ public Object getValue( String s )
+ {
+ return getAttribute( s );
+ }
+
+ public String[] getValueNames()
+ {
+ return getAttributeNamesArray();
+ }
+
+ public void putValue( String s, Object o )
+ {
+ setAttribute( s, o );
+ }
+
+ public void removeValue( String s )
+ {
+ removeAttribute( s );
+ }
+
+ public void invalidate()
+ {
+ removeAllAttributes();
+ }
+
+ public boolean isNew()
+ {
+ return _session.isNew();
+ }
+
+ /**
+ * Since _session is transient, this method is called by {@link ScopedRequestImpl#getSession}
+ * to reinitialize it each time.
+ */
+ void setSession( HttpSession session, ServletContext cxt )
+ {
+ _session = session;
+ _servletContext = cxt;
+ }
+
+ /**
+ * Returns the real (outer) HttpSession.
+ */
+ public HttpSession getOuterSession()
+ {
+ return _session;
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/validation/ValidatorRules.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/validation/ValidatorRules.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/validation/ValidatorRules.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/validation/ValidatorRules.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,131 @@
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.validation;
+
+
+
+public class ValidatorRules {
+
+}
+
+/* TODO: re-add Validator support
+ extends FieldChecks
+{
+ private static final Logger _log = Logger.getInstance( ValidatorRules.class );
+
+ /**
+ * Check if a given expression evaluates to <code>true</code>.
+ *
+ * @param bean the bean that validation is being performed on.
+ * @param va the <code>ValidatorAction</code> that is currently being performed.
+ * @param field the <code>Field</code> object associated with the current field being validated.
+ * @param errors the <code>ActionMessages</code> object to add errors to if any validation errors occur.
+ * @param request the current request object.
+ * @return <code>true</code> if the given expression evaluates to <code>true</code>
+ *
+ public static boolean validateValidWhen( Object bean, ValidatorAction va, Field field, ActionMessages errors,
+ HttpServletRequest request, ServletContext servletContext )
+ {
+
+ String value;
+
+ if ( isString( bean ) )
+ {
+ value = ( String ) bean;
+ }
+ else
+ {
+ value = ValidatorUtil.getValueAsString( bean, field.getProperty() );
+ }
+
+ if ( ! GenericValidator.isBlankOrNull( value ) )
+ {
+ String condition = field.getVarValue( "netui_validwhen" );
+
+ try
+ {
+ if ( ! InternalExpressionUtils.evaluateCondition( condition, bean, request, servletContext ) )
+ {
+ errors.add( field.getKey(), Resources.getActionError( request, va, field ) );
+ return false;
+ }
+ }
+ catch ( Exception e )
+ {
+ _log.error( "Error evaluating expression " + condition + " for ValidWhen rule on field "
+ + field.getProperty() + " on bean of type " +
+ ( bean != null ? bean.getClass().getName() : null ) );
+
+ errors.add( field.getKey(), Resources.getActionError( request, va, field ) );
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Check if a field's value is within a range ("min" and "max" Long variables on the passed-in Field).
+ *
+ * @param bean the bean that validation is being performed on.
+ * @param va the <code>ValidatorAction</code> that is currently being performed.
+ * @param field the <code>Field</code> object associated with the current field being validated.
+ * @param errors the <code>ActionMessages</code> object to add errors to if any validation errors occur.
+ * @param request the current request object.
+ * @return <code>true</code> if in range, false otherwise.
+ *
+ public static boolean validateLongRange( Object bean, ValidatorAction va, Field field, ActionMessages errors,
+ HttpServletRequest request )
+ {
+
+ String value;
+
+ if ( isString( bean ) )
+ {
+ value = ( String ) bean;
+ }
+ else
+ {
+ value = ValidatorUtil.getValueAsString( bean, field.getProperty() );
+ }
+
+ if ( ! GenericValidator.isBlankOrNull( value ) )
+ {
+ try
+ {
+ long longValue = Long.parseLong( value );
+ long min = Long.parseLong( field.getVarValue( "min" ) );
+ long max = Long.parseLong( field.getVarValue( "max" ) );
+
+ if ( longValue < min || longValue > max )
+ {
+ errors.add( field.getKey(), Resources.getActionError( request, va, field ) );
+ return false;
+ }
+ }
+ catch ( Exception e )
+ {
+ errors.add( field.getKey(), Resources.getActionError( request, va, field ) );
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
+*/
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/validation/defaultMessages.properties
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/validation/defaultMessages.properties?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/validation/defaultMessages.properties (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/validation/defaultMessages.properties Thu Aug 25 22:46:03 2005
@@ -0,0 +1,48 @@
+errors.required={0} is required.
+errors.minlength={0} cannot be less than {1} characters.
+errors.maxlength={0} cannot be greater than {1} characters.
+errors.invalid={0} is invalid.
+
+errors.byte={0} must be a byte.
+errors.short={0} must be a short.
+errors.integer={0} must be an integer.
+errors.long={0} must be a long.
+errors.float={0} must be a float.
+errors.double={0} must be a double.
+
+errors.date={0} is not a date.
+errors.range={0} is not in the range {1} through {2}.
+errors.creditcard={0} is an invalid credit card number.
+errors.email={0} is an invalid e-mail address.
+errors.required={0} is required.
+errors.minlength={0} cannot be less than {1} characters.
+errors.maxlength={0} cannot be greater than {1} characters.
+errors.invalid={0} is invalid.
+
+errors.byte={0} must be a byte.
+errors.short={0} must be a short.
+errors.integer={0} must be an integer.
+errors.long={0} must be a long.
+errors.float={0} must be a float.
+errors.double={0} must be a double.
+
+errors.date={0} is not a date.
+errors.range={0} is not in the range {1} through {2}.
+errors.creditcard={0} is an invalid credit card number.
+errors.email={0} is an invalid e-mail address.
+errors.required={0} is required.
+errors.minlength={0} cannot be less than {1} characters.
+errors.maxlength={0} cannot be greater than {1} characters.
+errors.invalid={0} is invalid.
+
+errors.byte={0} must be a byte.
+errors.short={0} must be a short.
+errors.integer={0} must be an integer.
+errors.long={0} must be a long.
+errors.float={0} must be a float.
+errors.double={0} must be a double.
+
+errors.date={0} is not a date.
+errors.range={0} is not in the range {1} through {2}.
+errors.creditcard={0} is an invalid credit card number.
+errors.email={0} is an invalid e-mail address.
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xmlhttprequest/XmlHttpRequestServlet.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xmlhttprequest/XmlHttpRequestServlet.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xmlhttprequest/XmlHttpRequestServlet.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xmlhttprequest/XmlHttpRequestServlet.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2005 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.xmlhttprequest;
+
+
+
+/**
+ * Servlet to handle XMLHttpRequests sent from pages.
+ */
+public class XmlHttpRequestServlet {
+
+}
+
+/* TODO: re-add backend XMLHttpRequest support
+ extends HttpServlet
+{
+ private static final Logger logger = Logger.getInstance(XmlHttpRequestServlet.class);
+
+ public void init() throws ServletException
+ {
+ RequestInterceptorContext.init();
+ // TODO: does ErrorCRT really need to be an interceptor?
+ RequestInterceptorContext.addInterceptor(new ErrorCRI());
+ }
+
+ public void doGet(HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ //System.err.println("Inside the XmlHppRequestServlet:" + request.getRequestURI());
+
+ // create an XML empty document, that isn't cached on the client
+ response.setContentType("text/xml");
+ response.setHeader("Pragma", "No-cache");
+ response.setHeader("Cache-Control", "no-cache");
+
+ ServletContext ctxt = getServletContext();
+ RequestInterceptorContext context = new RequestInterceptorContext();
+ List interceptors = context.getRequestInterceptors();
+
+ // Register the default URLRewriter
+ URLRewriterService.registerURLRewriter(0, new DefaultURLRewriter());
+
+ try
+ {
+ Interceptors.doPreIntercept(context, interceptors);
+ }
+ catch (InterceptorException e)
+ {
+ throw new ServletException(e);
+ }
+
+ // Note that we're not worrying about post-intercept or whether any of the pre-interceptors cancelled the
+ // request, since there's no further processing in the request.
+ }
+
+ public void doPost(HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ doGet(request, response);
+ }
+
+ class ErrorCRI extends RequestInterceptor
+ {
+ public void preRequest(RequestInterceptorContext ctxt, InterceptorChain chain) throws InterceptorException
+ {
+ // Create the command by striping off the context path and the extension
+ HttpServletRequest request = ctxt.getRequest();
+ String cmd = request.getRequestURI();
+ String ctxtPath = request.getContextPath();
+
+ // catch any runtime errors here and return.
+ try {
+ cmd = cmd.substring(ctxtPath.length() + 1);
+ int idx = cmd.lastIndexOf('.');
+ if (idx != -1) {
+ cmd = cmd.substring(0, idx);
+ }
+
+ if ("netuiError".equals(cmd)) {
+ String error = request.getParameter("error");
+ logger.error("NetUI JavaScript Error:" + error);
+ System.err.println("NetUI JavaScript Error:" + error);
+ }
+ }
+ catch (RuntimeException e) {
+ logger.error("Runtime Error creating XmlRequestServlet Command:" + e.getClass().getName(),e);
+ }
+
+ chain.continueChain();
+ }
+
+ public void postRequest(RequestInterceptorContext context, InterceptorChain chain) throws InterceptorException
+ {
+ chain.continueChain();
+ }
+ }
+}
+*/
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xwork/AutoViewRenderResult.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xwork/AutoViewRenderResult.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xwork/AutoViewRenderResult.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xwork/AutoViewRenderResult.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,70 @@
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.xwork;
+
+import org.apache.ti.pageflow.FlowController;
+import org.apache.ti.pageflow.Forward;
+import org.apache.ti.pageflow.ModuleConfig;
+import org.apache.ti.pageflow.PageFlowConstants;
+import org.apache.ti.pageflow.PageFlowException;
+import org.apache.ti.pageflow.internal.ViewRenderer;
+import org.apache.ti.util.logging.Logger;
+
+/**
+ * There is a special forward ("auto"), which signals us to render using a registered ViewRenderer.
+ * This is used as part of popup window support.
+ */
+public class AutoViewRenderResult extends PageFlowResult {
+
+ private static final Logger _log = Logger.getInstance(AutoViewRenderResult.class);
+
+ protected boolean shouldSavePreviousPageInfo() {
+ return true;
+ }
+
+ public boolean isPath() {
+ return false;
+ }
+
+ protected Forward applyForward(Forward fwd, ModuleConfig altModuleConfig) {
+ PageFlowActionContext actionContext = PageFlowActionContext.get();
+ ViewRenderer vr = actionContext.getViewRenderer();
+
+ if (vr != null) {
+ _log.debug("null forward -- delegating to ViewRenderer " + vr + " to handle response.");
+
+ try {
+ vr.renderView();
+ } catch (Throwable th) {
+ try {
+ FlowController flowController = actionContext.getFlowController();
+ return flowController.handleException(th);
+ } catch (PageFlowException e) {
+ _log.error("Exception thrown while handling exception in ViewRenderer " + vr + ": "
+ + e.getMessage(), th);
+ }
+ }
+
+ } else {
+ _log.error("Auto-render forward " + PageFlowConstants.AUTO_VIEW_RENDER_FORWARD_NAME
+ + " used, but no ViewRenderer " + "was registered -- not doing any forward or redirect.");
+ }
+
+ return null;
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xwork/NavigateToActionResult.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xwork/NavigateToActionResult.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xwork/NavigateToActionResult.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xwork/NavigateToActionResult.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,91 @@
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.xwork;
+
+import org.apache.ti.pageflow.FlowControllerException;
+import org.apache.ti.pageflow.Forward;
+import org.apache.ti.pageflow.NoCurrentPageFlowException;
+import org.apache.ti.pageflow.NoPreviousActionException;
+import org.apache.ti.pageflow.PageFlowController;
+import org.apache.ti.pageflow.PageFlowUtils;
+import org.apache.ti.pageflow.PreviousActionInfo;
+import org.apache.ti.pageflow.internal.InternalUtils;
+import org.apache.ti.util.logging.Logger;
+
+public class NavigateToActionResult extends NavigateToResult {
+
+ private static final Logger _log = Logger.getInstance(NavigateToActionResult.class);
+
+ protected boolean preprocess(Forward fwd, PageFlowActionContext actionContext) {
+
+ //
+ // We need access to previousPageInfo from the *current PageFlow*. That is often this FlowController,
+ // but if it's a shared flow, then we don't want to use that.
+ //
+ PageFlowController curJpf = PageFlowUtils.getCurrentPageFlow();
+
+ if (curJpf == null) {
+ FlowControllerException ex = new NoCurrentPageFlowException(this);
+ InternalUtils.throwPageFlowException(ex);
+ assert false; // throwPageFlowException() must throw.
+ }
+
+ PreviousActionInfo prevActionInfo = curJpf.getPreviousActionInfo();
+
+ if (prevActionInfo != null) {
+ String actionURI = prevActionInfo.getActionURI();
+
+ if (_log.isDebugEnabled()) _log.debug("navigate-to-action: " + actionURI);
+
+ //
+ // If there's no form specified in this return-to-action forward, then use the original form that was saved
+ // in the action. Only do this if we're not doing a redirect, which precludes request attributes.
+ //
+ if (!isRedirect() && prevActionInfo.getFormBean() != null
+ && fwd.getFirstOutputForm() == null) {
+ fwd.addOutputForm(prevActionInfo.getFormBean());
+ }
+
+ String query = getQueryString(fwd, prevActionInfo);
+ setLocation(actionURI + query);
+ return false;
+ } else {
+ if (_log.isInfoEnabled()) {
+ _log.info("Attempted return-to-action, but previous action info was missing.");
+ }
+
+ FlowControllerException ex = new NoPreviousActionException(this, curJpf);
+ InternalUtils.throwPageFlowException(ex);
+ assert false; // previous method always throws
+ return true;
+ }
+ }
+
+ protected boolean shouldSavePreviousPageInfo() {
+ return true;
+ }
+
+ public boolean isPath() {
+ return false;
+ }
+
+ public String getNavigateToAsString() {
+ return "ti.NavigateTo.previousAction"; // TODO: constant
+ }
+
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xwork/NavigateToPageResult.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xwork/NavigateToPageResult.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xwork/NavigateToPageResult.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/xwork/NavigateToPageResult.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,286 @@
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.xwork;
+
+import com.opensymphony.xwork.ActionInvocation;
+import org.apache.ti.pageflow.FlowControllerException;
+import org.apache.ti.pageflow.Forward;
+import org.apache.ti.pageflow.NoCurrentPageFlowException;
+import org.apache.ti.pageflow.PageFlowController;
+import org.apache.ti.pageflow.PageFlowUtils;
+import org.apache.ti.pageflow.PreviousPageInfo;
+import org.apache.ti.pageflow.internal.InternalUtils;
+import org.apache.ti.util.logging.Logger;
+
+public class NavigateToPageResult extends NavigateToResult {
+
+ private static final Logger _log = Logger.getInstance(NavigateToPageResult.class);
+
+ /**
+ * 0 is current page, 1 is previous page, etc.
+ */
+ private int _previousPageIndex = -1;
+
+ public void execute(ActionInvocation invocation) throws Exception {
+ //
+ // We need access to previousPageInfo from the *current page flow*. That is often the current FlowController
+ // in the ActionConteext, but if it's a shared flow, then we don't want to use that.
+ //
+ PageFlowController curJpf = PageFlowUtils.getCurrentPageFlow();
+
+ if (curJpf == null) {
+ FlowControllerException ex = new NoCurrentPageFlowException(this);
+ InternalUtils.throwPageFlowException(ex);
+ assert false; // throwPageFlowException() must throw.
+ }
+
+ PreviousPageInfo prevPageInfo;
+
+ switch (getPreviousPageIndex()) {
+ case 0:
+ prevPageInfo = curJpf.getCurrentPageInfo();
+ break;
+
+ case 1:
+ prevPageInfo = curJpf.getPreviousPageInfo();
+ break;
+
+ default:
+ assert false : getPreviousPageIndex() + " is not a valid previous-page index";
+ // of course, in the future, we should support any index, up to an app-configured max
+ prevPageInfo = curJpf.getCurrentPageInfo();
+ }
+
+ // The previous result has already been initialized from the previous Forward.
+ // 1) Initialize from *this* forward, overwriting previously-initialized values.
+ // 2) Apply the previous Forward (sets values in the request).
+ // 3) Apply this Forward (sets values in the request, possibly overwriting those set above).
+ // 4) Allow the previous result to finish execution.
+ PageFlowActionContext actionContext = (PageFlowActionContext) invocation.getInvocationContext();
+ Forward currentForward = actionContext.getForward();
+ assert currentForward != null : "no forward found in context for Result \"" + getName() + '"';
+ PageFlowResult prevResult = prevPageInfo.getResult();
+ Forward previousForward = prevPageInfo.getForward();
+ prevResult.initFrom(currentForward, actionContext);
+ if (previousForward != null) prevResult.applyForward(previousForward, actionContext);
+ prevResult.applyForward(currentForward, actionContext);
+ actionContext.setPreviousPageInfo(prevPageInfo);
+ prevResult.finishExecution(currentForward, actionContext);
+ }
+
+ /*
+ // TODO: re-add logic for merging query strings (abstracted into a Servlet-specific version?)
+ //
+ // If there's a query string, override the previous query string.
+ //
+ String fwdPath = retFwd.getPath();
+ String newQueryString = fwd.getQueryString();
+ int existingQueryPos = fwdPath.indexOf( '?' );
+
+ //
+ // If the new forward (the one with ti.NavigateTo.currentPage/previousPage) has a query string, use that.
+ // Otherwise, if the old forward has no query string, restore the one from the PreviousPageInfo if
+ // appropriate.
+ //
+ if ( newQueryString != null )
+ {
+ // Chop off the old query string if necessary.
+ if ( existingQueryPos != -1 ) fwdPath = fwdPath.substring( 0, existingQueryPos );
+ retFwd.setPath( fwdPath + newQueryString );
+ }
+ else if ( existingQueryPos == -1 )
+ {
+ retFwd.setPath( fwdPath + getQueryString( fwd, prevPageInfo ) );
+ }
+
+ */
+ /*
+ protected Forward applyForward(Forward fwd, ModuleConfig altModuleConfig) {
+ //
+ // We need access to previousPageInfo from the *current page flow*. That is often the current FlowController
+ // in the ActionConteext, but if it's a shared flow, then we don't want to use that.
+ //
+ PageFlowController curJpf = PageFlowUtils.getCurrentPageFlow();
+
+ if ( curJpf == null )
+ {
+ FlowControllerException ex = new NoCurrentPageFlowException( this );
+ InternalUtils.throwPageFlowException( ex);
+ assert false; // throwPageFlowException() must throw.
+ }
+
+ PreviousPageInfo prevPageInfo;
+
+ switch ( getPreviousPageIndex() )
+ {
+ case 0:
+ prevPageInfo = curJpf.getCurrentPageInfo();
+ break;
+
+ case 1:
+ prevPageInfo = curJpf.getPreviousPageInfo();
+ break;
+
+ default:
+ assert false : getPreviousPageIndex() + " is not a valid previous-page index";
+ // of course, in the future, we should support any index, up to an app-configured max
+ prevPageInfo = curJpf.getCurrentPageInfo();
+ }
+
+ Forward retFwd = doReturnToPage(fwd, prevPageInfo, curJpf);
+
+ if ( prevPageInfo != null )
+ {
+ PageFlowActionContext actionContext = PageFlowActionContext.getContext();
+ //mapping = prevPageInfo.getAction();
+ //if ( form == null ) form = prevPageInfo.getFormBean();
+ }
+
+ if ( _log.isDebugEnabled() )
+ {
+ _log.debug( "navigate-to-page: " + ( fwd != null ? fwd.getPath() : "[null]" ) );
+ }
+
+ return retFwd;
+ }
+
+ protected Forward doReturnToPage( Forward fwd, PreviousPageInfo prevPageInfo, PageFlowController currentPageFlow)
+ {
+ if ( prevPageInfo == null )
+ {
+ if ( _log.isInfoEnabled() )
+ {
+ _log.info( "Attempted return-to-page, but previous page info was missing." );
+ }
+
+ FlowControllerException ex = new NoPreviousPageException( this, currentPageFlow );
+ InternalUtils.throwPageFlowException( ex);
+ }
+
+ //
+ // Figure out what URI to return to, and set the original form in the request or session.
+ //
+ Forward retFwd = prevPageInfo.getResult();
+ PageFlowAction prevAction = prevPageInfo.getAction();
+ PageFlowActionContext actionContext = PageFlowActionContext.getContext();
+
+ //
+ // Restore any forms that are specified by this forward (overwrite the original forms).
+ //
+ PageFlowUtils.setOutputForms( retFwd, false );
+ InternalUtils.addActionOutputs( retFwd.getActionOutputs(), false );
+
+ //
+ // If the user hit the previous page directly (without going through an action), prevMapping will be null.
+ //
+ if ( prevAction != null )
+ {
+ //
+ // If the currently-posted form is of the right type, initialize the page with that (but we don't overwrite
+ // the form that was set above).
+ //
+ Object currentForm = actionContext.getAction().getFormBean();
+ if ( currentForm != null ) PageFlowUtils.setOutputForm( currentForm, false );
+
+ //
+ // Initialize the page with the original form it got forwarded (but we don't overwrite the form that was
+ // set above).
+ //
+ InternalUtils.setFormInScope( prevAction.getFormBeanAttribute(), prevPageInfo.getFormBean(), false );
+ }
+
+ //
+ // If we're forwarding to a page in a different pageflow, we need to make sure the returned forward has
+ // the right namespace, and that it has contextRelative=true.
+ //
+ FlowController flowController = actionContext.getFlowController();
+
+ if ( ! retFwd.getPath().startsWith( "/" ) && flowController != currentPageFlow )
+ {
+ assert false : "NYI";
+ retFwd = new forward( retFwd.getName(),
+ '/' + currentPageFlow.getNamespace() + '/' + retFwd.getPath(),
+ retFwd.isRedirect(),
+ true );
+
+ }
+
+ if ( _log.isDebugEnabled() )
+ {
+ _log.debug( "Return-to-page in PageFlowController " + flowController.getClass().getName()
+ + ": original URI " + retFwd.getPath() );
+ }
+
+ if ( retFwd != null )
+ {
+ //
+ // If the new (return-to) forward specifies a redirect value explicitly, use that; otherwise
+ // use the redirect value from the original forward.
+ //
+ if ( ! hasExplicitRedirectValue() ) setRedirect( fwd.isRedirect() );
+
+ //
+ // If there's a query string, override the previous query string.
+ //
+ String fwdPath = retFwd.getPath();
+ String newQueryString = fwd.getQueryString();
+ int existingQueryPos = fwdPath.indexOf( '?' );
+
+ //
+ // If the new forward (the one with ti.NavigateTo.currentPage/previousPage) has a query string, use that.
+ // Otherwise, if the old forward has no query string, restore the one from the PreviousPageInfo if
+ // appropriate.
+ //
+ if ( newQueryString != null )
+ {
+ // Chop off the old query string if necessary.
+ if ( existingQueryPos != -1 ) fwdPath = fwdPath.substring( 0, existingQueryPos );
+ retFwd.setPath( fwdPath + newQueryString );
+ }
+ else if ( existingQueryPos == -1 )
+ {
+ retFwd.setPath( fwdPath + getQueryString( fwd, prevPageInfo ) );
+ }
+ }
+
+
+ actionContext.setPreviousPageInfo( prevPageInfo );
+ return retFwd;
+ }
+ */
+
+ protected boolean shouldSavePreviousPageInfo() {
+ return _previousPageIndex > 0;
+ }
+
+ public String getNavigateToAsString() {
+ return _previousPageIndex > 0 ? "ti.NavigateTo.previousPage" : "ti.NavigateTo.currentPage"; // TODO: constant
+ }
+
+ public boolean isPath() {
+ return false;
+ }
+
+ public int getPreviousPageIndex() {
+ return _previousPageIndex;
+ }
+
+ public void setPreviousPageIndex(int previousPageIndex) {
+ _previousPageIndex = previousPageIndex;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org