jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mets...@apache.org
Subject svn commit: r728341 - in /incubator/jspwiki/trunk: ./ lib/ src/com/ecyrd/jspwiki/ src/com/ecyrd/jspwiki/filters/ src/com/ecyrd/jspwiki/log/ src/com/ecyrd/jspwiki/parser/ src/com/ecyrd/jspwiki/plugin/ src/com/ecyrd/jspwiki/providers/ src/com/ecyrd/jspwi...
Date Sat, 20 Dec 2008 20:52:23 GMT
Author: metskem
Date: Sat Dec 20 12:52:22 2008
New Revision: 728341

URL: http://svn.apache.org/viewvc?rev=728341&view=rev
Log:
3.0.0-svn-37 JSPWIKI-291 Replace ORO regexp library with Java 5 regexps
and removed some unnecessary imports

Added:
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/RegExpUtil.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferredPagesPluginTest.java
Removed:
    incubator/jspwiki/trunk/lib/oro.jar
Modified:
    incubator/jspwiki/trunk/.classpath
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/build.xml
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/filters/SpamFilter.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/LoggerFactory.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/AbstractReferralPlugin.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/IfPlugin.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/PluginManager.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/ReferredPagesPlugin.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/providers/RCSFileProvider.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/attachment/AttachmentManagerTest.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/diff/ContextualDiffProviderTest.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/AllTests.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/CounterPluginTest.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/PluginManagerTest.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java

Modified: incubator/jspwiki/trunk/.classpath
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/.classpath?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/.classpath (original)
+++ incubator/jspwiki/trunk/.classpath Sat Dec 20 12:52:22 2008
@@ -12,7 +12,6 @@
 	<classpathentry kind="lib" path="tests/lib/xercesImpl-2.6.2.jar"/>
 	<classpathentry kind="lib" path="lib/sandler.jar"/>
 	<classpathentry kind="lib" path="lib/oscache.jar"/>
-	<classpathentry kind="lib" path="lib/oro.jar"/>
 	<classpathentry kind="lib" path="lib/nekohtml.jar"/>
 	<classpathentry kind="lib" path="lib/lucene.jar"/>
 	<classpathentry kind="lib" path="tests/lib/junit.jar"/>

Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Sat Dec 20 12:52:22 2008
@@ -1,3 +1,9 @@
+2008-12-20 Harry Metske <metskem@apache.org>
+
+        * 3.0.0-svn-37
+        
+        * JSPWIKI-291 Replace ORO regexp library with Java 5 regexps
+
 2008-12-20  Andrew Jaquith <ajaquith AT apache DOT org>
 
         * 3.0.0-svn-36

Modified: incubator/jspwiki/trunk/build.xml
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/build.xml?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/build.xml (original)
+++ incubator/jspwiki/trunk/build.xml Sat Dec 20 12:52:22 2008
@@ -672,7 +672,7 @@
   <target name="tests" depends="jar,tests-init,jartests,tests-db-init"
           description="Runs the JUnit tests.">
 
-    <junit printsummary="yes" haltonfailure="no" fork="yes">
+    <junit printsummary="yes" haltonfailure="no" fork="yes" maxmemory="128m">
         <classpath>
            <path refid="path.tests" />
         </classpath>

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java Sat Dec 20 12:52:22 2008
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "36";
+    public static final String     BUILD         = "37";
     
     /**
      *  This is the generic version string you should use

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/filters/SpamFilter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/filters/SpamFilter.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/filters/SpamFilter.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/filters/SpamFilter.java Sat Dec 20 12:52:22 2008
@@ -22,6 +22,10 @@
 
 import java.io.*;
 import java.util.*;
+import java.util.regex.MatchResult;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -35,7 +39,6 @@
 import org.apache.jspwiki.api.ModuleData;
 import com.ecyrd.jspwiki.log.Logger;
 import com.ecyrd.jspwiki.log.LoggerFactory;
-import org.apache.oro.text.regex.*;
 
 import com.ecyrd.jspwiki.*;
 import com.ecyrd.jspwiki.action.WikiContextFactory;
@@ -143,9 +146,6 @@
     private String          m_errorPage          = "RejectedMessage";
     private String          m_blacklist          = "SpamFilterWordList/blacklist.txt";
 
-    private PatternMatcher  m_matcher = new Perl5Matcher();
-    private PatternCompiler m_compiler = new Perl5Compiler();
-
     private Collection<Pattern> m_spamPatterns = null;
 
     private Date            m_lastRebuild = new Date( 0L );
@@ -240,9 +240,9 @@
 
         try
         {
-            m_urlPattern = m_compiler.compile( URL_REGEXP );
+            m_urlPattern = Pattern.compile( URL_REGEXP );
         }
-        catch( MalformedPatternException e )
+        catch( PatternSyntaxException e )
         {
             log.error("Internal error: Someone put in a faulty pattern.",e);
             throw new InternalWikiException("Faulty pattern.");
@@ -367,9 +367,9 @@
 
                 try
                 {
-                    compiledpatterns.add( m_compiler.compile( pattern ) );
+                    compiledpatterns.add( Pattern.compile( pattern ) );
                 }
-                catch( MalformedPatternException e )
+                catch( PatternSyntaxException e )
                 {
                     log.debug( "Malformed spam filter pattern "+pattern );
 
@@ -414,9 +414,9 @@
 
                     try
                     {
-                        compiledpatterns.add( m_compiler.compile( line ) );
+                        compiledpatterns.add( Pattern.compile( line ) );
                     }
-                    catch( MalformedPatternException e )
+                    catch( PatternSyntaxException e )
                     {
                         log.debug( "Malformed spam filter pattern "+line );
                     }
@@ -520,11 +520,12 @@
             String tstChange = change;
             int    urlCounter = 0;
 
-            while( m_matcher.contains(tstChange,m_urlPattern) )
+            Matcher matcher = m_urlPattern.matcher( tstChange );
+            while( matcher.find() )
             {
-                MatchResult m = m_matcher.getMatch();
+                MatchResult m = matcher.toMatchResult();
 
-                tstChange = tstChange.substring( m.endOffset(0) );
+                tstChange = tstChange.substring( m.end(0) );
 
                 urlCounter++;
             }
@@ -853,16 +854,17 @@
         {
             // log.debug("Attempting to match page contents with "+p.getPattern());
 
-            if( m_matcher.contains( change, p ) )
+            Matcher matcher = p.matcher( change );
+            if( matcher.find( ) )
             {
                 //
                 //  Spam filter has a match.
                 //
-                String uid = log( context, REJECT, REASON_REGEXP+"("+p.getPattern()+")", change);
+                String uid = log( context, REJECT, REASON_REGEXP+"("+p.pattern()+")", change);
 
-                log.info("SPAM:Regexp ("+uid+"). Content matches the spam filter '"+p.getPattern()+"'");
+                log.info("SPAM:Regexp ("+uid+"). Content matches the spam filter '"+p.pattern()+"'");
 
-                checkStrategy( context, REASON_REGEXP, "Herb says '"+p.getPattern()+"' is a bad spam word and I trust Herb! (Incident code "+uid+")");
+                checkStrategy( context, REASON_REGEXP, "Herb says '"+p.pattern()+"' is a bad spam word and I trust Herb! (Incident code "+uid+")");
             }
         }
     }

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/LoggerFactory.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/LoggerFactory.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/LoggerFactory.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/log/LoggerFactory.java Sat Dec 20 12:52:22 2008
@@ -100,19 +100,17 @@
      * @return A Logger instance. 
      */
     public static final synchronized Logger getLogger( String loggerName )
-    {
-        if( c_isLoggerFactoryClosed )
-        {
-            return null;
-        }
-        
+    {        
         if( c_registeredLoggers.get( loggerName ) == null )
         {
             LoggerImpl logger = new LoggerImpl( loggerName );
             c_registeredLoggers.put( loggerName, logger );
             if( c_isLog4jPresent )
             {
-                registerLoggerMBean( loggerName );
+                if( !c_isLoggerFactoryClosed )
+                {
+                    registerLoggerMBean( loggerName );
+                }
             }
             return logger;
         }

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java Sat Dec 20 12:52:22 2008
@@ -25,6 +25,10 @@
 import java.io.StringReader;
 import java.text.MessageFormat;
 import java.util.*;
+import java.util.regex.MatchResult;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
 
 import javax.servlet.http.HttpServletResponse;
 import javax.xml.transform.Result;
@@ -32,8 +36,6 @@
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.jspwiki.api.PluginException;
-import org.apache.oro.text.GlobCompiler;
-import org.apache.oro.text.regex.*;
 import org.jdom.*;
 
 import com.ecyrd.jspwiki.*;
@@ -49,6 +51,7 @@
 import com.ecyrd.jspwiki.providers.ProviderException;
 import com.ecyrd.jspwiki.render.CleanTextRenderer;
 import com.ecyrd.jspwiki.render.RenderingManager;
+import com.ecyrd.jspwiki.util.RegExpUtil;
 import com.ecyrd.jspwiki.util.TextUtil;
 
 /**
@@ -115,8 +118,6 @@
     /** Parser for extended link functionality. */
     private LinkParser     m_linkParser = new LinkParser();
 
-    private PatternMatcher m_inlineMatcher = new Perl5Matcher();
-
     /** Keeps track of any plain text that gets put in the Text nodes */
     private StringBuilder  m_plainTextBuf = new StringBuilder(20);
 
@@ -167,11 +168,19 @@
 
     private boolean                m_useRelNofollow      = false;
 
-    private PatternCompiler        m_compiler = new Perl5Compiler();
-
-    static final String WIKIWORD_REGEX = "(^|[[:^alnum:]]+)([[:upper:]]+[[:lower:]]+[[:upper:]]+[[:alnum:]]*|(http://|https://|mailto:)([A-Za-z0-9_/\\.\\+\\?\\#\\-\\@=&;~%]+))";
+//    static final String WIKIWORD_REGEX = "(^|[[:^alnum:]]+)([[:upper:]]+[[:lower:]]+[[:upper:]]+[[:alnum:]]*|(http://|https://|mailto:)([A-Za-z0-9_/\\.\\+\\?\\#\\-\\@=&;~%]+))";
+    private static final String    ALNUM = "\\p{javaLetterOrDigit}";
+    private static final String    NOT_ALNUM = "\\P{javaLetterOrDigit}";
+    private static final String    UPPER = "\\p{Lu}";
+    private static final String    LOWER = "\\p{Ll}";
+    
+    static final String WIKIWORD_REGEX = "(^|["+NOT_ALNUM+"]+)("+
+                                         UPPER+"+"
+                                         +LOWER+"+"
+                                         +UPPER+"+"
+                                         +ALNUM+"*"
+                                         +"|(http://|https://|mailto:)([A-Za-z0-9_/\\.\\+\\?\\#\\-\\@=&;~%]+))";
 
-    private PatternMatcher         m_camelCaseMatcher = new Perl5Matcher();
     private Pattern                m_camelCasePattern;
 
     private int                    m_rowNum              = 1;
@@ -256,7 +265,6 @@
     @SuppressWarnings("unchecked")
     private void initialize()
     {
-        PatternCompiler compiler         = new GlobCompiler();
         List<Pattern>   compiledpatterns;
 
         //
@@ -278,10 +286,10 @@
             {
                 try
                 {
-                    compiledpatterns.add( compiler.compile( (String)i.next(),
-                                                            GlobCompiler.DEFAULT_MASK|GlobCompiler.READ_ONLY_MASK ) );
+                    compiledpatterns.add( Pattern.compile( RegExpUtil
+                        .globToPerl5( ((String) i.next()).toCharArray(), RegExpUtil.DEFAULT_MASK|RegExpUtil.READ_ONLY_MASK ) ) );
                 }
-                catch( MalformedPatternException e )
+                catch( PatternSyntaxException e )
                 {
                     log.error("Malformed pattern in properties: ", e );
                 }
@@ -297,10 +305,9 @@
         {
             try
             {
-                m_camelCasePattern = m_compiler.compile( WIKIWORD_REGEX,
-                                                         Perl5Compiler.DEFAULT_MASK|Perl5Compiler.READ_ONLY_MASK );
+                m_camelCasePattern = Pattern.compile( WIKIWORD_REGEX, RegExpUtil.DEFAULT_MASK | RegExpUtil.READ_ONLY_MASK );
             }
-            catch( MalformedPatternException e )
+            catch( PatternSyntaxException e )
             {
                 log.error("Internal error: Someone put in a faulty pattern.",e);
                 throw new InternalWikiException("Faulty camelcasepattern in TranslatorReader");
@@ -694,7 +701,8 @@
 
             for( Iterator i = m_inlineImagePatterns.iterator(); i.hasNext(); )
             {
-                if( m_inlineMatcher.matches( link, (Pattern) i.next() ) )
+                Matcher matcher = ((Pattern) i.next()).matcher( link );
+                if( matcher.matches() )
                     return true;
             }
         }
@@ -801,24 +809,24 @@
 
                 if( m_camelCaseLinks && !m_isEscaping && buf.length() > 3 )
                 {
-                    // System.out.println("Buffer="+buf);
-
-                    while( m_camelCaseMatcher.contains( buf, m_camelCasePattern ) )
+                    Matcher camelCaseMatcher = null;
+                    while (( camelCaseMatcher =  m_camelCasePattern.matcher( buf )).find())
                     {
-                        MatchResult result = m_camelCaseMatcher.getMatch();
-
-                        String firstPart = buf.substring(0,result.beginOffset(0));
-                        String prefix = result.group(1);
+                        MatchResult result = camelCaseMatcher.toMatchResult();
+                        
+                        String firstPart = buf.substring( 0, result.start() );
+                        String prefix = result.group( 1 );
 
-                        if( prefix == null ) prefix = "";
+                        if( prefix == null )
+                            prefix = "";
 
-                        String camelCase = result.group(2);
-                        String protocol  = result.group(3);
-                        String uri       = protocol+result.group(4);
-                        buf              = buf.substring(result.endOffset(0));
+                        String camelCase = result.group( 2 );
+                        String protocol = result.group( 3 );
+                        String uri = protocol + result.group( 4 );
+                        buf = buf.substring( result.end() );
 
                         m_currentElement.addContent( firstPart );
-
+                        result.group( 2 );
                         //
                         //  Check if the user does not wish to do URL or WikiWord expansion
                         //
@@ -855,15 +863,11 @@
                                 uri = uri.substring(0,uri.length()-1);
                                 buf = c + buf;
                             }
-                            // System.out.println("URI match "+uri);
                             m_currentElement.addContent( prefix );
                             makeDirectURILink( uri );
                         }
                         else
                         {
-                            // System.out.println("Matched: '"+camelCase+"'");
-                            // System.out.println("Split to '"+firstPart+"', and '"+buf+"'");
-                            // System.out.println("prefix="+prefix);
                             m_currentElement.addContent( prefix );
 
                             makeCamelCaseLink( camelCase );
@@ -1343,7 +1347,6 @@
         else if( ( linkExists( possiblePage ) ) != null &&
                  hasLinkText )
         {
-            // System.out.println("Orig="+link+", Matched: "+matchedLink);
             callMutatorChain( m_localLinkMutatorChain, possiblePage );
 
             return makeLink( IMAGEWIKILINK, reallink, link, null, null );
@@ -3015,6 +3018,4 @@
 
     }
 
-
 }
-

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/AbstractReferralPlugin.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/AbstractReferralPlugin.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/AbstractReferralPlugin.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/AbstractReferralPlugin.java Sat Dec 20 12:52:22 2008
@@ -23,11 +23,12 @@
 import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.jspwiki.api.PluginException;
-import org.apache.oro.text.GlobCompiler;
-import org.apache.oro.text.regex.*;
 
 import com.ecyrd.jspwiki.*;
 import com.ecyrd.jspwiki.log.Logger;
@@ -37,6 +38,7 @@
 import com.ecyrd.jspwiki.preferences.Preferences;
 import com.ecyrd.jspwiki.preferences.Preferences.TimeFormat;
 import com.ecyrd.jspwiki.render.RenderingManager;
+import com.ecyrd.jspwiki.util.RegExpUtil;
 import com.ecyrd.jspwiki.util.TextUtil;
 
 /**
@@ -99,7 +101,7 @@
     protected           String   m_separator = ""; // null not blank
     protected           String   m_after = "\\\\";
 
-    protected           Pattern[]  m_exclude;
+    protected           Pattern[] m_exclude;
     protected           Pattern[]  m_include;
     
     protected           String m_show = "pages";
@@ -155,18 +157,18 @@
         {
             try
             {
-                PatternCompiler pc = new GlobCompiler();
-
                 String[] ptrns = StringUtils.split( s, "," );
 
                 m_exclude = new Pattern[ptrns.length];
 
                 for( int i = 0; i < ptrns.length; i++ )
                 {
-                    m_exclude[i] = pc.compile( ptrns[i] );
+                    m_exclude[i] = Pattern
+                        .compile( RegExpUtil.globToPerl5( ptrns[i].toCharArray(),
+                                                                        RegExpUtil.DEFAULT_MASK ) );
                 }
             }
-            catch( MalformedPatternException e )
+            catch( PatternSyntaxException e )
             {
                 throw new PluginException("Exclude-parameter has a malformed pattern: "+e.getMessage());
             }
@@ -179,18 +181,18 @@
         {
             try
             {
-                PatternCompiler pc = new GlobCompiler();
-
                 String[] ptrns = StringUtils.split( s, "," );
 
                 m_include = new Pattern[ptrns.length];
 
                 for( int i = 0; i < ptrns.length; i++ )
                 {
-                    m_include[i] = pc.compile( ptrns[i] );
+                    m_include[i] = Pattern
+                        .compile( RegExpUtil.globToPerl5( ptrns[i].toCharArray(),
+                                                                        RegExpUtil.DEFAULT_MASK ) );
                 }
             }
-            catch( MalformedPatternException e )
+            catch( PatternSyntaxException e )
             {
                 throw new PluginException("Include-parameter has a malformed pattern: "+e.getMessage());
             }
@@ -235,8 +237,6 @@
     {
         ArrayList<String> result = new ArrayList<String>();
 
-        PatternMatcher pm = new Perl5Matcher();
-
         for( Iterator i = c.iterator(); i.hasNext(); )
         {
             String pageName = (String) i.next();
@@ -253,7 +253,8 @@
             {
                 for( int j = 0; j < m_include.length; j++ )
                 {
-                    if( pm.matches( pageName, m_include[j] ) )
+                    Matcher matcher = m_include[j].matcher( pageName );
+                    if( matcher.matches() )
                     {
                         includeThis = true;
                         break;
@@ -265,7 +266,8 @@
             {
                 for( int j = 0; j < m_exclude.length; j++ )
                 {
-                    if( pm.matches( pageName, m_exclude[j] ) )
+                    Matcher matcher = m_exclude[j].matcher( pageName );
+                    if( matcher.matches() )
                     {
                         includeThis = false;
                         break; // The inner loop, continue on the next item
@@ -277,7 +279,7 @@
             {
                 result.add( pageName );
                 //
-                //  if we want to show the last modified date of the most recently change page, we keep a "high watermark" here:
+                //  if we want to show the last modified date of the most recently changed page, we keep a "high watermark" here:
                 WikiPage page = null;
                 if( m_lastModified )
                 {

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/IfPlugin.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/IfPlugin.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/IfPlugin.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/IfPlugin.java Sat Dec 20 12:52:22 2008
@@ -23,11 +23,12 @@
 
 import java.security.Principal;
 import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.jspwiki.api.ModuleData;
 import org.apache.jspwiki.api.PluginException;
-import org.apache.oro.text.regex.*;
 
 import com.ecyrd.jspwiki.WikiContext;
 import com.ecyrd.jspwiki.WikiProvider;
@@ -269,16 +270,13 @@
     private static boolean doMatch( String content, String pattern )
         throws PluginException
     {
-        PatternCompiler compiler = new Perl5Compiler();
-        PatternMatcher  matcher  = new Perl5Matcher();
-
         try
         {
-            Pattern matchp = compiler.compile( pattern, Perl5Compiler.SINGLELINE_MASK );
+            Pattern matchPattern = Pattern.compile( pattern );
             // m_exceptPattern = compiler.compile( exceptPattern, Perl5Compiler.SINGLELINE_MASK );
-            return matcher.matches( content, matchp );
+            return matchPattern.matcher( content ).matches();
         }
-        catch( MalformedPatternException e )
+        catch( PatternSyntaxException e )
         {
             throw new PluginException("Faulty pattern "+pattern);
         }

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/PluginManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/PluginManager.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/PluginManager.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/PluginManager.java Sat Dec 20 12:52:22 2008
@@ -24,6 +24,10 @@
 import java.lang.reflect.Modifier;
 import java.text.MessageFormat;
 import java.util.*;
+import java.util.regex.MatchResult;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
 
 import net.sourceforge.stripes.util.ResolverUtil;
 
@@ -31,7 +35,6 @@
 import org.apache.ecs.xhtml.*;
 import org.apache.jspwiki.api.ModuleData;
 import org.apache.jspwiki.api.PluginException;
-import org.apache.oro.text.regex.*;
 
 import com.ecyrd.jspwiki.*;
 import com.ecyrd.jspwiki.log.Logger;
@@ -208,13 +211,11 @@
         m_searchPath.add( DEFAULT_PACKAGE );
         m_searchPath.add( DEFAULT_FORMS_PACKAGE );
 
-        PatternCompiler compiler = new Perl5Compiler();
-
         try
         {
-            m_pluginPattern = compiler.compile( PLUGIN_INSERT_PATTERN );
+            m_pluginPattern = Pattern.compile( PLUGIN_INSERT_PATTERN );
         }
-        catch( MalformedPatternException e )
+        catch( PatternSyntaxException e )
         {
             log.error("Internal error: someone messed with pluginmanager patterns.", e );
             throw new InternalWikiException( "PluginManager patterns are broken" );
@@ -564,19 +565,18 @@
 
         ResourceBundle rb = context.getBundle(WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
         Object[] obArgs = { commandline };
-        PatternMatcher  matcher  = new Perl5Matcher();
+        Matcher  matcher  = m_pluginPattern.matcher( commandline );
 
         try
         {
-            if( matcher.contains( commandline, m_pluginPattern ) )
+            if( matcher.find( ) )
             {
-                MatchResult res = matcher.getMatch();
+                MatchResult res = matcher.toMatchResult();
 
-                String plugin   = res.group(2);
-                String args     = commandline.substring(res.endOffset(0),
-                                                        commandline.length() -
-                                                        (commandline.charAt(commandline.length()-1) == '}' ? 1 : 0 ) );
-                Map arglist     = parseArgs( args );
+                String plugin = res.group( 2 );
+                String args = commandline.substring( res.end(), commandline.length()
+                                                                - (commandline.charAt( commandline.length() - 1 ) == '}' ? 1 : 0) );
+                Map arglist = parseArgs( args );
 
                 return execute( context, plugin, arglist );
             }
@@ -613,18 +613,18 @@
    public PluginContent parsePluginLine( WikiContext context, String commandline, int pos )
         throws PluginException
     {
-        PatternMatcher  matcher  = new Perl5Matcher();
+        Matcher  matcher  = m_pluginPattern.matcher( commandline );
 
         try
         {
-            if( matcher.contains( commandline, m_pluginPattern ) )
+            if( matcher.find() )
             {
-                MatchResult res = matcher.getMatch();
+                MatchResult res = matcher.toMatchResult();
 
                 String plugin   = res.group(2);
-                String args     = commandline.substring(res.endOffset(0),
-                                                        commandline.length() -
-                                                        (commandline.charAt(commandline.length()-1) == '}' ? 1 : 0 ) );
+                String args = commandline.substring( res.end( 0 ),
+                                                     commandline.length()
+                                                         - (commandline.charAt( commandline.length() - 1 ) == '}' ? 1 : 0) );
                 Map<String, Object> arglist = parseArgs( args );
 
                 // set wikitext bounds of plugin as '_bounds' parameter, e.g., [345,396]

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/ReferredPagesPlugin.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/ReferredPagesPlugin.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/ReferredPagesPlugin.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/plugin/ReferredPagesPlugin.java Sat Dec 20 12:52:22 2008
@@ -21,9 +21,10 @@
 package com.ecyrd.jspwiki.plugin;
 
 import java.util.*;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
 
 import org.apache.jspwiki.api.PluginException;
-import org.apache.oro.text.regex.*;
 
 import com.ecyrd.jspwiki.*;
 import com.ecyrd.jspwiki.log.Logger;
@@ -37,7 +38,6 @@
  *  <p>Parameters</p>
  *  <ul>
  *    <li><b>name</b> - Name of the root page. Default name of calling page
- *    <li><b>type</b> - local|externalattachment
  *    <li><b>depth</b> - How many levels of pages to be parsed.
  *    <li><b>include</b> - Include only these pages. (eg. include='UC.*|BP.*' )
  *    <li><b>exclude</b> - Exclude with this pattern. (eg. exclude='LeftMenu' )
@@ -53,7 +53,6 @@
     private int            m_depth;
     private HashSet<String> m_exists  = new HashSet<String>();
     private StringBuilder   m_result  = new StringBuilder(1024);
-    private PatternMatcher m_matcher = new Perl5Matcher();
     private Pattern        m_includePattern;
     private Pattern        m_excludePattern;
     private boolean m_formatCompact  = true;
@@ -65,9 +64,6 @@
     /** The parameter name for the depth.  Value is <tt>{@value}</tt>. */
     public static final String PARAM_DEPTH   = "depth";
 
-    /** The parameter name for the type of the references.  Value is <tt>{@value}</tt>. */
-    public static final String PARAM_TYPE    = "type";
-    
     /** The parameter name for the included pages.  Value is <tt>{@value}</tt>. */
     public static final String PARAM_INCLUDE = "include";
     
@@ -136,19 +132,18 @@
         // glob compiler :  * is 0..n instance of any char  -- more convenient as input
         // perl5 compiler : .* is 0..n instances of any char -- more powerful
         //PatternCompiler g_compiler = new GlobCompiler();
-        PatternCompiler compiler = new Perl5Compiler();
 
         try
         {
-            m_includePattern = compiler.compile(includePattern);
+            m_includePattern = Pattern.compile( includePattern );
 
-            m_excludePattern = compiler.compile(excludePattern);
+            m_excludePattern = Pattern.compile( excludePattern );
         }
-        catch( MalformedPatternException e )
+        catch( PatternSyntaxException e )
         {
             if (m_includePattern == null )
             {
-                throw new PluginException("Illegal include pattern detected.");
+                throw new PluginException( "Illegal include pattern detected." );
             }
             else if (m_excludePattern == null )
             {
@@ -214,8 +209,8 @@
             if( !m_engine.pageExists( link ) ) continue; // hide links to non
                                                          // existing pages
 
-            if(  m_matcher.matches( link , m_excludePattern ) ) continue;
-            if( !m_matcher.matches( link , m_includePattern ) ) continue;
+            if( m_excludePattern.matcher( link ).find()) continue;
+            if( !m_includePattern.matcher( link ).find() ) continue;
 
             if( m_exists.contains( link ) )
             {

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/providers/RCSFileProvider.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/providers/RCSFileProvider.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/providers/RCSFileProvider.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/providers/RCSFileProvider.java Sat Dec 20 12:52:22 2008
@@ -30,6 +30,10 @@
 import java.util.List;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.regex.MatchResult;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
 import java.text.SimpleDateFormat;
 import java.text.ParseException;
 
@@ -39,8 +43,6 @@
 import com.ecyrd.jspwiki.util.FileUtil;
 import com.ecyrd.jspwiki.util.TextUtil;
 
-import org.apache.oro.text.regex.*;
-
 import com.ecyrd.jspwiki.*;
 
 /**
@@ -136,8 +138,7 @@
     public WikiPage getPageInfo( String page, int version )
         throws ProviderException
     {
-        PatternMatcher  matcher  = new Perl5Matcher();
-        PatternCompiler compiler = new Perl5Compiler();
+        Matcher  matcher  = null;
         BufferedReader  stdout   = null;
 
         WikiPage info = super.getPageInfo( page, version );
@@ -156,20 +157,21 @@
             stdout = new BufferedReader( new InputStreamReader(process.getInputStream() ) );
 
             String line;
-            Pattern headpattern = compiler.compile( PATTERN_REVISION );
+            Pattern headpattern = Pattern.compile( PATTERN_REVISION );
             // This complicated pattern is required, since on Linux RCS adds
             // quotation marks, but on Windows, it does not.
-            Pattern userpattern = compiler.compile( PATTERN_AUTHOR );
-            Pattern datepattern = compiler.compile( PATTERN_DATE );
-            Pattern notepattern = compiler.compile( PATTERN_CHANGENOTE );
+            Pattern userpattern = Pattern.compile( PATTERN_AUTHOR );
+            Pattern datepattern = Pattern.compile( PATTERN_DATE );
+            Pattern notepattern = Pattern.compile( PATTERN_CHANGENOTE );
 
             boolean found = false;
 
             while( (line = stdout.readLine()) != null )
             {
-                if( matcher.contains( line, headpattern ) )
+                matcher = headpattern.matcher( line ); 
+                if( matcher.find() )
                 {
-                    MatchResult result = matcher.getMatch();
+                    MatchResult result = matcher.toMatchResult();
 
                     try
                     {
@@ -187,9 +189,11 @@
                         // Just continue reading through
                     }
                 }
-                else if( matcher.contains( line, datepattern ) && found )
+                else
+                    matcher = datepattern.matcher( line );
+                    if( matcher.find() && found )
                 {
-                    MatchResult result = matcher.getMatch();
+                    MatchResult result = matcher.toMatchResult();
                     Date d = parseDate( result.group(1) );
 
                     if( d != null )
@@ -209,17 +213,19 @@
                     break;
                 }
 
-                if( found && matcher.contains( line, userpattern ) )
+                matcher = userpattern.matcher( line );
+                if( found && matcher.find() )
                 {
-                    MatchResult result = matcher.getMatch();
-                    info.setAuthor( TextUtil.urlDecodeUTF8(result.group(1)) );
+                    MatchResult result = matcher.toMatchResult();
+                    info.setAuthor( TextUtil.urlDecodeUTF8( result.group( 1 ) ) );
                 }
 
-                if( found && matcher.contains( line, notepattern ) )
+                matcher = notepattern.matcher( line );
+                if( found && matcher.find() )
                 {
-                    MatchResult result = matcher.getMatch();
+                    MatchResult result = matcher.toMatchResult();
 
-                    info.setAttribute( WikiPage.CHANGENOTE, TextUtil.urlDecodeUTF8(result.group(1)) );
+                    info.setAttribute( WikiPage.CHANGENOTE, TextUtil.urlDecodeUTF8( result.group( 1 ) ) );
                 }
             }
 
@@ -279,8 +285,7 @@
 
         try
         {
-            PatternMatcher  matcher           = new Perl5Matcher();
-            PatternCompiler compiler          = new Perl5Compiler();
+            Matcher  matcher           = null;;
             int             checkedOutVersion = -1;
             String          line;
             String          cmd               = m_checkoutVersionCommand;
@@ -296,13 +301,14 @@
 
             stderr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
 
-            Pattern headpattern = compiler.compile( PATTERN_REVISION );
+            Pattern headpattern = Pattern.compile( PATTERN_REVISION );
 
             while( (line = stderr.readLine()) != null )
             {
-                if( matcher.contains( line, headpattern ) )
+                matcher = headpattern.matcher( line );
+                if( matcher.find() )
                 {
-                    MatchResult mr = matcher.getMatch();
+                    MatchResult mr = matcher.toMatchResult();
                     checkedOutVersion = Integer.parseInt( mr.group(1) );
                 }
             }
@@ -343,7 +349,7 @@
             }
 
         }
-        catch( MalformedPatternException e )
+        catch( PatternSyntaxException e )
         {
             throw new InternalWikiException("Malformed pattern in RCSFileProvider!");
         }
@@ -467,8 +473,7 @@
     // FIXME: Put the rcs date formats into properties as well.
     public List getVersionHistory( String page )
     {
-        PatternMatcher matcher = new Perl5Matcher();
-        PatternCompiler compiler = new Perl5Compiler();
+        Matcher matcher =null;
         BufferedReader stdout  = null;
 
         log.debug("Getting RCS version history");
@@ -477,13 +482,13 @@
 
         try
         {
-            Pattern revpattern  = compiler.compile( PATTERN_REVISION );
-            Pattern datepattern = compiler.compile( PATTERN_DATE );
+            Pattern revpattern  = Pattern.compile( PATTERN_REVISION );
+            Pattern datepattern = Pattern.compile( PATTERN_DATE );
             // This complicated pattern is required, since on Linux RCS adds
             // quotation marks, but on Windows, it does not.
-            Pattern userpattern = compiler.compile( PATTERN_AUTHOR );
+            Pattern userpattern = Pattern.compile( PATTERN_AUTHOR );
 
-            Pattern notepattern = compiler.compile( PATTERN_CHANGENOTE );
+            Pattern notepattern = Pattern.compile( PATTERN_CHANGENOTE );
 
             String cmd = TextUtil.replaceString( m_fullLogCommand,
                                                  "%s",
@@ -500,11 +505,12 @@
 
             while( (line = stdout.readLine()) != null )
             {
-                if( matcher.contains( line, revpattern ) )
+                matcher =revpattern.matcher( line ); 
+                if( matcher.find() )
                 {
                     info = m_engine.createPage( WikiName.valueOf( page ) );
 
-                    MatchResult result = matcher.getMatch();
+                    MatchResult result = matcher.toMatchResult();
 
                     int vernum = Integer.parseInt( result.group(1) );
                     info.setVersion( vernum );
@@ -512,25 +518,28 @@
                     list.add( info );
                 }
 
-                if( matcher.contains( line, datepattern ) && info != null )
+                matcher = datepattern.matcher( line );
+                if( matcher.find() && info != null )
                 {
-                    MatchResult result = matcher.getMatch();
+                    MatchResult result = matcher.toMatchResult();
 
                     Date d = parseDate( result.group(1) );
 
                     info.setLastModified( d );
                 }
 
-                if( matcher.contains( line, userpattern ) && info != null )
+                matcher = userpattern.matcher( line );
+                if( matcher.find() && info != null )
                 {
-                    MatchResult result = matcher.getMatch();
+                    MatchResult result = matcher.toMatchResult();
 
                     info.setAuthor( TextUtil.urlDecodeUTF8(result.group(1)) );
                 }
 
-                if( matcher.contains( line, notepattern ) && info != null )
+                matcher = notepattern.matcher( line );
+                if( matcher.find() && info != null )
                 {
-                    MatchResult result = matcher.getMatch();
+                    MatchResult result = matcher.toMatchResult();
 
                     info.setAttribute( WikiPage.CHANGENOTE, TextUtil.urlDecodeUTF8(result.group(1)) );
                 }

Added: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/RegExpUtil.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/RegExpUtil.java?rev=728341&view=auto
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/RegExpUtil.java (added)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/RegExpUtil.java Sat Dec 20 12:52:22 2008
@@ -0,0 +1,186 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+    
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.  
+*/
+package com.ecyrd.jspwiki.util;
+
+/**
+ * Copied code from the org.apache.oro.text.regex.GlobCompiler
+ * All credits to the author's
+ */
+public final class RegExpUtil
+{
+    private RegExpUtil()
+    {
+        // private constructor prevents construction
+    }
+
+    /**
+     * The default mask . It is equal to 0
+     * The default behavior is for a glob expression to be case sensitive
+     * unless it is compiled with the CASE_INSENSITIVE_MASK option.
+     */
+    public static final int DEFAULT_MASK = 0;
+
+    /**
+     * A mask passed as an option to
+     * indicate a compiled glob expression should be case insensitive.
+     */
+    public static final int CASE_INSENSITIVE_MASK = 0x0001;
+
+    /**
+     * A mask to indicate that a * should not be allowed to match the null string.
+     * Thenormal behavior of the * metacharacter is that it may match any 0 or more
+     * characters. This mask causes it to match 1 or more characters of
+     * anything.
+     */
+    public static final int STAR_CANNOT_MATCH_NULL_MASK = 0x0002;
+
+    /**
+     * A mask to indicate that a ? should not be allowed to match the null string.
+     * The normal behavior of the ? metacharacter is that it may match any 1
+     * character. This mask causes it to match 0 or 1 characters.
+     */
+    public static final int QUESTION_MATCHES_ZERO_OR_ONE_MASK = 0x0004;
+
+    /**
+     * A mask to indicate that the resulting Perl5Pattern should be treated as a read only
+     * data structure by Perl5Matcher, making it safe to share a single
+     * Perl5Pattern instance among multiple threads without needing
+     * synchronization. Without this option, Perl5Matcher reserves the right to
+     * store heuristic or other information in Perl5Pattern that might
+     * accelerate future matches. When you use this option, Perl5Matcher will
+     * not store or modify any information in a Perl5Pattern. Use this option
+     * when you want to share a Perl5Pattern instance among multiple threads
+     * using different Perl5Matcher instances.
+     */
+    public static final int READ_ONLY_MASK = 0x0008;
+
+    /**
+     * This static method is the basic engine of the Glob PatternCompiler
+     * implementation. It takes a glob expression in the form of a character
+     * array and converts it into a String representation of a Perl5 pattern.
+     * The method is made public so that programmers may use it for their own
+     * purposes. However, the GlobCompiler compile methods work by converting
+     * the glob pattern to a Perl5 pattern using this method, and then invoking
+     * the compile() method of an internally stored Perl5Compiler instance.
+     * <p>
+     * 
+     * @param pattern A character array representation of a Glob pattern.
+     * @return A String representation of a Perl5 pattern equivalent to the Glob
+     *         pattern.
+     */
+    public static String globToPerl5( char[] pattern, int options )
+    {
+        boolean inCharSet = false;
+        boolean starCannotMatchNull = false;
+        boolean questionMatchesZero = false;
+        
+        int ch;
+        StringBuffer buffer;
+
+        buffer = new StringBuffer( 2 * pattern.length );
+        inCharSet = false;
+
+        questionMatchesZero = (options & QUESTION_MATCHES_ZERO_OR_ONE_MASK) != 0;
+        starCannotMatchNull = (options & STAR_CANNOT_MATCH_NULL_MASK) != 0;
+
+        for( ch = 0; ch < pattern.length; ch++ )
+        {
+            switch( pattern[ch] )
+            {
+                case '*':
+                    if( inCharSet )
+                        buffer.append( '*' );
+                    else
+                    {
+                        if( starCannotMatchNull )
+                            buffer.append( ".+" );
+                        else
+                            buffer.append( ".*" );
+                    }
+                    break;
+                case '?':
+                    if( inCharSet )
+                        buffer.append( '?' );
+                    else
+                    {
+                        if( questionMatchesZero )
+                            buffer.append( ".?" );
+                        else
+                            buffer.append( '.' );
+                    }
+                    break;
+                case '[':
+                    inCharSet = true;
+                    buffer.append( pattern[ch] );
+
+                    if( ch + 1 < pattern.length )
+                    {
+                        switch( pattern[ch + 1] )
+                        {
+                            case '!':
+                            case '^':
+                                buffer.append( '^' );
+                                ++ch;
+                                continue;
+                            case ']':
+                                buffer.append( ']' );
+                                ++ch;
+                                continue;
+                        }
+                    }
+                    break;
+                case ']':
+                    inCharSet = false;
+                    buffer.append( pattern[ch] );
+                    break;
+                case '\\':
+                    buffer.append( '\\' );
+                    if( ch == pattern.length - 1 )
+                    {
+                        buffer.append( '\\' );
+                    }
+                    else if( isGlobMetaCharacter( pattern[ch + 1] ) )
+                        buffer.append( pattern[++ch] );
+                    else
+                        buffer.append( '\\' );
+                    break;
+                default:
+                    if( !inCharSet && isPerl5MetaCharacter( pattern[ch] ) )
+                        buffer.append( '\\' );
+                    buffer.append( pattern[ch] );
+                    break;
+            }
+        }
+
+        return buffer.toString();
+    }
+
+    private static boolean isPerl5MetaCharacter( char ch )
+    {
+        return "'*?+[]()|^$.{}\\".indexOf( ch ) >= 0;
+    }
+
+    private static boolean isGlobMetaCharacter( char ch )
+    {
+        return "*?[]".indexOf( ch ) >= 0;
+    }
+
+}

Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/attachment/AttachmentManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/attachment/AttachmentManagerTest.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/attachment/AttachmentManagerTest.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/attachment/AttachmentManagerTest.java Sat Dec 20 12:52:22 2008
@@ -30,7 +30,6 @@
 import junit.framework.TestSuite;
 
 import com.ecyrd.jspwiki.TestEngine;
-import com.ecyrd.jspwiki.content.WikiName;
 import com.ecyrd.jspwiki.providers.ProviderException;
 import com.ecyrd.jspwiki.util.FileUtil;
 

Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/diff/ContextualDiffProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/diff/ContextualDiffProviderTest.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/diff/ContextualDiffProviderTest.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/diff/ContextualDiffProviderTest.java Sat Dec 20 12:52:22 2008
@@ -30,7 +30,6 @@
 import junit.framework.TestSuite;
 
 import com.ecyrd.jspwiki.*;
-import com.ecyrd.jspwiki.content.WikiName;
 
 public class ContextualDiffProviderTest extends TestCase
 {

Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/AllTests.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/AllTests.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/AllTests.java Sat Dec 20 12:52:22 2008
@@ -46,6 +46,7 @@
         suite.addTest( TableOfContentsTest.suite() );
         suite.addTest( UndefinedPagesPluginTest.suite() );
         suite.addTest( DenouncePluginTest.suite() );
+        suite.addTest( ReferredPagesPluginTest.suite() );
 
         return suite;
     }

Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/CounterPluginTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/CounterPluginTest.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/CounterPluginTest.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/CounterPluginTest.java Sat Dec 20 12:52:22 2008
@@ -34,7 +34,6 @@
 import com.ecyrd.jspwiki.NoRequiredPropertyException;
 import com.ecyrd.jspwiki.TestEngine;
 import com.ecyrd.jspwiki.WikiContext;
-import com.ecyrd.jspwiki.content.WikiName;
 import com.ecyrd.jspwiki.parser.JSPWikiMarkupParser;
 import com.ecyrd.jspwiki.parser.MarkupParser;
 import com.ecyrd.jspwiki.parser.WikiDocument;

Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/PluginManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/PluginManagerTest.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/PluginManagerTest.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/PluginManagerTest.java Sat Dec 20 12:52:22 2008
@@ -31,7 +31,6 @@
 import com.ecyrd.jspwiki.TestEngine;
 import com.ecyrd.jspwiki.WikiContext;
 import com.ecyrd.jspwiki.WikiEngine;
-import com.ecyrd.jspwiki.content.WikiName;
 import com.ecyrd.jspwiki.plugin.PluginManager.WikiPluginInfo;
 import com.ecyrd.jspwiki.providers.ProviderException;
 

Added: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferredPagesPluginTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferredPagesPluginTest.java?rev=728341&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferredPagesPluginTest.java (added)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferredPagesPluginTest.java Sat Dec 20 12:52:22 2008
@@ -0,0 +1,130 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.    
+ */
+
+package com.ecyrd.jspwiki.plugin;
+
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.WikiContext;
+
+public class ReferredPagesPluginTest extends TestCase
+{
+    Properties props = new Properties();
+
+    TestEngine engine;
+
+    WikiContext context;
+
+    PluginManager manager;
+
+    public ReferredPagesPluginTest( String s )
+    {
+        super( s );
+    }
+
+    public void setUp() throws Exception
+    {
+        props.load( TestEngine.findTestProperties() );
+
+        engine = new TestEngine( props );
+
+        engine.saveText( "SomeBodyPointsToMe", "Somebody points to this page" );
+        engine.saveText( "IPointToSomeoneElse", "Reference to [SomeBodyPointsToMe]." );
+        engine.saveText( "IPointToSomeoneElseToo", "Reference to [SomeBodyPointsToMe]." );
+        engine.saveText( "SomeBodyPointsToMeToo", "Somebody points to this page too" );
+        engine.saveText( "IPointToTwoPages", "Reference to [SomeBodyPointsToMe]  and   [SomeBodyPointsToMeToo]." );
+
+        context = engine.getWikiContextFactory().newViewContext( null, null, engine.createPage( "IPointToSomeoneElse" ) );
+        manager = new PluginManager( engine, props );
+    }
+
+    public void tearDown()
+    {
+        TestEngine.deleteTestPage( "SomeBodyPointsToMe" );
+        TestEngine.deleteTestPage( "IPointToSomeoneElse" );
+        TestEngine.deleteTestPage( "IPointToSomeoneElseToo" );
+        TestEngine.deleteTestPage( "SomeBodyPointsToMeToo");
+        TestEngine.deleteTestPage( "IPointToTwoPages" );
+        
+        TestEngine.emptyWorkDir();
+    }
+
+    /**
+     * Plain test without parameters
+     * 
+     * @throws Exception
+     */
+    public void testReferredPage() throws Exception
+    {
+        context = engine.getWikiContextFactory().newViewContext( null, null, engine.createPage(  "IPointToSomeoneElse" ) );
+
+        String res = manager.execute( context, "{INSERT com.ecyrd.jspwiki.plugin.ReferredPagesPlugin}" );
+
+        assertEquals(
+                      "<div class=\"ReferredPagesPlugin\">\n<a class=\"wikipage\" href=\"/Wiki.jsp?page=IPointToSomeoneElse\" title=\"ReferredPagesPlugin: depth[1] include[.*] exclude[^$] format[compact]\">IPointToSomeoneElse</a>\n<ul>\n<li><a class=\"wikipage\" href=\"/Wiki.jsp?page=SomeBodyPointsToMe\">SomeBodyPointsToMe</a></li>\n</ul>\n</div>\n",
+                      res );
+    }
+
+    /**
+     * Test with the page parameter (page A tells us which pages page B points
+     * to)
+     * 
+     * @throws Exception
+     */
+    public void testReferredPageParmPage() throws Exception
+    {
+        context = engine.getWikiContextFactory().newViewContext( null, null, engine.createPage(  "IPointToSomeoneElse" ) );
+
+        String res = manager.execute( context, "{INSERT com.ecyrd.jspwiki.plugin.ReferredPagesPlugin page=IPointToSomeoneElseToo}" );
+
+        assertEquals(
+                      "<div class=\"ReferredPagesPlugin\">\n<a class=\"wikipage\" href=\"/Wiki.jsp?page=IPointToSomeoneElseToo\" title=\"ReferredPagesPlugin: depth[1] include[.*] exclude[^$] format[compact]\">IPointToSomeoneElseToo</a>\n<ul>\n<li><a class=\"wikipage\" href=\"/Wiki.jsp?page=SomeBodyPointsToMe\">SomeBodyPointsToMe</a></li>\n</ul>\n</div>\n",
+                      res );
+    }
+
+    /**
+     * Test with the include parameter
+     * 
+     * @throws Exception
+     */
+    public void testReferredPageParmInClude() throws Exception
+    {
+        context = engine.getWikiContextFactory().newViewContext( null, null, engine.createPage(  "IPointToTwoPages" ) );
+
+        String res = manager.execute( context,
+                                      "{INSERT com.ecyrd.jspwiki.plugin.ReferredPagesPlugin include='SomeBodyPointsToMe.*'}" );
+
+        assertEquals(
+                      "<div class=\"ReferredPagesPlugin\">\n<a class=\"wikipage\" href=\"/Wiki.jsp?page=IPointToTwoPages\" title=\"ReferredPagesPlugin: depth[1] include[SomeBodyPointsToMe.*] exclude[^$] format[compact]\">IPointToTwoPages</a>\n<ul>\n<li><a class=\"wikipage\" href=\"/Wiki.jsp?page=SomeBodyPointsToMe\">SomeBodyPointsToMe</a></li>\n<li><a class=\"wikipage\" href=\"/Wiki.jsp?page=SomeBodyPointsToMeToo\">SomeBodyPointsToMeToo</a></li>\n</ul>\n</div>\n",
+                      res );
+
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( ReferredPagesPluginTest.class );
+    }
+}

Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java?rev=728341&r1=728340&r2=728341&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java Sat Dec 20 12:52:22 2008
@@ -32,7 +32,6 @@
 
 import com.ecyrd.jspwiki.TestEngine;
 import com.ecyrd.jspwiki.WikiContext;
-import com.ecyrd.jspwiki.content.WikiName;
 
 public class ReferringPagesPluginTest extends TestCase
 {



Mime
View raw message