⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 portletframe.java

📁 GridSphere 门户 提供一个基于 portlet 的高级开放源代码门户。GridSphere 是在欧盟提供基金的 GridLab 项目下开发的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a> * @version $Id: PortletFrame.java 5032 2006-08-17 18:15:06Z novotny $ */package org.gridsphere.layout;import org.gridsphere.layout.event.PortletComponentEvent;import org.gridsphere.layout.event.PortletFrameEvent;import org.gridsphere.layout.event.PortletFrameListener;import org.gridsphere.layout.event.PortletTitleBarEvent;import org.gridsphere.layout.event.impl.PortletFrameEventImpl;import org.gridsphere.layout.view.FrameView;import org.gridsphere.portlet.impl.PortletURLImpl;import org.gridsphere.portlet.impl.SportletProperties;import org.gridsphere.portlet.impl.StoredPortletResponseImpl;import org.gridsphere.portlet.service.PortletServiceException;import org.gridsphere.portlet.service.spi.PortletServiceFactory;import org.gridsphere.portletcontainer.ApplicationPortlet;import org.gridsphere.portletcontainer.DefaultPortletAction;import org.gridsphere.portletcontainer.DefaultPortletRender;import org.gridsphere.portletcontainer.GridSphereEvent;import org.gridsphere.portletcontainer.impl.PortletInvoker;import org.gridsphere.services.core.cache.CacheService;import org.gridsphere.services.core.mail.MailMessage;import org.gridsphere.services.core.mail.MailService;import org.gridsphere.services.core.portal.PortalConfigService;import org.gridsphere.services.core.registry.PortletRegistryService;import org.gridsphere.services.core.user.User;import javax.portlet.*;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.PrintWriter;import java.io.Serializable;import java.io.StringWriter;import java.security.Principal;import java.text.DateFormat;import java.util.*;/** * <code>PortletFrame</code> provides the visual representation of a portlet. A portlet frame * contains a portlet title bar unless visible is set to false. */public class PortletFrame extends BasePortletComponent implements Serializable, Cloneable {    public static final String FRAME_CLOSE_OK_ACTION = "close";    public static final String FRAME_CLOSE_CANCEL_ACTION = "cancelClose";    public static final String DELETE_PORTLET = "deletePortlet";    private transient CacheService cacheService = null;    private transient PortalConfigService portalConfigService = null;    private transient PortletRegistryService portletRegistryService = null;    private transient PortletInvoker portletInvoker = null;    // renderPortlet is true in doView and false on minimized    private boolean renderPortlet = true;    private String portletClass = null;    private PortletTitleBar titleBar = null;    private boolean transparent = false;    private String innerPadding = "";   // has to be empty and not 0!    private String outerPadding = "";   // has to be empty and not 0!    private long cacheExpiration = 0;    // keep track of the original width    private String originalWidth = "";    // switch to determine if the user wishes to close this portlet    private boolean isClosing = false;    // render params are the persistent per portlet parameters stored as key names and string[] values    private Map renderParams = new HashMap();    private boolean onlyRender = true;    private transient FrameView frameView = null;    private String lastFrame = "";    private String portletName = "Untitled";    private String windowId = "unknown";    //private Supports[] supports = null;    /**     * Constructs an instance of PortletFrame     */    public PortletFrame() {    }    public String getPortletName() {        return portletName;    }    /**     * Sets the portlet title bar contained by this portlet frame     *     * @param titleBar the portlet title bar     */    public void setPortletTitleBar(PortletTitleBar titleBar) {        this.titleBar = titleBar;    }    /**     * Returns the portlet title bar contained by this portlet frame     *     * @return the portlet title bar     */    public PortletTitleBar getPortletTitleBar() {        return titleBar;    }    /**     * Sets the portlet class contained by this portlet frame     *     * @param portletClass the fully qualified portlet classname     */    public void setPortletClass(String portletClass) {        this.portletClass = portletClass;    }    /**     * Returns the portlet class contained by this portlet frame     *     * @return the fully qualified portlet classname     */    public String getPortletClass() {        return portletClass;    }    /**     * Sets the inner padding of the portlet frame     *     * @param innerPadding the inner padding     */    public void setInnerPadding(String innerPadding) {        this.innerPadding = innerPadding;    }    /**     * Returns the inner padding of the portlet frame     *     * @return the inner padding     */    public String getInnerPadding() {        return innerPadding;    }    /**     * Sets the outer padding of the portlet frame     *     * @param outerPadding the outer padding     */    public void setOuterPadding(String outerPadding) {        this.outerPadding = outerPadding;    }    /**     * Returns the outer padding of the portlet frame     *     * @return the outer padding     */    public String getOuterPadding() {        return outerPadding;    }    /**     * If set to <code>true</code> the portlet is rendered transparently without a     * defining border and title bar. This is used for example for the LogoutPortlet     *     * @param transparent if set to <code>true</code>, portlet frame is displayed transparently, <code>false</code> otherwise     */    public void setTransparent(boolean transparent) {        this.transparent = transparent;    }    /**     * If set to <code>true</code> the portlet is rendered transparently without a     * defining border and title bar. This is used for example for the LogoutPortlet     *     * @return <code>true</code> if the portlet frame is displayed transparently, <code>false</code> otherwise     */    public boolean getTransparent() {        return this.transparent;    }    /**     * Initializes the portlet frame component. Since the components are isolated     * after Castor unmarshalls from XML, the ordering is determined by a     * passed in List containing the previous portlet components in the tree.     *     * @param list a <code>List</code> of component identifiers     * @return a <code>List</code> of updated component identifiers     * @see ComponentIdentifier     */    public List<ComponentIdentifier> init(PortletRequest req, List<ComponentIdentifier> list) {        try {            cacheService = (CacheService) PortletServiceFactory.createPortletService(CacheService.class, true);            portalConfigService = (PortalConfigService) PortletServiceFactory.createPortletService(PortalConfigService.class, true);            portletRegistryService = (PortletRegistryService) PortletServiceFactory.createPortletService(PortletRegistryService.class, true);        } catch (PortletServiceException e) {            log.error("Unable to init services! ", e);        }        list = super.init(req, list);        portletInvoker = new PortletInvoker();        frameView = (FrameView) getRenderClass(req, "Frame");        ComponentIdentifier compId = new ComponentIdentifier();        compId.setPortletComponent(this);        compId.setPortletClass(portletClass);        compId.setComponentID(list.size());        compId.setComponentLabel(label);        compId.setClassName(this.getClass().getName());        list.add(compId);        this.originalWidth = width;        titleBar = new PortletTitleBar();        // if title bar is not assigned a label and we have one then use it        if ((!label.equals("")) && (titleBar.getLabel().equals(""))) titleBar.setLabel(label + "TB");        titleBar.setPortletClass(portletClass);        titleBar.setCanModify(canModify);        list = titleBar.init(req, list);        titleBar.addComponentListener(this);        titleBar.setParentComponent(this);        // invalidate cache        req.setAttribute(CacheService.NO_CACHE, "true");        if (windowId == null) windowId = componentIDStr;        String appID = portletRegistryService.getApplicationPortletID(portletClass);        ApplicationPortlet appPortlet = portletRegistryService.getApplicationPortlet(appID);        if (appPortlet != null) {            //supports = appPortlet.getSupports();            portletName = appPortlet.getPortletName();            cacheExpiration = appPortlet.getCacheExpires();        }        return list;    }    /**     * Fires a frame event notification     *     * @param event a portlet frame event     */    protected void fireFrameEvent(PortletFrameEvent event) {        Iterator it = listeners.iterator();        PortletFrameListener l;        while (it.hasNext()) {            l = (PortletFrameListener) it.next();            l.handleFrameEvent(event);        }    }    /**     * Performs an action on this portlet frame component     *     * @param event a gridsphere event     */    public void actionPerformed(GridSphereEvent event) {        super.actionPerformed(event);        HttpServletRequest request = event.getHttpServletRequest();        String id = request.getSession(true).getId();        // remove cached output        cacheService.removeCached(this.getComponentID() + portletClass + id);        PortletComponentEvent titleBarEvent = event.getLastRenderEvent();        if ((titleBarEvent != null) && (titleBarEvent instanceof PortletTitleBarEvent)) {            PortletTitleBarEvent tbEvt = (PortletTitleBarEvent) titleBarEvent;            if (tbEvt.hasWindowStateAction()) {                WindowState state = tbEvt.getState();                PortletFrameEventImpl frameEvent = null;                if (state.equals(WindowState.MINIMIZED)) {                    renderPortlet = false;                    frameEvent = new PortletFrameEventImpl(this, PortletFrameEvent.FrameAction.FRAME_MINIMIZED, COMPONENT_ID);                } else if (state.equals(WindowState.NORMAL)) {                    renderPortlet = true;                    frameEvent = new PortletFrameEventImpl(this, PortletFrameEvent.FrameAction.FRAME_RESTORED, COMPONENT_ID);                    frameEvent.setOriginalWidth(originalWidth);                } else if (state.equals(WindowState.MAXIMIZED)) {                    renderPortlet = true;                    frameEvent = new PortletFrameEventImpl(this, PortletFrameEvent.FrameAction.FRAME_MAXIMIZED, COMPONENT_ID);                } else if (state.equals(new WindowState("CLOSE"))) {                    renderPortlet = true;                    isClosing = true;                    // check for portlet closing action                    if (event.hasAction()) {                        if (event.getAction().getName().equals(FRAME_CLOSE_OK_ACTION)) {                            isClosing = false;                            frameEvent = new PortletFrameEventImpl(this, PortletFrameEvent.FrameAction.FRAME_CLOSED, COMPONENT_ID);                            request.setAttribute(SportletProperties.INIT_PAGE, "true");                        }                        if (event.getAction().getName().equals(FRAME_CLOSE_CANCEL_ACTION)) {                            isClosing = false;                        }                    }                }                Iterator it = listeners.iterator();                PortletComponent comp;                while (it.hasNext()) {                    comp = (PortletComponent) it.next();                    event.addNewRenderEvent(frameEvent);                    comp.actionPerformed(event);                }            }        } else {            // now perform actionPerformed on Portlet if it has an action            titleBar.actionPerformed(event);            request.setAttribute(SportletProperties.COMPONENT_ID, componentIDStr);            request.setAttribute(SportletProperties.PORTLET_WINDOW_ID, windowId);            ActionResponse res = event.getActionResponse();            request.setAttribute(SportletProperties.PORTLETID, portletClass);            // Override if user is a guest            Principal principal = event.getActionRequest().getUserPrincipal();            // String userName = "";            try {                if (principal == null) {                    res.setPortletMode(PortletMode.VIEW);                    //userName = "guest";                } else {                    PortletMode mode = titleBar.getPortletMode();                    res.setPortletMode(mode);                    // userName = principal.getName();                }            } catch (PortletModeException e) {                System.err.println("unsupported mode ");            }            titleBar.setPortletMode(event.getActionRequest().getPortletMode());            //System.err.println("in PortletFrame action invoked for " + portletClass);            if (event.hasAction()                    && (!event.getAction().getName().equals(FRAME_CLOSE_OK_ACTION))                    && (!event.getAction().getName().equals(FRAME_CLOSE_CANCEL_ACTION))) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -