You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2009/09/13 19:52:33 UTC

svn commit: r814361 - in /incubator/jspwiki/trunk/src/java/org/apache/wiki: filters/ parser/ plugin/ render/ tags/ ui/stripes/

Author: ajaquith
Date: Sun Sep 13 17:52:31 2009
New Revision: 814361

URL: http://svn.apache.org/viewvc?rev=814361&view=rev
Log:
Fixed Parser/Renderer bug that made them allergic to WikiContexts that do not have "pages" (e.g., UserPreferences). Because WikiContexts are *not* guaranteed to have pages in 3.0, this was important to fix. Fixed related bug in TranslateTag; we now render the body content by calling RenderingManager directly, rather than inefficiently channeling it through WikiEngine (and looking up nonexistent cached documents, etc.).

Modified:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/FilterManager.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/PageViewPlugin.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/render/RenderingManager.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TranslateTag.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/VariableTag.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/DefaultWikiContext.java

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/FilterManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/FilterManager.java?rev=814361&r1=814360&r2=814361&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/FilterManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/FilterManager.java Sun Sep 13 17:52:31 2009
@@ -32,6 +32,7 @@
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.api.FilterException;
 import org.apache.wiki.api.WikiException;
+import org.apache.wiki.api.WikiPage;
 import org.apache.wiki.event.WikiEventManager;
 import org.apache.wiki.event.WikiPageEvent;
 import org.apache.wiki.log.Logger;
@@ -439,10 +440,11 @@
      */
     public final void fireEvent( int type, WikiContext context )
     {
-        if ( WikiEventManager.isListening(this) && WikiPageEvent.isValidType(type) )
+        if ( WikiEventManager.isListening( this ) && WikiPageEvent.isValidType( type ) )
         {
-            WikiEventManager.fireEvent(this,
-                    new WikiPageEvent(m_engine,type,context.getPage().getName()) );
+            WikiPage page = context.getPage();
+            String pageName = page == null ? "(no page)" : page.getName();
+            WikiEventManager.fireEvent( this, new WikiPageEvent( m_engine,type,pageName ) );
         }
     }
 

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java?rev=814361&r1=814360&r2=814361&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java Sun Sep 13 17:52:31 2009
@@ -326,7 +326,8 @@
         //
         Properties props      = m_engine.getWikiProperties();
 
-        String cclinks = (String)m_context.getPage().getAttribute( PROP_CAMELCASELINKS );
+        WikiPage page = m_context.getPage();
+        String cclinks = page == null ? null : (String)page.getAttribute( PROP_CAMELCASELINKS );
 
         if( cclinks != null )
         {
@@ -540,6 +541,7 @@
         ResourceBundle rb = m_context.getBundle(InternationalizationManager.CORE_BUNDLE);
         Object[] args = { link };
 
+        String pageName = m_context.getPage() == null ? DUMMY_PAGE : m_context.getPage().getName();
         switch(type)
         {
             case READ:
@@ -562,12 +564,12 @@
                 //  to make sure the links are unique across Wiki.
                 //
             case LOCALREF:
-                el = createAnchor( LOCALREF, "#ref-"+m_context.getPage().getName()+"-"+link, "["+text+"]", "" );
+                el = createAnchor( LOCALREF, "#ref-"+pageName+"-"+link, "["+text+"]", "" );
                 break;
 
             case LOCAL:
                 el = new Element("a").setAttribute("class","footnote");
-                el.setAttribute("name", "ref-"+m_context.getPage().getName()+"-"+link.substring(1));
+                el.setAttribute("name", "ref-"+pageName+"-"+link.substring(1));
                 el.addContent("["+text+"]");
                 break;
 
@@ -1230,7 +1232,8 @@
     {
         Element el = null;
 
-        String pageName = m_context.getPage().getName();
+        WikiPage page = m_context.getPage();
+        String pageName = page == null ? DUMMY_PAGE : m_context.getPage().getName();
 
         String outTitle = makeSectionTitle( title );
 
@@ -1456,7 +1459,10 @@
                 val = m_engine.getVariableManager().expandVariables( m_context,
                                                                      val );
 
-                m_context.getPage().setAttribute( name, val );
+                if ( m_context.getPage() != null )
+                {
+                    m_context.getPage().setAttribute( name, val );
+                }
             }
         }
         catch( Exception e )
@@ -2749,6 +2755,9 @@
     
     /** The token is to be ignored. */
     protected static final int IGNORE    = 2;
+    
+    /** Dummy page name used when the WikiContext does not have a page associated with it. */
+    private static final String DUMMY_PAGE = "__no_page__";
 
     /**
      *  Return CHARACTER, if you think this was a plain character; ELEMENT, if

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/PageViewPlugin.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/PageViewPlugin.java?rev=814361&r1=814360&r2=814361&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/PageViewPlugin.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/PageViewPlugin.java Sun Sep 13 17:52:31 2009
@@ -343,12 +343,12 @@
                 {
                     ReferenceManager refManager = engine.getReferenceManager();
 
-                    Iterator iter = refManager.findCreated().iterator();
+                    Iterator<String> iter = refManager.findCreated().iterator();
 
                     while ( iter != null && iter.hasNext() )
                     {
 
-                        String name = (String) iter.next();
+                        String name = iter.next();
                         boolean use = false;
 
                         for( int n = 0; !use && n < refer.length; n++ )

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/render/RenderingManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/render/RenderingManager.java?rev=814361&r1=814360&r2=814361&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/render/RenderingManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/render/RenderingManager.java Sun Sep 13 17:52:31 2009
@@ -306,7 +306,7 @@
     }
 
     /**
-     *   Convinience method for rendering, using the default parser and renderer.  Note that
+     *   Convenience method for rendering, using the default parser and renderer.  Note that
      *   you can't use this method to do any arbitrary rendering, as the pagedata MUST
      *   be the data from the that the WikiContext refers to - this method caches the HTML
      *   internally, and will return the cached version.  If the pagedata is different

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TranslateTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TranslateTag.java?rev=814361&r1=814360&r2=814361&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TranslateTag.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/TranslateTag.java Sun Sep 13 17:52:31 2009
@@ -28,6 +28,9 @@
 import org.apache.wiki.action.WikiContextFactory;
 import org.apache.wiki.log.Logger;
 import org.apache.wiki.log.LoggerFactory;
+import org.apache.wiki.parser.MarkupParser;
+import org.apache.wiki.parser.WikiDocument;
+import org.apache.wiki.render.RenderingManager;
 
 
 /**
@@ -49,26 +52,22 @@
         {
             WikiContext context = WikiContextFactory.findContext( pageContext );
 
-            //
-            //  Because the TranslateTag should not affect any of the real page attributes
-            //  we have to make a clone here.
-            //
-            
-            context = context.deepClone();
-            
-            //
-            //  Get the page data.
-            //
+            // Get the body content (wiki markup) to be rendered
             BodyContent bc = getBodyContent();
             String wikiText = bc.getString();
+            if ( wikiText != null ) wikiText.trim();
             bc.clearBody();
 
-            if( wikiText != null )
+            if( wikiText != null && wikiText.length() > 0 )
             {
-                wikiText = wikiText.trim();
-            
-                String result = context.getEngine().textToHTML( context, wikiText );
-
+                // Parse the wiki markup
+                RenderingManager renderer = context.getEngine().getRenderingManager();
+                MarkupParser mp = renderer.getParser( context, wikiText );
+                mp.disableAccessRules();
+                WikiDocument doc = mp.parse();
+                
+                // Get the text directly from the RenderingManager, without caching
+                String result = renderer.getHTML( context, doc );
                 getPreviousOut().write( result );
             }
         }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/VariableTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/VariableTag.java?rev=814361&r1=814360&r2=814361&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/VariableTag.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/VariableTag.java Sun Sep 13 17:52:31 2009
@@ -106,7 +106,10 @@
         {
             value = msg;
         }
-        out.write( TextUtil.replaceEntities(value) );
+        if ( value != null )
+        {
+            out.write( TextUtil.replaceEntities(value) );
+        }
         return SKIP_BODY;
     }
 }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/DefaultWikiContext.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/DefaultWikiContext.java?rev=814361&r1=814360&r2=814361&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/DefaultWikiContext.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/DefaultWikiContext.java Sun Sep 13 17:52:31 2009
@@ -55,7 +55,7 @@
 
     private HashMap<String, Object> m_variableMap = new HashMap<String, Object>();
 
-    private String m_requestContext = null;
+    private String m_requestContext = WikiContext.NONE;
 
     private WikiSession m_session = null;