Example #1
0
    @Override
    public void execute(Event<UISpaceSearch> event) throws Exception {
      WebuiRequestContext ctx = event.getRequestContext();
      UISpaceSearch uiSpaceSearch = event.getSource();
      String charSearch = ctx.getRequestParameter(OBJECTID);
      ResourceBundle resApp = ctx.getApplicationResourceBundle();
      String defaultSpaceNameAndDesc =
          resApp.getString(uiSpaceSearch.getId() + ".label.DefaultSpaceNameAndDesc");
      String searchCondition =
          (((UIFormStringInput) uiSpaceSearch.getChildById(SPACE_SEARCH)).getValue());
      if ((searchCondition == null || searchCondition.equals(defaultSpaceNameAndDesc))
          && charSearch == null) {
        uiSpaceSearch.setSelectedChar(null);
        uiSpaceSearch.setSpaceNameSearch(null);
        ctx.addUIComponentToUpdateByAjax(uiSpaceSearch);
      } else {
        if (searchCondition != null) {
          searchCondition = searchCondition.trim();
        }
        if (charSearch != null) {
          ((UIFormStringInput) uiSpaceSearch.getChildById(SPACE_SEARCH))
              .setValue(defaultSpaceNameAndDesc);
        }
        uiSpaceSearch.setSelectedChar(charSearch);
        uiSpaceSearch.setSpaceNameSearch(searchCondition);
        uiSpaceSearch.setNewSearch(true);

        Event<UIComponent> searchEvent =
            uiSpaceSearch.<UIComponent>getParent().createEvent(SEARCH, Event.Phase.DECODE, ctx);
        if (searchEvent != null) {
          searchEvent.broadcast();
        }
      }
    }
Example #2
0
  public String event(String name, String componentId, String beanId) throws Exception {
    StringBuilder b = new StringBuilder();
    // TODO: Tung.Pham modified
    // ------------------------
    b.append("javascript:");
    WebuiRequestContext rcontext = WebuiRequestContext.getCurrentInstance();
    UIComponent subComponent = findComponentById(componentId);
    org.exoplatform.webui.config.Event event =
        subComponent.getComponentConfig().getUIComponentEventConfig(name);
    if (event == null) {
      return "??config??";
    }
    String confirm = event.getConfirm();
    if (confirm != null && confirm.trim().length() > 0) {
      try {
        confirm = rcontext.getApplicationResourceBundle().getString(confirm);
      } catch (MissingResourceException exp) {
        confirm = confirm.substring(confirm.lastIndexOf('.') + 1);
      }
      b.append("if(confirm('").append(confirm.replaceAll("'", "\\\\'")).append("'))");
    }
    b.append("eXo.webui.UIForm.submitEvent('").append(getFormId()).append("','");
    // b.append("javascript:eXo.webui.UIForm.submitEvent('").append(getId()).append("','");
    // -------------------------

    b.append(name).append("','");
    b.append("&amp;").append(SUBCOMPONENT_ID).append("=").append(componentId);
    if (beanId != null) {
      b.append("&amp;").append(OBJECTID).append("=").append(beanId);
    }
    b.append("')");
    return b.toString();
  }
Example #3
0
  public String getEditModeContent() {
    StringBuilder portletContent = new StringBuilder();
    try {
      PortalRequestContext prcontext =
          (PortalRequestContext) WebuiRequestContext.getCurrentInstance();
      prcontext.ignoreAJAXUpdateOnPortlets(true);
      StatefulPortletContext portletContext = uiPortlet_.getPortletContext();

      ExoPortletInvocationContext portletInvocationContext =
          new ExoPortletInvocationContext(prcontext, uiPortlet_);

      List<Cookie> requestCookies =
          new ArrayList<Cookie>(Arrays.asList(prcontext.getRequest().getCookies()));

      PortletInvocation portletInvocation = uiPortlet_.create(RenderInvocation.class, prcontext);
      RenderInvocation renderInvocation = (RenderInvocation) portletInvocation;
      // make sure we are in the EDIT mode, and not whatever the current portlet mode is for the
      // Portlet
      renderInvocation.setMode(Mode.create(PortletMode.EDIT.toString()));

      PortletInvocationResponse portletResponse = uiPortlet_.invoke(renderInvocation);
      portletContent.append(uiPortlet_.generateRenderMarkup(portletResponse, prcontext).toString());
    } catch (Throwable ex) {
      WebuiRequestContext webuiRequest = WebuiRequestContext.getCurrentInstance();
      portletContent.append(
          webuiRequest.getApplicationResourceBundle().getString("UIPortlet.message.RuntimeError"));
      log.error(
          "The portlet "
              + uiPortlet_.getName()
              + " could not be loaded. Check if properly deployed.",
          ExceptionUtil.getRootCause(ex));
    }
    return portletContent.toString();
  }
  public void processRender(WebuiRequestContext context) throws Exception {
    ResourceBundle res = context.getApplicationResourceBundle();
    UIForm uiForm = getAncestorOfType(UIForm.class);
    String formId = null;
    if (uiForm.getId().equals("UISearchForm")) formId = uiForm.<UIComponent>getParent().getId();
    else formId = uiForm.getId();

    Writer w = context.getWriter();
    w.write("<select class=\"selectbox\" id=\"");
    w.write(getId());
    w.write("\" name=\"");
    w.write(name);
    w.write("\"");
    renderHTMLAttributes(w);
    if (onchange_ != null) {
      w.append(" onchange=\"").append(renderOnChangeEvent(uiForm)).append("\"");
    }

    if (isMultiple_) w.write(" multiple=\"true\"");
    if (size_ > 1) w.write(" size=\"" + size_ + "\"");

    if (isDisabled()) w.write(" disabled ");

    w.write(">\n");

    for (SelectItem item : options_) {
      String label = item.getLabel();
      if (item instanceof SelectOption) {
        try {
          label = res.getString(formId + ".label.option." + ((SelectOption) item).getValue());
        } catch (MissingResourceException ex) {
          label = formId + ".label.option." + ((SelectOption) item).getValue();
        }
        w.write(renderOption(((SelectOption) item), label));

      } else if (item instanceof SelectOptionGroup) {
        label = item.getLabel();
        try {
          label = res.getString(getFrom().getId() + ".optionGroup.label." + label);
        } catch (MissingResourceException ex) {
          log.info("Could not find: " + getFrom().getId() + ".optionGroup.label." + label);
        }
        w.write("<optgroup label=\"");
        w.write(label);
        w.write("\">\n");
        for (SelectOption opt : ((SelectOptionGroup) item).getOptions()) {
          label = opt.getLabel();
          try {
            label = res.getString(formId + ".label.option." + opt.getValue());
          } catch (MissingResourceException ex) {
            label = formId + ".label.option." + opt.getValue();
          }
          w.write(renderOption(opt, label));
        }
        w.write("</optgroup>\n");
      }
    }
    w.write("</select>\n");
    if (this.isMandatory()) w.write(" *");
  }
Example #5
0
 public static String getLabel(String componentid, String id) throws Exception {
   WebuiRequestContext context = RequestContext.getCurrentInstance();
   ResourceBundle res = context.getApplicationResourceBundle();
   String label = componentid + ".label." + id;
   try {
     return res.getString(label);
   } catch (MissingResourceException e) {
     return id;
   }
 }
Example #6
0
 public static String getResourceBundle(String key, String defaultValue) {
   WebuiRequestContext context = RequestContext.getCurrentInstance();
   ResourceBundle res = context.getApplicationResourceBundle();
   try {
     return res.getString(key);
   } catch (MissingResourceException e) {
     log.warn("Can not find the resource for key: " + key);
     return defaultValue;
   }
 }
Example #7
0
 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;
 }
Example #8
0
    @Override
    public void execute(Event<UIMembersPortlet> event) throws Exception {
      WebuiRequestContext ctx = event.getRequestContext();
      UIMembersPortlet uiMembersPortlet = event.getSource();

      UIProfileUserSearch uiSearch = uiMembersPortlet.uiSearchMemberOfSpace;

      String charSearch = ctx.getRequestParameter(OBJECTID);

      ResourceBundle resApp = ctx.getApplicationResourceBundle();

      String defaultNameVal = resApp.getString(uiSearch.getId() + ".label.name");
      String defaultPosVal = resApp.getString(uiSearch.getId() + ".label.position");
      String defaultSkillsVal = resApp.getString(uiSearch.getId() + ".label.skills");

      ProfileFilter filter = uiSearch.getProfileFilter();

      try {
        uiMembersPortlet.setSelectedChar(charSearch);
        if (charSearch != null) { // search by alphabet
          ((UIFormStringInput) uiSearch.getChildById(SEARCH)).setValue(defaultNameVal);
          ((UIFormStringInput) uiSearch.getChildById(Profile.POSITION)).setValue(defaultPosVal);
          ((UIFormStringInput) uiSearch.getChildById(Profile.EXPERIENCES_SKILLS))
              .setValue(defaultSkillsVal);
          filter.setName(charSearch);
          filter.setPosition("");
          filter.setSkills("");
          filter.setFirstCharacterOfName(charSearch.toCharArray()[0]);
          if (ALL_FILTER.equals(charSearch)) {
            filter.setFirstCharacterOfName(EMPTY_CHARACTER);
            filter.setName("");
          }
          uiSearch.setRawSearchConditional("");
        }

        uiSearch.setProfileFilter(filter);
        uiSearch.setNewSearch(true);
      } catch (Exception e) {
        uiSearch.setIdentityList(new ArrayList<Identity>());
      }

      uiMembersPortlet.loadSearch();
      uiMembersPortlet.setLoadAtEnd(false);
    }
  @Override
  protected String loadConfirmMesssage(
      org.exoplatform.webui.config.Event event, WebuiRequestContext context, String beanId) {

    String confirm = event.getConfirm();
    if (confirm.length() < 1) return confirm;
    UIGridUser uiGrid = getChild(UIGridUser.class);
    try {
      confirm = context.getApplicationResourceBundle().getString(confirm);
      MembershipUser membershipUser = uiGrid.searchMembershipUser(beanId);
      if (membershipUser == null) return confirm;
      Group selectGroup = getSelectedGroup();
      if (selectGroup == null) return confirm;
      confirm = confirm.replaceAll("\\{0\\}", membershipUser.getUserName());
      confirm = confirm.replaceAll("\\{1\\}", selectGroup.getId().substring(1));
    } catch (Exception e) {

    }
    return confirm;
  }
 @Override
 protected void processEvent(Event<PreviewPageActionComponent> event) throws Exception {
   UIWikiPortlet wikiPortlet = event.getSource().getAncestorOfType(UIWikiPortlet.class);
   WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
   ResourceBundle res = context.getApplicationResourceBundle();
   UIWikiMaskWorkspace uiMaskWS = wikiPortlet.getChild(UIWikiMaskWorkspace.class);
   UIWikiPageEditForm wikiPageEditForm =
       event.getSource().getAncestorOfType(UIWikiPageEditForm.class);
   UIWikiPagePreview wikiPagePreview =
       uiMaskWS.createUIComponent(UIWikiPagePreview.class, null, null);
   UIWikiRichTextArea wikiRichTextArea = wikiPageEditForm.getChild(UIWikiRichTextArea.class);
   UIWikiPageTitleControlArea wikiPageTitleArea =
       wikiPageEditForm.getChild(UIWikiPageTitleControlArea.class);
   String markupSyntax = Utils.getDefaultSyntax();
   boolean isRichTextRendered = wikiRichTextArea.isRendered();
   RenderingService renderingService =
       (RenderingService) PortalContainer.getComponent(RenderingService.class);
   String markup;
   if (isRichTextRendered) {
     String htmlContent = wikiRichTextArea.getUIFormTextAreaInput().getValue();
     markup =
         renderingService.render(
             htmlContent, Syntax.XHTML_1_0.toIdString(), markupSyntax, false);
     Utils.feedDataForWYSIWYGEditor(wikiPageEditForm, markup);
   } else {
     UIFormTextAreaInput markupInput =
         wikiPageEditForm.findComponentById(UIWikiPageEditForm.FIELD_CONTENT);
     markup = (markupInput.getValue() == null) ? "" : markupInput.getValue();
   }
   wikiPagePreview.renderWikiMarkup(markup, markupSyntax);
   String pageTitle = wikiPageTitleArea.getTitle();
   if (pageTitle != null) wikiPagePreview.setPageTitle(wikiPageTitleArea.getTitle());
   else {
     wikiPagePreview.setPageTitle(res.getString("UIWikiPageTitleControlArea.label.Untitled"));
   }
   uiMaskWS.setUIComponent(wikiPagePreview);
   uiMaskWS.setShow(true);
   uiMaskWS.setPopupTitle(res.getString("UIEditorTabs.action.PreviewPage"));
   event.getRequestContext().addUIComponentToUpdateByAjax(uiMaskWS);
   super.processEvent(event);
 }
Example #11
0
 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);
 }
Example #12
0
  /**
   * constructor
   *
   * @param name
   * @throws Exception
   */
  public UISpaceSettings(String name) throws Exception {
    super(name);
    WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance();
    ResourceBundle resourceBundle = requestContext.getApplicationResourceBundle();
    UIFormStringInput spaceDisplayName =
        new UIFormStringInput(SPACE_DISPLAY_NAME, SPACE_DISPLAY_NAME, null);
    spaceDisplayName.setHTMLAttribute(
        HTML_ATTRIBUTE_PLACEHOLDER,
        resourceBundle.getString("UISpaceSettings.label.spaceDisplayName"));
    addUIFormInput(
        spaceDisplayName
            .addValidator(MandatoryValidator.class)
            .addValidator(
                ExpressionValidator.class, "^([\\p{L}\\s\\d\']+[\\s]?)+$", MSG_INVALID_SPACE_NAME)
            .addValidator(StringLengthValidator.class, 3, 30));

    UIFormTextAreaInput description =
        new UIFormTextAreaInput(SPACE_DESCRIPTION, SPACE_DESCRIPTION, null);
    description.setHTMLAttribute(
        HTML_ATTRIBUTE_PLACEHOLDER,
        resourceBundle.getString("UISpaceSettings.label.spaceDescription"));
    addUIFormInput(description.addValidator(StringLengthValidator.class, 0, 255));
  }
Example #13
0
  /**
   * constructor
   *
   * @throws Exception
   */
  public UISpaceInfo() throws Exception {
    WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance();
    ResourceBundle resourceBundle = requestContext.getApplicationResourceBundle();
    UIFormStringInput spaceId = new UIFormStringInput(SPACE_ID, SPACE_ID, null).setRendered(false);
    spaceId.setHTMLAttribute(
        HTML_ATTRIBUTE_TITLE, resourceBundle.getString("UISpaceInfo.label.SpaceId"));
    addUIFormInput(spaceId);

    UIFormStringInput spaceDisplayName =
        new UIFormStringInput(SPACE_DISPLAY_NAME, SPACE_DISPLAY_NAME, null);
    spaceDisplayName.setHTMLAttribute(
        HTML_ATTRIBUTE_PLACEHOLDER,
        resourceBundle.getString("UISpaceSettings.label.spaceDisplayName"));
    addUIFormInput(
        spaceDisplayName
            .addValidator(MandatoryValidator.class)
            .addValidator(
                ExpressionValidator.class,
                "^([\\p{L}\\d\']+[\\s]?)+$",
                "UISpaceInfo.msg.name-invalid")
            .addValidator(StringLengthValidator.class, 3, 30));

    UIFormTextAreaInput description =
        new UIFormTextAreaInput(SPACE_DESCRIPTION, SPACE_DESCRIPTION, null);
    description.setHTMLAttribute(
        HTML_ATTRIBUTE_PLACEHOLDER,
        resourceBundle.getString("UISpaceSettings.label.spaceDescription"));
    addUIFormInput(description.addValidator(StringLengthValidator.class, 0, 255));

    // temporary disable tag
    UIFormStringInput tag = new UIFormStringInput(SPACE_TAG, SPACE_TAG, null).setRendered(false);
    tag.setHTMLAttribute(HTML_ATTRIBUTE_TITLE, resourceBundle.getString("UISpaceInfo.label.tag"));
    addUIFormInput(tag);

    PopupContainer popupContainer = createUIComponent(PopupContainer.class, null, null);
    addChild(popupContainer);
  }
Example #14
0
  public void processRender(WebuiRequestContext context) throws Exception {
    ResourceBundle res = context.getApplicationResourceBundle();
    String label = getId() + ".label";
    try {
      label = res.getString(label);
    } catch (MissingResourceException e) {
      label = null;
    }

    Writer w = context.getWriter();
    if (label != null) {
      w.write("<label class=\"uiCheckbox\">");
    } else {
      w.write("<span class=\"uiCheckbox\">");
    }
    w.append("<input type='checkbox' id=\"").append(getId()).append("\" name='");
    w.write(name);
    w.write("'");
    if (onchange_ != null) {
      UIForm uiForm = getAncestorOfType(UIForm.class);
      w.append(" onclick=\"").append(renderOnChangeEvent(uiForm)).append("\"");
    }
    if (checked) w.write(" checked ");
    if (isDisabled()) w.write(" disabled ");

    renderHTMLAttributes(w);

    w.write(" class='checkbox'/><span>");
    if (label != null) {
      w.write(label);
      w.write("</span></label>");
    } else {
      w.write("</span></span>");
    }
    if (this.isMandatory()) w.write(" *");
  }
    public void execute(Event<UIForgetPassword> event) throws Exception {
      UIForgetPassword uiForm = event.getSource();
      UILogin uilogin = uiForm.getParent();
      WebuiRequestContext requestContext = event.getRequestContext();
      PortalRequestContext portalContext = PortalRequestContext.getCurrentInstance();
      String url = portalContext.getRequest().getRequestURL().toString();
      MailService mailSrc = uiForm.getApplicationComponent(MailService.class);
      OrganizationService orgSrc = uiForm.getApplicationComponent(OrganizationService.class);
      String userName = uiForm.getUIStringInput(Username).getValue();
      String email = uiForm.getUIStringInput(Email).getValue();
      uiForm.reset();

      User user = null;

      String tokenId = null;

      // User provided his username
      if (userName != null) {
        user = orgSrc.getUserHandler().findUserByName(userName);
        if (user == null) {
          requestContext
              .getUIApplication()
              .addMessage(new ApplicationMessage("UIForgetPassword.msg.user-not-exist", null));
          return;
        }
      }

      // User provided his email address
      if (user == null && email != null) {
        Query query = new Query();
        // Querying on email won't work. PLIDM-12
        // Note that querying on email is inefficient as it loops over all users...
        query.setEmail(email);
        PageList<User> users = orgSrc.getUserHandler().findUsers(query);
        if (users.getAll().size() > 0) {
          user = users.getAll().get(0);
        } else {
          requestContext
              .getUIApplication()
              .addMessage(new ApplicationMessage("UIForgetPassword.msg.email-not-exist", null));
          return;
        }
      }

      email = user.getEmail();

      // Create token
      RemindPasswordTokenService tokenService =
          uiForm.getApplicationComponent(RemindPasswordTokenService.class);
      Credentials credentials = new Credentials(user.getUserName(), "");
      tokenId = tokenService.createToken(credentials);

      String portalName = URLEncoder.encode(Util.getUIPortal().getName(), "UTF-8");

      ResourceBundle res = requestContext.getApplicationResourceBundle();
      String headerMail = "headermail";
      String footerMail = "footer";
      try {
        headerMail =
            res.getString(uiForm.getId() + ".mail.header")
                + "\n\n"
                + res.getString(uiForm.getId() + ".mail.user")
                + user.getUserName()
                + "\n"
                + res.getString(uiForm.getId() + ".mail.link");
        footerMail = "\n\n\n" + res.getString(uiForm.getId() + ".mail.footer");
      } catch (MissingResourceException e) {
        e.printStackTrace();
      }
      String host = url.substring(0, url.indexOf(requestContext.getRequestContextPath()));
      String activeLink =
          host
              + requestContext.getRequestContextPath()
              + "/public/"
              + portalName
              + "?portal:componentId=UIPortal&portal:action=RecoveryPasswordAndUsername&tokenId="
              + tokenId;
      String mailText = headerMail + "\n" + activeLink + footerMail;
      try {
        mailSrc.sendMessage(
            res.getString("UIForgetPassword.mail.from"),
            email,
            res.getString("UIForgetPassword.mail.subject"),
            mailText);
      } catch (Exception e) {
        requestContext
            .getUIApplication()
            .addMessage(new ApplicationMessage("UIForgetPassword.msg.send-mail-fail", null));
        requestContext.addUIComponentToUpdateByAjax(uilogin);

        return;
      }

      uilogin.getChild(UILoginForm.class).setRendered(true);
      uilogin.getChild(UIForgetPasswordWizard.class).setRendered(false);
      uilogin.getChild(UIForgetPassword.class).setRendered(false);
      requestContext
          .getUIApplication()
          .addMessage(new ApplicationMessage("UIForgetPassword.msg.send-mail-success", null));
      requestContext.addUIComponentToUpdateByAjax(uilogin);
    }
Example #16
0
 public String getLabel(String id) throws Exception {
   WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
   ResourceBundle res = context.getApplicationResourceBundle();
   return getLabel(res, id);
 }
Example #17
0
 public static String getResourceBundle(String resourceBundl) {
   WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
   ResourceBundle res = context.getApplicationResourceBundle();
   return res.getString(resourceBundl);
 }