public KBArticleMarkdownConverter(
      String markdown, String fileEntryName, Map<String, String> metadata)
      throws KBArticleImportException {

    MarkdownConverter markdownConverter = MarkdownConverterFactoryUtil.create();

    String html = null;

    try {
      html = markdownConverter.convert(markdown);
    } catch (IOException ioe) {
      throw new KBArticleImportException(
          "Unable to convert Markdown to HTML: " + ioe.getLocalizedMessage(), ioe);
    }

    String heading = getHeading(html);

    if (Validator.isNull(heading)) {
      throw new KBArticleImportException(
          "Unable to extract title heading from file: " + fileEntryName);
    }

    _urlTitle = getUrlTitle(heading);

    _title = HtmlUtil.unescape(stripIds(heading));

    html = stripIds(html);

    _html = stripHeading(html);

    String baseSourceURL = metadata.get(_METADATA_BASE_SOURCE_URL);

    _sourceURL = buildSourceURL(baseSourceURL, fileEntryName);
  }
  @Override
  public String getPortletFileEntryURL(
      ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString, boolean absoluteURL) {

    StringBundler sb = new StringBundler(10);

    if (themeDisplay != null) {
      if (absoluteURL) {
        sb.append(themeDisplay.getPortalURL());
      }
    }

    sb.append(PortalUtil.getPathContext());
    sb.append("/documents/");
    sb.append(WebServerServlet.PATH_PORTLET_FILE_ENTRY);
    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getGroupId());
    sb.append(StringPool.SLASH);

    String title = fileEntry.getTitle();

    if (fileEntry.isInTrash()) {
      title = TrashUtil.getOriginalTitle(fileEntry.getTitle());
    }

    sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(title)));

    sb.append(StringPool.SLASH);
    sb.append(HttpUtil.encodeURL(fileEntry.getUuid()));

    if (themeDisplay != null) {
      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

      if (portletDisplay != null) {
        String portletId = portletDisplay.getId();

        if (portletId.equals(PortletKeys.TRASH) && !queryString.contains("status=")) {

          if (Validator.isNotNull(queryString)) {
            queryString += StringPool.AMPERSAND;
          }

          queryString += "status=" + WorkflowConstants.STATUS_IN_TRASH;
        }
      }
    }

    if (Validator.isNotNull(queryString)) {
      sb.append(StringPool.QUESTION);
      sb.append(queryString);
    }

    String portletFileEntryURL = sb.toString();

    if ((themeDisplay != null) && themeDisplay.isAddSessionIdToURL()) {
      return PortalUtil.getURLWithSessionId(portletFileEntryURL, themeDisplay.getSessionId());
    }

    return portletFileEntryURL;
  }
  @Override
  public String getRestoreLink(PortletRequest portletRequest, long classPK)
      throws PortalException, SystemException {

    String portletId = PortletKeys.WIKI;

    WikiPage page = WikiPageLocalServiceUtil.getPage(classPK);

    long plid = PortalUtil.getPlidFromPortletId(page.getGroupId(), PortletKeys.WIKI);

    if (plid == LayoutConstants.DEFAULT_PLID) {
      plid = PortalUtil.getControlPanelPlid(portletRequest);

      portletId = PortletKeys.WIKI_ADMIN;
    }

    PortletURL portletURL =
        PortletURLFactoryUtil.create(portletRequest, portletId, plid, PortletRequest.RENDER_PHASE);

    WikiNode node = page.getNode();

    portletURL.setParameter("struts_action", "/wiki/view");
    portletURL.setParameter("nodeName", node.getName());
    portletURL.setParameter("title", HtmlUtil.unescape(page.getTitle()));

    return portletURL.toString();
  }
  protected void deleteEntries(
      ActionRequest actionRequest, ActionResponse actionResponse, boolean moveToTrash)
      throws Exception {

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

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

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

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

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

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

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

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

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

      hideDefaultSuccessMessage(actionRequest);
    }

    sendEditEntryRedirect(actionRequest, actionResponse);
  }
  protected void deleteArticles(
      ActionRequest actionRequest, ActionResponse actionResponse, boolean moveToTrash)
      throws Exception {

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

    String[] deleteArticleIds = null;

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

    if (Validator.isNotNull(articleId)) {
      deleteArticleIds = new String[] {articleId};
    } else {
      deleteArticleIds = StringUtil.split(ParamUtil.getString(actionRequest, "articleIds"));
    }

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

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

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

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

      hideDefaultSuccessMessage(actionRequest);
    }

    sendEditArticleRedirect(actionRequest, actionResponse);
  }
  public void moveEntries(ActionRequest actionRequest, ActionResponse actionResponse)
      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) {
      _journalFolderService.moveFolder(folderId, newFolderId, serviceContext);
    }

    List<String> invalidArticleIds = new ArrayList<>();

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

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

    for (String articleId : articleIds) {
      try {
        _journalArticleService.moveArticle(
            themeDisplay.getScopeGroupId(),
            HtmlUtil.unescape(articleId),
            newFolderId,
            serviceContext);
      } catch (InvalidDDMStructureException idse) {
        if (_log.isWarnEnabled()) {
          _log.warn(idse.getMessage());
        }

        invalidArticleIds.add(articleId);
      }
    }

    if (!invalidArticleIds.isEmpty()) {
      StringBundler sb = new StringBundler(4);

      sb.append("Folder ");
      sb.append(newFolderId);
      sb.append(" does not allow the structures for articles: ");
      sb.append(StringUtil.merge(invalidArticleIds));

      throw new InvalidDDMStructureException(sb.toString());
    }

    sendEditEntryRedirect(actionRequest, actionResponse);
  }
  public void expireArticles(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    if (Validator.isNotNull(articleId)) {
      ActionUtil.expireArticle(actionRequest, articleId);
    } else {
      String[] expireArticleIds =
          StringUtil.split(ParamUtil.getString(actionRequest, "expireArticleIds"));

      for (String expireArticleId : expireArticleIds) {
        ActionUtil.expireArticle(actionRequest, HtmlUtil.unescape(expireArticleId));
      }
    }

    sendEditArticleRedirect(actionRequest, actionResponse);
  }
  public void expireEntries(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

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

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

    for (long expireFolderId : expireFolderIds) {
      ActionUtil.expireFolder(themeDisplay.getScopeGroupId(), expireFolderId, serviceContext);
    }

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

    for (String expireArticleId : expireArticleIds) {
      ActionUtil.expireArticle(actionRequest, HtmlUtil.unescape(expireArticleId));
    }

    sendEditEntryRedirect(actionRequest, actionResponse);
  }
Ejemplo n.º 9
0
  public static String getPreviewURL(
      FileEntry fileEntry,
      FileVersion fileVersion,
      ThemeDisplay themeDisplay,
      String queryString,
      boolean appendToken) {

    StringBundler sb = new StringBundler(13);

    sb.append(themeDisplay.getPortalURL());
    sb.append(themeDisplay.getPathContext());
    sb.append("/documents/");
    sb.append(fileEntry.getRepositoryId());
    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getFolderId());
    sb.append(StringPool.SLASH);
    sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(fileEntry.getTitle()), true));
    sb.append("?version=");
    sb.append(fileVersion.getVersion());

    if (appendToken) {
      sb.append("&t=");

      Date modifiedDate = fileVersion.getModifiedDate();

      sb.append(modifiedDate.getTime());
    }

    sb.append(queryString);

    String previewURL = sb.toString();

    if (themeDisplay.isAddSessionIdToURL()) {
      return PortalUtil.getURLWithSessionId(previewURL, themeDisplay.getSessionId());
    }

    return previewURL;
  }
 public void setDescription(String description) {
   _description = HtmlUtil.unescape(description);
 }
 public void setTitle(String title) {
   _title = HtmlUtil.unescape(title);
 }
Ejemplo n.º 12
0
 public void setRowBreak(String rowBreak) {
   _rowBreak = HtmlUtil.unescape(rowBreak);
 }
Ejemplo n.º 13
0
  @Override
  public String getWebDavURL(
      ThemeDisplay themeDisplay,
      Folder folder,
      FileEntry fileEntry,
      boolean manualCheckInRequired,
      boolean openDocumentUrl)
      throws PortalException, SystemException {

    StringBundler webDavURL = new StringBundler(8);

    boolean secure = false;

    if (themeDisplay.isSecure() || PropsValues.WEBDAV_SERVLET_HTTPS_REQUIRED) {

      secure = true;
    }

    String portalURL =
        PortalUtil.getPortalURL(themeDisplay.getServerName(), themeDisplay.getServerPort(), secure);

    webDavURL.append(portalURL);

    webDavURL.append(themeDisplay.getPathContext());
    webDavURL.append("/webdav");

    if (manualCheckInRequired) {
      webDavURL.append(MANUAL_CHECK_IN_REQUIRED_PATH);
    }

    String fileEntryTitle = null;

    if (fileEntry != null) {
      String extension = fileEntry.getExtension();

      fileEntryTitle = HtmlUtil.unescape(fileEntry.getTitle());

      if (openDocumentUrl
          && isOfficeExtension(extension)
          && !fileEntryTitle.endsWith(StringPool.PERIOD + extension)) {

        webDavURL.append(OFFICE_EXTENSION_PATH);

        fileEntryTitle += StringPool.PERIOD + extension;
      }
    }

    Group group = themeDisplay.getScopeGroup();

    webDavURL.append(group.getFriendlyURL());
    webDavURL.append("/document_library");

    StringBuilder sb = new StringBuilder();

    if ((folder != null) && (folder.getFolderId() != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {

      Folder curFolder = folder;

      while (true) {
        sb.insert(0, HttpUtil.encodeURL(curFolder.getName(), true));
        sb.insert(0, StringPool.SLASH);

        if (curFolder.getParentFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

          break;
        }

        curFolder = DLAppLocalServiceUtil.getFolder(curFolder.getParentFolderId());
      }
    }

    if (fileEntry != null) {
      sb.append(StringPool.SLASH);
      sb.append(HttpUtil.encodeURL(fileEntryTitle, true));
    }

    webDavURL.append(sb.toString());

    return webDavURL.toString();
  }
Ejemplo n.º 14
0
  @Override
  public String getPreviewURL(
      FileEntry fileEntry,
      FileVersion fileVersion,
      ThemeDisplay themeDisplay,
      String queryString,
      boolean appendVersion,
      boolean absoluteURL) {

    StringBundler sb = new StringBundler(17);

    if (themeDisplay != null) {
      if (absoluteURL) {
        sb.append(themeDisplay.getPortalURL());
      }
    }

    sb.append(PortalUtil.getPathContext());
    sb.append("/documents/");
    sb.append(fileEntry.getRepositoryId());
    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getFolderId());
    sb.append(StringPool.SLASH);

    String title = fileEntry.getTitle();

    if (fileEntry.isInTrash()) {
      title = TrashUtil.getOriginalTitle(fileEntry.getTitle());
    }

    sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(title)));

    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getUuid());

    if (appendVersion) {
      sb.append("?version=");
      sb.append(fileVersion.getVersion());
    }

    if (ImageProcessorUtil.isImageSupported(fileVersion)) {
      if (appendVersion) {
        sb.append("&t=");
      } else {
        sb.append("?t=");
      }

      Date modifiedDate = fileVersion.getModifiedDate();

      sb.append(modifiedDate.getTime());
    }

    sb.append(queryString);

    if (themeDisplay != null) {
      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

      if (portletDisplay != null) {
        String portletId = portletDisplay.getId();

        if (portletId.equals(PortletKeys.TRASH)) {
          sb.append("&status=");
          sb.append(WorkflowConstants.STATUS_IN_TRASH);
        }
      }
    }

    String previewURL = sb.toString();

    if ((themeDisplay != null) && themeDisplay.isAddSessionIdToURL()) {
      return PortalUtil.getURLWithSessionId(previewURL, themeDisplay.getSessionId());
    }

    return previewURL;
  }
Ejemplo n.º 15
0
 public void setSubtitle(String subtitle) {
   _subtitle = HtmlUtil.unescape(subtitle);
 }