Example #1
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("&").append(SUBCOMPONENT_ID).append("=").append(componentId);
    if (beanId != null) {
      b.append("&").append(OBJECTID).append("=").append(beanId);
    }
    b.append("')");
    return b.toString();
  }
Example #2
0
  @SuppressWarnings("unchecked")
  public void begin() throws Exception {
    WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
    String b = context.getURLBuilder().createURL(this, null, null);

    Writer writer = context.getWriter();
    writer
        .append("<form class=\"UIForm\" id=\"")
        .append(getId())
        .append("\" action=\"")
        .append(b)
        .append('\"');
    if (getSubmitAction() != null) {
      writer
          .append(" onsubmit=\"")
          .append(HTMLEntityEncoder.getInstance().encodeHTMLAttribute(getSubmitAction()))
          .append("\"");
    }
    if (multipart_) {
      writer.append(" enctype=\"multipart/form-data\"");
    }
    writer.append(" method=\"post\">");
    writer.append("<div><input type=\"hidden\" name=\"").append(ACTION).append("\" value=\"\"/>");
    writer
        .append("<input type=\"hidden\" name=\"")
        .append(CSRFTokenUtil.CSRF_TOKEN)
        .append("\" value=\"");
    writer.append(CSRFTokenUtil.getToken());
    writer.append("\"/></div>");
  }
  public void processRender(UIStandaloneApplication uicomponent, WebuiRequestContext context)
      throws Exception {

    PortalRequestContext prc = (PortalRequestContext) context;
    OutputStream responseOutputStream = prc.getResponse().getOutputStream();

    PortalPrinter parentWriter = new PortalPrinter(responseOutputStream, true, 5000);
    PortalPrinter childWriter = new PortalPrinter(responseOutputStream, true, 25000, true);

    context.setWriter(childWriter);
    processRender(
        uicomponent,
        context,
        "system:/groovy/portal/webui/workspace/UIStandaloneApplicationChildren.gtmpl");

    context.setWriter(parentWriter);
    processRender(
        uicomponent,
        context,
        "system:/groovy/portal/webui/workspace/UIStandaloneApplication.gtmpl");

    try {
      // flush the parent writer to the output stream so that we are really to accept the child
      // content
      parentWriter.flushOutputStream();
      // now that the parent has been flushed, we can flush the contents of the child to the output
      childWriter.flushOutputStream();
    } catch (IOException ioe) {
      // We want to ignore the ClientAbortException since this is caused by the users
      // browser closing the connection and is not something we should be logging.
      if (!ioe.getClass().toString().contains("ClientAbortException")) {
        throw ioe;
      }
    }
  }
  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);
  }
Example #5
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 #6
0
  public static List<SelectItemOption<String>> getTimesSelectBoxOptions(
      String labelFormat, String valueFormat, long timeInteval) {

    WebuiRequestContext context = RequestContext.getCurrentInstance();
    Locale locale = context.getParentAppRequestContext().getLocale();
    return getTimesSelectBoxOptions(labelFormat, valueFormat, timeInteval, locale);
  }
Example #7
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();
  }
Example #8
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);
 }
  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 #10
0
  public String getFileURL(String path) throws Exception {
    WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
    if (!(context instanceof PortalRequestContext)) {
      context = (WebuiRequestContext) context.getParentAppRequestContext();
    }
    String portalName = getPortalName();
    String requestURL = ((PortalRequestContext) context).getRequest().getRequestURL().toString();
    String domainURL = requestURL.substring(0, requestURL.indexOf(portalName));
    Session session = getCurrentSession();
    String workspace = session.getWorkspace().getName();
    String repository =
        ((ManageableRepository) session.getRepository()).getConfiguration().getName();

    String url =
        domainURL
            + portalName
            + "/"
            + PortalContainer.getCurrentRestContextName()
            + "/jcr/"
            + repository
            + "/"
            + workspace
            + path;
    return url;
  }
 public String getActionUpload() {
   WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
   WebuiRequestContext pcontext = (WebuiRequestContext) context.getParentAppRequestContext();
   if (pcontext == null) pcontext = context;
   String uploadAction = pcontext.getRequestContextPath() + "/upload?";
   uploadAction += "uploadId=" + uploadId_ + "&action=upload";
   return uploadAction;
 }
    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);
    }
Example #13
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);
      }
    }
    public void execute(Event<UIAccountChangePass> event) throws Exception {
      UIAccountChangePass uiForm = event.getSource();
      OrganizationService service = uiForm.getApplicationComponent(OrganizationService.class);
      WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
      UIApplication uiApp = context.getUIApplication();
      String username = Util.getPortalRequestContext().getRemoteUser();
      User user = service.getUserHandler().findUserByName(username);
      String currentPass = uiForm.getUIStringInput("currentpass").getValue();
      String newPass = uiForm.getUIStringInput("newpass").getValue();
      String confirmnewPass = uiForm.getUIStringInput("confirmnewpass").getValue();

      Authenticator authenticator = uiForm.getApplicationComponent(Authenticator.class);
      boolean authenticated;
      try {
        UsernameCredential usernameCred = new UsernameCredential(username);
        PasswordCredential passwordCred = new PasswordCredential(currentPass);
        authenticator.validateUser(new Credential[] {usernameCred, passwordCred});
        authenticated = true;
      } catch (Exception ex) {
        authenticated = false;
      }

      if (!authenticated) {
        uiApp.addMessage(
            new ApplicationMessage(
                "UIAccountChangePass.msg.currentpassword-is-not-match", null, 1));
        uiForm.reset();
        event.getRequestContext().addUIComponentToUpdateByAjax(uiForm);
        return;
      }

      if (!newPass.equals(confirmnewPass)) {
        uiApp.addMessage(
            new ApplicationMessage("UIAccountChangePass.msg.password-is-not-match", null, 1));
        uiForm.reset();
        event.getRequestContext().addUIComponentToUpdateByAjax(uiForm);
        return;
      }
      try {
        user.setPassword(newPass);
        service.getUserHandler().saveUser(user, true);
        uiApp.addMessage(
            new ApplicationMessage("UIAccountChangePass.msg.change.pass.success", null));
        UIAccountSetting ui = uiForm.getParent();
        ui.getChild(UIAccountProfiles.class).setRendered(true);
        ui.getChild(UIAccountChangePass.class).setRendered(false);
        event.getRequestContext().addUIComponentToUpdateByAjax(ui);
      } catch (Exception e) {
        uiApp.addMessage(
            new ApplicationMessage(
                "UIAccountChangePass.msg.change.pass.fail", null, ApplicationMessage.ERROR));
      }
      uiForm.reset();
      event.getRequestContext().addUIComponentToUpdateByAjax(uiForm);
      return;
    }
Example #15
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 #16
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 #17
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);
 }
Example #18
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;
 }
  /*
   * (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);
  }
Example #20
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();");
 }
    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 processAction(UIStandaloneApplication uicomponent, WebuiRequestContext context)
     throws Exception {
   String componentId = context.getRequestParameter(context.getUIComponentIdParameterName());
   if (componentId == null) {
     return;
   }
   UIComponent uiTarget = uicomponent.findComponentById(componentId);
   if (uiTarget == null) {
     return;
   }
   if (uiTarget == uicomponent) {
     super.processAction(uicomponent, context);
   }
   uiTarget.processAction(context);
 }
Example #23
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;
   }
 }
  @Override
  public void serveResource(WebuiRequestContext context) throws Exception {
    super.serveResource(context);

    ResourceRequest req = context.getRequest();
    String nodeURI = req.getResourceID();

    JSONArray jsChilds = getChildrenAsJSON(nodeURI);
    if (jsChilds == null) {
      return;
    }

    MimeResponse res = context.getResponse();
    res.setContentType("text/json");
    res.getWriter().write(jsChilds.toString());
  }
  public void decode(Object input, WebuiRequestContext context) throws Exception {
    String[] values = context.getRequestParameterValues(getId());
    if (values == null) {
      value_ = null;
      for (SelectItem option : options_) {
        if (option instanceof SelectOption) ((SelectOption) option).setSelected(false);
        else if (option instanceof SelectOptionGroup) {
          for (SelectOption opt : ((SelectOptionGroup) option).getOptions()) {
            opt.setSelected(false);
          }
        }
      }
      return;
    }

    int i = 0;
    value_ = values[0];
    for (SelectItem item : options_) {
      if (item instanceof SelectOption) {
        if (i > -1 && ((SelectOption) item).getValue().equals(values[i])) {
          ((SelectOption) item).setSelected(true);
          if (values.length == ++i) i = -1;
        } else ((SelectOption) item).setSelected(false);
      } else if (item instanceof SelectOptionGroup) {
        for (SelectOption opt : ((SelectOptionGroup) item).getOptions()) {
          if (i > -1 && (opt).getValue().equals(values[i])) {
            (opt).setSelected(true);
            if (values.length == ++i) i = -1;
          } else {
            (opt).setSelected(false);
          }
        }
      }
    }
  }
 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);
 }
Example #27
0
 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);
   }
 }
Example #28
0
    @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;
      }
    }
Example #29
0
 /**
  * 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();
 }
Example #30
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);
    }