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

📄 portlettitlebar.java

📁 GridSphere 门户 提供一个基于 portlet 的高级开放源代码门户。GridSphere 是在欧盟提供基金的 GridLab 项目下开发的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }    /**     * Indicates an error ocurred suring the processing of this title bar     *     * @return <code>true</code> if an error occured during rendering,     *         <code>false</code> otherwise     */    public boolean hasRenderError() {        return hasError;    }    /**     * Returns any errors associated with the functioning of this title bar     *     * @return any title bar errors that occured     */    public String getErrorMessage() {        return errorMessage;    }    /**     * Initializes the portlet title bar. 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 list of component identifiers     * @return a list of updated component identifiers     * @see ComponentIdentifier     */    public List<ComponentIdentifier> init(PortletRequest req, List<ComponentIdentifier> list) {        list = super.init(req, list);        titleView = (Render) getRenderClass(req, "TitleBar");        portletInvoker = new PortletInvoker();        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);        portletRegistryService = (PortletRegistryService) PortletServiceFactory.createPortletService(PortletRegistryService.class, true);        String appID = portletRegistryService.getApplicationPortletID(portletClass);        ApplicationPortlet appPortlet = portletRegistryService.getApplicationPortlet(appID);        if (appPortlet != null) {            allowedWindowStates = appPortlet.getAllowedWindowStates();            allowedWindowStates = sort(allowedWindowStates);            if (canModify) {                if (!allowedWindowStates.contains(new WindowState("CLOSED"))) {                    allowedWindowStates.add(new WindowState("CLOSED"));                }            }        }        displayModes = req.getAttribute(SportletProperties.DISPLAY_MODES).equals(Boolean.TRUE);        displayStates = req.getAttribute(SportletProperties.DISPLAY_STATES).equals(Boolean.TRUE);        return list;    }    /**     * Simple sorting algoritm that sorts in increasing order a <code>List</code>     * containing objects that implement <code>Comparator</code>     *     * @param list a <code>List</code> to be sorted     * @return the sorted list     */    private List<javax.portlet.WindowState> sort(List<javax.portlet.WindowState> list) {        List<javax.portlet.WindowState> tmp = new ArrayList<javax.portlet.WindowState>();        if (list.contains(WindowState.MINIMIZED)) {            tmp.add(WindowState.MINIMIZED);        }        if (list.contains(WindowState.NORMAL)) {            tmp.add(WindowState.NORMAL);        }        if (list.contains(WindowState.MAXIMIZED)) {            tmp.add(WindowState.MAXIMIZED);        }        if (list.contains(new WindowState("CLOSED"))) {            tmp.add(new WindowState("CLOSED"));        }        if (list.contains(new WindowState("FLOATING"))) {            tmp.add(new WindowState("FLOATING"));        }        return tmp;    }    /**     * Creates the portlet window state hyperlinks displayed in the title bar     *     * @param event the gridsphere event     * @return a list of window state hyperlinks     */    public List<PortletStateLink> createWindowLinks(GridSphereEvent event) {        super.doRender(event);        PortletURL portletURL;        RenderResponse res = event.getRenderResponse();        if (allowedWindowStates.isEmpty()) return null;        if (!displayStates) return null;        //String[] windowStates = new String[allowedWindowStates.size()];        List<javax.portlet.WindowState> windowStates = new ArrayList<javax.portlet.WindowState>();        for (WindowState state : allowedWindowStates) {            windowStates.add(state);            // remove current state from list            if (state.equals(windowState) && (!windowState.equals(new WindowState("closed")))) {                windowStates.remove(state);            }        }        // get rid of floating if window state is minimized        if (windowState.equals(WindowState.MINIMIZED)) {            windowStates.remove(new WindowState("floating"));        }        // Localize the window state names        RenderRequest req = event.getRenderRequest();        Locale locale = req.getLocale();        // create a URI for each of the window states        PortletStateLink stateLink;        List<PortletStateLink> stateLinks = new ArrayList<PortletStateLink>();        for (WindowState state : windowStates) {            portletURL = res.createActionURL();            try {                stateLink = new PortletStateLink(state, locale);                portletURL.setWindowState(state);                stateLink.setHref(portletURL.toString());                if (state.equals(new WindowState("floating"))) {                    stateLink.setHref(portletURL.toString() + "\" onclick=\"return GridSphere_popup(this, 'notes')\"");                }                stateLinks.add(stateLink);            } catch (WindowStateException e) {                log.error("a window state exception occurred! " + state);            }        }        return stateLinks;    }    /**     * Creates the portlet mode hyperlinks displayed in the title bar     *     * @param event the gridsphere event     * @return a list of portlet mode hyperlinks     */    public List<PortletTitleBar.PortletModeLink> createModeLinks(GridSphereEvent event) {        super.doRender(event);        RenderResponse res = event.getRenderResponse();        RenderRequest req = event.getRenderRequest();        if (!displayModes) return null;        // make modes from supported modes        Set<String> supportedModes = (Set<String>) req.getAttribute(SportletProperties.ALLOWED_MODES);        if (supportedModes == null) return null;        // Unless user is admin they should not see configure mode        boolean hasConfigurePermission = req.isUserInRole(PortletRole.ADMIN.getName());        List<String> smodes = new ArrayList<String>();        for (String mode : supportedModes) {            if (mode.equalsIgnoreCase("config")) {                if (hasConfigurePermission) {                    smodes.add(mode);                }            } else {                smodes.add(mode);            }            // remove current mode from list            smodes.remove(portletMode.toString());        }        // Localize the portlet mode names        Locale locale = req.getLocale();        List<PortletModeLink> portletLinks = new ArrayList<PortletModeLink>();        for (String mode : smodes) {            // create a URI for each of the portlet modes            PortletModeLink modeLink;            PortletURL portletURL = res.createActionURL();            try {                PortletMode pmode = new PortletMode(mode);                modeLink = new PortletModeLink(pmode, locale);                portletURL.setPortletMode(pmode);                modeLink.setHref(portletURL.toString());                portletLinks.add(modeLink);            } catch (PortletModeException e) {                log.error("Unable to get mode for : " + mode);            }        }        return portletLinks;    }    /**     * Performs an action on this portlet title bar component     *     * @param event a gridsphere event     */    public void actionPerformed(GridSphereEvent event) {        super.actionPerformed(event);        isActive = true;        HttpServletRequest req = event.getHttpServletRequest();        ActionResponse res = event.getActionResponse();        req.setAttribute(SportletProperties.PORTLETID, portletClass);        // Render title bar        Set<String> supportedModes = null;        String appID = portletRegistryService.getApplicationPortletID(portletClass);        ApplicationPortlet appPortlet = portletRegistryService.getApplicationPortlet(appID);        if (appPortlet != null) {            supportedModes = appPortlet.getSupportedModes(event.getClient().getMimeType());        }        req.setAttribute(SportletProperties.ALLOWED_MODES, supportedModes);        // pop last event off stack        event.getLastRenderEvent();        PortletTitleBarEvent titleBarEvent = new PortletTitleBarEventImpl(this, event, COMPONENT_ID);        Principal principal = event.getActionRequest().getUserPrincipal();        if (principal != null) {            if (titleBarEvent.hasAction()) {                if (titleBarEvent.hasWindowStateAction()) {                    // don't set window state if it is floating                    if (!titleBarEvent.getState().equals(new WindowState("floating")))                        windowState = titleBarEvent.getState();                    //System.err.println("setting window state= " + windowState);                    PortletWindowEvent winEvent = null;                    // if receive a window state that is not supported do nothing                    if (!allowedWindowStates.contains(windowState)) return;                    if (windowState.equals(WindowState.MAXIMIZED)) {                        winEvent = new PortletWindowEventImpl(req, PortletWindowEvent.WINDOW_MAXIMIZED);                    } else if (windowState.equals(WindowState.MINIMIZED)) {                        winEvent = new PortletWindowEventImpl(req, PortletWindowEvent.WINDOW_MINIMIZED);                    } else if (windowState.equals(WindowState.NORMAL)) {                        winEvent = new PortletWindowEventImpl(req, PortletWindowEvent.WINDOW_RESTORED);                    } else if (windowState.equals(new WindowState("CLOSED"))) {                        winEvent = new PortletWindowEventImpl(req, PortletWindowEvent.WINDOW_CLOSED);                    }                    if (winEvent != null) {                        try {                            portletInvoker.windowEvent((String) req.getAttribute(SportletProperties.PORTLETID), winEvent, req, (HttpServletResponse) res);                        } catch (Exception e) {                            hasError = true;                            errorMessage += "Failed to invoke window event method of portlet: " + portletClass;                        }                    }                }                if (titleBarEvent.hasPortletModeAction()) {                    /*                    if (titleBarEvent.getMode().equals(Portlet.Mode.CONFIGURE)) {                        @TODO fix me                        boolean hasrole = aclService.hasRequiredRole(req, portletClass, true);                        if (!hasrole) return;                    }*/                    previousMode = portletMode;                    portletMode = titleBarEvent.getMode();                    //System.err.println("mode = " + portletMode);                    //System.err.println("prev mode = " + previousMode);                }            }        }        req.setAttribute(SportletProperties.PORTLET_WINDOW, windowState);        try {            res.setPortletMode(portletMode);        } catch (PortletModeException e) {            log.error("Unable to set mode to " + portletMode);        }        req.setAttribute(SportletProperties.PREVIOUS_MODE, previousMode);        for (PortletComponent comp : listeners) {            event.addNewRenderEvent(titleBarEvent);            comp.actionPerformed(event);        }    }    /**     * Fires a title bar event notification     *     * @param event a portlet title bar event     */    protected void fireTitleBarEvent(PortletTitleBarEvent event) {        for (PortletComponent titleBarListener : listeners) {            ((PortletTitleBarListener) titleBarListener).handleTitleBarEvent(event);        }    }    public List<PortletTitleBar.PortletModeLink> getModeLinks() {        return modeLinks;    }    public List<PortletTitleBar.PortletStateLink> getWindowLinks() {        return windowLinks;    }    public void doRender(GridSphereEvent event) {        super.doRender(event);        hasError = false;        // title bar: configure, edit, help, title, min, max        RenderRequest req = event.getRenderRequest();        RenderResponse res = event.getRenderResponse();        Set<String> supportedModes = null;        String appID = portletRegistryService.getApplicationPortletID(portletClass);        ApplicationPortlet appPortlet = portletRegistryService.getApplicationPortlet(appID);        if (appPortlet != null) {            supportedModes = appPortlet.getSupportedModes(event.getClient().getMimeType());        }        req.setAttribute(SportletProperties.ALLOWED_MODES, supportedModes);        PortalContext portalContext = appPortlet.getPortalContext();        req.setAttribute(SportletProperties.PORTAL_CONTEXT, portalContext);        // get the appropriate title for this client        Locale locale = req.getLocale();        Principal principal = req.getUserPrincipal();        if (principal != null) {            if (portletClass != null) {                modeLinks = createModeLinks(event);                windowLinks = createWindowLinks(event);            }        }        //System.err.println("in title bar render portletclass=" + portletClass + ": setting prev mode= " + previousMode + " cur mode= " + portletMode);        req.setAttribute(SportletProperties.PORTLET_MODE, portletMode);        req.setAttribute(SportletProperties.PREVIOUS_MODE, previousMode);        req.setAttribute(SportletProperties.PORTLET_WINDOW, windowState);        StringBuffer preTitle = titleView.doStart(event, this);        req.setAttribute(SportletProperties.RENDER_OUTPUT + COMPONENT_ID + ".pre", preTitle.toString());        StringBuffer postTitle = titleView.doEnd(event, this);        req.setAttribute(SportletProperties.RENDER_OUTPUT + COMPONENT_ID + ".post", postTitle.toString());        StringWriter storedWriter = new StringWriter();        PrintWriter writer = new PrintWriter(storedWriter);        PortletResponse wrappedResponse = new StoredPortletResponseImpl((HttpServletRequest) req, (HttpServletResponse) res, writer);        try {            //System.err.println("invoking  doTitle:" + title);            portletInvoker.doTitle((String) req.getAttribute(SportletProperties.PORTLETID), (HttpServletRequest) req, (HttpServletResponse) wrappedResponse);            //out.println(" (" + portletMode.toString() + ") ");            title = storedWriter.toString();        } catch (Exception e) {            ResourceBundle bundle = ResourceBundle.getBundle("gridsphere.resources.Portlet", locale);            title = bundle.getString("PORTLET_UNAVAILABLE");            hasError = true;            errorMessage = portletClass + " " + title + "!\n"; //"PortletException:" + e.getMessage();            log.error(portletClass + " is currently unavailable:", e);        }    }    public String getPreBufferedTitle(PortletRequest req) {        String preTitle = (String) req.getAttribute(SportletProperties.RENDER_OUTPUT + COMPONENT_ID + ".pre");        req.removeAttribute(SportletProperties.RENDER_OUTPUT + COMPONENT_ID + ".pre");        return preTitle;    }    public String getPostBufferedTitle(PortletRequest req) {        String postTitle = (String) req.getAttribute(SportletProperties.RENDER_OUTPUT + COMPONENT_ID + ".post");        req.removeAttribute(SportletProperties.RENDER_OUTPUT + COMPONENT_ID + ".post");        return postTitle;    }    public Object clone() throws CloneNotSupportedException {        PortletTitleBar t = (PortletTitleBar) super.clone();        t.title = this.title;        t.portletClass = this.portletClass;        t.portletMode = new PortletMode(this.portletMode.toString());        t.windowState = new WindowState(this.windowState.toString());        t.previousMode = this.previousMode;        return t;    }    public String toString() {        StringBuffer sb = new StringBuffer();        sb.append(super.toString());        return sb.toString();    }}

⌨️ 快捷键说明

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