public void setValues(final UIPortlet uiPortlet) throws Exception { uiPortlet_ = uiPortlet; invokeGetBindingBean(uiPortlet_); String icon = uiPortlet.getIcon(); if (icon == null || icon.length() < 0) { icon = "PortletIcon"; } getChild(UIFormInputIconSelector.class).setSelectedIcon(icon); getChild(UIFormInputThemeSelector.class) .getChild(UIItemThemeSelector.class) .setSelectedTheme(uiPortlet.getSuitedTheme(null)); if (hasEditMode()) { uiPortlet.setCurrentPortletMode(PortletMode.EDIT); } else { Map<String, String> portletPreferenceMaps = new HashMap<String, String>(); org.gatein.pc.api.Portlet portlet = uiPortlet.getProducedOfferedPortlet(); Set<String> keySet = portlet.getInfo().getPreferences().getKeys(); for (String key : keySet) { PreferenceInfo preferenceInfo = portlet.getInfo().getPreferences().getPreference(key); if (!preferenceInfo.isReadOnly()) { String ppValue = (preferenceInfo.getDefaultValue().size() > 0) ? preferenceInfo.getDefaultValue().get(0) : ""; portletPreferenceMaps.put(key, ppValue); } } Portlet pp = uiPortlet.getPreferences(); if (pp != null) { for (Preference pref : pp) { if (!pref.isReadOnly()) { portletPreferenceMaps.put( pref.getName(), (pref.getValues().size() > 0) ? pref.getValues().get(0) : ""); } } } if (portletPreferenceMaps.size() > 0) { Set<String> ppKeySet = portletPreferenceMaps.keySet(); UIFormInputSet uiPortletPrefSet = getChildById(FIELD_PORTLET_PREF); uiPortletPrefSet.getChildren().clear(); for (String ppKey : ppKeySet) { String ppValue = portletPreferenceMaps.get(ppKey); UIFormStringInput preferenceStringInput = new UIFormStringInput(ppKey, null, ppValue); preferenceStringInput.setLabel(ppKey); preferenceStringInput.addValidator(MandatoryValidator.class); uiPortletPrefSet.addUIFormInput(preferenceStringInput); } uiPortletPrefSet.setRendered(true); setSelectedTab(FIELD_PORTLET_PREF); return; } setSelectedTab("PortletSetting"); } }
/** * 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); }
public void testDestroyClones() throws Exception { // switch the behavior for portlet management BehaviorRegistry behaviorRegistry = producer.getBehaviorRegistry(); behaviorRegistry.setPortletManagementBehavior( new DestroyClonesPortletManagementBehavior(behaviorRegistry)); PortletContext original = PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE, false); PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original); ExtendedAssert.assertNotNull(clone); Portlet portlet = consumer.getPortlet(clone); ExtendedAssert.assertNotNull(portlet); ExtendedAssert.assertEquals( BasicPortletManagementBehavior.CLONED_HANDLE, portlet.getContext().getId()); List clones = new ArrayList(1); clones.add(clone); List result = consumer.destroyClones(clones); ExtendedAssert.assertTrue(result.isEmpty()); try { consumer.getPortlet(clone); ExtendedAssert.fail("Should have failed: clone should not exist anymore!"); } catch (PortletInvokerException expected) { } // re-create clone and try again with an added invalid portlet context clone = consumer.createClone(PortletStateType.OPAQUE, original); PortletContext invalidContext = PortletContext.createPortletContext("invalid", false); clones.add(invalidContext); result = consumer.destroyClones(clones); ExtendedAssert.assertEquals(1, result.size()); DestroyCloneFailure failure = (DestroyCloneFailure) result.get(0); ExtendedAssert.assertEquals("invalid", failure.getPortletId()); try { consumer.getPortlet(clone); ExtendedAssert.fail("Should have failed: clone should not exist anymore!"); } catch (PortletInvokerException expected) { } }
public void testClone() throws Exception { PortletContext original = PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE, false); PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original); ExtendedAssert.assertNotNull(clone); ExtendedAssert.assertFalse(original.equals(clone)); ExtendedAssert.assertEquals(BasicPortletManagementBehavior.CLONED_HANDLE, clone.getId()); Portlet originalPortlet = consumer.getPortlet(original); Portlet clonePortlet = consumer.getPortlet(clone); ExtendedAssert.assertNotNull(clonePortlet); ExtendedAssert.assertFalse(originalPortlet.getContext().equals(clonePortlet.getContext())); // information about the portlet should be the same MetaInfo originalInfo = originalPortlet.getInfo().getMeta(); MetaInfo cloneInfo = clonePortlet.getInfo().getMeta(); ExtendedAssert.assertEquals( originalInfo.getMetaValue(MetaInfo.TITLE), cloneInfo.getMetaValue(MetaInfo.TITLE)); ExtendedAssert.assertEquals( originalInfo.getMetaValue(MetaInfo.DESCRIPTION), cloneInfo.getMetaValue(MetaInfo.DESCRIPTION)); }
Page(PortletInvoker invoker, String s) throws ServletException { LinkedHashMap<String, Window> windows = new LinkedHashMap<String, Window>(); int count = 0; Map<String, String[]> parameters; // if (s == null || s.length() == 0 || (s.length() == 1 && s.charAt(0) == '/')) { parameters = null; } else { Segment segments = (Segment) Chunk.parse(s); // Skip context path segments = (Segment) segments.next; // Servlet parameter parameters = segments.parameters; // for (Segment segment : (Segment) segments.next) { Portlet found = null; if (invoker != null) { try { for (Portlet portlet : invoker.getPortlets()) { if (portlet.getInfo().getName().equals(segment.value)) { found = portlet; break; } } } catch (PortletInvokerException e) { // ? } } // LinkedHashMap<String, String[]> windowParameters; Mode windowMode; WindowState windowState; if (segment.parameters != null) { windowParameters = new LinkedHashMap<String, String[]>(segment.parameters); String[] modeParameter = windowParameters.remove("javax.portlet.portlet_mode"); String[] windowStateParameter = windowParameters.remove("javax.portlet.window_state"); windowMode = modeParameter != null ? Mode.create(modeParameter[0]) : null; windowState = windowStateParameter != null ? WindowState.create(windowStateParameter[0]) : null; } else { windowParameters = null; windowMode = null; windowState = null; } // Window context = new Window( "" + count++, found, segment.value, windowMode, windowState, windowParameters); // windows.put(context.id, context); } } // this.windows = windows; this.parameters = parameters; }