private void postActivityToSpace(
      UIComponent source, WebuiRequestContext requestContext, Map<String, String> activityParams)
      throws Exception {
    final UIComposer uiComposer = (UIComposer) source;
    ActivityManager activityManager = uiComposer.getApplicationComponent(ActivityManager.class);
    IdentityManager identityManager = uiComposer.getApplicationComponent(IdentityManager.class);

    SpaceService spaceSrv = uiComposer.getApplicationComponent(SpaceService.class);
    Space space = spaceSrv.getSpaceByUrl(SpaceUtils.getSpaceUrlByContext());

    Identity spaceIdentity =
        identityManager.getOrCreateIdentity(
            SpaceIdentityProvider.NAME, space.getPrettyName(), false);
    String remoteUser = requestContext.getRemoteUser();
    ExoSocialActivity activity =
        saveActivity(activityParams, activityManager, identityManager, spaceIdentity, remoteUser);

    UISpaceActivitiesDisplay uiDisplaySpaceActivities =
        (UISpaceActivitiesDisplay) getActivityDisplay();
    UIActivitiesContainer activitiesContainer =
        uiDisplaySpaceActivities.getActivitiesLoader().getActivitiesContainer();
    activitiesContainer.addActivity(activity);
    requestContext.addUIComponentToUpdateByAjax(activitiesContainer);
    requestContext.addUIComponentToUpdateByAjax(uiComposer);
  }
Ejemplo n.º 2
0
    @Override
    public void execute(Event<UIAvatarUploader> event) throws Exception {
      WebuiRequestContext ctx = event.getRequestContext();
      UIApplication uiApplication = ctx.getUIApplication();
      UIAvatarUploader uiAvatarUploader = event.getSource();
      UIFormUploadInput uiAvatarUploadInput = uiAvatarUploader.getChild(UIFormUploadInput.class);
      UIPopupWindow uiPopup = uiAvatarUploader.getParent();
      InputStream uploadedStream = uiAvatarUploadInput.getUploadDataAsStream();

      if (uploadedStream == null) {
        uiApplication.addMessage(
            new ApplicationMessage(MSG_IMG_NOT_UPLOADED, null, ApplicationMessage.ERROR));
        ctx.addUIComponentToUpdateByAjax(uiAvatarUploader);
        return;
      }
      UploadResource uploadResource = uiAvatarUploadInput.getUploadResource();

      String mimeType = uploadResource.getMimeType();
      String uploadId = uiAvatarUploadInput.getUploadId();
      if (!uiAvatarUploader.isAcceptedMimeType(mimeType)) {
        UploadService uploadService =
            (UploadService) PortalContainer.getComponent(UploadService.class);
        uploadService.removeUploadResource(uploadId);
        uiApplication.addMessage(
            new ApplicationMessage(MSG_MIMETYPE_NOT_ACCEPTED, null, ApplicationMessage.ERROR));
        ctx.addUIComponentToUpdateByAjax(uiAvatarUploader);
      } else {
        MimeTypeResolver mimeTypeResolver = new MimeTypeResolver();
        String fileName = uploadResource.getFileName();

        // @since 1.1.3
        String extension = mimeTypeResolver.getExtension(mimeType);
        if ("".equals(extension)) {
          mimeType = uiAvatarUploader.getStandardMimeType(mimeType);
        }

        // Resize avatar to fixed width if can't(avatarAttachment == null) keep
        // origin avatar
        AvatarAttachment avatarAttachment =
            ImageUtils.createResizedAvatarAttachment(
                uploadedStream, WIDTH, 0, null, fileName, mimeType, null);
        if (avatarAttachment == null) {
          avatarAttachment =
              new AvatarAttachment(
                  null, fileName, mimeType, uploadedStream, null, System.currentTimeMillis());
        }

        UploadService uploadService =
            (UploadService) PortalContainer.getComponent(UploadService.class);
        uploadService.removeUploadResource(uploadId);
        UIAvatarUploadContent uiAvatarUploadContent =
            uiAvatarUploader.createUIComponent(UIAvatarUploadContent.class, null, null);
        uiAvatarUploadContent.setAvatarAttachment(avatarAttachment);
        uiPopup.setUIComponent(uiAvatarUploadContent);
        ctx.addUIComponentToUpdateByAjax(uiPopup);
      }
    }
Ejemplo n.º 3
0
 /**
  * Creates the popup window. Each portlet have a <code>UIPopupContainer</code> . <br>
  * Every <code>UIPopupWindow</code> created by this method is belong to this container.
  *
  * @param container the current container
  * @param component the component which will be display as a popup
  * @param popupWindowId the popup's ID
  * @param width the width of the popup
  * @throws Exception the exception
  */
 public static void createPopupWindow(
     UIContainer container, UIComponent component, String popupWindowId, int width)
     throws Exception {
   UIPopupContainer popupContainer = initPopup(container, component, popupWindowId, width);
   WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance();
   requestContext.addUIComponentToUpdateByAjax(popupContainer);
 }
Ejemplo n.º 4
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();
        }
      }
    }
    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);
    }
Ejemplo n.º 6
0
 /**
  * Creates the popup window. Each portlet have a <code>UIPopupContainer</code> . <br>
  * Every <code>UIPopupWindow</code> created by this method is belong to this container.
  *
  * @param container the current container
  * @param component the component which will be display as a popup
  * @param popupWindowId the popup's ID
  * @param width the width of the popup
  * @param isShowMask Set as true to create mask layer
  * @throws Exception the exception
  */
 public static void createPopupWindow(
     UIContainer container,
     UIComponent component,
     String popupWindowId,
     int width,
     boolean isShowMask)
     throws Exception {
   UIPopupContainer popupContainer = initPopup(container, component, popupWindowId, width);
   UIPopupWindow popupWindow = popupContainer.getChildById(popupWindowId);
   popupWindow.setShowMask(isShowMask);
   WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance();
   requestContext.addUIComponentToUpdateByAjax(popupContainer);
 }
Ejemplo n.º 7
0
 public void doMove(Event<UITabContainer> event, boolean isToLeft) throws Exception {
   UITabContainer container = event.getSource();
   String objectId = event.getRequestContext().getRequestParameter(OBJECTID);
   if (container == null || objectId == null) {
     return;
   }
   container.moveTab(container, objectId, isToLeft);
   WebuiRequestContext context = event.getRequestContext();
   context.addUIComponentToUpdateByAjax(container);
   context
       .getJavascriptManager()
       .require("SHARED/portal", "portal")
       .addScripts("portal.PortalComposer.toggleSaveButton();");
 }
Ejemplo n.º 8
0
    public void execute(Event<UIDropDownControl> event) throws Exception {
      UIDropDownControl uiDropDown = event.getSource();
      UIUserActivitiesDisplay uiUserActivities = uiDropDown.getParent();
      WebuiRequestContext requestContext = event.getRequestContext();
      String selectedDisplayMode = requestContext.getRequestParameter(OBJECTID);

      if (selectedDisplayMode.equals(DisplayMode.ALL_ACTIVITIES.toString())) {
        uiUserActivities.setSelectedDisplayMode(DisplayMode.ALL_ACTIVITIES);
      } else if (selectedDisplayMode.equals(DisplayMode.MY_ACTIVITIES.toString())) {
        uiUserActivities.setSelectedDisplayMode(DisplayMode.MY_ACTIVITIES);
      } else if (selectedDisplayMode.equals(DisplayMode.MY_SPACE.toString())) {
        uiUserActivities.setSelectedDisplayMode(DisplayMode.MY_SPACE);
      } else {
        uiUserActivities.setSelectedDisplayMode(DisplayMode.CONNECTIONS);
      }

      if (selectedDisplayMode != null) {
        uiUserActivities.setSelectedDisplayMode(selectedDisplayMode);
        uiUserActivities.init();

        uiUserActivities.setChangedMode(false);

        // int numberOfUpdates = uiUserActivities.getNumberOfUpdatedActivities();

        //
        event
            .getRequestContext()
            .getJavascriptManager()
            .require("SHARED/social-ui-activity-updates", "activityUpdates")
            .addScripts(
                "activityUpdates.resetCookie('"
                    + String.format(
                        Utils.ACTIVITY_STREAM_TAB_SELECTED_COOKIED, Utils.getViewerRemoteId())
                    + "','"
                    + selectedDisplayMode
                    + "');");
        //
        //       event.getRequestContext().getJavascriptManager()
        //       .require("SHARED/social-ui-activity-updates",
        // "activityUpdates").addScripts("activityUpdates.resetCookie('" +
        // String.format(Utils.LAST_UPDATED_ACTIVITIES_NUM, selectedDisplayMode,
        // Utils.getViewerRemoteId()) + "','" + numberOfUpdates + "');");

      }

      requestContext.addUIComponentToUpdateByAjax(uiUserActivities);

      Utils.resizeHomePage();
    }
 public void processDecode(UIStandaloneApplication uicomponent, WebuiRequestContext context)
     throws Exception {
   String componentId = context.getRequestParameter(context.getUIComponentIdParameterName());
   if (componentId == null) {
     return;
   }
   UIComponent uiTarget = uicomponent.findComponentById(componentId);
   if (uiTarget == null) {
     context.addUIComponentToUpdateByAjax(uicomponent.getChild(UIStandaloneAppContainer.class));
     return;
   }
   if (uiTarget == uicomponent) {
     super.processDecode(uicomponent, context);
   }
   uiTarget.processDecode(context);
 }
Ejemplo n.º 10
0
    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();
    }
Ejemplo n.º 11
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.exoplatform.webui.event.EventListener#execute(org.exoplatform
  * .webui.event.Event)
  */
 public void execute(Event<UINavigationForm> event) throws Exception {
   UINavigationForm uiNavigationForm = event.getSource();
   UIPageSelector pageSelector =
       uiNavigationForm.createUIComponent(UIPageSelector.class, null, null);
   pageSelector.setSourceComponent(
       uiNavigationForm, new String[] {DETAIL_TARGET_PAGE_STRING_INPUT});
   UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class);
   UIPopupContainer popupContainer = uiExplorer.getChild(UIPopupContainer.class);
   popupContainer.removeChildById(DETAIL_TARGET_PAGE_SELECTOR_POPUP_WINDOW);
   UIPopupWindow popupWindow =
       popupContainer.addChild(
           UIPopupWindow.class, null, DETAIL_TARGET_PAGE_SELECTOR_POPUP_WINDOW);
   popupWindow.setUIComponent(pageSelector);
   popupWindow.setWindowSize(800, 0);
   popupWindow.setShow(true);
   popupWindow.setRendered(true);
   popupWindow.setResizable(true);
   WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance();
   requestContext.addUIComponentToUpdateByAjax(popupContainer);
   uiNavigationForm.setPopupId(DETAIL_TARGET_PAGE_SELECTOR_POPUP_WINDOW);
 }
    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);
    }