private String getAddSkinScript(Set<UIComponent> updateComponents) { if (updateComponents == null) return null; List<UIPortlet> uiportlets = new ArrayList<UIPortlet>(); for (UIComponent uicomponent : updateComponents) { if (uicomponent instanceof UIContainer) { UIContainer uiContainer = (UIContainer) uicomponent; uiContainer.findComponentOfType(uiportlets, UIPortlet.class); } } List<SkinConfig> skins = new ArrayList<SkinConfig>(); SkinService skinService = getApplicationComponent(SkinService.class); for (UIPortlet uiPortlet : uiportlets) { String module = uiPortlet.getExoWindowID().getPortletApplicationName() + "/" + uiPortlet.getExoWindowID().getPortletName(); SkinConfig skinConfig = skinService.getSkin(module, skin_); if (skinConfig != null) skins.add(skinConfig); } StringBuilder b = new StringBuilder(1000); for (SkinConfig ele : skins) { SkinURL url = ele.createURL(); url.setOrientation(orientation_); b.append("eXo.core.Skin.addSkin('") .append(ele.getId()) .append("','") .append(url) .append("');\n"); } return b.toString(); }
private SkinConfig getPortletSkinConfig(UIPortlet portlet) { String module = portlet.getExoWindowID().getPortletApplicationName() + "/" + portlet.getExoWindowID().getPortletName(); return getSkin(module); }
public void execute(Event<UIPortal> event) throws Exception { UIPortal uiPortal = event.getSource(); String portletId = event.getRequestContext().getRequestParameter("portletId"); UIPortlet uiPortlet = uiPortal.findComponentById(portletId); WebuiRequestContext context = event.getRequestContext(); uiPortlet.createEvent("ChangeWindowState", event.getExecutionPhase(), context).broadcast(); }
private static void buildUIContainer(UIContainer uiContainer, Object model, boolean dashboard) throws Exception { UIComponent uiComponent = null; WebuiRequestContext context = Util.getPortalRequestContext(); if (model instanceof SiteBody) { UISiteBody uiSiteBody = uiContainer.createUIComponent(context, UISiteBody.class, null, null); uiSiteBody.setStorageId(((SiteBody) model).getStorageId()); uiComponent = uiSiteBody; } else if (model instanceof PageBody) { UIPageBody uiPageBody = uiContainer.createUIComponent(context, UIPageBody.class, null, null); uiPageBody.setStorageId(((PageBody) model).getStorageId()); uiComponent = uiPageBody; } else if (model instanceof Application) { Application application = (Application) model; if (dashboard && application.getType() == ApplicationType.GADGET) { Application<Gadget> ga = (Application<Gadget>) application; UIGadget uiGadget = uiContainer.createUIComponent(context, UIGadget.class, null, null); uiGadget.setStorageId(application.getStorageId()); toUIGadget(uiGadget, ga); uiComponent = uiGadget; } else { UIPortlet uiPortlet = uiContainer.createUIComponent(context, UIPortlet.class, null, null); uiPortlet.setStorageId(application.getStorageId()); if (application.getStorageName() != null) { uiPortlet.setStorageName(application.getStorageName()); } toUIPortlet(uiPortlet, application); uiComponent = uiPortlet; } } else if (model instanceof Container) { Container container = (Container) model; UIComponentFactory<? extends UIContainer> factory = UIComponentFactory.getInstance(UIContainer.class); UIContainer uiTempContainer = factory.createUIComponent(container.getFactoryId(), context); if (uiTempContainer == null) { log.warn( "Can't find container factory for: {}. Default container is used", container.getFactoryId()); uiTempContainer = uiContainer.createUIComponent(context, UIContainer.class, null, null); } toUIContainer(uiTempContainer, (Container) model, dashboard); uiComponent = uiTempContainer; } uiContainer.addChild(uiComponent); }
private static void buildUIContainer(UIContainer uiContainer, Object model, boolean dashboard) throws Exception { UIComponent uiComponent = null; WebuiRequestContext context = Util.getPortalRequestContext(); if (model instanceof SiteBody) { UISiteBody uiSiteBody = uiContainer.createUIComponent(context, UISiteBody.class, null, null); uiSiteBody.setStorageId(((SiteBody) model).getStorageId()); uiComponent = uiSiteBody; } else if (model instanceof PageBody) { UIPageBody uiPageBody = uiContainer.createUIComponent(context, UIPageBody.class, null, null); uiPageBody.setStorageId(((PageBody) model).getStorageId()); uiComponent = uiPageBody; } else if (model instanceof Application) { Application application = (Application) model; if (dashboard && application.getType() == ApplicationType.GADGET) { Application<Gadget> ga = (Application<Gadget>) application; UIGadget uiGadget = uiContainer.createUIComponent(context, UIGadget.class, null, null); uiGadget.setStorageId(application.getStorageId()); toUIGadget(uiGadget, ga); uiComponent = uiGadget; } else { UIPortlet uiPortlet = uiContainer.createUIComponent(context, UIPortlet.class, null, null); uiPortlet.setStorageId(application.getStorageId()); if (application.getStorageName() != null) { uiPortlet.setStorageName(application.getStorageName()); } toUIPortlet(uiPortlet, application); uiComponent = uiPortlet; } } else if (model instanceof Container) { Container container = (Container) model; UIContainer uiTempContainer; if (UITabContainer.TAB_CONTAINER.equals(container.getFactoryId())) { uiTempContainer = uiContainer.createUIComponent(context, UITabContainer.class, null, null); } else if (UIColumnContainer.COLUMN_CONTAINER.equals(container.getFactoryId())) { uiTempContainer = uiContainer.createUIComponent(context, UIColumnContainer.class, null, null); } else { uiTempContainer = uiContainer.createUIComponent(context, UIContainer.class, null, null); } toUIContainer(uiTempContainer, (Container) model, dashboard); uiComponent = uiTempContainer; } uiContainer.addChild(uiComponent); }
public static void toUIPage(UIPage uiPage, Page model) throws Exception { toUIContainer(uiPage, model); uiPage.setSiteKey(new SiteKey(model.getOwnerType(), model.getOwnerId())); uiPage.setIcon(model.getIcon()); uiPage.setAccessPermissions(model.getAccessPermissions()); uiPage.setEditPermission(model.getEditPermission()); uiPage.setFactoryId(model.getFactoryId()); uiPage.setPageId(model.getPageId()); uiPage.setTitle(model.getTitle()); uiPage.setShowMaxWindow(model.isShowMaxWindow()); uiPage.setModifiable(model.isModifiable()); List<UIPortlet> portlets = new ArrayList<UIPortlet>(); uiPage.findComponentOfType(portlets, UIPortlet.class); for (UIPortlet portlet : portlets) { portlet.setPortletInPortal(false); } }
/** * Add Application to UiPage * * @param event * @throws Exception */ private static void addApplicationToPage(Event<UIAddNewApplication> event, boolean atStartup) throws Exception { UIPortalApplication uiPortalApp = Util.getUIPortalApplication(); UIPortal uiPortal = uiPortalApp.getShowedUIPortal(); PortalRequestContext pcontext = Util.getPortalRequestContext(); UIDesktopPage uiDesktopPage = uiPortal.findFirstComponentOfType(UIDesktopPage.class); if (uiDesktopPage == null) { pcontext.addUIComponentToUpdateByAjax( uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID)); UIMaskWorkspace maskWorkspace = uiPortalApp.getChildById(UIPortalApplication.UI_MASK_WS_ID); maskWorkspace.createEvent("Close", Event.Phase.DECODE, event.getRequestContext()).broadcast(); pcontext.setFullRender(true); return; } String applicationId = event.getRequestContext().getRequestParameter(UIComponent.OBJECTID); Application application = event.getSource().getApplication(applicationId); ApplicationType appType = application.getType(); UIPortlet uiPortlet = uiDesktopPage.createUIComponent(UIPortlet.class, null, null); ApplicationState appState; // TODO: Check if there 's already a portlet window of this portlet. A CloneApplicationState // should be created in such case appState = new TransientApplicationState<Object>(application.getContentId()); uiPortlet.setState(new PortletState(appState, appType)); uiPortlet.setPortletInPortal(false); if (atStartup) { uiPortlet.getProperties().setProperty("appStatus", "HIDE"); } String portletName = application.getApplicationName(); String displayName = application.getDisplayName(); if (displayName != null) { uiPortlet.setTitle(displayName); } else if (portletName != null) { uiPortlet.setTitle(portletName); } uiPortlet.setDescription(application.getDescription()); List<String> accessPers = application.getAccessPermissions(); String[] accessPermissions = accessPers.toArray(new String[accessPers.size()]); uiPortlet.setAccessPermissions(accessPermissions); // Add portlet to page uiDesktopPage.addChild(uiPortlet); if (uiDesktopPage.isModifiable()) { Page page = (Page) PortalDataMapper.buildModelObject(uiDesktopPage); if (page.getChildren() == null) { page.setChildren(new ArrayList<ModelObject>()); } DataStorage dataService = uiPortalApp.getApplicationComponent(DataStorage.class); dataService.save(page); // Rebuild the uiPage to synchronize (storageId, storageName) mapping page = dataService.getPage(page.getPageId()); page.setModifiable(true); uiDesktopPage.getChildren().clear(); PortalDataMapper.toUIPage(uiDesktopPage, page); } UIWorkingWorkspace uiWorkingWS = uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID); pcontext.setFullRender(true); pcontext.addUIComponentToUpdateByAjax(uiWorkingWS); }
/** * Fill the UI component with both information from the persistent model and some coming from the * portlet.xml defined by the JSR 286 specification */ private static <S> void toUIPortlet(UIPortlet<S, ?> uiPortlet, Application<S> model) { // PortletState<S> portletState = new PortletState<S>(model.getState(), model.getType()); /* * Fill UI component object with info from the XML file that persist portlet information */ uiPortlet.setWidth(model.getWidth()); uiPortlet.setHeight(model.getHeight()); uiPortlet.setState(portletState); uiPortlet.setTitle(model.getTitle()); uiPortlet.setIcon(model.getIcon()); uiPortlet.setDescription(model.getDescription()); uiPortlet.setShowInfoBar(model.getShowInfoBar()); uiPortlet.setShowWindowState(model.getShowApplicationState()); uiPortlet.setShowPortletMode(model.getShowApplicationMode()); uiPortlet.setProperties(model.getProperties()); uiPortlet.setTheme(model.getTheme()); if (model.getAccessPermissions() != null) uiPortlet.setAccessPermissions(model.getAccessPermissions()); uiPortlet.setModifiable(model.isModifiable()); Portlet portlet = uiPortlet.getProducedOfferedPortlet(); if (portlet == null || portlet.getInfo() == null) return; PortletInfo portletInfo = portlet.getInfo(); /* * Define which portlet modes the portlet supports and hence should be shown in the portlet info bar */ Set<ModeInfo> modes = portletInfo.getCapabilities().getModes(MediaType.create("text/html")); List<String> supportModes = new ArrayList<String>(); for (ModeInfo modeInfo : modes) { String modeName = modeInfo.getModeName().toLowerCase(); if ("config".equals(modeInfo.getModeName())) { supportModes.add(modeName); } else { supportModes.add(modeName); } } if (supportModes.size() > 1) supportModes.remove("view"); uiPortlet.setSupportModes(supportModes); }
private static <S> Application<S> toPortletModel(UIPortlet<S, ?> uiPortlet) { Application<S> model; PortletState<S> state = uiPortlet.getState(); ApplicationType<S> type = state.getApplicationType(); if (type == ApplicationType.PORTLET) { model = (Application<S>) Application.createPortletApplication(uiPortlet.getStorageId()); } else if (type == ApplicationType.GADGET) { model = (Application<S>) Application.createGadgetApplication(uiPortlet.getStorageId()); } else if (type == ApplicationType.WSRP_PORTLET) { model = (Application<S>) Application.createWSRPApplication(uiPortlet.getStorageId()); } else { throw new AssertionError(); } // model.setStorageName(uiPortlet.getStorageName()); model.setState(state.getApplicationState()); model.setTitle(uiPortlet.getTitle()); model.setWidth(uiPortlet.getWidth()); model.setHeight(uiPortlet.getHeight()); model.setDescription(uiPortlet.getDescription()); model.setShowInfoBar(uiPortlet.getShowInfoBar()); model.setShowApplicationState(uiPortlet.getShowWindowState()); model.setShowApplicationMode(uiPortlet.getShowPortletMode()); model.setDescription(uiPortlet.getDescription()); model.setIcon(uiPortlet.getIcon()); model.setProperties(uiPortlet.getProperties()); model.setTheme(uiPortlet.getTheme()); model.setAccessPermissions(uiPortlet.getAccessPermissions()); model.setModifiable(uiPortlet.isModifiable()); return model; }
/** * The processrender() method handles the creation of the returned HTML either for a full page * render or in the case of an AJAX call The first request, Ajax is not enabled (means no * ajaxRequest parameter in the request) and hence the super.processRender() method is called. * This will hence call the processrender() of the Lifecycle object as this method is not * overidden in UIPortalApplicationLifecycle. There we simply render the bounded template (groovy * usually). Note that bounded template are also defined in component annotations, so for the * current class it is UIPortalApplication.gtmpl On second calls, request have the "ajaxRequest" * parameter set to true in the URL. In that case the algorithm is a bit more complex: a) The list * of components that should be updated is extracted using the * context.getUIComponentToUpdateByAjax() method. That list was setup during the process action * phase b) Portlets and other UI components to update are split in 2 different lists c) Portlets * full content are returned and set with the tag <div class="PortalResponse"> d) Block to updates * (which are UI components) are set within the <div class="PortalResponseData"> tag e) Then the * scripts and the skins to reload are set in the <div class="PortalResponseScript"> */ public void processRender(WebuiRequestContext context) throws Exception { Writer w = context.getWriter(); if (!context.useAjax()) { super.processRender(context); } else { PortalRequestContext pcontext = (PortalRequestContext) context; UIMaskWorkspace uiMaskWS = getChildById(UIPortalApplication.UI_MASK_WS_ID); if (uiMaskWS.isUpdated()) pcontext.addUIComponentToUpdateByAjax(uiMaskWS); if (getUIPopupMessages().hasMessage()) { pcontext.addUIComponentToUpdateByAjax(getUIPopupMessages()); } Set<UIComponent> list = context.getUIComponentToUpdateByAjax(); List<UIPortlet> uiPortlets = new ArrayList<UIPortlet>(3); List<UIComponent> uiDataComponents = new ArrayList<UIComponent>(5); if (list != null) { for (UIComponent uicomponent : list) { if (uicomponent instanceof UIPortlet) uiPortlets.add((UIPortlet) uicomponent); else uiDataComponents.add(uicomponent); } } w.write("<div class=\"PortalResponse\">"); w.write("<div class=\"PortalResponseData\">"); for (UIComponent uicomponent : uiDataComponents) { if (log.isDebugEnabled()) log.debug("AJAX call: Need to refresh the UI component " + uicomponent.getName()); renderBlockToUpdate(uicomponent, context, w); } w.write("</div>"); if (!context.getFullRender()) { for (UIPortlet uiPortlet : uiPortlets) { if (log.isDebugEnabled()) log.debug("AJAX call: Need to refresh the Portlet " + uiPortlet.getWindowId()); w.write("<div class=\"PortletResponse\" style=\"display: none\">"); w.append( "<div class=\"PortletResponsePortletId\">" + uiPortlet.getExoWindowID().getUniqueID() + "</div>"); w.append("<div class=\"PortletResponseData\">"); /* * If the portlet is using our UI framework or supports it then it * will return a set of block to updates. If there is not block to * update the javascript client will see that as a full refresh of the * content part */ uiPortlet.processRender(context); w.append("</div>"); w.append("<div class=\"PortletResponseScript\"></div>"); w.write("</div>"); } } w.write("<div class=\"PortalResponseScript\">"); w.write(pcontext.getJavascriptManager().getJavascript()); w.write("eXo.core.Browser.onLoad();\n"); w.write(pcontext.getJavascriptManager().getCustomizedOnLoadScript()); String skin = getAddSkinScript(list); if (skin != null) { w.write(skin); } w.write("</div>"); w.write("</div>"); } }