@Override public String[] getAssetTagNames(PortletPreferences portletPreferences, long scopeGroupId) throws Exception { String[] allAssetTagNames = new String[0]; for (int i = 0; true; i++) { String[] queryValues = portletPreferences.getValues("queryValues" + i, null); if ((queryValues == null) || (queryValues.length == 0)) { break; } boolean queryContains = GetterUtil.getBoolean(portletPreferences.getValue("queryContains" + i, StringPool.BLANK)); boolean queryAndOperator = GetterUtil.getBoolean( portletPreferences.getValue("queryAndOperator" + i, StringPool.BLANK)); String queryName = portletPreferences.getValue("queryName" + i, StringPool.BLANK); if (!Validator.equals(queryName, "assetCategories") && queryContains && queryAndOperator) { allAssetTagNames = queryValues; } } return allAssetTagNames; }
@Override protected PortletPreferences doProcessImportPortletPreferences( PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences) throws Exception { portletDataContext.importPortletPermissions(WikiPermission.RESOURCE_NAME); StagedModelDataHandlerUtil.importReferenceStagedModels(portletDataContext, WikiNode.class); StagedModelDataHandlerUtil.importReferenceStagedModels(portletDataContext, WikiPage.class); long nodeId = GetterUtil.getLong(portletPreferences.getValue("nodeId", StringPool.BLANK)); if (nodeId > 0) { Map<Long, Long> nodeIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(WikiNode.class); nodeId = MapUtil.getLong(nodeIds, nodeId, nodeId); portletPreferences.setValue("nodeId", String.valueOf(nodeId)); } return portletPreferences; }
protected String addJournalContentPortletToLayout( long userId, Layout layout, JournalArticle journalArticle, String columnId) throws Exception { LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); String journalPortletId = layoutTypePortlet.addPortletId(userId, PortletKeys.JOURNAL_CONTENT, columnId, -1); LayoutLocalServiceUtil.updateLayout( layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings()); javax.portlet.PortletPreferences prefs = getPortletPreferences(layout.getCompanyId(), layout.getPlid(), journalPortletId); prefs.setValue("articleId", journalArticle.getArticleId()); prefs.setValue("groupId", String.valueOf(journalArticle.getGroupId())); prefs.setValue("showAvailableLocales", Boolean.TRUE.toString()); updatePortletPreferences(layout.getPlid(), journalPortletId, prefs); return journalPortletId; }
@Override public void processAction( ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String cmd = ParamUtil.getString(actionRequest, Constants.CMD); if (!cmd.equals(Constants.UPDATE)) { return; } PortletPreferences preferences = actionRequest.getPreferences(); String[] symbols = StringUtil.split(ParamUtil.getString(actionRequest, "symbols").toUpperCase()); preferences.setValues("symbols", symbols); try { preferences.store(); } catch (ValidatorException ve) { SessionErrors.add(actionRequest, ValidatorException.class.getName(), ve); return; } SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doEdit"); }
protected long getResourcePrimKey(RenderRequest renderRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletPreferences preferences = renderRequest.getPreferences(); long defaultValue = GetterUtil.getLong(preferences.getValue("resourcePrimKey", null)); String mvcPath = ParamUtil.getString(renderRequest, "mvcPath"); if (((defaultValue == 0) && mvcPath.equals(viewTemplate)) || mvcPath.equals("/display/select_configuration_article.jsp")) { return 0; } long resourcePrimKey = ParamUtil.getLong(renderRequest, "resourcePrimKey", defaultValue); if ((resourcePrimKey == 0) || (resourcePrimKey != defaultValue)) { return resourcePrimKey; } PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); if (!KBArticlePermission.contains(permissionChecker, defaultValue, ActionKeys.VIEW)) { return 0; } return defaultValue; }
public void processAction( PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String cmd = ParamUtil.getString(actionRequest, Constants.CMD); if (!cmd.equals(Constants.UPDATE)) { return; } boolean allAssetVocabularies = ParamUtil.getBoolean(actionRequest, "allAssetVocabularies"); long[] assetVocabularyIds = StringUtil.split(ParamUtil.getString(actionRequest, "assetVocabularyIds"), 0L); String portletResource = ParamUtil.getString(actionRequest, "portletResource"); PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource); preferences.setValue("all-asset-vocabularies", String.valueOf(allAssetVocabularies)); preferences.setValues("asset-vocabulary-ids", ArrayUtil.toStringArray(assetVocabularyIds)); preferences.store(); SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doConfigure"); }
public void editSharing(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { Portlet portlet = ActionUtil.getPortlet(actionRequest); PortletPreferences portletPreferences = ActionUtil.getLayoutPortletSetup(actionRequest, portlet); actionRequest = ActionUtil.getWrappedActionRequest(actionRequest, portletPreferences); updateAnyWebsite(actionRequest, portletPreferences); updateFacebook(actionRequest, portletPreferences); updateFriends(actionRequest, portletPreferences); updateGoogleGadget(actionRequest, portletPreferences); updateNetvibes(actionRequest, portletPreferences); portletPreferences.store(); if (!SessionErrors.isEmpty(actionRequest)) { return; } String portletResource = ParamUtil.getString(actionRequest, "portletResource"); SessionMessages.add( actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET, portletResource); SessionMessages.add( actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_UPDATED_CONFIGURATION); }
private Map<String, Object> _getPortletPreferences(RenderRequest renderRequest) { Map<String, Object> contextObjects = new HashMap<String, Object>(); PortletPreferences portletPreferences = renderRequest.getPreferences(); Map<String, String[]> map = portletPreferences.getMap(); for (Map.Entry<String, String[]> entry : map.entrySet()) { String[] values = entry.getValue(); if ((values == null) || (values.length == 0)) { continue; } String value = values[0]; if (value == null) { continue; } contextObjects.put(entry.getKey(), value); } return contextObjects; }
protected void login( ThemeDisplay themeDisplay, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { HttpServletRequest request = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(actionRequest)); HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); String login = ParamUtil.getString(actionRequest, "login"); String password = actionRequest.getParameter("password"); boolean rememberMe = ParamUtil.getBoolean(actionRequest, "rememberMe"); if (!themeDisplay.isSignedIn()) { String portletId = PortalUtil.getPortletId(actionRequest); PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(themeDisplay.getLayout(), portletId); String authType = portletPreferences.getValue("authType", null); AuthenticatedSessionManagerUtil.login( request, response, login, password, rememberMe, authType); } String redirect = ParamUtil.getString(actionRequest, "redirect"); if (Validator.isNotNull(redirect)) { redirect = PortalUtil.escapeRedirect(redirect); if (Validator.isNotNull(redirect) && !redirect.startsWith(Http.HTTP)) { redirect = getCompleteRedirectURL(request, redirect); } } String mainPath = themeDisplay.getPathMain(); if (PropsValues.PORTAL_JAAS_ENABLE) { if (Validator.isNotNull(redirect)) { redirect = mainPath.concat("/portal/protected?redirect=").concat(HttpUtil.encodeURL(redirect)); } else { redirect = mainPath.concat("/portal/protected"); } actionResponse.sendRedirect(redirect); } else { if (Validator.isNotNull(redirect)) { actionResponse.sendRedirect(redirect); } else { boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin"); if (doActionAfterLogin) { return; } else { actionResponse.sendRedirect(mainPath); } } } }
/* * Process the "finished" action for the edit page. Set the "url" to the value specified in the * edit page. */ private void processEditFinishedAction(ActionRequest request, ActionResponse response) throws PortletException { String nbPublis = request.getParameter(TEXTBOX_NB_ITEMS); String maxAge = request.getParameter(TEXTBOX_MAX_AGE); String displayDescription = request.getParameter("displayDescription"); // Check if it is a number try { int nb = Integer.parseInt(nbPublis); Integer.parseInt(maxAge); if (nb < 0 || nb > 30) { throw new NumberFormatException(); } // store preference PortletPreferences pref = request.getPreferences(); try { pref.setValue("nbPublis", nbPublis); pref.setValue("maxAge", maxAge); pref.setValue("displayDescription", displayDescription); pref.store(); } catch (ValidatorException ve) { log("could not set nbPublis", ve); throw new PortletException("IFramePortlet.processEditFinishedAction", ve); } catch (IOException ioe) { log("could not set nbPublis", ioe); throw new PortletException("IFramePortlet.prcoessEditFinishedAction", ioe); } response.setPortletMode(PortletMode.VIEW); } catch (NumberFormatException e) { response.setRenderParameter(ERROR_BAD_VALUE, "true"); response.setPortletMode(PortletMode.EDIT); } }
@Override public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { PortletSession session = request.getPortletSession(); MainSessionController mainSessionController = (MainSessionController) session.getAttribute( MainSessionController.MAIN_SESSION_CONTROLLER_ATT, PortletSession.APPLICATION_SCOPE); String spaceId = (String) session.getAttribute("Silverpeas_Portlet_SpaceId", PortletSession.APPLICATION_SCOPE); PortletPreferences pref = request.getPreferences(); int nbPublis = 5; if (StringUtil.isInteger(pref.getValue("nbPublis", "5"))) { nbPublis = Integer.parseInt(pref.getValue("nbPublis", "5")); } int maxAge = 0; if (StringUtil.isInteger(pref.getValue("maxAge", "0"))) { maxAge = Integer.parseInt(pref.getValue("maxAge", "0")); } KmeliaTransversal kmeliaTransversal = new KmeliaTransversal(mainSessionController); List<PublicationDetail> publications = kmeliaTransversal.getUpdatedPublications(spaceId, maxAge, nbPublis); if (StringUtil.isDefined(spaceId)) { String rssUrl = getRSSUrl(mainSessionController, spaceId); request.setAttribute("rssUrl", rssUrl); } request.setAttribute("Publications", publications); include(request, response, "portlet.jsp"); }
@Override public void removeAndStoreSelection( List<String> assetEntryUuids, PortletPreferences portletPreferences) throws Exception { if (assetEntryUuids.size() == 0) { return; } String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]); List<String> assetEntryXmlsList = ListUtil.fromArray(assetEntryXmls); Iterator<String> itr = assetEntryXmlsList.iterator(); while (itr.hasNext()) { String assetEntryXml = itr.next(); Document document = SAXReaderUtil.read(assetEntryXml); Element rootElement = document.getRootElement(); String assetEntryUuid = rootElement.elementText("asset-entry-uuid"); if (assetEntryUuids.contains(assetEntryUuid)) { itr.remove(); } } portletPreferences.setValues( "assetEntryXml", assetEntryXmlsList.toArray(new String[assetEntryXmlsList.size()])); portletPreferences.store(); }
@Override public Long[] getClassTypeIds( PortletPreferences portletPreferences, String className, Long[] availableClassTypeIds) { boolean anyAssetType = GetterUtil.getBoolean( portletPreferences.getValue("anyClassType" + className, Boolean.TRUE.toString())); if (anyAssetType) { return availableClassTypeIds; } long defaultClassTypeId = GetterUtil.getLong(portletPreferences.getValue("anyClassType" + className, null)); if (defaultClassTypeId > 0) { return new Long[] {defaultClassTypeId}; } Long[] classTypeIds = ArrayUtil.toArray( StringUtil.split(portletPreferences.getValue("classTypeIds" + className, null), 0L)); if (classTypeIds != null) { return classTypeIds; } else { return availableClassTypeIds; } }
@Override public long[] getClassNameIds( PortletPreferences portletPreferences, long[] availableClassNameIds) { boolean anyAssetType = GetterUtil.getBoolean(portletPreferences.getValue("anyAssetType", Boolean.TRUE.toString())); if (anyAssetType) { return availableClassNameIds; } long defaultClassNameId = GetterUtil.getLong(portletPreferences.getValue("anyAssetType", null)); if (defaultClassNameId > 0) { return new long[] {defaultClassNameId}; } long[] classNameIds = GetterUtil.getLongValues(portletPreferences.getValues("classNameIds", null)); if (classNameIds != null) { return classNameIds; } else { return availableClassNameIds; } }
@Override public String doExportData( PortletDataContext context, String portletId, PortletPreferences preferences) throws PortletDataException { long communityId = context.getScopeGroupId(); LOGGER.debug( "Exporting CRUD portlet data for portletId {}, communityId {}", portletId, communityId); try { preferences.setValue("VERSION", String.valueOf(EXPORT_VERSION)); if (configurationService.hasConfigData(portletId, communityId)) { exportRolesAndPermissions(context, portletId, preferences, communityId); exportConfig(context, portletId, communityId); preferences.store(); ConfigurationMetaData metaData = configurationService.getConfigurationMetaData(portletId, communityId); return metaData.getFileName(); } else { preferences.store(); return "Keine Konfiguration vorhanden"; } } catch (Exception e) { throw new PortletDataException("Error exporting portlet " + portletId + "/" + communityId, e); } }
protected void updatePreferencesClassPKs(PortletPreferences preferences, String key) throws Exception { String[] oldValues = preferences.getValues(key, null); if (oldValues == null) { return; } String[] newValues = new String[oldValues.length]; for (int i = 0; i < oldValues.length; i++) { String oldValue = oldValues[i]; String newValue = oldValue; String[] oldPrimaryKeys = StringUtil.split(oldValue); for (String oldPrimaryKey : oldPrimaryKeys) { if (!Validator.isNumber(oldPrimaryKey)) { break; } Long newPrimaryKey = _ddmStructurePKs.get(GetterUtil.getLong(oldPrimaryKey)); if (Validator.isNotNull(newPrimaryKey)) { newValue = StringUtil.replace(newValue, oldPrimaryKey, String.valueOf(newPrimaryKey)); } } newValues[i] = newValue; } preferences.setValues(key, newValues); }
public void processAction(PortletConfig config, ActionRequest req, ActionResponse res) throws Exception { try { String cmd = ParamUtil.getString(req, Constants.CMD); if (!cmd.equals(Constants.UPDATE)) { return; } String content = ParamUtil.getString(req, "content"); if (Validator.isNull(content)) { throw new AnnouncementsContentException(); } String portletResource = ParamUtil.getString(req, "portletResource"); String languageId = LanguageUtil.getLanguageId(req); PortletPreferences prefs = PortletPreferencesFactoryUtil.getPortletSetup(req, portletResource, false, false); LocalizationUtil.setPrefsValue(prefs, "content", languageId, content); prefs.store(); SessionMessages.add(req, config.getPortletName() + ".doConfigure"); } catch (AnnouncementsContentException ace) { SessionErrors.add(req, ace.getClass().getName()); } }
@Action public Response updateGrade(String grade, String location) throws java.io.IOException, javax.portlet.PortletException { preferences.setValue("grade", grade); preferences.store(); return Weather_.index(location); }
void setProperty(final String key, final Object value) { try { if (!preferences.isReadOnly(key)) preferences.setValue(key, value.toString()); } catch (final ReadOnlyException e) { if (logger.isErrorEnabled()) logger.error(e); } }
public static ExpandoTable checkTable( long companyId, String tableName, PortletPreferences preferences) throws Exception { ExpandoTable expandoTable = null; try { expandoTable = ExpandoTableLocalServiceUtil.getTable(companyId, WebFormUtil.class.getName(), tableName); } catch (NoSuchTableException nste) { expandoTable = addTable(companyId, tableName); int i = 1; String fieldLabel = preferences.getValue("fieldLabel" + i, StringPool.BLANK); String fieldType = preferences.getValue("fieldType" + i, StringPool.BLANK); while ((i == 1) || (Validator.isNotNull(fieldLabel))) { if (!fieldType.equalsIgnoreCase("paragraph")) { ExpandoColumnLocalServiceUtil.addColumn( expandoTable.getTableId(), fieldLabel, ExpandoColumnConstants.STRING); } i++; fieldLabel = preferences.getValue("fieldLabel" + i, StringPool.BLANK); } ExpandoColumnLocalServiceUtil.addColumn( expandoTable.getTableId(), "userId", ExpandoColumnConstants.STRING); } return expandoTable; }
protected String getOldScopeName(ActionRequest actionRequest, Portlet portlet) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Layout layout = themeDisplay.getLayout(); PortletPreferences portletPreferences = actionRequest.getPreferences(); String scopeType = GetterUtil.getString(portletPreferences.getValue("lfrScopeType", null)); if (Validator.isNull(scopeType)) { return null; } String scopeName = null; if (scopeType.equals("company")) { scopeName = themeDisplay.translate("global"); } else if (scopeType.equals("layout")) { String scopeLayoutUuid = GetterUtil.getString(portletPreferences.getValue("lfrScopeLayoutUuid", null)); Layout scopeLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId( scopeLayoutUuid, layout.getGroupId(), layout.isPrivateLayout()); if (scopeLayout != null) { scopeName = scopeLayout.getName(themeDisplay.getLocale()); } } else { throw new IllegalArgumentException("Scope type " + scopeType + " is invalid"); } return scopeName; }
protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { _log.debug("VIEW"); // Portlet preferences PortletPreferences prefs = request.getPreferences(); String users = prefs.getValue("users", "root"); // Business Invocation BlogAPI blogService = blogService(); ArrayList<Blog> blogs = blogService.getBlogs(); // Checking Admin rights if (request.getUserPrincipal() != null && request.getUserPrincipal().getName() != null) { for (String user : users.split(",")) if (user.equals(request.getUserPrincipal().getName())) { request.setAttribute("admin", request.getUserPrincipal().getName()); break; } } else { request.setAttribute("admin", null); } request.setAttribute("blogs", blogs); // Controlling the view String view = "/jsp/management.jsp"; PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher(view); prd.include(request, response); }
protected void deleteLDAPServer(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long ldapServerId = ParamUtil.getLong(actionRequest, "ldapServerId"); // Remove preferences String postfix = LDAPSettingsUtil.getPropertyPostfix(ldapServerId); String[] keys = new String[_KEYS.length]; for (int i = 0; i < _KEYS.length; i++) { keys[i] = _KEYS[i] + postfix; } CompanyServiceUtil.removePreferences(themeDisplay.getCompanyId(), keys); // Update preferences PortletPreferences preferences = PrefsPropsUtil.getPreferences(themeDisplay.getCompanyId()); UnicodeProperties properties = new UnicodeProperties(); String ldapServerIds = preferences.getValue("ldap.server.ids", StringPool.BLANK); ldapServerIds = StringUtil.remove(ldapServerIds, String.valueOf(ldapServerId)); properties.put("ldap.server.ids", ldapServerIds); CompanyServiceUtil.updatePreferences(themeDisplay.getCompanyId(), properties); }
protected void updateCaptcha(ActionRequest actionRequest, PortletPreferences preferences) throws Exception { boolean reCaptchaEnabled = ParamUtil.getBoolean(actionRequest, "reCaptchaEnabled"); String reCaptchaPrivateKey = ParamUtil.getString(actionRequest, "reCaptchaPrivateKey"); String reCaptchaPublicKey = ParamUtil.getString(actionRequest, "reCaptchaPublicKey"); Captcha captcha = null; if (reCaptchaEnabled) { captcha = new ReCaptchaImpl(); } else { captcha = new SimpleCaptchaImpl(); } validateCaptcha(actionRequest); if (SessionErrors.isEmpty(actionRequest)) { preferences.setValue(PropsKeys.CAPTCHA_ENGINE_IMPL, captcha.getClass().getName()); preferences.setValue(PropsKeys.CAPTCHA_ENGINE_RECAPTCHA_KEY_PRIVATE, reCaptchaPrivateKey); preferences.setValue(PropsKeys.CAPTCHA_ENGINE_RECAPTCHA_KEY_PUBLIC, reCaptchaPublicKey); preferences.store(); CaptchaImpl captchaImpl = (CaptchaImpl) CaptchaUtil.getCaptcha(); captchaImpl.setCaptcha(captcha); } }
public void processAction(PortletConfig config, ActionRequest req, ActionResponse res) throws Exception { String cmd = ParamUtil.getString(req, Constants.CMD); String portletResource = ParamUtil.getString(req, "portletResource"); PortletPreferences prefs = PortletPreferencesFactoryUtil.getPortletSetup(req, portletResource, true, true); if (cmd.equals("remove-footer-article")) { removeFooterArticle(req, prefs); } else if (cmd.equals("remove-header-article")) { removeHeaderArticle(req, prefs); } else if (cmd.equals("set-footer-article")) { setFooterArticle(req, prefs); } else if (cmd.equals("set-header-article")) { setHeaderArticle(req, prefs); } else if (cmd.equals(Constants.UPDATE)) { updateConfiguration(req, prefs); } if (SessionErrors.isEmpty(req)) { try { prefs.store(); } catch (ValidatorException ve) { SessionErrors.add(req, ValidatorException.class.getName(), ve); return; } SessionMessages.add(req, config.getPortletName() + ".doConfigure"); } }
protected void updatePreferences(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException { String cmd = ParamUtil.getString(actionRequest, Constants.CMD); if (!cmd.equals(Constants.UPDATE)) { return; } PortletPreferences preferences = actionRequest.getPreferences(); String[] symbols = StringUtil.split( ParamUtil.getString(actionRequest, "symbols").toUpperCase(), StringPool.SPACE); Arrays.sort(symbols); preferences.setValues("symbols", symbols); try { preferences.store(); } catch (ValidatorException ve) { SessionErrors.add(actionRequest, ValidatorException.class.getName(), ve); return; } PortletConfig portletConfig = getPortletConfig(); SessionMessages.add( actionRequest, portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_UPDATED_PREFERENCES); }
@Override public String getURLViewInContext( LiferayPortletRequest liferayPortletRequest, LiferayPortletResponse liferayPortletResponse, String noSuchEntryRedirect) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) liferayPortletRequest.getAttribute(WebKeys.THEME_DISPLAY); Layout layout = themeDisplay.getLayout(); if (Validator.isNotNull(_article.getLayoutUuid())) { layout = LayoutLocalServiceUtil.getLayoutByUuidAndCompanyId( _article.getLayoutUuid(), _article.getCompanyId()); } String portletId = (String) liferayPortletRequest.getAttribute(WebKeys.PORTLET_ID); PortletPreferences portletSetup = PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, portletId); String linkToLayoutUuid = GetterUtil.getString(portletSetup.getValue("portletSetupLinkToLayoutUuid", null)); if (Validator.isNotNull(_article.getLayoutUuid()) && Validator.isNull(linkToLayoutUuid)) { Group group = themeDisplay.getScopeGroup(); if (group.getGroupId() != _article.getGroupId()) { group = GroupLocalServiceUtil.getGroup(_article.getGroupId()); } String groupFriendlyURL = PortalUtil.getGroupFriendlyURL(group, layout.isPrivateLayout(), themeDisplay); return PortalUtil.addPreservedParameters( themeDisplay, groupFriendlyURL .concat(JournalArticleConstants.CANONICAL_URL_SEPARATOR) .concat(_article.getUrlTitle())); } List<Long> hitLayoutIds = JournalContentSearchLocalServiceUtil.getLayoutIds( _article.getGroupId(), layout.isPrivateLayout(), _article.getArticleId()); if (!hitLayoutIds.isEmpty()) { Long hitLayoutId = hitLayoutIds.get(0); Layout hitLayout = LayoutLocalServiceUtil.getLayout( _article.getGroupId(), layout.isPrivateLayout(), hitLayoutId.longValue()); return PortalUtil.getLayoutURL(hitLayout, themeDisplay); } return noSuchEntryRedirect; }
private void exportRolesAndPermissions( PortletDataContext context, String portletId, PortletPreferences preferences, long communityId) throws ReadOnlyException, PortalException, SystemException { PortletConfig portletConfig = configurationService.getPortletConfig(portletId, communityId).getPortletConfig(); if (portletConfig.getRoles() != null) { List<RoleConfig> roleList = collectPortletRoles(portletConfig.getRoles().getRole()); String[] roleNames = new String[roleList.size()]; int idx = 0; for (RoleConfig role : roleList) { long primkey = configurationService.readRoleResourceIdPrimKey(portletId, communityId, role.getName()); roleNames[idx++] = role.getName(); preferences.setValue(ROLE_PREF_PREFIX + String.valueOf(primkey), role.getName()); context.addPermissions(PortletRole.RESOURCE_KEY, primkey); } preferences.setValues(ROLE_NAMES_PREF, roleNames); } }
/** * Resets/restores the values in the portletPreferences.xhtml Facelet composition with portlet * preference default values. */ public void reset() { FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); PortletRequest portletRequest = (PortletRequest) externalContext.getRequest(); PortletPreferences portletPreferences = portletRequest.getPreferences(); try { Enumeration<String> preferenceNames = portletPreferences.getNames(); while (preferenceNames.hasMoreElements()) { String preferenceName = preferenceNames.nextElement(); portletPreferences.reset(preferenceName); } portletPreferences.store(); // Switch the portlet mode back to VIEW. ActionResponse actionResponse = (ActionResponse) externalContext.getResponse(); actionResponse.setPortletMode(PortletMode.VIEW); actionResponse.setWindowState(WindowState.NORMAL); FacesContextHelperUtil.addGlobalSuccessInfoMessage(); } catch (Exception e) { FacesContextHelperUtil.addGlobalUnexpectedErrorMessage(); } }
private Map<String, Object> _getPortletPreferences(RenderRequest renderRequest) { Map<String, Object> contextObjects = new HashMap<>(); PortletPreferences portletPreferences = renderRequest.getPreferences(); Map<String, String[]> map = portletPreferences.getMap(); contextObjects.put(PortletDisplayTemplateConstants.PORTLET_PREFERENCES, map); for (Map.Entry<String, String[]> entry : map.entrySet()) { String[] values = entry.getValue(); if (ArrayUtil.isEmpty(values)) { continue; } String value = values[0]; if (value == null) { continue; } contextObjects.put(entry.getKey(), value); } return contextObjects; }