/** * Gets and initialize variable.<br> * * @throws Exception */ public UIGroovyPortlet() throws Exception { PortletRequestContext context = (PortletRequestContext) WebuiRequestContext.getCurrentInstance(); PortletRequest prequest = context.getRequest(); template_ = prequest.getPreferences().getValue("template", DEFAULT_TEMPLATE); windowId = prequest.getWindowID(); }
/** * Gets the viewable node by WCMComposer (depends on site mode) * * @param repository the repository's name * @param workspace the workspace's name * @param nodeIdentifier the node's path or node's UUID * @param version the base version (e.g. <code>WCMComposer.BASE_VERSION</code> ) * @param cacheVisibility the visibility of cache * @return the viewable node. Return <code>null</code> if <code>nodeIdentifier</code> is invalid * @see #getViewableNodeByComposer(String repository, String workspace, String nodeIdentifier) * getViewableNodeByComposer() * @see WCMComposer */ public static Node getViewableNodeByComposer( String repository, String workspace, String nodeIdentifier, String version, String cacheVisibility) { try { HashMap<String, String> filters = new HashMap<String, String>(); StringBuffer filterLang = new StringBuffer(Util.getPortalRequestContext().getLocale().getLanguage()); String country = Util.getPortalRequestContext().getLocale().getCountry(); if (country != null && country.length() > 0) { filterLang.append("_").append(country); } filters.put(WCMComposer.FILTER_LANGUAGE, filterLang.toString()); filters.put(WCMComposer.FILTER_MODE, Utils.getCurrentMode()); PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance(); PortletMode portletMode = portletRequestContext.getApplicationMode(); filters.put(WCMComposer.PORTLET_MODE, portletMode.toString()); if (version != null) filters.put(WCMComposer.FILTER_VERSION, version); filters.put(WCMComposer.FILTER_VISIBILITY, cacheVisibility); return WCMCoreUtils.getService(WCMComposer.class) .getContent( workspace, Text.escapeIllegalJcrChars(nodeIdentifier), filters, WCMCoreUtils.getUserSessionProvider()); } catch (Exception e) { return null; } }
@Override public ResultNode createData(Node node, Row row) { try { PortalRequestContext portalRequestContext = Util.getPortalRequestContext(); PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance(); PortletRequest portletRequest = portletRequestContext.getRequest(); StringBuffer baseURI = new StringBuffer(); baseURI .append(portletRequest.getScheme()) .append("://") .append(portletRequest.getServerName()); if (portletRequest.getServerPort() != 80) { baseURI.append(":").append(String.format("%s", portletRequest.getServerPort())); } baseURI.append(portalRequestContext.getPortalContextPath()); if (node.isNodeType("mop:pagelink")) { node = node.getParent(); } if (node.isNodeType("gtn:language")) { node = node.getParent().getParent(); } String userNaviUri = baseURI.toString() + "/" + PageDataCreator.getUserNavigationURI(node).toString(); if (userNavigationUriList.contains(userNaviUri)) { return null; } userNavigationUriList.add(userNaviUri); return new ResultNode(node, row, userNaviUri); } catch (Exception e) { return null; } }
public static void savePortletPreference( FAQSetting setting, String emailAddNewQuestion, String emailEditResponseQuestion) { try { PortletRequestContext pcontext = (PortletRequestContext) WebuiRequestContext.getCurrentInstance(); PortletPreferences portletPref = pcontext.getRequest().getPreferences(); portletPref.setValue("display", setting.getDisplayMode()); portletPref.setValue("orderBy", setting.getOrderBy()); portletPref.setValue("orderType", setting.getOrderType()); portletPref.setValue("isDiscussForum", String.valueOf(setting.getIsDiscussForum())); portletPref.setValue("idNameCategoryForum", setting.getIdNameCategoryForum()); portletPref.setValue("enableAutomaticRSS", setting.isEnableAutomaticRSS() + ""); portletPref.setValue("enableViewAvatar", setting.isEnableViewAvatar() + ""); portletPref.setValue("enanbleVotesAndComments", setting.isEnanbleVotesAndComments() + ""); portletPref.setValue( "enableAnonymousSubmitQuestion", setting.isEnableAnonymousSubmitQuestion() + ""); portletPref.setValue("SendMailAddNewQuestion", emailAddNewQuestion); portletPref.setValue("SendMailEditResponseQuestion", emailEditResponseQuestion); portletPref.setValue("emailMoveQuestion", setting.getEmailMoveQuestion()); portletPref.setValue( "isPostQuestionInRootCategory", setting.isPostQuestionInRootCategory() + ""); portletPref.store(); } catch (Exception e) { log.error("Fail to save portlet preferences: ", e); } }
public void processRender(WebuiApplication app, WebuiRequestContext context) throws Exception { getChildren().clear(); PortletRequestContext pContext = (PortletRequestContext) context; PortletMode currentMode = pContext.getApplicationMode(); if (getChild(UIDocumentDemo.class) == null) addChild(UIDocumentDemo.class, null, null); super.processRender(app, context); }
public static void saveFAQPortletPreference(List<String> list, boolean useAjax) throws Exception { PortletRequestContext pcontext = (PortletRequestContext) WebuiRequestContext.getCurrentInstance(); PortletPreferences portletPref = pcontext.getRequest().getPreferences(); String str = list.toString(); str = str.replace("[", "").replace("]", "").replaceAll(" ", ""); portletPref.setValue("displayCategories", str); portletPref.setValue("useAjax", String.valueOf(useAjax)); portletPref.store(); }
public static String getServerBaseUrl() { PortletRequestContext portletRequestContext = RequestContext.getCurrentInstance(); String url = portletRequestContext.getRequest().getScheme() + "://" + portletRequestContext.getRequest().getServerName() + ":" + String.format("%s", portletRequestContext.getRequest().getServerPort()) + "/"; return url; }
public static int getLimitUploadSize() { PortletRequestContext pcontext = (PortletRequestContext) RequestContext.getCurrentInstance(); PortletPreferences portletPref = pcontext.getRequest().getPreferences(); int limitMB; try { limitMB = Integer.parseInt(portletPref.getValue(UPLOAD_LIMIT, "").trim()); } catch (NumberFormatException e) { limitMB = DEFAULT_VALUE_UPLOAD_PORTAL; } return limitMB; }
public static List<String> getCategoriesIdFAQPortlet() throws Exception { PortletRequestContext pcontext = (PortletRequestContext) WebuiRequestContext.getCurrentInstance(); PortletPreferences portletPref = pcontext.getRequest().getPreferences(); String str = portletPref.getValue("displayCategories", ""); List<String> list = new ArrayList<String>(); if (!isFieldEmpty(str)) { list.addAll(Arrays.asList(str.split(","))); } return list; }
public static int getLimitUploadSize(boolean isAvatar) { PortletRequestContext pcontext = (PortletRequestContext) WebuiRequestContext.getCurrentInstance(); PortletPreferences portletPref = pcontext.getRequest().getPreferences(); int limitMB = DEFAULT_VALUE_UPLOAD_PORTAL; if (isAvatar) { limitMB = Integer.parseInt(portletPref.getValue(UPLOAD_AVATAR_SIZE, "").trim()); } else { limitMB = Integer.parseInt(portletPref.getValue(UPLOAD_FILE_SIZE, "").trim()); } return limitMB; }
public static String getEmailMoveQuestion(FAQSetting faqSetting) { PortletRequestContext pcontext = (PortletRequestContext) WebuiRequestContext.getCurrentInstance(); PortletPreferences portletPref = pcontext.getRequest().getPreferences(); String str = portletPref.getValue("emailMoveQuestion", ""); if (isFieldEmpty(str)) { WebuiRequestContext context = WebuiRequestContext.getCurrentInstance(); ResourceBundle res = context.getApplicationResourceBundle(); str = res.getString("SendEmail.MoveQuetstion.Default"); } faqSetting.setEmailMoveQuestion(str); return str; }
/** * Refresh whole portal by AJAX. * * @param context the portlet request context */ public static void updatePortal(PortletRequestContext context) { UIPortalApplication portalApplication = Util.getUIPortalApplication(); PortalRequestContext portalRequestContext = (PortalRequestContext) context.getParentAppRequestContext(); UIWorkingWorkspace uiWorkingWS = portalApplication.getChildById(UIPortalApplication.UI_WORKING_WS_ID); portalRequestContext.addUIComponentToUpdateByAjax(uiWorkingWS); portalRequestContext.ignoreAJAXUpdateOnPortlets(true); }
/** * Activate mode. * * @param newMode the mode * @throws Exception the exception */ public void activateMode(PortletMode newMode) throws Exception { if (getChild(UIPresentationContainer.class) != null) { removeChild(UIPresentationContainer.class); } if (getChild(UISCVPreferences.class) != null) { removeChild(UISCVPreferences.class); } if (PortletMode.VIEW.equals(newMode)) { PortletRequestContext pContext = (PortletRequestContext) WebuiRequestContext.getCurrentInstance(); uiPresentation = addChild( UIPresentationContainer.class, null, UIPresentationContainer.class.getSimpleName() + pContext.getWindowId()); } else if (PortletMode.EDIT.equals(newMode)) { popPreferences = addChild(UISCVPreferences.class, null, null); popPreferences.setInternalPreferencesMode(true); } }
public static void getPorletPreference(FAQSetting faqSetting) { PortletRequestContext pcontext = (PortletRequestContext) WebuiRequestContext.getCurrentInstance(); PortletPreferences portletPref = pcontext.getRequest().getPreferences(); faqSetting.setEnableViewAvatar( Boolean.parseBoolean(portletPref.getValue("enableViewAvatar", ""))); faqSetting.setEnableAutomaticRSS( Boolean.parseBoolean(portletPref.getValue("enableAutomaticRSS", ""))); faqSetting.setEnanbleVotesAndComments( Boolean.parseBoolean(portletPref.getValue("enanbleVotesAndComments", ""))); faqSetting.setEnableAnonymousSubmitQuestion( Boolean.parseBoolean(portletPref.getValue("enableAnonymousSubmitQuestion", ""))); faqSetting.setDisplayMode(portletPref.getValue("display", "")); faqSetting.setOrderBy(portletPref.getValue("orderBy", "")); faqSetting.setOrderType(portletPref.getValue("orderType", "")); faqSetting.setIsDiscussForum(Boolean.parseBoolean(portletPref.getValue("isDiscussForum", ""))); faqSetting.setIdNameCategoryForum(portletPref.getValue("idNameCategoryForum", "")); faqSetting.setEmailMoveQuestion(portletPref.getValue("emailMoveQuestion", "")); faqSetting.setPostQuestionInRootCategory( Boolean.parseBoolean(portletPref.getValue("isPostQuestionInRootCategory", "true"))); }
public static String getRealPortletId(PortletRequestContext portletRequestContext) { String portletId = portletRequestContext.getWindowId(); int modeState = Util.getUIPortalApplication().getModeState(); switch (modeState) { case UIPortalApplication.NORMAL_MODE: return portletId; case UIPortalApplication.APP_BLOCK_EDIT_MODE: return "UIPortlet-" + portletId; case UIPortalApplication.APP_VIEW_EDIT_MODE: return "EditMode-" + portletId; default: return null; } }
public static void getEmailSetting(FAQSetting faqSetting, boolean isNew, boolean isSettingForm) { PortletRequestContext pcontext = (PortletRequestContext) WebuiRequestContext.getCurrentInstance(); PortletPreferences portletPref = pcontext.getRequest().getPreferences(); String emailContent = ""; if (isNew) { emailContent = portletPref.getValue("SendMailAddNewQuestion", ""); } else { if (isSettingForm) emailContent = portletPref.getValue("SendMailEditResponseQuestion", ""); } WebuiRequestContext context = WebuiRequestContext.getCurrentInstance(); ResourceBundle res = context.getApplicationResourceBundle(); if (emailContent == null || emailContent.trim().length() < 1) { if (isNew) { emailContent = res.getString("SendEmail.AddNewQuestion.Default"); } else { if (isSettingForm) emailContent = res.getString("SendEmail.EditQuestion.Default"); else emailContent = res.getString("SendEmail.ResponseQuestion.Default"); } } faqSetting.setEmailSettingSubject(res.getString("SendEmail.Default.Subject")); faqSetting.setEmailSettingContent(emailContent); }
/* * (non-Javadoc) * @see * org.exoplatform.webui.core.UIPortletApplication#processRender(org.exoplatform * .webui.application.WebuiApplication, * org.exoplatform.webui.application.WebuiRequestContext) */ public void processRender(WebuiApplication app, WebuiRequestContext context) throws Exception { PortletRequestContext pContext = (PortletRequestContext) context; PortletMode newMode = pContext.getApplicationMode(); PortletPreferences preferences = pContext.getRequest().getPreferences(); Boolean sharedCache = "true".equals(preferences.getValue(ENABLE_CACHE, "true")); if (context.getRemoteUser() == null || (Utils.isLiveMode() && sharedCache && !Utils.isPortalEditMode() && Utils.isPortletViewMode(pContext))) { WCMService wcmService = getApplicationComponent(WCMService.class); pContext .getResponse() .setProperty(MimeResponse.EXPIRATION_CACHE, "" + wcmService.getPortletExpirationCache()); if (log.isTraceEnabled()) log.trace("SCV rendering : cache set to " + wcmService.getPortletExpirationCache()); } if (!newMode.equals(mode)) { activateMode(newMode); mode = newMode; } Node nodeView = null; if (uiPresentation != null) { nodeView = uiPresentation.getNodeView(); if (nodeView != null) { TemplateService templateService = getApplicationComponent(TemplateService.class); uiPresentation .getChild(UIPresentation.class) .setTemplatePath(templateService.getTemplatePath(nodeView, false)); } } if (uiPresentation != null && uiPresentation.isContextual() && nodeView != null) { RenderResponse response = context.getResponse(); Element title = response.createElement("title"); title.setTextContent(uiPresentation.getTitle(nodeView)); response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, title); } if (context.getRemoteUser() != null && WCMComposer.MODE_EDIT.equals(Utils.getCurrentMode())) { pContext.getJavascriptManager().loadScriptResource(ResourceScope.SHARED, "content-selector"); pContext.getJavascriptManager().loadScriptResource(ResourceScope.SHARED, "quick-edit"); } setId(UISingleContentViewerPortlet.class.getSimpleName() + pContext.getWindowId()); super.processRender(app, context); }
/** * Check if the portlet current mode is view mode or not * * @param pContext The request context of a portlet * @return return true if current portlet mode is view mode; otherwise return false */ public static boolean isPortletViewMode(PortletRequestContext pContext) { return PortletMode.VIEW.equals(pContext.getApplicationMode()); }
public void changeToViewMode() throws Exception { PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance(); portletRequestContext.setApplicationMode(PortletMode.VIEW); }
/** * Instantiates a new uI single content viewer portlet. * * @throws Exception the exception */ public UISingleContentViewerPortlet() throws Exception { addChild(UIPopupContainer.class, null, "UIPopupContainer-" + new Date().getTime()); PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance(); preferences = portletRequestContext.getRequest().getPreferences(); }
public static boolean getUseAjaxFAQPortlet() { PortletRequestContext pcontext = (PortletRequestContext) WebuiRequestContext.getCurrentInstance(); PortletPreferences portletPref = pcontext.getRequest().getPreferences(); return Boolean.parseBoolean(portletPref.getValue("useAjax", "false")); }
/** * Get one portlet preference by name * * @param preferenceName the name of preference * @return the portlet preference's value */ public static String getPortletPreference(String preferenceName) { PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance(); PortletPreferences preferences = portletRequestContext.getRequest().getPreferences(); return preferences.getValue(preferenceName, null); }
public void init() { PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance(); PortletPreferences preferences = portletRequestContext.getRequest().getPreferences(); text = preferences.getValue(UIBasicPortlet.TEXT_PREFERENCE, null); }
/** * Get all portlet preferences * * @return all portlet preferences */ public static PortletPreferences getAllPortletPreferences() { PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance(); return portletRequestContext.getRequest().getPreferences(); }
/** * @param orgNode Processed node * @param propertyName which property used for editing * @param inputType input type for editing: TEXT, TEXTAREA, WYSIWYG * @param cssClass class name for CSS, should implement: cssClass, [cssClass]Title Edit[cssClass] * as relative css Should create the function: * InlineEditor.presentationRequestChange[cssClass] to request the rest-service * @param isGenericProperty set as true to use generic javascript function, other wise, must * create the correctspond function InlineEditor.presentationRequestChange[cssClass] * @param arguments Extra parameter for Input component (toolbar, width, height,.. for * CKEditor/TextArea) * @return String that can be put on groovy template * @throws Exception * @author vinh_nguyen */ public static String getInlineEditingField( Node orgNode, String propertyName, String defaultValue, String inputType, String idGenerator, String cssClass, boolean isGenericProperty, String... arguments) throws Exception { HashMap<String, String> parsedArguments = parseArguments(arguments); String height = parsedArguments.get(HEIGHT); String bDirection = parsedArguments.get(BUTTON_DIR); String publishLink = parsedArguments.get(FAST_PUBLISH_LINK); Locale locale = WebuiRequestContext.getCurrentInstance().getLocale(); String language = locale.getLanguage(); ResourceBundleService resourceBundleService = WCMCoreUtils.getService(ResourceBundleService.class); ResourceBundle resourceBundle; resourceBundle = resourceBundleService.getResourceBundle(LOCALE_WEBUI_DMS, locale); PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance(); String draft = INLINE_DRAFT; String published = INLINE_PUBLISHED; try { draft = portletRequestContext.getApplicationResourceBundle().getString("PublicationStates.draft"); published = portletRequestContext .getApplicationResourceBundle() .getString("PublicationStates.published"); } catch (MissingResourceException ex) { if (LOG.isWarnEnabled()) { LOG.warn(ex.getMessage()); } } String portletRealID = org.exoplatform.wcm.webui.Utils.getRealPortletId( (PortletRequestContext) WebuiRequestContext.getCurrentInstance()); StringBuffer sb = new StringBuffer(); StringBuffer actionsb = new StringBuffer(); String repo = ((ManageableRepository) orgNode.getSession().getRepository()).getConfiguration().getName(); String workspace = orgNode.getSession().getWorkspace().getName(); String uuid = orgNode.getUUID(); String strSuggestion = ""; String acceptButton = ""; String cancelButton = ""; portletRealID = portletRealID.replace('-', '_'); String showBlockId = "Current" + idGenerator + "_" + portletRealID; String editBlockEditorID = "Edit" + idGenerator + "_" + portletRealID; String editFormID = "Edit" + idGenerator + "Form_" + portletRealID; String newValueInputId = "new" + idGenerator + "_" + portletRealID; String currentValueID = "old" + idGenerator + "_" + portletRealID; String siteName = org.exoplatform.portal.webui.util.Util.getPortalRequestContext().getPortalOwner(); String currentValue = StringUtils.replace(defaultValue, "{portalName}", siteName); try { strSuggestion = resourceBundle.getString("UIPresentation.label.EditingSuggestion"); acceptButton = resourceBundle.getString("UIPresentation.title.AcceptButton"); cancelButton = resourceBundle.getString("UIPresentation.title.CancelButton"); } catch (MissingResourceException e) { if (LOG.isWarnEnabled()) { LOG.warn(e.getMessage()); } } actionsb.append(" return InlineEditor.presentationRequestChange"); if (isGenericProperty) { actionsb .append("Property") .append("('") .append("/property?', '") .append(propertyName) .append("', '"); } else { actionsb.append(cssClass).append("('"); } actionsb .append(currentValueID) .append("', '") .append(newValueInputId) .append("', '") .append(repo) .append("', '") .append(workspace) .append("', '") .append(uuid) .append("', '") .append(editBlockEditorID) .append("', '") .append(showBlockId) .append("', '") .append(siteName) .append("', '") .append(language); if (inputType.equals(INPUT_WYSIWYG)) { actionsb.append("', 1);"); } else { actionsb.append("');"); } String strAction = actionsb.toString(); if (orgNode.hasProperty(propertyName)) { try { if (propertyName.equals(EXO_TITLE)) return ContentReader.getXSSCompatibilityContent( orgNode.getProperty(propertyName).getString()); if (org.exoplatform.wcm.webui.Utils.getCurrentMode().equals(WCMComposer.MODE_LIVE)) return StringUtils.replace( orgNode.getProperty(propertyName).getString(), "{portalName}", siteName); else return "<div class=\"WCMInlineEditable\" contenteditable=\"true\" propertyName=\"" + propertyName + "\" repo=\"" + repo + "\" workspace=\"" + workspace + "\"" + " uuid=\"" + uuid + "\" siteName=\"" + siteName + "\" publishedMsg=\"" + published + "\" draftMsg=\"" + draft + "\" fastpublishlink=\"" + publishLink + "\" language=\"" + language + "\" >" + orgNode.getProperty(propertyName).getString() + "</div>"; } catch (Exception e) { if (org.exoplatform.wcm.webui.Utils.getCurrentMode().equals(WCMComposer.MODE_LIVE)) return currentValue; else return "<div class=\"WCMInlineEditable\" contenteditable=\"true\" propertyName=\"" + propertyName + "\" repo=\"" + repo + "\" workspace=\"" + workspace + "\" " + "uuid=\"" + uuid + "\" siteName=\"" + siteName + "\" publishedMsg=\"" + published + "\" draftMsg=\"" + draft + "\" fastpublishlink=\"" + publishLink + "\" language=\"" + language + "\" >" + defaultValue + "</div>"; } } sb.append("<div class=\"InlineEditing\" >\n"); sb.append("\n<div rel=\"tooltip\" data-placement=\"bottom\" id=\"") .append(showBlockId) .append("\" Class=\"") .append(cssClass) .append("\""); sb.append("title=\"").append(strSuggestion).append("\""); sb.append(" onClick=\"InlineEditor.presentationSwitchBlock('") .append(showBlockId) .append("', '") .append(editBlockEditorID) .append("');\""); sb.append("onmouseout=\"this.className='") .append(cssClass) .append("';\" onblur=\"this.className='") .append(cssClass) .append("';\" onfocus=\"this.className='") .append(cssClass) .append("Hover") .append("';\" onmouseover=\"this.className='") .append(cssClass) .append("Hover';\">") .append(currentValue) .append("</div>\n"); sb.append("\t<div id=\"") .append(editBlockEditorID) .append("\" class=\"Edit") .append(cssClass) .append("\">\n"); sb.append("\t\t<form name=\"") .append(editFormID) .append("\" id=\"") .append(editFormID) .append("\" onSubmit=\"") .append(strAction) .append("\">\n"); sb.append("<DIV style=\"display:none; visible:hidden\" id=\"") .append(currentValueID) .append("\" name=\"") .append(currentValueID) .append("\">") .append(currentValue) .append("</DIV>"); if (bDirection != null && bDirection.equals(LEFT2RIGHT)) { sb.append("\t\t<a href=\"#\" rel=\"tooltip\" data-placement=\"bottom\"") .append(" class =\"AcceptButton\" style=\"float:left\" onclick=\"") .append(strAction) .append("\" title=\"" + acceptButton + "\"> </a>\n"); sb.append( "\t\t<a href=\"#\" rel=\"tooltip\" data-placement=\"bottom\" class =\"CancelButton\" style=\"float:left\" ") .append("onClick=\"InlineEditor.presentationSwitchBlock('"); sb.append(editBlockEditorID) .append("', '") .append(showBlockId) .append("');\" title=\"" + cancelButton + "\"> </a>\n"); } else { sb.append( "\t\t<a href=\"#\" rel=\"tooltip\" data-placement=\"bottom\" class =\"CancelButton\" ") .append("onClick=\"InlineEditor.presentationSwitchBlock('"); sb.append(editBlockEditorID) .append("', '") .append(showBlockId) .append("');\" title=\"" + cancelButton + "\"> </a>\n"); sb.append( "\t\t<a href=\"#\" rel=\"tooltip\" data-placement=\"bottom\" class =\"AcceptButton\" onclick=\"") .append(strAction) .append("\" title=\"" + acceptButton + "\"> </a>\n"); } sb.append("\t\t<div class=\"Edit").append(cssClass).append("Input\">\n "); sb.append("\n\t\t</div>\n\t</form>\n</div>\n\n</div>"); return sb.toString(); }