Author: michaelo
Date: Sat Feb  6 22:32:41 2016
New Revision: 1728892

URL: http://svn.apache.org/viewvc?rev=1728892&view=rev
Log:
[DOXIASITETOOLS-93] request-scoped default Velocity Tools are not accessible

Modified:
    
maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java
    
maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/site/apt/index.apt.vm

Modified: 
maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java?rev=1728892&r1=1728891&r2=1728892&view=diff
==============================================================================
--- 
maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java
 (original)
+++ 
maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java
 Sat Feb  6 22:32:41 2016
@@ -69,7 +69,25 @@ import org.apache.maven.doxia.siterender
 import org.apache.maven.doxia.util.XmlValidator;
 import org.apache.velocity.Template;
 import org.apache.velocity.context.Context;
+import org.apache.velocity.tools.Scope;
 import org.apache.velocity.tools.ToolManager;
+import org.apache.velocity.tools.config.EasyFactoryConfiguration;
+import org.apache.velocity.tools.generic.AlternatorTool;
+import org.apache.velocity.tools.generic.ClassTool;
+import org.apache.velocity.tools.generic.ComparisonDateTool;
+import org.apache.velocity.tools.generic.ContextTool;
+import org.apache.velocity.tools.generic.ConversionTool;
+import org.apache.velocity.tools.generic.DisplayTool;
+import org.apache.velocity.tools.generic.EscapeTool;
+import org.apache.velocity.tools.generic.FieldTool;
+import org.apache.velocity.tools.generic.LinkTool;
+import org.apache.velocity.tools.generic.LoopTool;
+import org.apache.velocity.tools.generic.MathTool;
+import org.apache.velocity.tools.generic.NumberTool;
+import org.apache.velocity.tools.generic.RenderTool;
+import org.apache.velocity.tools.generic.ResourceTool;
+import org.apache.velocity.tools.generic.SortTool;
+import org.apache.velocity.tools.generic.XmlTool;
 import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
@@ -444,8 +462,46 @@ public class DefaultSiteRenderer
     }
 
     /**
+     * Creates a Velocity Context with all generic tools configured wit the 
site rendering context.
+     *
+     * @param siteRenderingContext the site rendering context
+     * @return a Velocity tools managed context
+     */
+    protected Context createToolManagedVelocityContext( SiteRenderingContext 
siteRenderingContext )
+    {
+        Locale locale = siteRenderingContext.getLocale();
+        String dateFormat = 
siteRenderingContext.getDecoration().getPublishDate().getFormat();
+
+        EasyFactoryConfiguration config = new EasyFactoryConfiguration( false 
);
+        config.property( "safeMode", Boolean.FALSE );
+        config.toolbox( Scope.REQUEST )
+            .tool( ContextTool.class )
+            .tool( LinkTool.class )
+            .tool( LoopTool.class )
+            .tool( RenderTool.class );
+        config.toolbox( Scope.APPLICATION ).property( "locale", locale )
+            .tool( AlternatorTool.class )
+            .tool( ClassTool.class )
+            .tool( ComparisonDateTool.class ).property( "format", dateFormat )
+            .tool( ConversionTool.class ).property( "dateFormat", dateFormat )
+            .tool( DisplayTool.class )
+            .tool( EscapeTool.class )
+            .tool( FieldTool.class )
+            .tool( MathTool.class )
+            .tool( NumberTool.class )
+            .tool( ResourceTool.class ).property( "bundles", new String[] { 
"site-renderer" } )
+            .tool( SortTool.class )
+            .tool( XmlTool.class );
+
+        ToolManager manager = new ToolManager( false, false );
+        manager.configure( config );
+
+        return manager.createContext();
+    }
+
+    /**
      * Create a Velocity Context for a Doxia document, containing every 
information about rendered document.
-     * 
+     *
      * @param sink the site renderer sink for the document
      * @param siteRenderingContext the site rendering context
      * @return
@@ -453,9 +509,7 @@ public class DefaultSiteRenderer
     protected Context createDocumentVelocityContext( RenderingContext 
renderingContext,
                                                      SiteRenderingContext 
siteRenderingContext )
     {
-        ToolManager toolManager = new ToolManager( true );
-        Context context = toolManager.createContext();
-
+        Context context = createToolManagedVelocityContext( 
siteRenderingContext );
         // 
----------------------------------------------------------------------
         // Data objects
         // 
----------------------------------------------------------------------
@@ -535,7 +589,7 @@ public class DefaultSiteRenderer
     /**
      * Create a Velocity Context for the site template decorating the 
document. In addition to all the informations
      * from the document, this context contains data gathered in {@link 
SiteRendererSink} during document rendering.
-     * 
+     *
      * @param siteRendererSink the site renderer sink for the document
      * @param siteRenderingContext the site rendering context
      * @return

Modified: 
maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/site/apt/index.apt.vm
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/site/apt/index.apt.vm?rev=1728892&r1=1728891&r2=1728892&view=diff
==============================================================================
--- 
maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/site/apt/index.apt.vm 
(original)
+++ 
maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/site/apt/index.apt.vm 
Sat Feb  6 22:32:41 2016
@@ -99,43 +99,48 @@ Doxia Site Tools - Site Renderer
 | <<<plexus>>>                    | 
{{{http://git.eclipse.org/c/sisu/org.eclipse.sisu.plexus.git/tree/org.eclipse.sisu.plexus/src/org/codehaus/plexus/PlexusContainer.java}<<<PlexusContainer>>>}}
 |  |
 
*---------------------------------+------------------------------------------------------+-------------------------------+
 
-  And there are {{{http://velocity.apache.org/tools/releases/2.0/generic.html} 
Velocity Generic Tools}}:
+  Additionally, there are 
{{{http://velocity.apache.org/tools/releases/2.0/generic.html} Velocity Generic 
Tools}} populated
+  with the site locale, the decoration model's date format, and site 
renderer's resource bundle:
 
 #set( $generic = 
"http://velocity.apache.org/tools/releases/2.0/javadoc/org/apache/velocity/tools/generic";
 )
-*------------------+--------------------------------------------------+-------------------------------+
-|| variable        || type                                            || 
description                 ||
-*------------------+--------------------------------------------------+-------------------------------+
-| <<<alternator>>> | {{{$generic/AlternatorTool.html}AlternatorTool}} | For 
creating Alternators to easily alternate over a set of values
-*------------------+--------------------------------------------------+-------------------------------+
-| <<<convert>>>    | {{{$generic/ConversionTool.html}ConversionTool}} | For 
converting String values to richer object types
-*------------------+--------------------------------------------------+-------------------------------+
-| <<<date>>>       | {{{$generic/DateTool.html}DateTool}}             | For 
manipulating, formatting, and comparing dates
-*------------------+--------------------------------------------------+-------------------------------+
-| <<<display>>>    | {{{$generic/DisplayTool.html}DisplayTool}}       | For 
controlling display of references (e.g. truncating values, "pretty printing" 
lists, and displaying alternates when a reference is null)
-*------------------+--------------------------------------------------+-------------------------------+
-| <<<esc>>>        | {{{$generic/EscapeTool.html}EscapeTool}}         | For 
common escaping needs in Velocity templates (e.g. escaping html, xml, 
javascript etc.)
-*------------------+--------------------------------------------------+-------------------------------+
-| <<<field>>>      | {{{$generic/FieldTool.html}FieldTool}}           | For 
(easy) access to static fields in a class, such as string constants
-*------------------+--------------------------------------------------+-------------------------------+
-| <<<loop>>>       | {{{$generic/LoopTool.html}LoopTool}}             | A 
convenience tool to use with \#foreach loops. It wraps a list with a custom 
iterator to provide greater control, allowing loops to end early, skip ahead 
and more
-*------------------+--------------------------------------------------+-------------------------------+
-| <<<math>>>       | {{{$generic/MathTool.html}MathTool}}             | For 
performing math functions
-*------------------+--------------------------------------------------+-------------------------------+
-| <<<number>>>     | {{{$generic/NumberTool.html}NumberTool}}         | For 
formatting and converting numbers
-*------------------+--------------------------------------------------+-------------------------------+
-| <<<render>>>     | {{{$generic/RenderTool.html}RenderTool}}         | To 
evaluate and render arbitrary strings of VTL, including recursive rendering
-*------------------+--------------------------------------------------+-------------------------------+
-| <<<text>>>       | {{{$generic/ResourceTool.html}ResourceTool}}     | For 
simplified access to ResourceBundles for internationalization or other dynamic 
content needs
-*------------------+--------------------------------------------------+-------------------------------+
-| <<<sorter>>>     | {{{$generic/SortTool.html}SortTool}}             | Used 
to sort collections (or arrays, iterators, etc) on any arbitary set of 
properties exposed by the objects contained within the collection
-*------------------+--------------------------------------------------+-------------------------------+
-| <<<xml>>>        | {{{$generic/XmlTool.html}XmlTool}}               | For 
reading/navigating XML files. This uses dom4j under the covers and provides 
complete XPath support
-*------------------+--------------------------------------------------+-------------------------------+
-~~| <<<context>>>    | (causes RuntimeException)
-~~| <<<link>>>       | (causes NullPointerException)
+*------------------+----------------------------------------------------------+-------------------------------+
+|| variable        || type                                                    
|| description                 ||
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<alternator>>> | {{{$generic/AlternatorTool.html}AlternatorTool}}         
| For creating alternators to easily alternate over a set of values.
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<class>>>      | {{{$generic/ClassTool.html}ClassTool}}                   
| For simplifying reflective lookup of information about classes and their 
fields, methods and constructors.
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<context>>>    | {{{$generic/ContextTool.html}ContextTool}}               
| For convenient access to context data and metadata.
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<convert>>>    | {{{$generic/ConversionTool.html}ConversionTool}}         
| For converting String values to richer object types.
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<date>>>       | {{{$generic/ComparisonDateTool.html}ComparisonDateTool}} 
| For manipulating, formatting, and comparing dates.
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<display>>>    | {{{$generic/DisplayTool.html}DisplayTool}}               
| For controlling display of references (e.g., truncating values, "pretty 
printing" lists, and displaying alternates when a reference is null).
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<esc>>>        | {{{$generic/EscapeTool.html}EscapeTool}}                 
| For common escaping needs in Velocity templates (e.g. escaping html, xml, 
javascript etc.).
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<field>>>      | {{{$generic/FieldTool.html}FieldTool}}                   
| For (easy) access to static fields in a class, such as string constants.
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<link>>>       | {{{$generic/LinkTool.html}LinkTool}}                     
| For creating and manipulating URIs and URLs. The API for this tool is 
designed to closely resemble that of the VelocityView tool of the same name.
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<loop>>>       | {{{$generic/LoopTool.html}LoopTool}}                     
| A convenience tool to use with \#foreach loops. It wraps a list with a custom 
iterator to provide greater control, allowing loops to end early, skip ahead 
and more.
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<math>>>       | {{{$generic/MathTool.html}MathTool}}                     
| For performing math functions.
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<number>>>     | {{{$generic/NumberTool.html}NumberTool}}                 
| For formatting and converting numbers.
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<render>>>     | {{{$generic/RenderTool.html}RenderTool}}                 
| To evaluate and render arbitrary strings of VTL, including recursive 
rendering.
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<text>>>       | {{{$generic/ResourceTool.html}ResourceTool}}             
| For simplified access to resource bundles for internationalization or other 
dynamic content needs.
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<sorter>>>     | {{{$generic/SortTool.html}SortTool}}                     
| Used to sort collections (or arrays, iterators, etc) on any arbitary set of 
properties exposed by the objects contained within the collection.
+*------------------+----------------------------------------------------------+-------------------------------+
+| <<<xml>>>        | {{{$generic/XmlTool.html}XmlTool}}                       
| For reading/navigating XML files. This uses dom4j under the covers and 
provides complete XPath support.
+*------------------+----------------------------------------------------------+-------------------------------+
 
-  See 
<<<{{{./xref/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.html\#L440}DefaultSiteRenderer.createDocumentVelocityContext(...)}}>>>
-  source for more details.
+  See 
<<<{{{./xref/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.html\#L470}DefaultSiteRenderer.createToolManagedVelocityContext(...)}}>>>
+  source for more details and the 
{{{http://velocity.apache.org/tools/devel/summary.html}tools usage summary}}.
 
 ** Maven Site Plugin
 


Reply via email to