Esempio n. 1
0
 /**
  * Utility method for building a URL link to a wiki edit page for a specified topic.
  *
  * @param context The servlet context for the link that is being created.
  * @param virtualWiki The virtual wiki for the link that is being created.
  * @param topic The name of the topic for which an edit link is being created.
  * @param query Any existing query parameters to append to the edit link. This value may be either
  *     <code>null</code> or empty.
  * @param section The section defined by the name parameter within the HTML page for the topic
  *     being edited. If provided then the edit link will allow editing of only the specified
  *     section.
  * @return A url that links to the edit page for the specified topic. Note that this method
  *     returns only the URL, not a fully-formed HTML anchor tag.
  * @throws DataAccessException Thrown if any error occurs while builing the link URL.
  */
 public static String buildEditLinkUrl(
     String context, String virtualWiki, String topic, String query, int section)
     throws DataAccessException {
   query = LinkUtil.appendQueryParam(query, "topic", topic);
   if (section > 0) {
     query += "&amp;section=" + section;
   }
   WikiLink wikiLink = new WikiLink();
   // FIXME - hard coding
   wikiLink.setDestination("Special:Edit");
   wikiLink.setQuery(query);
   return LinkUtil.buildTopicUrl(context, virtualWiki, wikiLink);
 }
Esempio n. 2
0
 /**
  * Parse a wiki topic link and return a <code>WikiLink</code> object representing the link. Wiki
  * topic links are of the form "Topic?Query#Section".
  *
  * @param raw The raw topic link text.
  * @return A WikiLink object that represents the link.
  */
 public static WikiLink parseWikiLink(String raw) {
   // note that this functionality was previously handled with a regular
   // expression, but the expression caused CPU usage to spike to 100%
   // with topics such as "Urnordisch oder Nordwestgermanisch?"
   String processed = raw.trim();
   WikiLink wikiLink = new WikiLink();
   if (StringUtils.isBlank(processed)) {
     return new WikiLink();
   }
   // first look for a section param - "#..."
   int sectionPos = processed.indexOf('#');
   if (sectionPos != -1 && sectionPos < processed.length()) {
     String sectionString = processed.substring(sectionPos + 1);
     wikiLink.setSection(sectionString);
     if (sectionPos == 0) {
       // link is of the form #section, no more to process
       return wikiLink;
     }
     processed = processed.substring(0, sectionPos);
   }
   // now see if the link ends with a query param - "?..."
   int queryPos = processed.indexOf('?', 1);
   if (queryPos != -1 && queryPos < processed.length()) {
     String queryString = processed.substring(queryPos + 1);
     wikiLink.setQuery(queryString);
     processed = processed.substring(0, queryPos);
   }
   // since we're having so much fun, let's find a namespace (default empty).
   String namespaceString = "";
   int namespacePos = processed.indexOf(':', 1);
   if (namespacePos != -1 && namespacePos < processed.length()) {
     namespaceString = processed.substring(0, namespacePos);
   }
   wikiLink.setNamespace(namespaceString);
   String topic = processed;
   if (namespacePos > 0 && (namespacePos + 1) < processed.length()) {
     // get namespace, unless topic ends with a colon
     topic = processed.substring(namespacePos + 1);
   }
   wikiLink.setArticle(Utilities.decodeTopicName(topic, true));
   // destination is namespace + topic
   wikiLink.setDestination(Utilities.decodeTopicName(processed, true));
   return wikiLink;
 }
Esempio n. 3
0
 @Test
 public void testSetQuery() throws Throwable {
   WikiLink wikiLink = new WikiLink("/wiki", "en", null);
   wikiLink.setQuery("testWikiLinkQuery");
   assertEquals("wikiLink.getQuery()", "testWikiLinkQuery", wikiLink.getQuery());
 }