portletconnection.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 759 行 · 第 1/2 页
JAVA
759 行
/* * The Apache Software License, Version 1.1 * * Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Caucho Technology (http://www.caucho.com/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "Hessian", "Resin", and "Caucho" must not be used to * endorse or promote products derived from this software without prior * written permission. For written permission, please contact * info@caucho.com. * * 5. Products derived from this software may not be called "Resin" * nor may "Resin" appear in their names without prior written * permission of Caucho Technology. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Sam */package com.caucho.portal.generic;import com.caucho.portal.generic.context.ConnectionContext;import javax.portlet.PortletException;import javax.portlet.PortletRequest;import javax.portlet.PortletSecurityException;import javax.portlet.PortletSession;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.PrintWriter;import java.io.UnsupportedEncodingException;import java.security.Principal;import java.util.Enumeration;import java.util.Locale;import java.util.Set;import java.util.logging.Level;import java.util.logging.Logger;/** * A PortletConnection is used to obtain {@link Action} and {@link Render} * objects. * * For implementations that support only one portlet for each connection, * the pattern of use is: * * <pre> * Window window = ...; * Portlet portlet = ...; * * Action action = connection.getAction(window); * * if (action != null) { * try { * if (action.isTarget()) * action.processAction(portlet); * } * finally { * action.finish(); * } * } * * Render render = connection.getRender(window); * * if (render != null) { * try { * render.render(portlet); * } * finally { * render.finish(); * } * } * * </pre> * * For implementations that support more than one portlet for each connection, * each portlet is identified with a namespace. An optional Renderer is * specified, it is used to obtain a Writer or OutputStream when the portlet * requests it. * * <pre> * Window window = ...; * Portlet portlet = ...; * String namespace = "..."; * * Action action = connection.getAction(window, namespace); * * if (action != null) { * try { * if (action.isTarget()) * action.processAction(portlet); * } * finally { * action.finish(); * } * } * * Render render = connection.getRender(window, namespace); * * if (render != null) { * try { * render.render(portlet); * } * finally { * render.finish(); * } * } * * </pre> * * @see PortletConnection#getAction * @see PortletConnection#getRender * @see Action * @see Render * */abstract public class PortletConnection{ /** * Name of the request attribute that stores the connection */ public static final String PORTLET_CONNECTION = "com.caucho.portal.generic.PortletConnection"; /** * Return the connection that corresponds to the PortletRequest */ public static PortletConnection getConnection(PortletRequest portletRequest) { return (PortletConnection) portletRequest.getAttribute(PORTLET_CONNECTION); } /** * Return the Portal that corresponds to the PortletRequest, or null * if there is not a current Portal or Connection. */ public static Portal getPortal(PortletRequest portletRequest) { PortletConnection connection = getConnection(portletRequest); if (connection == null) return null; else return connection.getPortal(); } /** * Return the Action that corresponds to the PortletRequest, or null * if there is not a current Action or Connection. */ public static Action getAction(PortletRequest portletRequest) { PortletConnection connection = getConnection(portletRequest); if (connection == null) return null; else return connection.getCurrentAction(); } /** * Return the Render that corresponds to the PortletRequest, or null * if there is not a current Render or Connection. */ public static Render getRender(PortletRequest portletRequest) { PortletConnection connection = getConnection(portletRequest); if (connection == null) return null; else return connection.getCurrentRender(); } // -- static final public Logger log = Logger.getLogger(PortletConnection.class.getName()); private static int _connectionCount = 10; private ConnectionContext _context; private String _connectionId; private Portal _portal; private boolean _connectionFailed; private Exception _connectionFailedCause; protected PortletConnection() { int id = _connectionCount++; _connectionId = Integer.toString(id, Character.MAX_RADIX); _context = new ConnectionContext(this); } /** * A unique identifier for this connection object, used for debugging */ public String getId() { return _connectionId; } public void start(Portal portal, InvocationFactory invocationFactory) { if (_portal != null) throw new IllegalStateException("missing finish()?"); _portal = portal; _context.start(invocationFactory); } public void finish() { _context.finish(); _portal = null; _connectionFailedCause = null; _connectionFailed = false; } public Portal getPortal() { return _portal; } /** * Used to indicate that the connection has failed. A connection fails if an * unrecoverable error occurs. */ public void setConnectionFailed() { if (!_connectionFailed) { PortletException ex = new PortletException("connection failed"); setConnectionFailed(ex); } } /** * Used to indicate that the connection has failed. A connection fails if an * unrecoverable error occurs. */ public void setConnectionFailed(Exception ex) { if (!_connectionFailed) { _connectionFailed = true; _connectionFailedCause = ex; log.log(Level.FINE, ex.toString(), ex); } } /** * A connection fails if an unrecoverable error occurs. */ public boolean isConnectionFailed() { return _connectionFailed; } /** * Handle a constraint failure by sending some response to the client. * * @return false if the connection cannot handle the constraint failure. */ abstract public boolean handleConstraintFailure( Constraint constraint, int failureCode ) throws IOException; /** * Handle an exception by sending some response to the client. * * @return false if the connection cannot handle the constraint failure. */ abstract public boolean handleException(Exception exception); /** * Return true if the connection can guarantee integrity * (preventing data tampering in the communication process). */ abstract public boolean canGuaranteeIntegrity(); /** * Return true if the connection can guarantee confidentiality (preventing * reading while in transit). */ abstract public boolean canGuaranteeConfidentiality(); /** * Set an attribute for the current connection. Attributes are name/value * pairs that are valid for the duration of one connection. */ abstract public void setAttribute(String name, Object o); /** * Get an attribute for the current connection. Attributes are name/value * pairs that are valid for the duration of one connection. */ abstract public Object getAttribute(String name); /** * Remove an attribute for the current connection. Attributes are name/value * pairs that are valid for the duration of one connection. */ abstract public void removeAttribute(String name); /** * Get a list of all attributes for the current connection. Attributes are * name/value pairs that are valid for the duration of one connection. * * @return an Enumeration of String */ abstract public Enumeration getAttributeNames(); /** * Return a {@link PortletSession} for the current client, or null if one is * not available. * * A PortletSession once established will be consistently returned for a * client on subsequent requests. Different clients will never have the same * PortletSession. * * @param create, if true create a new session if one does not already exist * for the client. */ abstract public PortletSession getPortletSession(boolean create); /** * Return the scheme portion of the url that was used to make the request. * * @see javax.portlet.PortletRequest#getScheme */ abstract public String getScheme(); /** * Return the host name portion of the url that was used to make the request. * * @see javax.portlet.PortletRequest#getServerName */ abstract public String getServerName(); /** * Return the port portion of the url that was used to make the request. * * @see javax.portlet.PortletRequest#getServerPort */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?