protected void sendHTML(
      HttpServletResponse response, String path, List<WebServerEntry> webServerEntries)
      throws Exception {

    Template template =
        TemplateManagerUtil.getTemplate(
            TemplateManager.FREEMARKER, _TEMPLATE_FTL, TemplateContextType.RESTRICTED);

    template.put("dateFormat", _dateFormat);
    template.put("entries", webServerEntries);
    template.put("path", HttpUtil.encodePath(path));

    if (_WEB_SERVER_SERVLET_VERSION_VERBOSITY_DEFAULT) {
    } else if (_WEB_SERVER_SERVLET_VERSION_VERBOSITY_PARTIAL) {
      template.put("releaseInfo", ReleaseInfo.getName());
    } else {
      template.put("releaseInfo", ReleaseInfo.getReleaseInfo());
    }

    template.put("validator", Validator_IW.getInstance());

    response.setContentType(ContentTypes.TEXT_HTML_UTF8);

    template.processTemplate(response.getWriter());
  }
  private String _getJavaScript() throws PortalException {
    String javaScript =
        "/com/liferay/frontend/image/editor/integration/document/library"
            + "/internal/display/context/dependencies"
            + "/edit_with_image_editor_js.ftl";

    Class<?> clazz = getClass();

    URLTemplateResource urlTemplateResource =
        new URLTemplateResource(javaScript, clazz.getResource(javaScript));

    Template template =
        TemplateManagerUtil.getTemplate(
            TemplateConstants.LANG_TYPE_FTL, urlTemplateResource, false);

    template.put("editLanguageKey", LanguageUtil.get(_request, "edit"));

    LiferayPortletResponse liferayPortletResponse = _getLiferayPortletResponse();

    template.put("namespace", liferayPortletResponse.getNamespace());

    UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter();

    template.processTemplate(unsyncStringWriter);

    return unsyncStringWriter.toString();
  }
Example #3
0
  protected Template getTemplate(
      String templateId,
      Map<String, String> tokens,
      String languageId,
      Document document,
      String script,
      String langType)
      throws Exception {

    TemplateResource templateResource = null;

    if (langType.equals(TemplateConstants.LANG_TYPE_XSL)) {
      XSLURIResolver xslURIResolver = new JournalXSLURIResolver(tokens, languageId);

      templateResource =
          new XSLTemplateResource(templateId, script, xslURIResolver, document.asXML());
    } else {
      templateResource = new StringTemplateResource(templateId, script);
    }

    TemplateResource errorTemplateResource = getErrorTemplateResource(langType);

    return TemplateManagerUtil.getTemplate(
        langType, templateResource, errorTemplateResource, _restricted);
  }
  protected Template getTemplate(String templateId, String script, String langType)
      throws Exception {

    TemplateResource templateResource = new StringTemplateResource(templateId, script);

    TemplateResource errorTemplateResource = getErrorTemplateResource(langType);

    return TemplateManagerUtil.getTemplate(
        langType, templateResource, errorTemplateResource, _restricted);
  }
  protected String getPageDiff(long companyId, WikiPage latestPage, WikiPage page, Locale locale)
      throws SystemException {

    try {
      String templateId = "com/liferay/portlet/wiki/dependencies/rss.vm";

      String templateContent = ContentUtil.get(templateId);

      Template template =
          TemplateManagerUtil.getTemplate(
              TemplateManager.VELOCITY,
              new StringTemplateResource(templateId, templateContent),
              TemplateContextType.STANDARD);

      template.put("companyId", companyId);
      template.put("contextLine", Diff.CONTEXT_LINE);
      template.put("diffUtil", new DiffUtil());
      template.put("languageUtil", LanguageUtil.getLanguage());
      template.put("locale", locale);

      String sourceContent = WikiUtil.processContent(latestPage.getContent());
      String targetContent = WikiUtil.processContent(page.getContent());

      sourceContent = HtmlUtil.escape(sourceContent);
      targetContent = HtmlUtil.escape(targetContent);

      List<DiffResult>[] diffResults =
          DiffUtil.diff(
              new UnsyncStringReader(sourceContent), new UnsyncStringReader(targetContent));

      template.put("sourceResults", diffResults[0]);
      template.put("targetResults", diffResults[1]);

      UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter();

      template.processTemplate(unsyncStringWriter);

      return unsyncStringWriter.toString();
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }