Example #1
0
 /**
  * Process an action request.
  *
  * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest,
  *     javax.portlet.ActionResponse)
  */
 public void processAction(ActionRequest request, ActionResponse response)
     throws PortletException, java.io.IOException {
   if (request.getParameter(FORM_SUBMIT) != null) {
     // Set form text in the session bean
     Vlado2PortletSessionBean sessionBean = getSessionBean(request);
     if (sessionBean != null) sessionBean.setFormText(request.getParameter(FORM_TEXT));
   }
   if (request.getParameter(EDIT_SUBMIT) != null) {
     PortletPreferences prefs = request.getPreferences();
     try {
       prefs.setValue(EDIT_KEY, request.getParameter(EDIT_TEXT));
       prefs.store();
     } catch (ReadOnlyException roe) {
     } catch (ValidatorException ve) {
     }
   }
   if (request.getParameter(CONFIG_SUBMIT) != null) {
     PortletPreferences prefs = request.getPreferences();
     try {
       prefs.setValue(CONFIG_KEY, request.getParameter(CONFIG_TEXT));
       prefs.store();
     } catch (ReadOnlyException roe) {
     } catch (ValidatorException ve) {
     }
   }
 }
  @RequestMapping(params = "action=save")
  public void saveConfiguration(
      ActionRequest request,
      ActionResponse response,
      @ModelAttribute("form") SearchPortletConfigurationForm form)
      throws PortletModeException {

    PortletPreferences prefs = request.getPreferences();

    try {

      prefs.setValue("gsaEnabled", String.valueOf(form.isGsaEnabled()));
      prefs.setValue("gsaBaseUrl", form.getGsaBaseUrl());
      prefs.setValue("gsaSite", form.getGsaSite());
      prefs.setValue("directoryEnabled", String.valueOf(form.isDirectoryEnabled()));
      prefs.setValue("portletRegistryEnabled", String.valueOf(form.isPortletRegistryEnabled()));
      prefs.store();

    } catch (ValidatorException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ReadOnlyException e) {
      e.printStackTrace();
    }

    response.setPortletMode(PortletMode.VIEW);
  }
  protected void updatePreferences(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    if (!cmd.equals(Constants.UPDATE)) {
      return;
    }

    PortletPreferences preferences = actionRequest.getPreferences();

    String[] symbols =
        StringUtil.split(
            ParamUtil.getString(actionRequest, "symbols").toUpperCase(), StringPool.SPACE);

    Arrays.sort(symbols);

    preferences.setValues("symbols", symbols);

    try {
      preferences.store();
    } catch (ValidatorException ve) {
      SessionErrors.add(actionRequest, ValidatorException.class.getName(), ve);

      return;
    }

    PortletConfig portletConfig = getPortletConfig();

    SessionMessages.add(
        actionRequest,
        portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_UPDATED_PREFERENCES);
  }
  @Override
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    if (!cmd.equals(Constants.UPDATE)) {
      return;
    }

    PortletPreferences preferences = actionRequest.getPreferences();

    String[] symbols =
        StringUtil.split(ParamUtil.getString(actionRequest, "symbols").toUpperCase());

    preferences.setValues("symbols", symbols);

    try {
      preferences.store();
    } catch (ValidatorException ve) {
      SessionErrors.add(actionRequest, ValidatorException.class.getName(), ve);

      return;
    }

    SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doEdit");
  }
Example #5
0
  public void EditPreferenceAction(ActionRequest req, ActionResponse res) {
    String cmd = ParamUtil.getString(req, Constants.CMD);

    if (!cmd.equals(Constants.UPDATE)) {
      return;
    }

    PortletPreferences prefs = req.getPreferences();
    int displayStyle = ParamUtil.getInteger(req, "displayStyle");
    // String styleSelected = ParamUtil.getString(req, "displayStyle","1");
    String[] selectCategories = req.getParameterValues("selectCategories");
    String defaultSize = ParamUtil.getString(req, "defaultSize");
    String widthSize = ParamUtil.getString(req, "widthSize");
    String heightSize = ParamUtil.getString(req, "heightSize");
    try {
      prefs.setValues("selectCategories", selectCategories);
      prefs.setValue("displayStyleExt", String.valueOf(displayStyle));
      prefs.setValue("defaultSize", defaultSize);
      prefs.setValue("widthSize", widthSize);
      prefs.setValue("heightSize", heightSize);

      prefs.store();
      res.setRenderParameter("jspPage", "/html/portlet/view_vclip/view.jsp");
    } catch (Exception e) {
      // TODO: handle exception
    }
  }
  protected String getOldScopeName(ActionRequest actionRequest, Portlet portlet) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    PortletPreferences portletPreferences = actionRequest.getPreferences();

    String scopeType = GetterUtil.getString(portletPreferences.getValue("lfrScopeType", null));

    if (Validator.isNull(scopeType)) {
      return null;
    }

    String scopeName = null;

    if (scopeType.equals("company")) {
      scopeName = themeDisplay.translate("global");
    } else if (scopeType.equals("layout")) {
      String scopeLayoutUuid =
          GetterUtil.getString(portletPreferences.getValue("lfrScopeLayoutUuid", null));

      Layout scopeLayout =
          _layoutLocalService.fetchLayoutByUuidAndGroupId(
              scopeLayoutUuid, layout.getGroupId(), layout.isPrivateLayout());

      if (scopeLayout != null) {
        scopeName = scopeLayout.getName(themeDisplay.getLocale());
      }
    } else {
      throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
    }

    return scopeName;
  }
  /*
   * Process the "finished" action for the edit page. Set the "url" to the value specified in the
   * edit page.
   */
  private void processEditFinishedAction(ActionRequest request, ActionResponse response)
      throws PortletException {
    String nbPublis = request.getParameter(TEXTBOX_NB_ITEMS);
    String maxAge = request.getParameter(TEXTBOX_MAX_AGE);
    String displayDescription = request.getParameter("displayDescription");

    // Check if it is a number
    try {
      int nb = Integer.parseInt(nbPublis);
      Integer.parseInt(maxAge);
      if (nb < 0 || nb > 30) {
        throw new NumberFormatException();
      }
      // store preference
      PortletPreferences pref = request.getPreferences();
      try {
        pref.setValue("nbPublis", nbPublis);
        pref.setValue("maxAge", maxAge);
        pref.setValue("displayDescription", displayDescription);
        pref.store();
      } catch (ValidatorException ve) {
        log("could not set nbPublis", ve);
        throw new PortletException("IFramePortlet.processEditFinishedAction", ve);
      } catch (IOException ioe) {
        log("could not set nbPublis", ioe);
        throw new PortletException("IFramePortlet.prcoessEditFinishedAction", ioe);
      }
      response.setPortletMode(PortletMode.VIEW);

    } catch (NumberFormatException e) {
      response.setRenderParameter(ERROR_BAD_VALUE, "true");
      response.setPortletMode(PortletMode.EDIT);
    }
  }
  /**
   * Takes a submitted contact and adds it to the database if it passes validation.
   *
   * @param request
   * @param response
   */
  public void registerContact(ActionRequest request, ActionResponse response) throws Exception {

    _log.debug("registerContact");

    Contact contact = ActionUtil.contactFromRequest(request);
    ArrayList<String> errors = new ArrayList();
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    String community = "";
    try {
      community = themeDisplay.getScopeGroupName();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    boolean regValid = ContactMeRegValidator.validateRegistration(contact, errors);

    if (regValid) {

      long userId = themeDisplay.getUserId();

      contact.setCreateDate(new Date(System.currentTimeMillis()));
      contact.setUserId(userId);
      contact.setStatus(Constants.CONTACT_RECEIVED);
      contact.setCommunity(community);

      ContactLocalServiceUtil.addContact(contact);
      SessionMessages.add(request, "thank-you-message");

      PortletPreferences preferences = request.getPreferences();

      long companyId = PortalUtil.getCompanyId(request);

      Message message = new Message();

      message.put("from-name", preferences.getValue("fromName", ""));
      message.put("from-address", preferences.getValue("fromEMail", ""));
      message.put("subject", preferences.getValue("subject", ""));
      message.put("body", preferences.getValue("body", ""));
      message.put("signature", preferences.getValue("signature", ""));
      message.put("to-name", contact.getFullname());
      message.put("to-address", contact.getEmail());
      message.put("community", contact.getCommunity());
      message.put("companyId", companyId);

      MessageBusUtil.sendMessage("liferay/contactme", message);

      response.setRenderParameter("jspPage", viewThankYouJSP);

    } else {
      for (String error : errors) {
        SessionErrors.add(request, error);
      }
      SessionErrors.add(request, "error-saving-contact");
      response.setRenderParameter("jspPage", viewAddContactJSP);
      request.setAttribute("cmContact", contact);
    }
  }
 @Override
 public void processAction(
     PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
     throws Exception {
   super.processAction(portletConfig, actionRequest, actionResponse);
   if (Constants.UPDATE.equals(ParamUtil.getString(actionRequest, Constants.CMD))) {
     PortletPreferences prefs = actionRequest.getPreferences();
     prefs.setValue(PreferencesKeys.CHANGED, Boolean.toString(true));
     prefs.store();
   }
 }
  protected boolean isCommentsEnabled(ActionRequest actionRequest) throws Exception {

    PortletPreferences portletPreferences =
        PortletPreferencesFactoryUtil.getExistingPortletSetup(actionRequest);

    if (portletPreferences == null) {
      portletPreferences = actionRequest.getPreferences();
    }

    return GetterUtil.getBoolean(portletPreferences.getValue("enableComments", null), true);
  }
 /**
  * Default article.
  *
  * @param request the request
  * @param response the response
  */
 public void defaultArticle(ActionRequest request, ActionResponse response) {
   String defaultArticle = ParamUtil.getString(request, ARTICLE_ID);
   PortletPreferences preferences = request.getPreferences();
   try {
     preferences.setValue(DEFAULT_ARTICLE, defaultArticle);
     preferences.store();
   } catch (ReadOnlyException e) {
     LOG.error(e);
   } catch (ValidatorException e) {
     LOG.error(e);
   } catch (IOException e) {
     LOG.error(e);
   }
   SessionMessages.add(request, ARTICLE_DEAFULT);
 }
Example #12
0
  public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws PortletException, IOException {
    // grab parameters - they will be cleared in processing of edit response
    String webContentParameter =
        actionRequest.getParameter(WebContentRewriter.ACTION_PARAMETER_URL);
    String ssoPrincipalName = actionRequest.getParameter(SSO_EDIT_FIELD_PRINCIPAL);
    String ssoPrincipalPassword = actionRequest.getParameter(SSO_EDIT_FIELD_CREDENTIAL);

    // save the prefs
    super.processAction(actionRequest, actionResponse);

    // process credentials
    if (webContentParameter == null || actionRequest.getPortletMode() == PortletMode.EDIT) {
      // processPreferencesAction(request, actionResponse);
      // get the POST params -- requires HTML post params named above
      String siteUrl = actionRequest.getPreferences().getValue("SRC", "");
      String localUser = actionRequest.getUserPrincipal().getName();
      SSOSite site = sso.getSiteByUrl(siteUrl);
      try {
        if (!SecurityHelper.isEmpty(siteUrl)
            && !SecurityHelper.isEmpty(ssoPrincipalName)
            && !SecurityHelper.isEmpty(ssoPrincipalPassword)) {
          if (site == null) {
            site = sso.newSite(siteUrl, siteUrl);
            sso.addSite(site);
            SSOPortletUtil.updateUser(
                sso, actionRequest, site, ssoPrincipalName, ssoPrincipalPassword);
          } else {
            SSOPortletUtil.updateUser(
                sso, actionRequest, site, ssoPrincipalName, ssoPrincipalPassword);
          }
        }
      } catch (SSOException e) {
        String errorMessage =
            "Failed to add remote user for the portal principal, "
                + actionRequest.getUserPrincipal().getName()
                + ".";
        if (e.getCause() != null) {
          errorMessage += " (" + e.getCause() + ")";
        }
        StatusMessage statusMessage = new StatusMessage(errorMessage, StatusMessage.ERROR);
        PortletMessaging.publish(actionRequest, "SSOWebContent", "status", statusMessage);
        actionResponse.setPortletMode(PortletMode.EDIT); // stay on edit
      }
    }
  }
  /* ACTION call from Portlet's <form> of EDIT JSP */
  public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException {

    String saveSettingsGoogleMapsUtility =
        actionRequest.getParameter("saveSettingsGoogleMapsUtility");
    /*You can add other getParameter of EDIT JSP*/

    if (saveSettingsGoogleMapsUtility != null) {
      PortletPreferences prefs = actionRequest.getPreferences();

      if (actionRequest.getParameter("inTypeUtility") != null)
        prefs.setValue("typeUtility", actionRequest.getParameter("inTypeUtility"));

      if (actionRequest.getParameter("inStreetView") != null)
        prefs.setValue("chkStreetView", actionRequest.getParameter("inStreetView"));
      if (actionRequest.getParameter("inZoom") != null)
        prefs.setValue("chkZoom", actionRequest.getParameter("inZoom"));
      if (actionRequest.getParameter("inDraggable") != null)
        prefs.setValue("chkDraggable", actionRequest.getParameter("inDraggable"));
      if (actionRequest.getParameter("inPanControl") != null)
        prefs.setValue("chkPanControl", actionRequest.getParameter("inPanControl"));
      if (actionRequest.getParameter("inRotateControl") != null)
        prefs.setValue("chkRotateControl", actionRequest.getParameter("inRotateControl"));
      if (actionRequest.getParameter("inScaleControl") != null)
        prefs.setValue("chkScaleControl", actionRequest.getParameter("inScaleControl"));

      if (actionRequest.getParameter("inTypeMap") != null)
        prefs.setValue("typeMap", actionRequest.getParameter("inTypeMap"));

      if (actionRequest.getParameter("inAddress") != null)
        prefs.setValue("address", actionRequest.getParameter("inAddress"));
      if (actionRequest.getParameter("inDescriptionMarker") != null)
        prefs.setValue("descriptionMarker", actionRequest.getParameter("inDescriptionMarker"));
      if (actionRequest.getParameter("inTypeIcon") != null)
        prefs.setValue("typeIcon", actionRequest.getParameter("inTypeIcon"));

      if (actionRequest.getParameter("inFromAddress") != null)
        prefs.setValue("fromAddress", actionRequest.getParameter("inFromAddress"));
      if (actionRequest.getParameter("inToAddress") != null)
        prefs.setValue("toAddress", actionRequest.getParameter("inToAddress"));

      prefs.store();
      actionResponse.setPortletMode(PortletMode.VIEW);
    }
  }
Example #14
0
  public void addEntry(ActionRequest request, ActionResponse response) {
    try {
      PortletPreferences prefs = request.getPreferences();

      String[] guestbookEntries = prefs.getValues("guestbook-entries", new String[1]);

      ArrayList<String> entries = new ArrayList<String>();

      if (guestbookEntries != null) {

        entries =
            new ArrayList<String>(
                Arrays.asList(prefs.getValues("guestbook-entries", new String[1])));
      }

      String userName = ParamUtil.getString(request, "name");
      String message = ParamUtil.getString(request, "message");
      String entry = userName + "^" + message;

      entries.add(entry);

      String[] array = entries.toArray(new String[entries.size()]);

      prefs.setValues("guestbook-entries", array);

      try {

        prefs.store();

      } catch (IOException ex) {

        Logger.getLogger(GuestbookPortlet.class.getName()).log(Level.SEVERE, null, ex);

      } catch (ValidatorException ex) {

        Logger.getLogger(GuestbookPortlet.class.getName()).log(Level.SEVERE, null, ex);
      }

    } catch (ReadOnlyException ex) {

      Logger.getLogger(GuestbookPortlet.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
 public void saveName(ActionRequest actionRequest, ActionResponse actionResponse)
     throws IOException, PortletException {
   _log.debug("saveName started");
   final String name =
       ParamUtil.get(actionRequest, MyHelloWorldMVCUtil.REQUEST_PARAM_NAME, StringPool.BLANK);
   final PortletPreferences portletPreferences = actionRequest.getPreferences();
   if (Validator.isBlank(name)) {
     _log.error("Name is blank. You must introduce valid value for name parameter.");
   } else {
     portletPreferences.setValue(MyHelloWorldMVCUtil.PORTLET_PREFERENCES_PARAM_NAME, name);
     _log.info(
         "saving new value ("
             + name
             + ") of "
             + MyHelloWorldMVCUtil.PORTLET_PREFERENCES_PARAM_NAME
             + " on portletPreferences");
     portletPreferences.store();
   }
   // Una vez que terminas la lógica de saveName forward a la vista
   actionResponse.setPortletMode(PortletMode.VIEW);
 }
  /*
   * (non-Javadoc)
   * @see org.jasig.portlet.cms.service.dao.IContentDao#saveContent(javax.portlet.ActionRequest, java.lang.String, java.lang.String)
   */
  public void saveContent(ActionRequest request, String content, String localeKey) {
    try {

      PortletPreferences preferences = request.getPreferences();
      if (StringUtils.isNotBlank(localeKey)) {
        preferences.setValue(getLocaleSpecificKey(localeKey), content);
      } else {
        preferences.setValue(CONTENT_KEY, content);
      }
      preferences.store();

    } catch (ReadOnlyException e) {
      throw new ContentPersistenceException("Failed to save read-only preference", e);
    } catch (ValidatorException e) {
      throw new ContentPersistenceException(
          "Portlet preferences validation error while attempting to persist portlet content", e);
    } catch (IOException e) {
      throw new ContentPersistenceException(
          "IO error while attempting to persist portlet content", e);
    }
  }
  public void process(ActionRequest request, ActionResponse response)
      throws PortletException, IOException {
    final PortletPreferences prefs = request.getPreferences();

    final Boolean stripScriptComments = new Boolean(request.getParameter(SCRIPTSTRIPCOMMENT));
    prefs.setValue(SCRIPTSTRIPCOMMENT, stripScriptComments.toString());

    final Boolean insertDocType = new Boolean(request.getParameter(INSERTDOCTYPE));
    prefs.setValue(INSERTDOCTYPE, insertDocType.toString());

    final Boolean stripComments = new Boolean(request.getParameter(STRIPCOMMENTS));
    prefs.setValue(STRIPCOMMENTS, stripComments.toString());

    final Boolean balanceTags = new Boolean(request.getParameter(BALANCETAGS));
    prefs.setValue(BALANCETAGS, balanceTags.toString());

    final Boolean reportErrors = new Boolean(request.getParameter(REPORTERRORS));
    prefs.setValue(REPORTERRORS, reportErrors.toString());

    prefs.store();
  }
  public void editSupportedClients(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    PortletPreferences portletPreferences = actionRequest.getPreferences();

    actionRequest = ActionUtil.getWrappedActionRequest(actionRequest, portletPreferences);

    Set<String> allPortletModes = portlet.getAllPortletModes();

    for (String portletMode : allPortletModes) {
      String mobileDevicesParam = "portletSetupSupportedClientsMobileDevices_" + portletMode;

      boolean mobileDevices = ParamUtil.getBoolean(actionRequest, mobileDevicesParam);

      portletPreferences.setValue(mobileDevicesParam, String.valueOf(mobileDevices));
    }

    portletPreferences.store();
  }
  @RequestMapping(
      value = {"EDIT"},
      params = {"action=updatePreferences"})
  public void updatePreferences(
      ActionRequest request,
      ActionResponse response,
      @RequestParam(value = "viewUserBox", required = false) String[] viewUserBox,
      @RequestParam(value = "viewManagerBox", required = false) String[] viewManagerBox,
      @RequestParam(value = "userViewMode", required = false) String userViewMode,
      @RequestParam(value = "managerViewMode", required = false) String managerViewMode,
      @RequestParam(value = "viewMaxTickets", required = false) String viewMaxTickets)
      throws Exception {

    final PortletPreferences prefs = request.getPreferences();

    if (userViewMode.equalsIgnoreCase("enable")) {
      if (viewUserBox == null) {
        String[] defUserValues = {"owner"};
        prefs.setValues(WebController.PREF_TAB_USER, defUserValues);
      } else {
        prefs.setValues(WebController.PREF_TAB_USER, viewUserBox);
      }
      prefs.store();
    }
    if (managerViewMode.equalsIgnoreCase("enable")) {
      if (viewManagerBox == null) {
        String[] defManagerValues = {"managed"};
        prefs.setValues(WebController.PREF_TAB_MANAGER, defManagerValues);
      } else {
        prefs.setValues(WebController.PREF_TAB_MANAGER, viewManagerBox);
      }
      prefs.store();
    }
    if ((this.testFieldValue(ALL_NUMBER_REGEX, viewMaxTickets) == SUCCESS)
        && (!prefs.isReadOnly(WebController.PREF_MAX_TICKETS))) {
      prefs.setValue(WebController.PREF_MAX_TICKETS, viewMaxTickets);
      prefs.store();
    }
    response.setPortletMode(PortletMode.VIEW);
  }
  protected void updateScope(ActionRequest actionRequest, Portlet portlet) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String oldScopeName = getOldScopeName(actionRequest, portlet);

    PortletPreferences portletPreferences = actionRequest.getPreferences();

    String[] scopes = StringUtil.split(ParamUtil.getString(actionRequest, "scope"));

    String scopeType = scopes[0];

    portletPreferences.setValue("lfrScopeType", scopeType);

    String scopeLayoutUuid = StringPool.BLANK;

    if ((scopes.length > 1) && scopeType.equals("layout")) {
      scopeLayoutUuid = scopes[1];
    }

    portletPreferences.setValue("lfrScopeLayoutUuid", scopeLayoutUuid);

    String portletTitle = getPortletTitle(actionRequest, portlet, portletPreferences);

    Tuple newScopeTuple = getNewScope(actionRequest);

    String newScopeName = (String) newScopeTuple.getObject(1);

    String newPortletTitle =
        PortalUtil.getNewPortletTitle(portletTitle, oldScopeName, newScopeName);

    if (!newPortletTitle.equals(portletTitle)) {
      portletPreferences.setValue(
          "portletSetupTitle_" + themeDisplay.getLanguageId(), newPortletTitle);
      portletPreferences.setValue("portletSetupUseCustomTitle", Boolean.TRUE.toString());
    }

    portletPreferences.store();
  }
  /**
   * Down article.
   *
   * @param request the request
   * @param response the response
   * @throws PortletException the portlet exception
   * @throws IOException Signals that an I/O exception has occurred.
   * @throws PortalException the portal exception
   * @throws SystemException the system exception
   */
  public void downArticle(ActionRequest request, ActionResponse response)
      throws PortletException, IOException, PortalException, SystemException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    long groupId = themeDisplay.getScopeGroupId();
    request.setAttribute(GROUP_ID, groupId);

    String articleId = ParamUtil.getString(request, ARTICLE_ID);
    PortletPreferences preferences = request.getPreferences();

    String[] ids =
        preferences.getValue(ARTICLE_ID, LR_EMPTY_VALUE).split(ARTICLE_SELECTION_DELIMITER);
    List<String> currentArticles = new ArrayList<String>();
    for (int i = 0; i < ids.length; i++) {
      currentArticles.add(ids[i]);
    }

    int index = currentArticles.indexOf(articleId);
    if (index != (currentArticles.size() - 1)) {
      Collections.swap(currentArticles, index, index + 1);
    }

    String articlesRaw = StringPool.BLANK;
    for (int i = 0; i < currentArticles.size(); i++) {
      articlesRaw += currentArticles.get(i) + StringPool.SPACE;
    }

    updatePreferences(request, response, articlesRaw);
    ids = preferences.getValue(ARTICLE_ID, LR_EMPTY_VALUE).split(ARTICLE_SELECTION_DELIMITER);
    request.setAttribute(IDS, ids);

    String defaultArticle = preferences.getValue(DEFAULT_ARTICLE, LR_EMPTY_VALUE);
    request.setAttribute(DEFAULT_ARTICLE, defaultArticle);

    SessionMessages.add(request, ARTICLE_UP_DOWN);

    sendRedirect(request, response);
  }
Example #22
0
  private void getPortletInfo(ActionRequest actionRequest) {
    log.info("getPortletInfo");
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PortletConfig portletConfig =
        (PortletConfig) actionRequest.getAttribute("javax.portlet.config");
    _portletName = portletConfig.getPortletName();
    PortletURL pURL =
        PortletURLFactoryUtil.create(
            actionRequest,
            _portletName + "_WAR_" + _portletName + "portlet",
            themeDisplay.getPlid(),
            PortletRequest.ACTION_PHASE);
    /*try {
    	pURL.setWindowState(WindowState.NORMAL );
    } catch (WindowStateException e1) {
    	// TODO Auto-generated catch block
    	e1.printStackTrace();
    }*/
    pURL.setParameter(ActionRequest.ACTION_NAME, ProxyConstant.ACTION_LINK);
    _portletURL = pURL.toString();

    // read portlet config;
    PortletPreferences preferences = actionRequest.getPreferences();
    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    if (Validator.isNotNull(portletResource)) {
      try {
        preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);
      } catch (PortalException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (SystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    _proxyURL = preferences.getValue("url", "");
  } /*
  public void processAction(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    if (!Constants.UPDATE.equals(actionRequest.getParameter(Constants.CMD))) {
      return;
    }

    PortletPreferences prefs;
    String portletResource = ParamUtil.getString(actionRequest, "portletResource");
    if (Validator.isNotNull(portletResource)) {
      prefs = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);
    } else {
      prefs = actionRequest.getPreferences();
    }

    prefs.setValue("showActionSocial", actionRequest.getParameter("showActionSocial"));
    prefs.setValue("showActionAudit", actionRequest.getParameter("showActionAudit"));

    prefs.store();
    SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doConfigure");
    // SessionMessages.add(actionRequest,"success");
  }
  public void processAction(ActionRequest request, ActionResponse response)
      throws PortletException, java.io.IOException {
    String action = request.getParameter("action");
    if ("send".equals(action)) {
      String toEmail = request.getParameter("toEmail");
      String cc = request.getParameter("cc");
      String bcc = request.getParameter("bcc");
      String subject = request.getParameter("subject");
      String content = request.getParameter("content");
      if (subject == null || subject.length() <= 0 || toEmail == null || toEmail.length() <= 0) {
        request.setAttribute("error", "Message's to and subject are required field.");
        response.setPortletMode(PortletMode.EDIT);
        response.setRenderParameter("type", "create");
        return;
      }
      try {
        PortletPreferences portletPreferences = request.getPreferences();
        String fullName = portletPreferences.getValue("fullName", null);
        String incomingType = portletPreferences.getValue("incomingType", null);
        String incoming = portletPreferences.getValue("incoming", null);
        String incomingPort = portletPreferences.getValue("incomingPort", null);
        String incomingSSL = portletPreferences.getValue("incomingSSL", null);
        String outgoing = portletPreferences.getValue("outgoing", null);
        String outgoingPort = portletPreferences.getValue("outgoingPort", null);
        String outgoingSSL = portletPreferences.getValue("outgoingSSL", null);
        String email = portletPreferences.getValue("email", null);
        String password = portletPreferences.getValue("password", null);

        EmailClient client =
            new EmailClient(
                fullName,
                email,
                password,
                incomingType,
                incoming,
                incomingPort,
                incomingSSL,
                outgoing,
                outgoingPort,
                outgoingPort);
        client.sendMessage(toEmail, cc, bcc, subject, content);
      } catch (Exception e) {
        request.setAttribute("error", e.getMessage());
      }
    } else if ("reply".equals(action)) {
      String page = request.getParameter("pageId");
      if (page == null) page = "1";
      int pageId = Integer.parseInt(page);
      String toEmail = request.getParameter("toEmail");
      String subject = request.getParameter("subject");
      String content = request.getParameter("content");
      request.setAttribute("toEmail", toEmail);
      request.setAttribute("subject", "Re: " + subject);
      request.setAttribute("content", content);
      request.setAttribute("pageId", pageId);
      response.setPortletMode(PortletMode.EDIT);
      response.setRenderParameter("type", "create");
    } else if ("config".equals(action)) {
      String fullName = request.getParameter("fullName");
      String incomingType = request.getParameter("incomingType");
      String incoming = request.getParameter("incoming");
      String incomingPort = request.getParameter("incomingPort");
      String incomingSSL = request.getParameter("incomingSSL");
      String outgoing = request.getParameter("outgoing");
      String outgoingPort = request.getParameter("outgoingPort");
      String outgoingSSL = request.getParameter("outgoingSSL");
      String email = request.getParameter("email");
      String password = request.getParameter("password");
      String number = request.getParameter("number");
      if (incoming == null
          || incoming.length() <= 0
          || outgoing == null
          || outgoing.length() <= 0
          || email == null
          || email.length() <= 0
          || password == null
          || password.length() <= 0) {
        request.setAttribute("error", "Please input all required fields.");
        request.setAttribute("mode", "config");
        return;
      }
      PortletPreferences portletPreferences = request.getPreferences();
      portletPreferences.setValue("fullName", fullName);
      portletPreferences.setValue("incomingType", incomingType);
      portletPreferences.setValue("incoming", incoming);
      portletPreferences.setValue("incomingPort", incomingPort);
      portletPreferences.setValue("incomingSSL", incomingSSL);
      portletPreferences.setValue("outgoing", outgoing);
      portletPreferences.setValue("outgoingPort", outgoingPort);
      portletPreferences.setValue("outgoingSSL", outgoingSSL);
      portletPreferences.setValue("email", email);
      portletPreferences.setValue("password", password);
      portletPreferences.setValue("number", number);
      portletPreferences.store();
      request.getPortletSession().removeAttribute("mails", PortletSession.PORTLET_SCOPE);
    } else if ("delete".equals(action)) {
      if (request.getParameter("parameter") != null) {
        int index = Integer.parseInt(request.getParameter("parameter"));
        List<MailBean> mails =
            (List<MailBean>)
                request.getPortletSession().getAttribute("mails", PortletSession.PORTLET_SCOPE);
        PortletPreferences portletPreferences = request.getPreferences();
        String incomingType = portletPreferences.getValue("incomingType", null);
        String incoming = portletPreferences.getValue("incoming", null);
        String incomingPort = portletPreferences.getValue("incomingPort", null);
        String incomingSSL = portletPreferences.getValue("incomingSSL", null);
        String outgoing = portletPreferences.getValue("outgoing", null);
        String outgoingPort = portletPreferences.getValue("outgoingPort", null);
        String outgoingSSL = portletPreferences.getValue("outgoingSSL", null);
        String email = portletPreferences.getValue("email", null);
        String password = portletPreferences.getValue("password", null);
        EmailClient client =
            new EmailClient(
                email,
                password,
                incomingType,
                incoming,
                incomingPort,
                incomingSSL,
                outgoing,
                outgoingPort,
                outgoingPort);
        try {
          client.deleteMessage(mails.get(index).getMsg());
          request.getPortletSession().removeAttribute("mails", PortletSession.PORTLET_SCOPE);
        } catch (Exception e) {
          request.setAttribute("error", e.getMessage());
        }
      }
    } else {
      String showHtmlEditor = request.getParameter("htmlEditor");
      if (showHtmlEditor != null) request.setAttribute("showHtmlEditor", true);
      String toEmail = request.getParameter("toEmail");
      if (toEmail != null) {
        request.setAttribute("toEmail", toEmail);
      }
      String cc = request.getParameter("cc");
      if (cc != null) {
        request.setAttribute("cc", cc);
      }
      String bcc = request.getParameter("bcc");
      if (bcc != null) {
        request.setAttribute("subject", bcc);
      }
      String subject = request.getParameter("subject");
      if (subject != null) {
        request.setAttribute("subject", subject);
      }
      String content = request.getParameter("content");
      if (content != null) {
        request.setAttribute("content", content);
      }
      response.setRenderParameter("type", "create");
    }
  }
  @Override
  public void processAction(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    validateFields(actionRequest);

    if (!SessionErrors.isEmpty(actionRequest)) {
      return;
    }

    Locale defaultLocale = LocaleUtil.getDefault();
    String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);

    boolean updateFields = ParamUtil.getBoolean(actionRequest, "updateFields");

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    PortletPreferences preferences = actionRequest.getPreferences();

    LocalizationUtil.setLocalizedPreferencesValues(actionRequest, preferences, "title");
    LocalizationUtil.setLocalizedPreferencesValues(actionRequest, preferences, "description");

    if (updateFields) {
      int i = 1;

      String databaseTableName = WebFormUtil.getNewDatabaseTableName(portletResource);

      preferences.setValue("databaseTableName", databaseTableName);

      int[] formFieldsIndexes =
          StringUtil.split(ParamUtil.getString(actionRequest, "formFieldsIndexes"), 0);

      for (int formFieldsIndex : formFieldsIndexes) {
        Map<Locale, String> fieldLabelMap =
            LocalizationUtil.getLocalizationMap(actionRequest, "fieldLabel" + formFieldsIndex);

        if (Validator.isNull(fieldLabelMap.get(defaultLocale))) {
          continue;
        }

        String fieldType = ParamUtil.getString(actionRequest, "fieldType" + formFieldsIndex);
        boolean fieldOptional =
            ParamUtil.getBoolean(actionRequest, "fieldOptional" + formFieldsIndex);
        Map<Locale, String> fieldOptionsMap =
            LocalizationUtil.getLocalizationMap(actionRequest, "fieldOptions" + formFieldsIndex);
        String fieldValidationScript =
            ParamUtil.getString(actionRequest, "fieldValidationScript" + formFieldsIndex);
        String fieldValidationErrorMessage =
            ParamUtil.getString(actionRequest, "fieldValidationErrorMessage" + formFieldsIndex);

        if (Validator.isNotNull(fieldValidationScript)
            ^ Validator.isNotNull(fieldValidationErrorMessage)) {

          SessionErrors.add(actionRequest, "validationDefinitionInvalid" + i);
        }

        updateModifiedLocales("fieldLabel" + i, fieldLabelMap, preferences);
        updateModifiedLocales("fieldOptions" + i, fieldOptionsMap, preferences);

        preferences.setValue("fieldType" + i, fieldType);
        preferences.setValue("fieldOptional" + i, String.valueOf(fieldOptional));
        preferences.setValue("fieldValidationScript" + i, fieldValidationScript);
        preferences.setValue("fieldValidationErrorMessage" + i, fieldValidationErrorMessage);

        i++;
      }

      if (!SessionErrors.isEmpty(actionRequest)) {
        return;
      }

      // Clear previous preferences that are now blank

      String fieldLabel =
          LocalizationUtil.getPreferencesValue(preferences, "fieldLabel" + i, defaultLanguageId);

      while (Validator.isNotNull(fieldLabel)) {
        Map<Locale, String> fieldLabelMap =
            LocalizationUtil.getLocalizationMap(actionRequest, "fieldLabel" + i);

        for (Locale locale : fieldLabelMap.keySet()) {
          String languageId = LocaleUtil.toLanguageId(locale);

          LocalizationUtil.setPreferencesValue(
              preferences, "fieldLabel" + i, languageId, StringPool.BLANK);

          LocalizationUtil.setPreferencesValue(
              preferences, "fieldOptions" + i, languageId, StringPool.BLANK);
        }

        preferences.setValue("fieldType" + i, StringPool.BLANK);
        preferences.setValue("fieldOptional" + i, StringPool.BLANK);
        preferences.setValue("fieldValidationScript" + i, StringPool.BLANK);
        preferences.setValue("fieldValidationErrorMessage" + i, StringPool.BLANK);

        i++;

        fieldLabel =
            LocalizationUtil.getPreferencesValue(preferences, "fieldLabel" + i, defaultLanguageId);
      }
    }

    if (SessionErrors.isEmpty(actionRequest)) {
      preferences.store();
    }

    super.processAction(portletConfig, actionRequest, actionResponse);
  }