示例#1
0
 /**
  * Return the URL of the index page for the wiki.
  *
  * @throws DataAccessException Thrown if any error occurs while retrieving data.
  */
 private String retrieveBaseUrl() throws DataAccessException {
   VirtualWiki virtualWiki = VirtualWiki.defaultVirtualWiki();
   String url = Environment.getValue(Environment.PROP_SERVER_URL);
   WikiLink wikiLink =
       LinkUtil.parseWikiLink(
           WikiUtil.WEBAPP_CONTEXT_PATH, virtualWiki.getName(), virtualWiki.getRootTopicName());
   url += LinkUtil.buildTopicUrl(wikiLink);
   return url;
 }
示例#2
0
 private String linkHtml(
     ParserInput parserInput,
     ParserOutput parserOutput,
     int mode,
     String link,
     String text,
     String punctuation,
     boolean numberedCaption)
     throws ParserException {
   if (link.toLowerCase().startsWith("mailto://")) {
     // fix bad mailto syntax
     link = "mailto:" + link.substring("mailto://".length());
   }
   String caption = link;
   if (!StringUtils.isBlank(text)) {
     // pass a parameter via the parserInput to prevent nested links from being generated
     parserInput.getTempParams().put(HTML_LINK_CAPTION, true);
     caption = JFlexParserUtil.parseFragment(parserInput, parserOutput, text, mode);
     parserInput.getTempParams().remove(HTML_LINK_CAPTION);
   } else if (numberedCaption) {
     // set the caption of the form "[1]"
     int counter = 1;
     if (parserInput.getTempParams().get(HTML_LINK_CAPTION_COUNTER) != null) {
       counter = (Integer) parserInput.getTempParams().get(HTML_LINK_CAPTION_COUNTER);
     }
     parserInput.getTempParams().put(HTML_LINK_CAPTION_COUNTER, counter + 1);
     caption = "[" + counter + "]";
   }
   return LinkUtil.buildExternalLinkHtml(link, "externallink", caption) + punctuation;
 }
示例#3
0
 private String buildSectionEditLink(ParserInput parserInput, int section) throws ParserException {
   if (!parserInput.getAllowSectionEdit()) {
     return "";
   }
   if (parserInput.getLocale() == null) {
     logger.info(
         "Unable to build section edit links for "
             + parserInput.getTopicName()
             + " - locale is empty");
     return "";
   }
   // FIXME - template inclusion causes section edits to break, so disable for now
   Integer inclusion = (Integer) parserInput.getTempParam(TemplateTag.TEMPLATE_INCLUSION);
   boolean disallowInclusion = (inclusion != null && inclusion > 0);
   if (disallowInclusion) {
     return "";
   }
   String url = "";
   try {
     url =
         LinkUtil.buildEditLinkUrl(
             parserInput.getContext(),
             parserInput.getVirtualWiki(),
             parserInput.getTopicName(),
             null,
             section);
   } catch (DataAccessException e) {
     logger.error(
         "Failure while building link for topic "
             + parserInput.getVirtualWiki()
             + " / "
             + parserInput.getTopicName(),
         e);
   }
   // arguments are edit link URL and edit label text
   Object[] args = new Object[2];
   args[0] = url;
   args[1] = Utilities.formatMessage("common.sectionedit", parserInput.getLocale());
   try {
     return WikiUtil.formatFromTemplate(TEMPLATE_HEADER_EDIT_LINK, args);
   } catch (IOException e) {
     throw new ParserException(e);
   }
 }