[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/engine ...

Christian Bauer christian at hibernate.org
Mon Apr 9 06:57:58 EDT 2007


  User: cbauer  
  Date: 07/04/09 06:57:58

  Modified:    examples/wiki/src/main/org/jboss/seam/wiki/core/engine  
                        DefaultWikiLinkResolver.java WikiLinkResolver.java
  Log:
  Added customizable wiki link protocols (e.g. for automatic links to JIRA issues)
  
  Revision  Changes    Path
  1.2       +18 -0     jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/engine/DefaultWikiLinkResolver.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DefaultWikiLinkResolver.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/engine/DefaultWikiLinkResolver.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- DefaultWikiLinkResolver.java	22 Mar 2007 12:47:50 -0000	1.1
  +++ DefaultWikiLinkResolver.java	9 Apr 2007 10:57:58 -0000	1.2
  @@ -30,6 +30,9 @@
       @In
       private NodeDAO nodeDAO;
   
  +    @In
  +    Map<String, LinkProtocol> linkProtocolMap;
  +
       public String convertToWikiProtocol(Long currentAreaNumber, String wikiText) {
           if (wikiText == null) return null;
   
  @@ -84,6 +87,7 @@
   
           Matcher wikiProtocolMatcher = Pattern.compile(REGEX_WIKI_PROTOCOL).matcher(linkText);
           Matcher knownProtocolMatcher = Pattern.compile(REGEX_KNOWN_PROTOCOL).matcher(linkText);
  +        Matcher customProtocolMatcher = Pattern.compile(REGEX_CUSTOM_PROTOCOL).matcher(linkText);
   
           WikiLink wikiLink;
   
  @@ -109,6 +113,20 @@
                   wikiLink.setDescription(BROKENLINK_DESCRIPTION);
               }
   
  +        // Check if it is a custom protocol
  +        } else if (customProtocolMatcher.find()) {
  +
  +            if (linkProtocolMap.containsKey(customProtocolMatcher.group(1))) {
  +                LinkProtocol protocol = linkProtocolMap.get(customProtocolMatcher.group(1));
  +                wikiLink = new WikiLink(false, true);
  +                wikiLink.setUrl(protocol.getRealLink(customProtocolMatcher.group(2)));
  +                wikiLink.setDescription(protocol.getPrefix() + "://" + customProtocolMatcher.group(2));
  +            } else {
  +                wikiLink = new WikiLink(true, false);
  +                wikiLink.setUrl(BROKENLINK_URL);
  +                wikiLink.setDescription(BROKENLINK_DESCRIPTION);
  +            }
  +
           // It must be a stored clear text link, such as [=>Target Name] or [=>Area Name|Target Name]
           // (This can happen if the string [foo=>bar] or [foo=>bar|baz] was stored in the database because the
           //  targets didn't exist at the time of saving)
  
  
  
  1.3       +5 -0      jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/engine/WikiLinkResolver.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: WikiLinkResolver.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/engine/WikiLinkResolver.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- WikiLinkResolver.java	2 Apr 2007 18:25:07 -0000	1.2
  +++ WikiLinkResolver.java	9 Apr 2007 10:57:58 -0000	1.3
  @@ -21,6 +21,11 @@
       public static final String REGEX_KNOWN_PROTOCOL = "(http://)|(https://)|(ftp://)|(mailto:)";
   
       /**
  +     * Matches customized protocols, e.g. [=>seamjira://123], which should be resolved and rendered
  +     */
  +    public static final String REGEX_CUSTOM_PROTOCOL = "([a-zA-Z]+)://(.+)";
  +
  +    /**
        * Prepended to primary identifiers when links are stored, e.g. [This is a stored link=>wiki://5]
        */
       public static final String REGEX_WIKI_PROTOCOL = "wiki://([0-9]+)";
  
  
  



More information about the jboss-cvs-commits mailing list