@Override
  public String getContent(
      long groupId,
      String articleId,
      String ddmTemplateKey,
      String viewMode,
      String languageId,
      PortletRequestModel portletRequestModel,
      ThemeDisplay themeDisplay) {

    JournalArticleDisplay articleDisplay =
        getDisplay(
            groupId,
            articleId,
            ddmTemplateKey,
            viewMode,
            languageId,
            1,
            portletRequestModel,
            themeDisplay);

    if (articleDisplay != null) {
      return articleDisplay.getContent();
    } else {
      return null;
    }
  }
  protected String getDDMContentSummary(
      Document document,
      Locale snippetLocale,
      PortletRequest portletRequest,
      PortletResponse portletResponse) {

    String content = StringPool.BLANK;

    if ((portletRequest == null) || (portletResponse == null)) {
      return content;
    }

    try {
      String articleId = document.get(Field.ARTICLE_ID);
      long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
      double version = GetterUtil.getDouble(document.get(Field.VERSION));
      PortletRequestModel portletRequestModel =
          new PortletRequestModel(portletRequest, portletResponse);
      ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

      JournalArticleDisplay articleDisplay =
          _journalContent.getDisplay(
              groupId,
              articleId,
              version,
              null,
              Constants.VIEW,
              LocaleUtil.toLanguageId(snippetLocale),
              1,
              portletRequestModel,
              themeDisplay);

      content = articleDisplay.getDescription();

      content = HtmlUtil.replaceNewLine(content);

      if (Validator.isNull(content)) {
        content = HtmlUtil.extractText(articleDisplay.getContent());
      }
    } catch (Exception e) {
      if (_log.isDebugEnabled()) {
        _log.debug(e, e);
      }
    }

    return content;
  }
  @Override
  public JournalArticleDisplay getDisplay(
      long groupId,
      String articleId,
      double version,
      String ddmTemplateKey,
      String viewMode,
      String languageId,
      int page,
      PortletRequestModel portletRequestModel,
      ThemeDisplay themeDisplay) {

    StopWatch stopWatch = new StopWatch();

    stopWatch.start();

    articleId = StringUtil.toUpperCase(GetterUtil.getString(articleId));
    ddmTemplateKey = StringUtil.toUpperCase(GetterUtil.getString(ddmTemplateKey));

    long layoutSetId = 0;
    boolean secure = false;

    if (themeDisplay != null) {
      try {
        if (!JournalArticlePermission.contains(
            themeDisplay.getPermissionChecker(), groupId, articleId, ActionKeys.VIEW)) {

          return null;
        }
      } catch (Exception e) {
      }

      LayoutSet layoutSet = themeDisplay.getLayoutSet();

      layoutSetId = layoutSet.getLayoutSetId();

      secure = themeDisplay.isSecure();
    }

    JournalContentKey journalContentKey =
        new JournalContentKey(
            groupId,
            articleId,
            version,
            ddmTemplateKey,
            layoutSetId,
            viewMode,
            languageId,
            page,
            secure);

    JournalArticleDisplay articleDisplay = _getPortalCache().get(journalContentKey);

    boolean lifecycleRender = false;

    if (portletRequestModel != null) {
      lifecycleRender = RenderRequest.RENDER_PHASE.equals(portletRequestModel.getLifecycle());
    }

    if ((articleDisplay == null) || !lifecycleRender) {
      articleDisplay =
          getArticleDisplay(
              groupId,
              articleId,
              ddmTemplateKey,
              viewMode,
              languageId,
              page,
              portletRequestModel,
              themeDisplay);

      if ((articleDisplay != null) && articleDisplay.isCacheable() && lifecycleRender) {

        _getPortalCache().put(journalContentKey, articleDisplay);
      }
    }

    if (_log.isDebugEnabled()) {
      _log.debug(
          "getDisplay for {"
              + groupId
              + ", "
              + articleId
              + ", "
              + ddmTemplateKey
              + ", "
              + viewMode
              + ", "
              + languageId
              + ", "
              + page
              + "} takes "
              + stopWatch.getTime()
              + " ms");
    }

    return articleDisplay;
  }
  public static void sendFile(PortletRequest portletRequest, PortletResponse portletResponse)
      throws IOException {

    long groupId = ParamUtil.getLong(portletRequest, "groupId");
    String articleId = ParamUtil.getString(portletRequest, "articleId");

    String targetExtension = ParamUtil.getString(portletRequest, "targetExtension");

    PortletPreferences portletPreferences = portletRequest.getPreferences();

    String[] allowedExtensions = StringUtil.split(portletPreferences.getValue("extensions", null));

    String languageId = LanguageUtil.getLanguageId(portletRequest);
    PortletRequestModel portletRequestModel =
        new PortletRequestModel(portletRequest, portletResponse);
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
    HttpServletRequest request = PortalUtil.getHttpServletRequest(portletRequest);
    HttpServletResponse response = PortalUtil.getHttpServletResponse(portletResponse);

    JournalArticleDisplay articleDisplay =
        JournalContentUtil.getDisplay(
            groupId, articleId, null, "export", languageId, 1, portletRequestModel, themeDisplay);

    int pages = articleDisplay.getNumberOfPages();

    StringBundler sb = new StringBundler(pages + 12);

    sb.append("<html>");

    sb.append("<head>");
    sb.append("<meta content=\"");
    sb.append(ContentTypes.TEXT_HTML_UTF8);
    sb.append("\" http-equiv=\"content-type\" />");
    sb.append("<base href=\"");
    sb.append(themeDisplay.getPortalURL());
    sb.append("\" />");
    sb.append("</head>");

    sb.append("<body>");

    sb.append(articleDisplay.getContent());

    for (int i = 2; i <= pages; i++) {
      articleDisplay =
          JournalContentUtil.getDisplay(groupId, articleId, "export", languageId, i, themeDisplay);

      sb.append(articleDisplay.getContent());
    }

    sb.append("</body>");
    sb.append("</html>");

    InputStream is = new UnsyncByteArrayInputStream(sb.toString().getBytes(StringPool.UTF8));

    String title = articleDisplay.getTitle();
    String sourceExtension = "html";

    String fileName = title.concat(StringPool.PERIOD).concat(sourceExtension);

    String contentType = MimeTypesUtil.getContentType(fileName);

    if (Validator.isNull(targetExtension)
        || !ArrayUtil.contains(allowedExtensions, targetExtension)) {

      ServletResponseUtil.sendFile(request, response, fileName, is, contentType);

      return;
    }

    String id =
        DLUtil.getTempFileId(
            articleDisplay.getId(), String.valueOf(articleDisplay.getVersion()), languageId);

    File convertedFile = DocumentConversionUtil.convert(id, is, sourceExtension, targetExtension);

    if (convertedFile != null) {
      fileName = title.concat(StringPool.PERIOD).concat(targetExtension);

      is = new FileInputStream(convertedFile);
    }

    ServletResponseUtil.sendFile(request, response, fileName, is, contentType);
  }