jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From juanpa...@apache.org
Subject [10/16] jspwiki git commit: make m_inlineImagePatterns accesible through MarkupParser
Date Sun, 16 Jul 2017 11:54:55 GMT
make m_inlineImagePatterns accesible through MarkupParser


Project: http://git-wip-us.apache.org/repos/asf/jspwiki/repo
Commit: http://git-wip-us.apache.org/repos/asf/jspwiki/commit/ed1b5a7a
Tree: http://git-wip-us.apache.org/repos/asf/jspwiki/tree/ed1b5a7a
Diff: http://git-wip-us.apache.org/repos/asf/jspwiki/diff/ed1b5a7a

Branch: refs/heads/master
Commit: ed1b5a7a5ffb7451301dcf75115e08b13bc9409b
Parents: c5bf2e9
Author: juanpablo <juanpablo@apache.org>
Authored: Tue Jul 4 19:14:18 2017 +0200
Committer: juanpablo <juanpablo@apache.org>
Committed: Sun Jul 16 13:26:32 2017 +0200

----------------------------------------------------------------------
 .../apache/wiki/parser/JSPWikiMarkupParser.java | 42 +-------------
 .../org/apache/wiki/parser/MarkupParser.java    | 59 +++++++++++++++++++-
 2 files changed, 57 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jspwiki/blob/ed1b5a7a/jspwiki-war/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
----------------------------------------------------------------------
diff --git a/jspwiki-war/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java b/jspwiki-war/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
index 675e68d..42f25d8 100644
--- a/jspwiki-war/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
+++ b/jspwiki-war/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
@@ -146,9 +146,6 @@ public class JSPWikiMarkupParser extends MarkupParser {
 
     private boolean        m_isOpenParagraph = false;
 
-    /** Keeps image regexp Patterns */
-    private List<Pattern>  m_inlineImagePatterns;
-
     /** Parser for extended link functionality. */
     private LinkParser     m_linkParser = new LinkParser();
 
@@ -230,8 +227,6 @@ public class JSPWikiMarkupParser extends MarkupParser {
         "h323:", "ipp:", "tftp:", "mupdate:", "pres:",
         "im:", "mtqp", "smb:" };
 
-    private static final String INLINE_IMAGE_PATTERNS = "JSPWikiMarkupParser.inlineImagePatterns";
-
     private static final String CAMELCASE_PATTERN     = "JSPWikiMarkupParser.camelCasePattern";
 
     private static final String[] CLASS_TYPES =
@@ -274,44 +269,9 @@ public class JSPWikiMarkupParser extends MarkupParser {
     }
 
     // FIXME: parsers should be pooled for better performance.
-    @SuppressWarnings("unchecked")
     private void initialize()
     {
-        PatternCompiler compiler         = new GlobCompiler();
-        List<Pattern>   compiledpatterns;
-
-        //
-        //  We cache compiled patterns in the engine, since their creation is
-        //  really expensive
-        //
-        compiledpatterns = (List<Pattern>)m_engine.getAttribute( INLINE_IMAGE_PATTERNS
);
-
-        if( compiledpatterns == null )
-        {
-            compiledpatterns = new ArrayList<Pattern>(20);
-            Collection< String > ptrns = m_engine.getAllInlinedImagePatterns();
-
-            //
-            //  Make them into Regexp Patterns.  Unknown patterns
-            //  are ignored.
-            //
-            for( Iterator< String > i = ptrns.iterator(); i.hasNext(); )
-            {
-                try
-                {
-                    compiledpatterns.add( compiler.compile( i.next(),
-                                                            GlobCompiler.DEFAULT_MASK|GlobCompiler.READ_ONLY_MASK
) );
-                }
-                catch( MalformedPatternException e )
-                {
-                    log.error("Malformed pattern in properties: ", e );
-                }
-            }
-
-            m_engine.setAttribute( INLINE_IMAGE_PATTERNS, compiledpatterns );
-        }
-
-        m_inlineImagePatterns = Collections.unmodifiableList(compiledpatterns);
+        initInlineImagePatterns();
 
         m_camelCasePattern = (Pattern) m_engine.getAttribute( CAMELCASE_PATTERN );
         if( m_camelCasePattern == null )

http://git-wip-us.apache.org/repos/asf/jspwiki/blob/ed1b5a7a/jspwiki-war/src/main/java/org/apache/wiki/parser/MarkupParser.java
----------------------------------------------------------------------
diff --git a/jspwiki-war/src/main/java/org/apache/wiki/parser/MarkupParser.java b/jspwiki-war/src/main/java/org/apache/wiki/parser/MarkupParser.java
index e23df81..056edf7 100644
--- a/jspwiki-war/src/main/java/org/apache/wiki/parser/MarkupParser.java
+++ b/jspwiki-war/src/main/java/org/apache/wiki/parser/MarkupParser.java
@@ -23,7 +23,16 @@ import java.io.IOException;
 import java.io.PushbackReader;
 import java.io.Reader;
 import java.util.ArrayList;
-
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.apache.oro.text.GlobCompiler;
+import org.apache.oro.text.regex.MalformedPatternException;
+import org.apache.oro.text.regex.Pattern;
+import org.apache.oro.text.regex.PatternCompiler;
 import org.apache.wiki.StringTransmutator;
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
@@ -52,9 +61,13 @@ public abstract class MarkupParser
     protected ArrayList<HeadingListener>         m_headingListenerChain     = new ArrayList<HeadingListener>();
     protected ArrayList<StringTransmutator>      m_linkMutators             = new ArrayList<StringTransmutator>();
 
-    protected boolean        m_inlineImages             = true;
-
+    protected boolean        m_inlineImages     = true;
     protected boolean        m_parseAccessRules = true;
+    /** Keeps image regexp Patterns */
+    protected List< Pattern > m_inlineImagePatterns = null;
+
+    private static Logger log = Logger.getLogger( MarkupParser.class );
+
     /** If set to "true", allows using raw HTML within Wiki text.  Be warned,
         this is a VERY dangerous option to set - never turn this on in a publicly
         allowable Wiki, unless you are absolutely certain of what you're doing. */
@@ -71,6 +84,8 @@ public abstract class MarkupParser
     /** Lists all punctuation characters allowed in page names. */
     public    static final String           PUNCTUATION_CHARS_ALLOWED = " ()&+,-=._$";
 
+    private static final String INLINE_IMAGE_PATTERNS = "JSPWikiMarkupParser.inlineImagePatterns";
+
     /**
      *  Constructs a MarkupParser.  The subclass must call this constructor
      *  to set up the necessary bits and pieces.
@@ -203,6 +218,44 @@ public abstract class MarkupParser
         return m_inlineImages;
     }
 
+    @SuppressWarnings( "unchecked" )
+    protected final void initInlineImagePatterns() {
+		PatternCompiler compiler = new GlobCompiler();
+        //
+        //  We cache compiled patterns in the engine, since their creation is really expensive
+        //
+        List< Pattern > compiledpatterns = ( List< Pattern > )m_engine.getAttribute(
INLINE_IMAGE_PATTERNS );
+
+        if( compiledpatterns == null ) {
+            compiledpatterns = new ArrayList< Pattern >( 20 );
+            Collection< String > ptrns = m_engine.getAllInlinedImagePatterns();
+
+            //
+            //  Make them into Regexp Patterns.  Unknown patterns are ignored.
+            //
+            for( Iterator< String > i = ptrns.iterator(); i.hasNext(); ) {
+            	String pattern = i.next();
+                try {
+                    compiledpatterns.add( compiler.compile( pattern,
+                                                            GlobCompiler.DEFAULT_MASK | GlobCompiler.READ_ONLY_MASK
) );
+                } catch( MalformedPatternException e ) {
+                    log.error( "Malformed pattern [" + pattern + "] in properties: ", e );
+                }
+            }
+
+            m_engine.setAttribute( INLINE_IMAGE_PATTERNS, compiledpatterns );
+        }
+
+        m_inlineImagePatterns = Collections.unmodifiableList( compiledpatterns );
+	}
+
+    public List< Pattern > getInlineImagePatterns() {
+    	if( m_inlineImagePatterns == null ) {
+    		initInlineImagePatterns();
+    	}
+    	return m_inlineImagePatterns;
+    }
+
     /**
      *  Parses the document.
      *  @return the parsed document, as a WikiDocument


Mime
View raw message