public static void getArticle(HttpServletRequest request) throws Exception {
    long groupId = ParamUtil.getLong(request, "groupId");
    long classNameId = ParamUtil.getLong(request, "classNameId");
    long classPK = ParamUtil.getLong(request, "classPK");
    String articleId = ParamUtil.getString(request, "articleId");
    String structureId = ParamUtil.getString(request, "structureId");

    JournalArticle article = null;

    if (Validator.isNotNull(articleId)) {
      article =
          JournalArticleServiceUtil.getLatestArticle(
              groupId, articleId, WorkflowConstants.STATUS_ANY);
    } else if ((classNameId > 0) && (classPK > 0)) {
      String className = PortalUtil.getClassName(classNameId);

      article = JournalArticleServiceUtil.getLatestArticle(groupId, className, classPK);
    } else if (Validator.isNotNull(structureId)) {
      JournalStructure structure = null;

      try {
        structure = JournalStructureServiceUtil.getStructure(groupId, structureId);
      } catch (NoSuchStructureException nsse1) {
        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

        if (groupId == themeDisplay.getCompanyGroupId()) {
          return;
        }

        try {
          structure =
              JournalStructureServiceUtil.getStructure(
                  themeDisplay.getCompanyGroupId(), structureId);
        } catch (NoSuchStructureException nsse2) {
          return;
        }
      }

      article =
          JournalArticleServiceUtil.getArticle(
              groupId, JournalStructure.class.getName(), structure.getId());

      article.setNew(true);

      article.setId(0);
      article.setClassNameId(0);
      article.setClassPK(0);
      article.setArticleId(null);
      article.setVersion(0);
    }

    request.setAttribute(WebKeys.JOURNAL_ARTICLE, article);
  }
Пример #2
0
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    try {
      long groupId = ParamUtil.getLong(request, "groupId");
      String articleId = ParamUtil.getString(request, "articleId");

      String languageId = LanguageUtil.getLanguageId(request);

      JournalArticle article =
          JournalArticleServiceUtil.getLatestArticle(
              groupId, articleId, WorkflowConstants.STATUS_APPROVED);

      String fileName = "content.xml";
      byte[] bytes = article.getContentByLocale(languageId).getBytes();

      ServletResponseUtil.sendFile(request, response, fileName, bytes, ContentTypes.TEXT_XML_UTF8);

      return null;
    } catch (Exception e) {
      PortalUtil.sendError(e, request, response);

      return null;
    }
  }
  protected void copyArticle(PortletRequest portletRequest) throws Exception {
    long groupId = ParamUtil.getLong(portletRequest, "groupId");
    String oldArticleId = ParamUtil.getString(portletRequest, "oldArticleId");
    String newArticleId = ParamUtil.getString(portletRequest, "newArticleId");
    boolean autoArticleId = ParamUtil.getBoolean(portletRequest, "autoArticleId");
    double version = ParamUtil.getDouble(portletRequest, "version");

    JournalArticleServiceUtil.copyArticle(
        groupId, oldArticleId, newArticleId, autoArticleId, version);
  }
Пример #4
0
  protected void moveEntries(ActionRequest actionRequest) throws Exception {
    long newFolderId = ParamUtil.getLong(actionRequest, "newFolderId");

    long[] folderIds = StringUtil.split(ParamUtil.getString(actionRequest, "folderIds"), 0L);

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

    for (long folderId : folderIds) {
      JournalFolderServiceUtil.moveFolder(folderId, newFolderId, serviceContext);
    }

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

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

    for (String articleId : articleIds) {
      JournalArticleServiceUtil.moveArticle(themeDisplay.getScopeGroupId(), articleId, newFolderId);
    }
  }
Пример #5
0
  protected void deleteEntries(ActionRequest actionRequest, boolean moveToTrash) throws Exception {

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

    List<TrashedModel> trashedModels = new ArrayList<TrashedModel>();

    long[] deleteFolderIds = StringUtil.split(ParamUtil.getString(actionRequest, "folderIds"), 0L);

    for (long deleteFolderId : deleteFolderIds) {
      if (moveToTrash) {
        JournalFolder folder = JournalFolderServiceUtil.moveFolderToTrash(deleteFolderId);

        trashedModels.add(folder);
      } else {
        JournalFolderServiceUtil.deleteFolder(deleteFolderId);
      }
    }

    String[] deleteArticleIds = StringUtil.split(ParamUtil.getString(actionRequest, "articleIds"));

    for (String deleteArticleId : deleteArticleIds) {
      if (moveToTrash) {
        JournalArticle article =
            JournalArticleServiceUtil.moveArticleToTrash(
                themeDisplay.getScopeGroupId(), deleteArticleId);

        trashedModels.add(article);
      } else {
        ActionUtil.deleteArticle(actionRequest, deleteArticleId);
      }
    }

    if (moveToTrash && !trashedModels.isEmpty()) {
      TrashUtil.addTrashSessionMessages(actionRequest, trashedModels);

      hideDefaultSuccessMessage(actionRequest);
    }
  }
Пример #6
0
  protected void visitArticles(Element element, Layout layout, ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    List<JournalArticle> journalArticles =
        JournalArticleServiceUtil.getArticlesByLayoutUuid(layout.getGroupId(), layout.getUuid());

    if (journalArticles.isEmpty()) {
      return;
    }

    Set<String> processedArticleIds = new HashSet<String>();

    for (JournalArticle journalArticle : journalArticles) {
      if (processedArticleIds.contains(journalArticle.getArticleId())
          || (journalArticle.getStatus() != WorkflowConstants.STATUS_APPROVED)) {

        continue;
      }

      String portalURL = PortalUtil.getPortalURL(layout, themeDisplay);

      String groupFriendlyURL =
          PortalUtil.getGroupFriendlyURL(
              GroupLocalServiceUtil.getGroup(journalArticle.getGroupId()), false, themeDisplay);

      StringBundler sb = new StringBundler(4);

      if (!groupFriendlyURL.startsWith(portalURL)) {
        sb.append(portalURL);
      }

      sb.append(groupFriendlyURL);
      sb.append(JournalArticleConstants.CANONICAL_URL_SEPARATOR);
      sb.append(journalArticle.getUrlTitle());

      String articleURL = PortalUtil.getCanonicalURL(sb.toString(), themeDisplay, layout);

      addURLElement(
          element,
          articleURL,
          null,
          journalArticle.getModifiedDate(),
          articleURL,
          getAlternateURLs(articleURL, themeDisplay, layout));

      Locale[] availableLocales = LanguageUtil.getAvailableLocales(layout.getGroupId());

      if (availableLocales.length > 1) {
        Locale defaultLocale = LocaleUtil.getSiteDefault();

        for (Locale availableLocale : availableLocales) {
          if (!availableLocale.equals(defaultLocale)) {
            String alternateURL =
                PortalUtil.getAlternateURL(articleURL, themeDisplay, availableLocale, layout);

            addURLElement(
                element,
                alternateURL,
                null,
                journalArticle.getModifiedDate(),
                articleURL,
                getAlternateURLs(articleURL, themeDisplay, layout));
          }
        }
      }

      processedArticleIds.add(journalArticle.getArticleId());
    }
  }
  @Override
  public String getRowCheckBox(
      HttpServletRequest request, boolean checked, boolean disabled, String primaryKey) {

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

    JournalArticle article = null;
    JournalFolder folder = null;

    String articleId = GetterUtil.getString(primaryKey);

    try {
      article = JournalArticleServiceUtil.getArticle(themeDisplay.getScopeGroupId(), articleId);
    } catch (Exception e1) {
      if (e1 instanceof NoSuchArticleException) {
        try {
          long folderId = GetterUtil.getLong(primaryKey);

          folder = JournalFolderServiceUtil.getFolder(folderId);
        } catch (Exception e2) {
          return StringPool.BLANK;
        }
      }
    }

    boolean showInput = false;

    String name = null;

    if (article != null) {
      name = JournalArticle.class.getSimpleName();

      try {
        if (JournalArticlePermission.contains(_permissionChecker, article, ActionKeys.DELETE)
            || JournalArticlePermission.contains(_permissionChecker, article, ActionKeys.EXPIRE)
            || JournalArticlePermission.contains(_permissionChecker, article, ActionKeys.UPDATE)) {

          showInput = true;
        }
      } catch (Exception e) {
      }
    } else if (folder != null) {
      name = JournalFolder.class.getSimpleName();

      try {
        if (JournalFolderPermission.contains(_permissionChecker, folder, ActionKeys.DELETE)) {

          showInput = true;
        }
      } catch (Exception e) {
      }
    }

    if (!showInput) {
      return StringPool.BLANK;
    }

    StringBundler sb = new StringBundler(9);

    sb.append("['");
    sb.append(_liferayPortletResponse.getNamespace());
    sb.append(RowChecker.ROW_IDS);
    sb.append(JournalFolder.class.getSimpleName());
    sb.append("Checkbox', '");
    sb.append(_liferayPortletResponse.getNamespace());
    sb.append(RowChecker.ROW_IDS);
    sb.append(JournalArticle.class.getSimpleName());
    sb.append("Checkbox']");

    String checkBoxRowIds = sb.toString();

    return getRowCheckBox(
        request,
        checked,
        disabled,
        _liferayPortletResponse.getNamespace() + RowChecker.ROW_IDS + name + "Checkbox",
        primaryKey,
        checkBoxRowIds,
        "'#" + getAllRowIds() + "Checkbox'",
        StringPool.BLANK);
  }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    UploadServletRequest uploadRequest = null;

    try {
      String cmd = ParamUtil.getString(request, Constants.CMD);

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

      long groupId = ParamUtil.getLong(request, "groupId");
      String articleId = ParamUtil.getString(request, "articleId");
      double version =
          ParamUtil.getDouble(request, "version", JournalArticleConstants.DEFAULT_VERSION);

      String languageId = LanguageUtil.getLanguageId(request);

      String output = null;

      if (cmd.equals(Constants.PREVIEW)) {
        uploadRequest = PortalUtil.getUploadServletRequest(request);

        String title = ParamUtil.getString(uploadRequest, "title");
        String description = ParamUtil.getString(uploadRequest, "description");
        String type = ParamUtil.getString(uploadRequest, "type");
        String structureId = ParamUtil.getString(uploadRequest, "structureId");
        String templateId = ParamUtil.getString(uploadRequest, "templateId");

        Date now = new Date();

        Date createDate = now;
        Date modifiedDate = now;
        Date displayDate = now;

        User user = PortalUtil.getUser(uploadRequest);

        String xml = ParamUtil.getString(uploadRequest, "xml");

        Document doc = SAXReaderUtil.read(xml);

        Element root = doc.getRootElement();

        String previewArticleId = "PREVIEW_" + PwdGenerator.getPassword(PwdGenerator.KEY3, 10);

        format(groupId, articleId, version, previewArticleId, root, uploadRequest);

        Map<String, String> tokens = JournalUtil.getTokens(groupId, themeDisplay);

        tokens.put("article_resource_pk", "-1");

        JournalArticle article = new JournalArticleImpl();

        article.setGroupId(groupId);
        article.setCompanyId(user.getCompanyId());
        article.setUserId(user.getUserId());
        article.setUserName(user.getFullName());
        article.setCreateDate(createDate);
        article.setModifiedDate(modifiedDate);
        article.setArticleId(articleId);
        article.setVersion(version);
        article.setTitle(title);
        article.setDescription(description);
        article.setContent(xml);
        article.setType(type);
        article.setStructureId(structureId);
        article.setTemplateId(templateId);
        article.setDisplayDate(displayDate);

        output =
            JournalArticleLocalServiceUtil.getArticleContent(
                article, templateId, null, languageId, themeDisplay);
      } else {
        output =
            JournalArticleServiceUtil.getArticleContent(
                groupId, articleId, version, languageId, themeDisplay);
      }

      request.setAttribute(WebKeys.JOURNAL_ARTICLE_CONTENT, output);

      if (output.startsWith("<?xml ")) {
        return mapping.findForward("portlet.journal.raw_article_content");
      } else {
        return mapping.findForward("portlet.journal.view_article_content");
      }
    } catch (Exception e) {
      PortalUtil.sendError(e, request, response);

      return null;
    } finally {
      if (uploadRequest != null) {
        uploadRequest.cleanUp();
      }
    }
  }