/** * 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; } }
/* * (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); }
/** * @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(); }