Esempio n. 1
0
  /**
   * Get download link of a node which stored binary data
   *
   * @param node Node
   * @return download link
   * @throws Exception
   */
  public static String getDownloadLink(Node node) throws Exception {

    if (!Utils.getRealNode(node).getPrimaryNodeType().getName().equals(NT_FILE)) return null;

    // Get binary data from node
    DownloadService dservice = WCMCoreUtils.getService(DownloadService.class);
    Node jcrContentNode = node.getNode(JCR_CONTENT);
    InputStream input = jcrContentNode.getProperty(JCR_DATA).getStream();

    // Get mimeType of binary data
    String mimeType = jcrContentNode.getProperty(JCR_MIMETYPE).getString();

    // Make download stream
    InputStreamDownloadResource dresource = new InputStreamDownloadResource(input, mimeType);

    // Make extension part for file if it have not yet
    DMSMimeTypeResolver mimeTypeSolver = DMSMimeTypeResolver.getInstance();
    String ext = "." + mimeTypeSolver.getExtension(mimeType);
    String fileName = Utils.getRealNode(node).getName();
    if (fileName.lastIndexOf(ext) < 0 && !mimeTypeSolver.getMimeType(fileName).equals(mimeType)) {
      dresource.setDownloadName(fileName + ext);
    } else {
      dresource.setDownloadName(fileName);
    }

    return dservice.getDownloadLink(dservice.addDownloadResource(dresource));
  }
    public void execute(Event<UIAdminToolbarContainer> event) throws Exception {
      UIAdminToolbarContainer uicomp = event.getSource();
      UserNavigation edittedNavigation = Utils.getSelectedNavigation();

      WebuiRequestContext context = event.getRequestContext();
      UIApplication uiApplication = context.getUIApplication();

      if (edittedNavigation == null) {
        uiApplication.addMessage(
            new ApplicationMessage("UISiteManagement.msg.Invalid-editPermission", null));
        return;
      }

      UserACL userACL = uicomp.getApplicationComponent(UserACL.class);
      if (edittedNavigation.getKey().getType().equals(SiteType.PORTAL)) {
        String portalName = Util.getPortalRequestContext().getPortalOwner();
        UserPortalConfigService configService =
            uicomp.getApplicationComponent(UserPortalConfigService.class);
        UserPortalConfig userPortalConfig =
            configService.getUserPortalConfig(
                portalName, context.getRemoteUser(), PortalRequestContext.USER_PORTAL_CONTEXT);
        if (userPortalConfig == null) {
          uiApplication.addMessage(
              new ApplicationMessage(
                  "UISiteManagement.msg.portal-not-exist", new String[] {portalName}));
          return;
        }
        if (!userACL.hasEditPermission(userPortalConfig.getPortalConfig())) {
          uiApplication.addMessage(
              new ApplicationMessage("UISiteManagement.msg.Invalid-editPermission", null));
          return;
        }
      } else if (edittedNavigation.getKey().getType().equals(PortalConfig.GROUP_TYPE)) {
        if (!userACL.hasEditPermissionOnNavigation(
            SiteKey.group(edittedNavigation.getKey().getTypeName()))) {
          uiApplication.addMessage(
              new ApplicationMessage("UISiteManagement.msg.Invalid-editPermission", null));
          return;
        }
      }

      if (uicomp.naviManager == null) {
        uicomp.naviManager = uicomp.createUIComponent(UINavigationManagement.class, null, null);
      }
      Utils.createPopupWindow(
          uicomp, uicomp.naviManager, EDIT_NAVIGATION_POPUP_CONTAINER_ID, 400, -1, -1);

      uicomp.naviManager.setSiteKey(edittedNavigation.getKey());
      UserPortal userPortal = getUserPortal();
      UINavigationNodeSelector selector =
          uicomp.naviManager.getChild(UINavigationNodeSelector.class);
      selector.setEdittedNavigation(edittedNavigation);
      selector.setUserPortal(userPortal);
      selector.initTreeData();

      context.addUIComponentToUpdateByAjax(uicomp);
    }
 /*
  * (non-Javadoc)
  * @see
  * org.exoplatform.webui.event.EventListener#execute(org.exoplatform
  * .webui.event.Event)
  */
 public void execute(Event<UIAdminToolbarContainer> event) throws Exception {
   PortalRequestContext context = Util.getPortalRequestContext();
   Boolean quickEdit =
       (Boolean) context.getRequest().getSession().getAttribute(Utils.TURN_ON_QUICK_EDIT);
   if (quickEdit == null || !quickEdit) {
     context.getRequest().getSession().setAttribute(Utils.TURN_ON_QUICK_EDIT, true);
     Utils.updatePortal((PortletRequestContext) event.getRequestContext());
   } else {
     context.getRequest().getSession().setAttribute(Utils.TURN_ON_QUICK_EDIT, false);
     Utils.updatePortal((PortletRequestContext) event.getRequestContext());
   }
 }
  /*
   * (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);
  }
Esempio n. 5
0
 /**
  * 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.UIComponent#getTemplateResourceResolver(org.
  * exoplatform.webui.application.WebuiRequestContext, java.lang.String)
  */
 public ResourceResolver getTemplateResourceResolver(
     WebuiRequestContext context, String template) {
   try {
     DMSConfiguration dmsConfiguration = getApplicationComponent(DMSConfiguration.class);
     String workspace = dmsConfiguration.getConfig().getSystemWorkspace();
     resourceResolver = new JCRResourceResolver(workspace);
   } catch (Exception e) {
     // Control unexpected exception in UI
     Utils.createPopupMessage(
         this, "UIMessageBoard.msg.get-template-resource", null, ApplicationMessage.ERROR);
   }
   return resourceResolver;
 }
    @Override
    public void execute(Event<PushNavigationActionComponent> event) throws Exception {

      PushNavigationActionComponent actionComponent = event.getSource();
      PushNavigationForm pushNavigationForm =
          actionComponent.createUIComponent(PushNavigationForm.class, null, null);

      pushNavigationForm.setSynchronizationService(SYNCHRONIZATION_SERVICE);
      pushNavigationForm.init();

      org.exoplatform.wcm.webui.Utils.createPopupWindow(
          actionComponent, pushNavigationForm, PushNavigationForm.POPUP_WINDOW, true, 640);
    }
    public void execute(Event<UIPageNodeForm> event) throws Exception {
      UIPageNodeForm uiPageNodeForm = event.getSource();
      UIAdminToolbarContainer uicomp =
          uiPageNodeForm.getAncestorOfType(UIAdminToolbarContainer.class);

      UINavigationNodeSelector selector =
          uicomp.naviManager.getChild(UINavigationNodeSelector.class);
      TreeNode selectedParent = (TreeNode) uiPageNodeForm.getSelectedParent();
      selector.selectNode(selectedParent);

      WebuiRequestContext context = event.getRequestContext();
      Utils.createPopupWindow(
          uicomp, uicomp.naviManager, EDIT_NAVIGATION_POPUP_CONTAINER_ID, 400, -1, -1);
      context.addUIComponentToUpdateByAjax(uicomp);

      TreeNode pageNode = uiPageNodeForm.getPageNode();
      if (pageNode != null) {
        selector.getUserNodeLabels().put(pageNode.getId(), pageNode.getI18nizedLabels());
      }
      selector.createEvent("NodeModified", Phase.PROCESS, context).broadcast();
    }
Esempio n. 9
0
 /**
  * @param : node: nt:file node with have the data stream
  * @return : Link to download the jcr:data of the given node
  * @throws Exception
  */
 public static String getDownloadRestServiceLink(Node node) throws Exception {
   ExoContainer container = ExoContainerContext.getCurrentContainer();
   PortalContainerInfo containerInfo =
       (PortalContainerInfo) container.getComponentInstanceOfType(PortalContainerInfo.class);
   String portalName = containerInfo.getContainerName();
   PortalContainerConfig portalContainerConfig =
       (PortalContainerConfig) container.getComponentInstance(PortalContainerConfig.class);
   String restContextName = portalContainerConfig.getRestContextName(portalName);
   StringBuilder sb = new StringBuilder();
   Node currentNode = org.exoplatform.wcm.webui.Utils.getRealNode(node);
   String ndPath = currentNode.getPath();
   if (ndPath.startsWith("/")) {
     ndPath = ndPath.substring(1);
   }
   String encodedPath = URLEncoder.encode(ndPath, "utf-8");
   encodedPath =
       encodedPath.replaceAll("%2F", "/"); // we won't encode the slash characters in the path
   sb.append("/").append(restContextName).append("/contents/download/");
   sb.append(currentNode.getSession().getWorkspace().getName()).append("/").append(encodedPath);
   if (node.isNodeType("nt:frozenNode")) {
     sb.append("?version=" + node.getParent().getName());
   }
   return sb.toString();
 }
 public boolean hasEditPermissionOnPage() throws Exception {
   return Utils.hasEditPermissionOnPage();
 }
 public boolean hasEditPermissionOnNavigation() throws Exception {
   return Utils.hasEditPermissionOnNavigation();
 }
 public boolean isUserNavigation() throws Exception {
   return SiteType.USER.equals(Utils.getSelectedNavigation().getKey().getType());
 }
 public boolean isPortaNavigation() throws Exception {
   return SiteType.PORTAL.equals(Utils.getSelectedNavigation().getKey().getType());
 }
 public boolean isGroupNavigation() throws Exception {
   return SiteType.GROUP.equals(Utils.getSelectedNavigation().getKey().getType());
 }
Esempio n. 15
0
  /**
   * @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 + "\">&nbsp;</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 + "\">&nbsp;</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 + "\">&nbsp;</a>\n");
      sb.append(
              "\t\t<a href=\"#\" rel=\"tooltip\" data-placement=\"bottom\" class =\"AcceptButton\" onclick=\"")
          .append(strAction)
          .append("\" title=\"" + acceptButton + "\">&nbsp;</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();
  }