protected void updateConfiguration(ActionRequest req, PortletPreferences prefs) throws Exception {

    String[] urls = req.getParameterValues("url");
    String[] titles = req.getParameterValues("title");
    int entriesPerFeed = ParamUtil.getInteger(req, "entriesPerFeed", 4);
    boolean showFeedTitle = ParamUtil.getBoolean(req, "showFeedTitle");
    boolean showFeedPublishedDate = ParamUtil.getBoolean(req, "showFeedPublishedDate");
    boolean showFeedDescription = ParamUtil.getBoolean(req, "showFeedDescription");
    boolean showFeedImage = ParamUtil.getBoolean(req, "showFeedImage");
    String feedImageAlignment = ParamUtil.getString(req, "feedImageAlignment");
    long headerArticleResouceId = ParamUtil.getLong(req, "headerArticleResouceId");
    long footerArticleResouceId = ParamUtil.getLong(req, "footerArticleResouceId");

    if (urls != null && titles != null) {
      prefs.setValues("urls", urls);
      prefs.setValues("titles", titles);
    } else {
      prefs.setValues("urls", new String[0]);
      prefs.setValues("titles", new String[0]);
    }

    prefs.setValue("items-per-channel", String.valueOf(entriesPerFeed));
    prefs.setValue("show-feed-title", String.valueOf(showFeedTitle));
    prefs.setValue("show-feed-published-date", String.valueOf(showFeedPublishedDate));
    prefs.setValue("show-feed-description", String.valueOf(showFeedDescription));
    prefs.setValue("show-feed-image", String.valueOf(showFeedImage));
    prefs.setValue("feed-image-alignment", String.valueOf(feedImageAlignment));
    prefs.setValue("header-article-resouce-id", String.valueOf(headerArticleResouceId));
    prefs.setValue("footer-article-resouce-id", String.valueOf(footerArticleResouceId));
  }
Esempio n. 2
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
    }
  }
  private void loadEveryDayForm(ActionForm form, ActionRequest req) {
    String[] everyDay = req.getParameterValues("everyDay");

    ContentImporterForm contentImporterForm = (ContentImporterForm) form;
    if (UtilMethods.isSet(everyDay) && contentImporterForm.isEveryInfo()) {
      for (String dayOfWeek : everyDay) {
        if (dayOfWeek.equals("MON")) contentImporterForm.setMonday(true);
        else if (dayOfWeek.equals("TUE")) contentImporterForm.setTuesday(true);
        else if (dayOfWeek.equals("WED")) contentImporterForm.setWednesday(true);
        else if (dayOfWeek.equals("THU")) contentImporterForm.setThusday(true);
        else if (dayOfWeek.equals("FRI")) contentImporterForm.setFriday(true);
        else if (dayOfWeek.equals("SAT")) contentImporterForm.setSaturday(true);
        else if (dayOfWeek.equals("SUN")) contentImporterForm.setSunday(true);
      }

      contentImporterForm.setEveryInfo(true);
      contentImporterForm.setEvery("isDays");
    } else {
      contentImporterForm.setEvery("");
      contentImporterForm.setMonday(false);
      contentImporterForm.setTuesday(false);
      contentImporterForm.setWednesday(false);
      contentImporterForm.setThusday(false);
      contentImporterForm.setFriday(false);
      contentImporterForm.setSaturday(false);
      contentImporterForm.setSunday(false);
    }
  }
 /**
  * Pass all the action request parameters to the render phase by putting them into the action
  * response object. This may not be called when the action will call {@link
  * javax.portlet.ActionResponse#sendRedirect sendRedirect}.
  *
  * @param request the current action request
  * @param response the current action response
  * @see javax.portlet.ActionResponse#setRenderParameter
  */
 public static void passAllParametersToRenderPhase(
     ActionRequest request, ActionResponse response) {
   try {
     Enumeration<String> en = request.getParameterNames();
     while (en.hasMoreElements()) {
       String param = en.nextElement();
       String values[] = request.getParameterValues(param);
       response.setRenderParameter(param, values);
     }
   } catch (IllegalStateException ex) {
     // Ignore in case sendRedirect was already set.
   }
 }
  protected void updateDisplaySettings(ActionRequest actionRequest, PortletPreferences preferences)
      throws Exception {

    String displayStyle = ParamUtil.getString(actionRequest, "displayStyle");
    boolean anyAssetType = ParamUtil.getBoolean(actionRequest, "anyAssetType");
    long[] classNameIds = StringUtil.split(ParamUtil.getString(actionRequest, "classNameIds"), 0L);
    boolean showAssetTitle = ParamUtil.getBoolean(actionRequest, "showAssetTitle");
    boolean showContextLink = ParamUtil.getBoolean(actionRequest, "showContextLink");
    int abstractLength = ParamUtil.getInteger(actionRequest, "abstractLength");
    String assetLinkBehaviour = ParamUtil.getString(actionRequest, "assetLinkBehaviour");
    boolean showAvailableLocales = ParamUtil.getBoolean(actionRequest, "showAvailableLocales");
    String[] extensions = actionRequest.getParameterValues("extensions");
    boolean enablePrint = ParamUtil.getBoolean(actionRequest, "enablePrint");
    boolean enableFlags = ParamUtil.getBoolean(actionRequest, "enableFlags");
    boolean enableRatings = ParamUtil.getBoolean(actionRequest, "enableRatings");
    boolean enableComments = ParamUtil.getBoolean(actionRequest, "enableComments");
    boolean enableCommentRatings = ParamUtil.getBoolean(actionRequest, "enableCommentRatings");
    boolean enableTagBasedNavigation =
        ParamUtil.getBoolean(actionRequest, "enableTagBasedNavigation");
    String medatadaFields = ParamUtil.getString(actionRequest, "metadataFields");

    preferences.setValue("selection-style", "manual");
    preferences.setValue("display-style", displayStyle);
    preferences.setValue("any-asset-type", String.valueOf(anyAssetType));
    preferences.setValues("class-name-ids", ArrayUtil.toStringArray(classNameIds));
    preferences.setValue("show-asset-title", String.valueOf(showAssetTitle));
    preferences.setValue("show-context-link", String.valueOf(showContextLink));
    preferences.setValue("abstract-length", String.valueOf(abstractLength));
    preferences.setValue("asset-link-behaviour", assetLinkBehaviour);
    preferences.setValue("show-available-locales", String.valueOf(showAvailableLocales));
    preferences.setValues("extensions", extensions);
    preferences.setValue("enable-print", String.valueOf(enablePrint));
    preferences.setValue("enable-flags", String.valueOf(enableFlags));
    preferences.setValue("enable-ratings", String.valueOf(enableRatings));
    preferences.setValue("enable-comments", String.valueOf(enableComments));
    preferences.setValue("enable-comment-ratings", String.valueOf(enableCommentRatings));
    preferences.setValue("enable-tag-based-navigation", String.valueOf(enableTagBasedNavigation));
    preferences.setValue("metadata-fields", medatadaFields);
  }
  protected void updateDynamicSettings(ActionRequest actionRequest, PortletPreferences preferences)
      throws Exception {

    updateDisplaySettings(actionRequest, preferences);
    updateQueryLogic(actionRequest, preferences);
    updateRssSettings(actionRequest, preferences);

    boolean mergeUrlTags = ParamUtil.getBoolean(actionRequest, "mergeUrlTags");
    boolean defaultScope = ParamUtil.getBoolean(actionRequest, "defaultScope");
    String[] scopeIds = StringUtil.split(ParamUtil.getString(actionRequest, "scopeIds"));
    long assetVocabularyId = ParamUtil.getLong(actionRequest, "assetVocabularyId");
    String orderByColumn1 = ParamUtil.getString(actionRequest, "orderByColumn1");
    String orderByColumn2 = ParamUtil.getString(actionRequest, "orderByColumn2");
    String orderByType1 = ParamUtil.getString(actionRequest, "orderByType1");
    String orderByType2 = ParamUtil.getString(actionRequest, "orderByType2");
    boolean excludeZeroViewCount = ParamUtil.getBoolean(actionRequest, "excludeZeroViewCount");
    boolean showQueryLogic = ParamUtil.getBoolean(actionRequest, "showQueryLogic");
    int delta = ParamUtil.getInteger(actionRequest, "delta");
    String paginationType = ParamUtil.getString(actionRequest, "paginationType");
    String[] extensions = actionRequest.getParameterValues("extensions");

    preferences.setValue("selection-style", "dynamic");
    preferences.setValue("merge-url-tags", String.valueOf(mergeUrlTags));
    preferences.setValue("default-scope", String.valueOf(defaultScope));
    preferences.setValues("scope-ids", ArrayUtil.toStringArray(scopeIds));
    preferences.setValue("asset-vocabulary-id", String.valueOf(assetVocabularyId));
    preferences.setValue("order-by-column-1", orderByColumn1);
    preferences.setValue("order-by-column-2", orderByColumn2);
    preferences.setValue("order-by-type-1", orderByType1);
    preferences.setValue("order-by-type-2", orderByType2);
    preferences.setValue("exclude-zero-view-count", String.valueOf(excludeZeroViewCount));
    preferences.setValue("show-query-logic", String.valueOf(showQueryLogic));
    preferences.setValue("delta", String.valueOf(delta));
    preferences.setValue("pagination-type", paginationType);
    preferences.setValues("extensions", extensions);
  }
  @Override
  public void processAction(ActionRequest request, ActionResponse response)
      throws PortletException, IOException {
    String ctx = request.getContextPath();
    boolean isClose = "true".equals(request.getParameter("close"));

    if (isClose) {
      // Clean up the session
      LOG.debug("Closing the form");
      request.getPortletSession().removeAttribute(VIEW_TYPE);
      response.sendRedirect(ctx + CLOSE_PAGE);
      return;
    }

    int projectIdToBookmark = Integer.valueOf(request.getParameter(PROJECT_ID_TO_BOOKMARK));
    int projectIdOfLists = Integer.valueOf(request.getParameter(PROJECT_ID_OF_LISTS));
    String newListName = request.getParameter(NEW_LIST_NAME);

    // If the user selected an item in the drop-down, then that means they are
    // changing lists
    int pidToCompare = Integer.valueOf(request.getParameter("pidToCompare"));
    boolean isChangePidOfLists = pidToCompare != projectIdOfLists;
    if (isChangePidOfLists) {
      LOG.debug("A new project has been selected: " + projectIdOfLists);
      response.setRenderParameter(PROJECT_ID_OF_LISTS, String.valueOf(projectIdOfLists));
      return;
    }

    try {
      LOG.debug("Saving the form...");

      boolean isSuccess;

      User user = PortalUtils.getUser(request);
      int userId = user.getId();
      Connection db = PortalUtils.useConnection(request);
      Project projectOfLists = new Project(db, projectIdOfLists);
      Project projectToBookmark = new Project(db, projectIdToBookmark);
      Collection<Integer> listIds = getListIds(request.getParameterValues(LIST));
      // verify user can modify lists for project
      boolean isAddNewList = false;
      if (ProjectUtils.hasAccess(projectOfLists.getId(), user, "project-lists-modify")) {

        if (!StringUtils.hasText(newListName) && (listIds.size() == 0)) {
          System.out.println("Error need to show From");
          request.getPortletSession().setAttribute(ACTION_ERROR, "Choose a list or create one");
          request.getPortletSession().setAttribute(VIEW_TYPE, VIEW_FORM_PAGE);
          return;
        }

        if (StringUtils.hasText(newListName)) {
          if (!ProjectUtils.hasAccess(projectOfLists.getId(), user, "project-lists-add")) {
            request
                .getPortletSession()
                .setAttribute(ACTION_ERROR, "Not authorized to create new list");
            request.getPortletSession().setAttribute(VIEW_TYPE, VIEW_FORM_PAGE);
            return;
          }
          int newListId = saveNewList(db, projectIdOfLists, newListName);
          if (newListId == -1) {
            request.getPortletSession().setAttribute(ACTION_ERROR, "Unable to create new list.");
            request.getPortletSession().setAttribute(VIEW_TYPE, SAVE_FAILURE);
            return;
          } else {
            listIds.add(newListId);
            isAddNewList = true;
          }
        }
        TaskList existingTasks =
            findExistingTasksForProjects(db, projectIdOfLists, projectIdToBookmark);
        // check to see if the user is deleting tasks (listItems)
        if ((isAddNewList && existingTasks.size() > listIds.size() - 1)
            || !isAddNewList && existingTasks.size() > listIds.size()) {
          if (!ProjectUtils.hasAccess(projectOfLists.getId(), user, "project-lists-delete")) {
            request
                .getPortletSession()
                .setAttribute(ACTION_ERROR, "Not authorized to delete items");
            request.getPortletSession().setAttribute(VIEW_TYPE, VIEW_FORM_PAGE);
            return;
          } else {
            deleteFromLists(db, existingTasks, listIds);
          }
        }
        isSuccess =
            saveToLists(
                db,
                existingTasks,
                listIds,
                userId,
                projectIdToBookmark,
                projectToBookmark.getTitle(),
                projectIdOfLists,
                request);
      } else {
        isSuccess = false;
        request.getPortletSession().setAttribute(ACTION_ERROR, "Not authorized to bookmark");
      }

      if (isSuccess) {
        // Close the panel, everything went well
        response.sendRedirect(ctx + "/close_panel_refresh.jsp");
      } else {
        request.getPortletSession().setAttribute(VIEW_TYPE, SAVE_FAILURE);
      }
    } catch (SQLException e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }
Esempio n. 8
0
  public void updateKBArticle(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    String portletId = PortalUtil.getPortletId(actionRequest);

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

    long resourcePrimKey = ParamUtil.getLong(actionRequest, "resourcePrimKey");

    long parentResourcePrimKey = ParamUtil.getLong(actionRequest, "parentResourcePrimKey");
    String title = ParamUtil.getString(actionRequest, "title");
    String content = ParamUtil.getString(actionRequest, "content");
    String description = ParamUtil.getString(actionRequest, "description");
    String[] sections = actionRequest.getParameterValues("sections");
    String dirName = ParamUtil.getString(actionRequest, "dirName");
    int workflowAction = ParamUtil.getInteger(actionRequest, "workflowAction");

    KBArticle kbArticle = null;

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(KBArticle.class.getName(), actionRequest);

    if (cmd.equals(Constants.ADD)) {
      kbArticle =
          KBArticleServiceUtil.addKBArticle(
              portletId,
              parentResourcePrimKey,
              title,
              content,
              description,
              sections,
              dirName,
              serviceContext);
    } else if (cmd.equals(Constants.UPDATE)) {
      kbArticle =
          KBArticleServiceUtil.updateKBArticle(
              resourcePrimKey, title, content, description, sections, dirName, serviceContext);
    }

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

    if (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT) {
      String namespace = actionResponse.getNamespace();
      String redirect = getRedirect(actionRequest, actionResponse);

      String editURL = PortalUtil.getLayoutFullURL(themeDisplay);

      editURL = HttpUtil.setParameter(editURL, "p_p_id", PortletKeys.KNOWLEDGE_BASE_ADMIN);
      editURL =
          HttpUtil.setParameter(editURL, namespace + "mvcPath", templatePath + "edit_article.jsp");
      editURL = HttpUtil.setParameter(editURL, namespace + "redirect", redirect);
      editURL =
          HttpUtil.setParameter(
              editURL, namespace + "resourcePrimKey", kbArticle.getResourcePrimKey());

      actionRequest.setAttribute(WebKeys.REDIRECT, editURL);
    }
  }
  private static boolean _saveScheduler(
      ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form, User user)
      throws Exception {
    boolean result = false;
    ContentImporterForm contentImporterForm = (ContentImporterForm) form;

    SimpleDateFormat sdf = new SimpleDateFormat(WebKeys.DateFormats.DOTSCHEDULER_DATE2);

    Date startDate = null;
    if (contentImporterForm.isHaveStartDate()) {
      try {
        startDate = sdf.parse(contentImporterForm.getStartDate());
      } catch (Exception e) {
      }
    }

    Date endDate = null;
    if (contentImporterForm.isHaveEndDate()) {
      try {
        endDate = sdf.parse(contentImporterForm.getEndDate());
      } catch (Exception e) {
      }
    }

    Map<String, Object> properties = new HashMap<String, Object>(10);

    properties.put("structure", "" + contentImporterForm.getStructure());

    if ((contentImporterForm.getFields() != null) && (0 < contentImporterForm.getFields().length)) {
      StringBuilder fields = new StringBuilder(64);
      fields.ensureCapacity(8);
      for (String field : contentImporterForm.getFields()) {
        if (0 < fields.length()) fields.append("," + field);
        else fields.append(field);
      }

      properties.put("fields", fields.toString());
    }

    if (UtilMethods.isSet(contentImporterForm.getFilePath()))
      properties.put("filePath", contentImporterForm.getFilePath());

    if (UtilMethods.isSet(contentImporterForm.getReportEmail()))
      properties.put("reportEmail", contentImporterForm.getReportEmail());

    if (UtilMethods.isSet(contentImporterForm.getCsvSeparatorDelimiter()))
      properties.put("csvSeparatorDelimiter", contentImporterForm.getCsvSeparatorDelimiter());

    if (UtilMethods.isSet(contentImporterForm.getCsvTextDelimiter()))
      properties.put("csvTextDelimiter", contentImporterForm.getCsvTextDelimiter());

    if (UtilMethods.isSet(contentImporterForm.getLanguage()))
      properties.put("language", Long.toString(contentImporterForm.getLanguage()));

    if (contentImporterForm.isPublishContent()) properties.put("publishContent", "true");
    else properties.put("publishContent", "false");

    if (contentImporterForm.isDeleteAllContent()) properties.put("deleteAllContent", "true");
    else properties.put("deleteAllContent", "false");

    if (contentImporterForm.isSaveWithoutVersions()) properties.put("saveWithoutVersions", "true");
    else properties.put("saveWithoutVersions", "false");

    properties.put("haveCronExpression", contentImporterForm.isHaveCronExpression());

    String cronSecondsField = "0";
    String cronMinutesField = "0";
    String cronHoursField = "*";
    String cronDaysOfMonthField = "*";
    String cronMonthsField = "*";
    String cronDaysOfWeekField = "?";
    String cronYearsField = "*";

    String cronExpression = "";

    if (contentImporterForm.isHaveCronExpression()) {
      cronExpression = contentImporterForm.getCronExpression();
    } else {
      if (contentImporterForm.isAtInfo()) {
        if (UtilMethods.isSet(req.getParameter("at")) && req.getParameter("at").equals("isTime")) {
          cronSecondsField = req.getParameter("atTimeSecond");
          cronMinutesField = req.getParameter("atTimeMinute");
          cronHoursField = req.getParameter("atTimeHour");
        }

        if (UtilMethods.isSet(req.getParameter("at"))
            && req.getParameter("at").equals("isBetween")) {
          cronHoursField =
              req.getParameter("betweenFromHour") + "-" + req.getParameter("betweenToHour");
        }
      }

      if (contentImporterForm.isEveryInfo()) {
        if (UtilMethods.isSet(req.getParameter("every"))
            && req.getParameter("every").equals("isDate")) {
          cronDaysOfMonthField = req.getParameter("everyDateDay");

          try {
            cronMonthsField = "" + (Integer.parseInt(req.getParameter("everyDateMonth")) + 1);
          } catch (Exception e) {
          }

          cronYearsField = req.getParameter("everyDateYear");
        }

        if (UtilMethods.isSet(req.getParameter("every"))
            && req.getParameter("every").equals("isDays")) {
          cronDaysOfMonthField = "?";

          String[] daysOfWeek = req.getParameterValues("everyDay");

          cronDaysOfWeekField = "";
          for (String day : daysOfWeek) {
            if (cronDaysOfWeekField.length() == 0) {
              cronDaysOfWeekField = day;
            } else {
              cronDaysOfWeekField = cronDaysOfWeekField + "," + day;
            }
          }
        }
      }

      if (UtilMethods.isSet(req.getParameter("eachInfo"))) {
        if (UtilMethods.isSet(req.getParameter("eachHours"))) {
          try {
            int eachHours = Integer.parseInt(req.getParameter("eachHours"));
            cronHoursField = cronHoursField + "/" + eachHours;
          } catch (Exception e) {
          }
        }

        if (UtilMethods.isSet(req.getParameter("eachMinutes"))) {
          try {
            int eachMinutes = Integer.parseInt(req.getParameter("eachMinutes"));
            cronMinutesField = cronMinutesField + "/" + eachMinutes;
          } catch (Exception e) {
          }
        }
      }

      cronExpression =
          cronSecondsField
              + " "
              + cronMinutesField
              + " "
              + cronHoursField
              + " "
              + cronDaysOfMonthField
              + " "
              + cronMonthsField
              + " "
              + cronDaysOfWeekField
              + " "
              + cronYearsField;
    }
    CronScheduledTask job = new CronScheduledTask();
    job.setJobName(contentImporterForm.getJobName());
    job.setJobGroup(contentImporterForm.getJobGroup());
    job.setJobDescription(contentImporterForm.getJobDescription());
    job.setJavaClassName("org.dotcms.plugins.contentImporter.quartz.ContentImporterThread");
    job.setProperties(properties);
    job.setStartDate(startDate);
    job.setEndDate(endDate);
    job.setCronExpression(cronExpression);

    try {
      QuartzUtils.scheduleTask(job);
    } catch (Exception e) {
      Logger.error(EditContentImporterJobAction.class, e.getMessage(), e);
      return false;
    }

    SessionMessages.add(req, "message", "message.Scheduler.saved");

    return true;
  }