Ejemplo n.º 1
0
  private String _convert(
      WikiPage page, PortletURL viewPageURL, PortletURL editPageURL, String attachmentURLPrefix)
      throws PageContentException, WikiFormatException {

    LiferayPortletURL liferayViewPageURL = (LiferayPortletURL) viewPageURL;
    LiferayPortletURL liferayEditPageURL = (LiferayPortletURL) editPageURL;

    WikiEngine engine = _getEngine(page.getFormat());

    String content = engine.convert(page, viewPageURL, editPageURL, attachmentURLPrefix);

    String editPageURLString = StringPool.BLANK;

    if (editPageURL != null) {
      liferayEditPageURL.setParameter("title", "__REPLACEMENT__", false);

      editPageURLString = editPageURL.toString();

      editPageURLString = StringUtil.replace(editPageURLString, "__REPLACEMENT__", "$1");
    }

    Matcher matcher = _editPageURLPattern.matcher(content);

    content = _convertURLs(editPageURLString, matcher);

    String viewPageURLString = StringPool.BLANK;

    if (viewPageURL != null) {
      liferayViewPageURL.setParameter("title", "__REPLACEMENT__", false);

      viewPageURLString = viewPageURL.toString();

      viewPageURLString = StringUtil.replace(viewPageURLString, "__REPLACEMENT__", "$1");
    }

    matcher = _viewPageURLPattern.matcher(content);

    content = _convertURLs(viewPageURLString, matcher);

    content = _replaceAttachments(content, page.getTitle(), attachmentURLPrefix);

    return content;
  }
Ejemplo n.º 2
0
  private WikiEngine _getEngine(String format) throws WikiFormatException {
    WikiEngine engine = _engines.get(format);

    if (engine != null) {
      return engine;
    }

    synchronized (_engines) {
      engine = _engines.get(format);

      if (engine != null) {
        return engine;
      }

      try {
        String engineClass = PropsUtil.get(PropsKeys.WIKI_FORMATS_ENGINE, new Filter(format));

        if (engineClass == null) {
          throw new WikiFormatException(format);
        }

        if (!InstancePool.contains(engineClass)) {
          engine = (WikiEngine) InstancePool.get(engineClass);

          engine.setMainConfiguration(
              _readConfigurationFile(PropsKeys.WIKI_FORMATS_CONFIGURATION_MAIN, format));

          engine.setInterWikiConfiguration(
              _readConfigurationFile(PropsKeys.WIKI_FORMATS_CONFIGURATION_INTERWIKI, format));
        } else {
          engine = (WikiEngine) InstancePool.get(engineClass);
        }

        _engines.put(format, engine);

        return engine;
      } catch (Exception e) {
        throw new WikiFormatException(e);
      }
    }
  }