incubator-jspwiki-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Janne Jalkanen <janne.jalka...@ecyrd.com>
Subject Re: svn commit: r917390 - in /incubator/jspwiki/trunk: ./ src/java/org/apache/wiki/ src/java/org/apache/wiki/plugin/ src/java/org/apache/wiki/preferences/ src/java/org/apache/wiki/rpc/json/ src/java/org/apache/wiki/tags/ src/java/org/apache/wiki/ui/
Date Tue, 02 Mar 2010 17:46:52 GMT

I'm not attached to RequestResourceTag per se, but I just need a way to use TemplateManager.requestResource() to include stuff from the plugins.  RequestResourceTag is just a way to avoid JSP scriptlets.

Note that admins do choose which plugins they run, so it's not arbitrary user-level execution.  I don't see any possibilty for security issues - if you already are running code in the Tomcat process, you can do pretty much whatever you want.

/Janne

On 2 Mar 2010, at 04:19, Andrew Jaquith wrote:

> Janne --
> 
> There is another way to make this work.
> 
> While I continue to feel that it makes more sense to use the Stripes
> layout tags, we could make the IncludeResources and RequestResource
> tags work if we did the following:
> 
> - When a RequestResource tag is encountered, stash the requested
> content into the request as an attribute
> - When the IncludeResource tag is encountered, retrieve the attributes
> and send to the output stream
> 
> This could work nicely in 3.0 because of how we separate the layout
> JSPs from the content JSPs. The content JSPs are processed before the
> layout JSPs, which means RequestResources tags always execute before
> the IncludeResources tags.
> 
> So, this would be pretty simple to implement, and it would not require
> a response wrapper. The code that requests and renders the resources
> would be private (inside the tags), and thus restricted to JSP authors
> who used the tags in their JSPs. That would satisfy my concerns about
> safety -- my chief concern was the public access to the resource
> request API by plugins. Plugin authors could always muck around with
> request attributes if they wanted to inject their own resource
> requests, but it would be clear that they were "off the reservation"
> at that point.
> 
> Andrew
> 
> On Mon, Mar 1, 2010 at 11:38 AM, Andrew Jaquith
> <andrew.r.jaquith@gmail.com> wrote:
>> Janne --
>> 
>> 
>> In 3.0, templates can fall back to resources they don't have by using
>> the JSTL "templates" variable. E.g., img
>> src="${templates['foo.png']}". This will consult the active template
>> first, then fall back to the default template. Pretty easy.
>> 
>> As for resources like JavaScript, CSS, etc., JSPs can request them by
>> overriding template component variables via the s:layout-component
>> tag. Components that can be overridden are: headTitle, stylesheet,
>> inlinecss, script, jslocalizedstrings, jsfunctio, headMetaRobots,
>> pageTitle, and content. Also pretty easy and logical -- especially
>> when used with JSTL.
>> 
>> So that's how it works for JSPs.
>> 
>> These two capabilities mean that the IncludeResources and
>> ResourceRequest tag aren't needed. They also don't WORK, because there
>> is no response wrapper available to trap output and inject content --
>> WikiJSPFilter has been gone for a while. Stripes already wraps
>> responses to support the layout tags, and having two wrappers would
>> produce unpredictable results. If we had to do it, we would want to do
>> it via an Interceptor that hooks the response just before it is sent
>> to the client.
>> 
>> Plugins are a different animal. I am opposed to allowing plugins to
>> load arbitrary resources. It's just not safe. As it happens, the ONLY
>> class in 2.8 that needed to add resources on the fly was
>> JSONRPCManager. The editors needed to add resources, but we can do
>> these via the layout tags and JSTL easily enough.
>> 
>> Anybody who requires certain resources for a plugin has an easy way to
>> do it, by hacking the JSPs. This is how the editor JSPs do it. If
>> allowing arbitrary resource injection by user-specified content is
>> absolutely required, the way to do it would be by writing an
>> Interceptor, and it would be need to be done SAFELY. I would a
>> specific example to be convinced about why this is a good idea.
>> 
>> But like I said, if we have to do this, there is a way to do it. It's
>> just not in the trunk.
>> 
>> Andrew
>> 
>> 
>> On Mon, Mar 1, 2010 at 10:46 AM, Janne Jalkanen
>> <janne.jalkanen@ecyrd.com> wrote:
>>> 
>>> Hm?  If RequestResourceTag and IncludeResourcesTag are gone, then how do plugins request resources, and how do individual templates then fall back to resources they don't include?  I've got a bunch of code that assumes that templates can fall back to resources (e.g. images) from default template, and plugins which request CSS and other components.
>>> 
>>> /Janne
>>> 
>>> On 1 Mar 2010, at 07:23, ajaquith@apache.org wrote:
>>> 
>>>> Author: ajaquith
>>>> Date: Mon Mar  1 05:23:10 2010
>>>> New Revision: 917390
>>>> 
>>>> URL: http://svn.apache.org/viewvc?rev=917390&view=rev
>>>> Log:
>>>> Cleaned out all of the deadwood in TemplateManager. Deprecated IncludeResourcesTag and RequestResourceTag. Resources can (and should) be included directly in template JSPs.
>>>> 
>>>> Modified:
>>>>    incubator/jspwiki/trunk/ChangeLog
>>>>    incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
>>>>    incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/Note.java
>>>>    incubator/jspwiki/trunk/src/java/org/apache/wiki/preferences/Preferences.java
>>>>    incubator/jspwiki/trunk/src/java/org/apache/wiki/rpc/json/JSONRPCManager.java
>>>>    incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/ContentTag.java
>>>>    incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/EditorTag.java
>>>>    incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IncludeResourcesTag.java
>>>>    incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IncludeTag.java
>>>>    incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/RequestResourceTag.java
>>>>    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/EditorManager.java
>>>>    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/TemplateManager.java
>>>>    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/TemplateResolution.java
>>>> 
>>>> Modified: incubator/jspwiki/trunk/ChangeLog
>>>> URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=917390&r1=917389&r2=917390&view=diff
>>>> ==============================================================================
>>>> --- incubator/jspwiki/trunk/ChangeLog (original)
>>>> +++ incubator/jspwiki/trunk/ChangeLog Mon Mar  1 05:23:10 2010
>>>> @@ -1,3 +1,30 @@
>>>> +2010-02-28 Andrew Jaquith <ajaquith AT apache DOT org>
>>>> +
>>>> +        * 3.0.0-svn-212
>>>> +
>>>> +        * Exceptions caught by WikiTagBase (and subclass tags) are now
>>>> +        re-thrown so that they propagate upstream. Previously, doCatch()
>>>> +        was swallowing them, which made for "interesting" JSP debugging.
>>>> +
>>>> +        * Edit.jsp, Wiki.jsp, and PageInfo.jsp changed to put the
>>>> +        edit tab on the right. For editing, the live-preview feature was
>>>> +        moved to a new "Preview" tab, also on the right. The View tab
>>>> +        now simply displays the most recent save.
>>>> +
>>>> +        * The Error.jsp references were made consistent in all JSPs.
>>>> +        Rather than use JSTL syntax (which won't evaluate when used
>>>> +        with <% page errorPage %> tag), the references now all use
>>>> +        /Error.jsp, which itself jsp:includes the template JSP
>>>> +        Error.jsp using JSTL. This makes the error page customizable
>>>> +        per-template, but still very easy to use.
>>>> +
>>>> +        * Cleaned out all of the deadwood in TemplateManager.
>>>> +        Deprecated IncludeResourcesTag and RequestResourceTag. Resources
>>>> +        can (and should) be included directly in template JSPs.
>>>> +
>>>> +        * Small changes to Admin/AdministerProfiles action beans as part
>>>> +        of a gradual overhaul to the Admin JSPs, which are being Stripesed.
>>>> +
>>>> 2010-02-28 Dirk Frederickx <brushed@apache.org>
>>>> 
>>>>         * v3.0.0-svn-211 : line up with latest template/stripes changes
>>>> @@ -35,7 +62,7 @@
>>>>         * fixed a couple of Plugin unit tests (support for wiki spaces is
>>>>           not yet there), only the ReferringPagesPlugin still fails.
>>>> 
>>>> -2010-02-23 Andrew Jaquith <ajaquith AT apache DOT org>
>>>> +2010-02-27 Andrew Jaquith <ajaquith AT apache DOT org>
>>>> 
>>>>         * 3.0.0-svn-209
>>>> 
>>>> 
>>>> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
>>>> URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java?rev=917390&r1=917389&r2=917390&view=diff
>>>> ==============================================================================
>>>> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java (original)
>>>> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java Mon Mar  1 05:23:10 2010
>>>> @@ -77,7 +77,7 @@
>>>>      *  <p>
>>>>      *  If the build identifier is empty, it is not added.
>>>>      */
>>>> -    public static final String     BUILD         = "211";
>>>> +    public static final String     BUILD         = "212";
>>>> 
>>>>     /**
>>>>      *  This is the generic version string you should use
>>>> 
>>>> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/Note.java
>>>> URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/Note.java?rev=917390&r1=917389&r2=917390&view=diff
>>>> ==============================================================================
>>>> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/Note.java (original)
>>>> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/Note.java Mon Mar  1 05:23:10 2010
>>>> @@ -27,6 +27,7 @@
>>>> import org.apache.wiki.WikiContext;
>>>> import org.apache.wiki.WikiEngine;
>>>> import org.apache.wiki.api.PluginException;
>>>> +import org.apache.wiki.ui.TemplateManager;
>>>> import org.apache.wiki.util.TextUtil;
>>>> 
>>>> 
>>>> @@ -86,9 +87,7 @@
>>>> 
>>>>         commentImage = "images/"+commentImage;
>>>> 
>>>> -        String resource = engine.getTemplateManager().findResource( ctx,
>>>> -                                                                    engine.getTemplateDir(),
>>>> -                                                                    commentImage );
>>>> +        String resource = TemplateManager.getResourceResolver( engine.getServletContext() ).get( commentImage );
>>>> 
>>>>         return ctx.getURL( WikiContext.NONE, resource );
>>>>     }
>>>> 
>>>> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/preferences/Preferences.java
>>>> URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/preferences/Preferences.java?rev=917390&r1=917389&r2=917390&view=diff
>>>> ==============================================================================
>>>> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/preferences/Preferences.java (original)
>>>> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/preferences/Preferences.java Mon Mar  1 05:23:10 2010
>>>> @@ -310,7 +310,7 @@
>>>>         }
>>>>         else if( "availableSkins".equals( key ) )
>>>>         {
>>>> -            return m_engine.getTemplateManager().listSkins( m_engine.getServletContext(), m_engine.getTemplateDir() );
>>>> +            return m_engine.getTemplateManager().listSkins();
>>>>         }
>>>>         else if( "availableTimeFormats".equals( key ) )
>>>>         {
>>>> 
>>>> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/rpc/json/JSONRPCManager.java
>>>> URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/rpc/json/JSONRPCManager.java?rev=917390&r1=917389&r2=917390&view=diff
>>>> ==============================================================================
>>>> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/rpc/json/JSONRPCManager.java (original)
>>>> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/rpc/json/JSONRPCManager.java Mon Mar  1 05:23:10 2010
>>>> @@ -38,7 +38,6 @@
>>>> import org.apache.wiki.log.LoggerFactory;
>>>> import org.apache.wiki.rpc.RPCCallable;
>>>> import org.apache.wiki.rpc.RPCManager;
>>>> -import org.apache.wiki.ui.TemplateManager;
>>>> import org.jabsorb.callback.InvocationCallback;
>>>> import org.jabsorb.JSONRPCBridge;
>>>> 
>>>> @@ -149,15 +148,6 @@
>>>>      */
>>>>     public static void requestJSON( WikiContext context )
>>>>     {
>>>> -        TemplateManager.addResourceRequest(context,
>>>> -                                           TemplateManager.RESOURCE_SCRIPT,
>>>> -                                           context.getURL(WikiContext.NONE,"scripts/json-rpc/jsonrpc.js"));
>>>> -
>>>> -        String jsonurl = context.getURL( WikiContext.NONE, "JSON-RPC" );
>>>> -        TemplateManager.addResourceRequest(context,
>>>> -                                           TemplateManager.RESOURCE_JSFUNCTION,
>>>> -                                           "jsonrpc = new JSONRpcClient(\""+jsonurl+"\");");
>>>> -
>>>>         getBridge(context).registerCallback(new WikiJSONAccessor(), HttpServletRequest.class);
>>>>     }
>>>> 
>>>> 
>>>> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/ContentTag.java
>>>> URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/ContentTag.java?rev=917390&r1=917389&r2=917390&view=diff
>>>> ==============================================================================
>>>> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/ContentTag.java (original)
>>>> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/ContentTag.java Mon Mar  1 05:23:10 2010
>>>> @@ -28,6 +28,7 @@
>>>> 
>>>> import org.apache.wiki.*;
>>>> import org.apache.wiki.providers.ProviderException;
>>>> +import org.apache.wiki.ui.TemplateManager;
>>>> 
>>>> 
>>>> /**
>>>> @@ -181,9 +182,7 @@
>>>>                 contentTemplate = beanName + "Content.jsp";
>>>>             }
>>>> 
>>>> -            String page = m_wikiContext.getEngine().getTemplateManager().findJSP( pageContext,
>>>> -                                                                                  m_wikiContext.getTemplate(),
>>>> -                                                                                  contentTemplate );
>>>> +            String page = TemplateManager.getResourceResolver( pageContext.getServletContext() ).get( contentTemplate );
>>>>             pageContext.include( page );
>>>>         }
>>>>         catch( ServletException e )
>>>> 
>>>> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/EditorTag.java
>>>> URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/EditorTag.java?rev=917390&r1=917389&r2=917390&view=diff
>>>> ==============================================================================
>>>> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/EditorTag.java (original)
>>>> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/EditorTag.java Mon Mar  1 05:23:10 2010
>>>> @@ -27,6 +27,7 @@
>>>> 
>>>> import org.apache.wiki.WikiEngine;
>>>> import org.apache.wiki.ui.EditorManager;
>>>> +import org.apache.wiki.ui.TemplateManager;
>>>> 
>>>> 
>>>> /**
>>>> @@ -58,10 +59,7 @@
>>>> 
>>>>         try
>>>>         {
>>>> -            String page = engine.getTemplateManager().findJSP( pageContext,
>>>> -                                                               m_wikiContext.getTemplate(),
>>>> -                                                               editorPath );
>>>> -
>>>> +            String page = TemplateManager.getResourceResolver( pageContext.getServletContext() ).get( editorPath );
>>>>             if( page == null )
>>>>             {
>>>>                 //FIXME: should be I18N ...
>>>> 
>>>> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IncludeResourcesTag.java
>>>> URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IncludeResourcesTag.java?rev=917390&r1=917389&r2=917390&view=diff
>>>> ==============================================================================
>>>> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IncludeResourcesTag.java (original)
>>>> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IncludeResourcesTag.java Mon Mar  1 05:23:10 2010
>>>> @@ -20,41 +20,34 @@
>>>>  */
>>>> package org.apache.wiki.tags;
>>>> 
>>>> -import org.apache.wiki.ui.TemplateManager;
>>>> 
>>>> /**
>>>> - *  This tag is used to include any programmatic includes into the
>>>> - *  output stream.  Actually, what it does is that it simply emits a
>>>> - *  tiny marker into the stream, and then a ServletFilter will take
>>>> - *  care of the actual inclusion.
>>>> - *
>>>> -*  @deprecated use the Stripes <code>layout-component</code> tags instead
>>>> + *  <p>This tag is used to include any programmatic includes into the
>>>> + *  output stream. In JSPWiki 2.8 and earlier, this tag emitted a
>>>> + *  tiny marker into the stream which was replaced by ServletFilter.
>>>> + *  <em>This tag has been deprecated because it is unsafe.</em> The
>>>> + *  Stripes layout tags should be used instead. See the default
>>>> + *  template {@code layout/DefaultLayout.jsp} for instructions on how
>>>> + *  to include scripts and other resources in JSPs.</p>
>>>> + *  @deprecated use the Stripes <code>layout-component</code> tags instead
>>>>  */
>>>> public class IncludeResourcesTag extends WikiTagBase
>>>> {
>>>>     private static final long serialVersionUID = 0L;
>>>> 
>>>> -    private String m_type;
>>>> -
>>>>     public void initTag()
>>>>     {
>>>>         super.initTag();
>>>> -        m_type = null;
>>>>     }
>>>> 
>>>>     public void setType( String type )
>>>>     {
>>>> -        m_type = type;
>>>>     }
>>>> 
>>>>     public int doWikiStartTag() throws Exception
>>>>     {
>>>> -        //String marker = m_wikiContext.getEngine().getTemplateManager().getMarker(m_wikiContext, m_type);
>>>> -        //String marker = TemplateManager.getMarker(pageContext, m_type);
>>>> -        String marker = TemplateManager.getMarker(m_wikiContext, m_type);
>>>> -
>>>> -        pageContext.getOut().println( marker );
>>>> -
>>>> +        pageContext.getOut().println( "<!-- Please use the Stripes layout tags instead " +
>>>> +                     "of IncludeResourcesTag. See layout/DefaultLayout.jsp for instructions. -->" );
>>>>         return SKIP_BODY;
>>>>     }
>>>> 
>>>> 
>>>> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IncludeTag.java
>>>> URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IncludeTag.java?rev=917390&r1=917389&r2=917390&view=diff
>>>> ==============================================================================
>>>> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IncludeTag.java (original)
>>>> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IncludeTag.java Mon Mar  1 05:23:10 2010
>>>> @@ -25,6 +25,7 @@
>>>> import javax.servlet.ServletException;
>>>> 
>>>> import org.apache.wiki.providers.ProviderException;
>>>> +import org.apache.wiki.ui.TemplateManager;
>>>> import org.apache.wiki.util.TextUtil;
>>>> 
>>>> 
>>>> @@ -72,10 +73,7 @@
>>>>     {
>>>>         try
>>>>         {
>>>> -            String page = m_wikiContext.getEngine().getTemplateManager().findJSP( pageContext,
>>>> -                                                                                  m_wikiContext.getTemplate(),
>>>> -                                                                                  m_page );
>>>> -
>>>> +            String page = TemplateManager.getResourceResolver( pageContext.getServletContext() ).get( m_page );
>>>>             if( page == null )
>>>>             {
>>>>                 pageContext.getOut().println("No template file called '"+TextUtil.replaceEntities(m_page)+"'");
>>>> 
>>>> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/RequestResourceTag.java
>>>> URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/RequestResourceTag.java?rev=917390&r1=917389&r2=917390&view=diff
>>>> ==============================================================================
>>>> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/RequestResourceTag.java (original)
>>>> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/RequestResourceTag.java Mon Mar  1 05:23:10 2010
>>>> @@ -20,21 +20,17 @@
>>>>  */
>>>> package org.apache.wiki.tags;
>>>> 
>>>> -import org.apache.wiki.ui.TemplateManager;
>>>> -
>>>> /**
>>>> - *  Provides easy access to TemplateManager.addResourceRequest().  You may use
>>>> - *  any of the request types defined there.
>>>> - *
>>>> - *  @see TemplateManager
>>>> + *  <p>In JSPWiki 2.8, this tag provided a way to instruct JSPWiki to insert
>>>> + *  resource requests into JSPs. <em>This tag has been deprecated because it
>>>> + *  is unsafe.</em> The Stripes layout tags should be used instead. See the default
>>>> + *  template {@code layout/DefaultLayout.jsp} for instructions on how
>>>> + *  to include scripts and other resources in JSPs.</p>
>>>>  *  @deprecated use the Stripes <code>layout-component</code> tags instead
>>>>  */
>>>> public class RequestResourceTag extends WikiTagBase
>>>> {
>>>>     private static final long serialVersionUID = 0L;
>>>> -
>>>> -    private String m_type;
>>>> -    private String m_resource;
>>>> 
>>>>     /**
>>>>      *  {@inheritDoc}
>>>> @@ -43,7 +39,6 @@
>>>>     public void initTag()
>>>>     {
>>>>         super.initTag();
>>>> -        m_type = m_resource = null;
>>>>     }
>>>> 
>>>>     /**
>>>> @@ -52,57 +47,47 @@
>>>>     @Override
>>>>     public int doWikiStartTag() throws Exception
>>>>     {
>>>> -        if( m_type != null && m_resource != null )
>>>> -        {
>>>> -            TemplateManager.addResourceRequest( m_wikiContext, m_type, m_resource );
>>>> -        }
>>>> -
>>>>         return SKIP_BODY;
>>>>     }
>>>> 
>>>>     /**
>>>> -     *  Returns the resource that is to be added.
>>>> +     *  Always returns the empty string.
>>>>      *
>>>>      *  @return The resource name.
>>>>      */
>>>>     public String getResource()
>>>>     {
>>>> -        return m_resource;
>>>> +        return "";
>>>>     }
>>>> 
>>>>     /**
>>>> -     *  Sets the resource name to be added.
>>>> +     *  This method does nothing.
>>>>      *
>>>>      *  @param r Resource identifier.
>>>>      */
>>>>     public void setResource(String r)
>>>>     {
>>>> -        m_resource = r;
>>>> +        // No-op.
>>>>     }
>>>> 
>>>>     /**
>>>> -     *  Get the resource type.
>>>> +     *  Always returns the empty string.
>>>>      *
>>>>      *  @return The type of the resource.
>>>>      */
>>>>     public String getType()
>>>>     {
>>>> -        return m_type;
>>>> +        return "";
>>>>     }
>>>> 
>>>>     /**
>>>> -     *  Set the type of the resource to be included.  For example, "script".  Please
>>>> -     *  see the TemplateManager class for more information about the different kinds
>>>> -     *  of types you can use.
>>>> -     *
>>>> -     *  @see TemplateManager
>>>> +     *  This method does nothing.
>>>>      *
>>>>      *  @param type The type to be set.
>>>>      */
>>>> 
>>>>     public void setType(String type)
>>>>     {
>>>> -        m_type = type;
>>>>     }
>>>> 
>>>> }
>>>> 
>>>> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/EditorManager.java
>>>> URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/EditorManager.java?rev=917390&r1=917389&r2=917390&view=diff
>>>> ==============================================================================
>>>> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/EditorManager.java (original)
>>>> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/EditorManager.java Mon Mar  1 05:23:10 2010
>>>> @@ -73,9 +73,6 @@
>>>>     /** Known name for the plain wikimarkup editor. */
>>>>     public static final String       EDITOR_PLAIN    = "plain";
>>>> 
>>>> -    /** Known name for the preview editor component. */
>>>> -    public static final String       EDITOR_PREVIEW  = "preview";
>>>> -
>>>>     /** Known attribute name for storing the user edited text inside a HTTP parameter. */
>>>>     public static final String       REQ_EDITEDTEXT  = "_editedtext";
>>>> 
>>>> @@ -189,9 +186,6 @@
>>>>      */
>>>>     public String getEditorName( WikiContext context )
>>>>     {
>>>> -        if( context.getRequestContext().equals(WikiContext.PREVIEW) )
>>>> -            return EDITOR_PREVIEW;
>>>> -
>>>>         String editor = null;
>>>> 
>>>>         // User has set an editor in preferences
>>>> 
>>>> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/TemplateManager.java
>>>> URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/TemplateManager.java?rev=917390&r1=917389&r2=917390&view=diff
>>>> ==============================================================================
>>>> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/TemplateManager.java (original)
>>>> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/TemplateManager.java Mon Mar  1 05:23:10 2010
>>>> @@ -20,8 +20,6 @@
>>>>  */
>>>> package org.apache.wiki.ui;
>>>> 
>>>> -import java.io.IOException;
>>>> -import java.io.InputStream;
>>>> import java.util.*;
>>>> 
>>>> import javax.servlet.ServletContext;
>>>> @@ -46,7 +44,7 @@
>>>>  */
>>>> public class TemplateManager extends ModuleManager
>>>> {
>>>> -    private static final String SKIN_DIRECTORY = "skins";
>>>> +    private static final String SKIN_DIR = "skins";
>>>> 
>>>>     /**
>>>>      * Attribute name for the resource resolver map returned by
>>>> @@ -55,61 +53,14 @@
>>>>      */
>>>>     private static final String RESOURCE_RESOLVER = "resourceResolver";
>>>> 
>>>> -    /**
>>>> -     * Requests a JavaScript function to be called during window.onload. Value
>>>> -     * is {@value}.
>>>> -     */
>>>> -    public static final String RESOURCE_JSFUNCTION = "jsfunction";
>>>> -
>>>> -    /**
>>>> -     * Requests a JavaScript associative array with all localized strings.
>>>> -     */
>>>> -    public static final String RESOURCE_JSLOCALIZEDSTRINGS = "jslocalizedstrings";
>>>> -
>>>> -    /**
>>>> -     * Requests a stylesheet to be inserted. Value is {@value}.
>>>> -     */
>>>> -    public static final String RESOURCE_STYLESHEET = "stylesheet";
>>>> -
>>>> -    /**
>>>> -     * Requests a script to be loaded. Value is {@value}.
>>>> -     */
>>>> -    public static final String RESOURCE_SCRIPT = "script";
>>>> -
>>>> -    /**
>>>> -     * Requests inlined CSS. Value is {@value}.
>>>> -     */
>>>> -    public static final String RESOURCE_INLINECSS = "inlinecss";
>>>> -
>>>>     /** The default directory for template resources. Value is {@value}. */
>>>> -    public static final String DIRECTORY = "templates";
>>>> +    public static final String TEMPLATE_DIR = "templates";
>>>> 
>>>>     /** The name of the default template. Value is {@value}. */
>>>>     public static final String DEFAULT_TEMPLATE = "default";
>>>> 
>>>> -    /** Name of the file that contains the properties. */
>>>> -    public static final String PROPERTYFILE = "template.properties";
>>>> -
>>>> -    /** I18N string to mark the default locale */
>>>> -    public static final String I18NDEFAULT_LOCALE = "prefs.user.language.default";
>>>> -
>>>> -    /**
>>>> -     * The name under which the resource includes map is stored in the
>>>> -     * WikiContext.
>>>> -     */
>>>> -    public static final String RESOURCE_INCLUDES = "jspwiki.resourceincludes";
>>>> -
>>>> -    // private Cache m_propertyCache;
>>>> -
>>>>     protected static final Logger log = LoggerFactory.getLogger( TemplateManager.class );
>>>> 
>>>> -    /** Requests a HTTP header. Value is {@value}. */
>>>> -    public static final String RESOURCE_HTTPHEADER = "httpheader";
>>>> -
>>>> -    private WikiEngine m_engine;
>>>> -
>>>> -    private static final List<WikiModuleInfo> EMPTY_MODULE_LIST = Collections.emptyList();
>>>> -
>>>>     /**
>>>>      * <p>Resolves requests for resources relative to the
>>>>      * <code>templates/<var>template</var></code> path to the actual resources,
>>>> @@ -125,8 +76,8 @@
>>>>      * for certain keys to return <code>null</code>. The map itself is
>>>>      * immutable.
>>>>      * </p>
>>>> -     * <p>The resource resolver is guaranteed to initialize if the ServletContext
>>>> -     * is active, even if the WikiEngine cannot initialize for some reason.
>>>> +     * <p>The resource resolver is guaranteed to initialize,
>>>> +     * even if the WikiEngine cannot initialize for some reason.
>>>>      * If the WikiEngine does not initialize, the default template
>>>>      * {@link #DEFAULT_TEMPLATE} will be used for all resource requests.</p>
>>>>      * @param servletContext the servlet context
>>>> @@ -156,10 +107,10 @@
>>>> 
>>>>             // Add all of the resources the template contains
>>>>             resolver = new HashMap<String,String>();
>>>> -            addResources( context, resolver, "/" + DIRECTORY + "/" + template + "/", null );
>>>> +            addResources( context, resolver, "/" + TEMPLATE_DIR + "/" + template + "/", null );
>>>> 
>>>>             // Add resources the template does not contain, but default does
>>>> -            addResources( context, resolver, "/" + DIRECTORY + "/" + DEFAULT_TEMPLATE + "/", null );
>>>> +            addResources( context, resolver, "/" + TEMPLATE_DIR + "/" + DEFAULT_TEMPLATE + "/", null );
>>>>             resolver = Collections.unmodifiableMap( resolver );
>>>>             context.setAttribute( RESOURCE_RESOLVER, resolver );
>>>>         }
>>>> @@ -167,18 +118,49 @@
>>>>     }
>>>> 
>>>>     /**
>>>> -     * Creates a new TemplateManager. There is typically one manager per engine.
>>>> -     *
>>>> -     * @param engine The owning engine.
>>>> -     * @param properties The property list used to initialize this.
>>>> +     * Adds all of the resources under a specified path prefix to the
>>>> +     * resource resolver map, with the "short name" of the path as the
>>>> +     * key, and the full path as the value. The short name is the portion
>>>> +     * of the path after the prefix. If a resource with that short name
>>>> +     * has already been added to the resource map, it will not be added
>>>> +     * again. Any resources ending in {@code /} (i.e., a directory path)
>>>> +     * will be processed recursively.
>>>> +     * @param context the servlet context
>>>> +     * @param resolver the resource resolver map
>>>> +     * @param prefix the path prefix that the search initiates from
>>>> +     * @param dir the directory to search relative to the path prefix. If not
>>>> +     * supplied, the path prefix directory itself will be searched
>>>>      */
>>>> -    public TemplateManager( WikiEngine engine, Properties properties )
>>>> +    @SuppressWarnings("unchecked")
>>>> +    private static void addResources( ServletContext context, Map<String,String> resolver, String prefix, String dir )
>>>>     {
>>>> -        super( engine );
>>>> -        m_engine = engine;
>>>> -        getResourceResolver( engine.getServletContext() );
>>>> -    }
>>>> +        String searchPath = dir == null ? prefix : prefix + dir;
>>>> +        Set<String> resources = context.getResourcePaths( searchPath );
>>>> +        if ( resources != null )
>>>> +        {
>>>> +            for ( String resource : resources )
>>>> +            {
>>>> +                String shortName = resource.substring( prefix.length() );
>>>> +
>>>> +                // Directory: process these entries too
>>>> +                if ( shortName.endsWith( "/" ) )
>>>> +                {
>>>> +                    addResources( context, resolver, prefix, shortName );
>>>> +                }
>>>> 
>>>> +                // Regular resource: add it if we don't have it already
>>>> +                else
>>>> +                {
>>>> +                    boolean alreadyProcessed = resolver.containsKey( shortName );
>>>> +                    if ( !alreadyProcessed )
>>>> +                    {
>>>> +                        resolver.put( shortName, resource );
>>>> +                    }
>>>> +                }
>>>> +            }
>>>> +        }
>>>> +    }
>>>> +
>>>>     /**
>>>>      * Tries to locate a given resource from the template directory, relative to
>>>>      * the root of the JSPWiki webapp context (for example, relative to
>>>> @@ -188,63 +170,62 @@
>>>>      * default template path either, <code>null</code> is returned.
>>>>      *
>>>>      *
>>>> -     * @param sContext the servlet context
>>>> +     * @param servletContext the servlet context
>>>>      * @param path the path to the resource; for example,
>>>> -     * <code>/templates/custom/FindContent.jsp</code>
>>>> +     * {@code /templates/custom/FindContent.jsp} or {@code jspwiki.css}.
>>>> +     * If the path starts with a slash (/), the resource is looked up
>>>> +     * relative to the webapp root
>>>>      * @return The name of the resource which was found; for example,
>>>>      * <code>/templates/custom/FindContent.jsp</code> (if it exists in the
>>>>      * <code>custom</code> template directory), or
>>>>      * <code>/templates/default/FindContent.jsp</code> (if not)
>>>>      */
>>>> -    private static String findResource( ServletContext sContext, String path )
>>>> +    private static String findResource( ServletContext servletContext, String path )
>>>>     {
>>>> -        InputStream is = sContext.getResourceAsStream( path );
>>>> -
>>>> -        if( is == null )
>>>> +        if( path.charAt( 0 ) == '/' )
>>>>         {
>>>> -            String defaultPath = makeFullJSPName( DEFAULT_TEMPLATE, removeTemplatePart( path ) );
>>>> -            is = sContext.getResourceAsStream( defaultPath );
>>>> -
>>>> -            if( is != null )
>>>> -                path = defaultPath;
>>>> -            else
>>>> -                path = null;
>>>> -        }
>>>> -
>>>> -        if( is != null )
>>>> -        {
>>>> -            try
>>>> -            {
>>>> -                is.close();
>>>> -            }
>>>> -            catch( IOException e )
>>>> -            {
>>>> -            }
>>>> +            // This is already a full path
>>>> +            return findResource( servletContext, path );
>>>>         }
>>>> -
>>>> -        return path;
>>>> +        return getResourceResolver( servletContext ).get( path );
>>>>     }
>>>> 
>>>>     /**
>>>> -     * Attempts to find a resource from the given template, and if it's not
>>>> -     * found attempts to locate it from the default template.
>>>> -     *
>>>> -     * @param sContext
>>>> -     * @param template
>>>> -     * @param name
>>>> -     * @return
>>>> +     * Returns a property, as defined in the template. The evaluation is lazy,
>>>> +     * i.e. the properties are not loaded until the template is actually used
>>>> +     * for the first time.
>>>> +     */
>>>> +    /*
>>>> +     * public String getTemplateProperty( WikiContext context, String key ) {
>>>> +     * String template = context.getTemplate(); try { Properties props =
>>>> +     * (Properties)m_propertyCache.getFromCache( template, -1 ); if( props ==
>>>> +     * null ) { try { props = getTemplateProperties( template );
>>>> +     * m_propertyCache.putInCache( template, props ); } catch( IOException e ) {
>>>> +     * log.warn("IO Exception while reading template properties",e); return
>>>> +     * null; } } return props.getProperty( key ); } catch( NeedsRefreshException
>>>> +     * ex ) { // FIXME return null; } }
>>>>      */
>>>> -    private static String findResource( ServletContext sContext, String template, String name )
>>>> +    /**
>>>> +     * Returns an absolute path to a given template.
>>>> +     */
>>>> +    private static final String getPath( String template )
>>>>     {
>>>> -        if( name.charAt( 0 ) == '/' )
>>>> -        {
>>>> -            // This is already a full path
>>>> -            return findResource( sContext, name );
>>>> -        }
>>>> +        return "/" + TEMPLATE_DIR + "/" + template + "/";
>>>> +    }
>>>> 
>>>> -        String fullname = makeFullJSPName( template, name );
>>>> +    private WikiEngine m_engine;
>>>> 
>>>> -        return findResource( sContext, fullname );
>>>> +    /**
>>>> +     * Creates a new TemplateManager. There is typically one manager per engine.
>>>> +     *
>>>> +     * @param engine The owning engine.
>>>> +     * @param properties The property list used to initialize this.
>>>> +     */
>>>> +    public TemplateManager( WikiEngine engine, Properties properties )
>>>> +    {
>>>> +        super( engine );
>>>> +        m_engine = engine;
>>>> +        getResourceResolver( engine.getServletContext() );
>>>>     }
>>>> 
>>>>     /**
>>>> @@ -252,53 +233,17 @@
>>>>      * current context or by the absolute name.
>>>>      *
>>>>      * @param pageContext the JSP PageContext
>>>> -     * @param name The name of the JSP page to look for (e.g "Wiki.jsp")
>>>> +     * @param name The name of the JSP page to look for (e.g {@code Wiki.jsp})
>>>>      * @return The context path to the resource
>>>> +     * @deprecated use {@link #getResourceResolver(ServletContext)} instead
>>>>      */
>>>>     public String findJSP( PageContext pageContext, String name )
>>>>     {
>>>>         ServletContext sContext = pageContext.getServletContext();
>>>> -
>>>>         return findResource( sContext, name );
>>>>     }
>>>> 
>>>>     /**
>>>> -     * Removes the template part of a name.
>>>> -     */
>>>> -    private static final String removeTemplatePart( String name )
>>>> -    {
>>>> -        int idx = 0;
>>>> -        if( name.startsWith( "/" ) )
>>>> -            idx = 1;
>>>> -
>>>> -        idx = name.indexOf( '/', idx );
>>>> -        if( idx != -1 )
>>>> -        {
>>>> -            idx = name.indexOf( '/', idx + 1 ); // Find second "/"
>>>> -
>>>> -            if( idx != -1 )
>>>> -            {
>>>> -                name = name.substring( idx + 1 );
>>>> -            }
>>>> -        }
>>>> -
>>>> -        log.info( "Final name = " + name );
>>>> -        return name;
>>>> -    }
>>>> -
>>>> -    /**
>>>> -     * Returns the full name (/templates/foo/bar) for name=bar, template=foo.
>>>> -     *
>>>> -     * @param template The name of the template.
>>>> -     * @param name The name of the resource.
>>>> -     * @return The full name for a template.
>>>> -     */
>>>> -    private static final String makeFullJSPName( String template, String name )
>>>> -    {
>>>> -        return "/" + DIRECTORY + "/" + template + "/" + name;
>>>> -    }
>>>> -
>>>> -    /**
>>>>      * Attempts to locate a resource under the given template. If that template
>>>>      * does not exist, or the page does not exist under that template, will
>>>>      * attempt to locate a similarly named file under the default template.
>>>> @@ -310,6 +255,7 @@
>>>>      * @param template From which template we should seek initially?
>>>>      * @param name Which resource are we looking for (e.g. "DefaultLayout.jsp")
>>>>      * @return path to the JSP page; null, if it was not found.
>>>> +     * @deprecated use {@link #getResourceResolver(ServletContext)} instead
>>>>      */
>>>>     public String findJSP( PageContext pageContext, String template, String name )
>>>>     {
>>>> @@ -319,8 +265,7 @@
>>>>                        + ((HttpServletRequest) pageContext.getRequest()).getRequestURI() + "'" );
>>>>             throw new InternalWikiException( "Illegal arguments to findJSP(); please check logs." );
>>>>         }
>>>> -
>>>> -        return findResource( pageContext.getServletContext(), template, name );
>>>> +        return findResource( pageContext.getServletContext(), name );
>>>>     }
>>>> 
>>>>     /**
>>>> @@ -337,45 +282,23 @@
>>>>      * @param template the name of the template to use
>>>>      * @param name the name of the resource to fine
>>>>      * @return the path to the resource
>>>> +     * @deprecated use {@link #getResourceResolver(ServletContext)} instead
>>>>      */
>>>>     public String findResource( WikiContext ctx, String template, String name )
>>>>     {
>>>>         if( m_engine.getServletContext() != null )
>>>>         {
>>>> -            return findResource( m_engine.getServletContext(), template, name );
>>>> +            return findResource( m_engine.getServletContext(), name );
>>>>         }
>>>> 
>>>>         return getPath( template ) + "/" + name;
>>>>     }
>>>> 
>>>>     /**
>>>> -     * Returns a property, as defined in the template. The evaluation is lazy,
>>>> -     * i.e. the properties are not loaded until the template is actually used
>>>> -     * for the first time.
>>>> -     */
>>>> -    /*
>>>> -     * public String getTemplateProperty( WikiContext context, String key ) {
>>>> -     * String template = context.getTemplate(); try { Properties props =
>>>> -     * (Properties)m_propertyCache.getFromCache( template, -1 ); if( props ==
>>>> -     * null ) { try { props = getTemplateProperties( template );
>>>> -     * m_propertyCache.putInCache( template, props ); } catch( IOException e ) {
>>>> -     * log.warn("IO Exception while reading template properties",e); return
>>>> -     * null; } } return props.getProperty( key ); } catch( NeedsRefreshException
>>>> -     * ex ) { // FIXME return null; } }
>>>> -     */
>>>> -    /**
>>>> -     * Returns an absolute path to a given template.
>>>> -     */
>>>> -    private static final String getPath( String template )
>>>> -    {
>>>> -        return "/" + DIRECTORY + "/" + template + "/";
>>>> -    }
>>>> -
>>>> -    /**
>>>> -     * Lists the skins available under this template. Returns an empty Set, if
>>>> -     * there are no extra skins available. Note that this method does not check
>>>> -     * whether there is anything actually in the directories, it just lists
>>>> -     * them. This may change in the future.
>>>> +     * Lists the skins available under the current template.
>>>> +     * Returns an empty Set, if there are no extra skins available.
>>>> +     * Note that this method does not check whether there is anything
>>>> +     * actually in the directories, it just lists them.
>>>>      *
>>>>      * @param servletContext the servlet context
>>>>      * @param template The template to search
>>>> @@ -383,14 +306,14 @@
>>>>      * @since 2.3.26
>>>>      */
>>>>     @SuppressWarnings( "unchecked" )
>>>> -    public Set<String> listSkins( ServletContext servletContext, String template )
>>>> +    public Set<String> listSkins()
>>>>     {
>>>> -        String place = makeFullJSPName( template, SKIN_DIRECTORY );
>>>> -        Set<String> skinSet = servletContext.getResourcePaths( place );
>>>> +        String skinPath = TEMPLATE_DIR + "/" + SKIN_DIR;
>>>> +        Set<String> skinSet = m_engine.getServletContext().getResourcePaths( skinPath );
>>>>         TreeSet<String> resultSet = new TreeSet<String>();
>>>> 
>>>>         if( log.isDebugEnabled() )
>>>> -            log.debug( "Listings skins from " + place );
>>>> +            log.debug( "Listings skins from " + skinPath );
>>>> 
>>>>         if( skinSet != null )
>>>>         {
>>>> @@ -414,215 +337,7 @@
>>>> 
>>>>         return resultSet;
>>>>     }
>>>> -
>>>> -    /**
>>>> -     * Always returns a valid property map.
>>>> -     */
>>>> -    /*
>>>> -     * private Properties getTemplateProperties( String templateName ) throws
>>>> -     * IOException { Properties p = new Properties(); ServletContext context =
>>>> -     * m_engine.getServletContext(); InputStream propertyStream =
>>>> -     * context.getResourceAsStream(getPath(templateName)+PROPERTYFILE); if(
>>>> -     * propertyStream != null ) { p.load( propertyStream );
>>>> -     * propertyStream.close(); } else { log.debug("Template '"+templateName+"'
>>>> -     * does not have a propertyfile '"+PROPERTYFILE+"'."); } return p; }
>>>> -     */
>>>> -    /**
>>>> -     * Returns the include resources marker for a given type. This is in a HTML
>>>> -     * or Javascript comment format.
>>>> -     *
>>>> -     * @param context the wiki context
>>>> -     * @param type the marker
>>>> -     * @return the generated marker comment
>>>> -     * @deprecated use the Stripes <code>layout-component</code> tags instead
>>>> -     */
>>>> -    public static String getMarker( WikiContext context, String type )
>>>> -    {
>>>> -        if( type.equals( RESOURCE_JSLOCALIZEDSTRINGS ) )
>>>> -        {
>>>> -            return getJSLocalizedStrings( context );
>>>> -        }
>>>> -        else if( type.equals( RESOURCE_JSFUNCTION ) )
>>>> -        {
>>>> -            return "/* INCLUDERESOURCES (" + type + ") */";
>>>> -        }
>>>> -        return "<!-- INCLUDERESOURCES (" + type + ") -->";
>>>> -    }
>>>> -
>>>> -    /**
>>>> -     * Extract all i18n strings in the javascript domain. (javascript.*) Returns
>>>> -     * a javascript snippet which defines the LoacalizedStings array.
>>>> -     *
>>>> -     * @param wiki context
>>>> -     * @return Javascript snippet which defines the LocaliedStrings array
>>>> -     * @since 2.5.108
>>>> -     * @deprecated use the Stripes <code>layout-component</code> tags instead
>>>> -     */
>>>> -    private static String getJSLocalizedStrings( WikiContext context )
>>>> -    {
>>>> -        StringBuilder sb = new StringBuilder();
>>>> -
>>>> -        sb.append( "var LocalizedStrings = {\n" );
>>>> -
>>>> -        ResourceBundle rb = context.getBundle( "templates.default" );
>>>> -
>>>> -        boolean first = true;
>>>> -
>>>> -        for( Enumeration<String> en = rb.getKeys(); en.hasMoreElements(); )
>>>> -        {
>>>> -            String key = en.nextElement();
>>>> -
>>>> -            if( key.startsWith( "javascript" ) )
>>>> -            {
>>>> -                if( first )
>>>> -                {
>>>> -                    first = false;
>>>> -                }
>>>> -                else
>>>> -                {
>>>> -                    sb.append( ",\n" );
>>>> -                }
>>>> -                sb.append( "\"" + key + "\":\"" + rb.getString( key ) + "\"" );
>>>> -            }
>>>> -        }
>>>> -        sb.append( "\n};\n" );
>>>> -
>>>> -        return(sb.toString());
>>>> -    }
>>>> -
>>>> -    /**
>>>> -     * Adds a resource request to the current request context. The content will
>>>> -     * be added at the resource-type marker (see IncludeResourcesTag) in
>>>> -     * WikiJSPFilter.
>>>> -     * <p>
>>>> -     * The resources can be of different types. For RESOURCE_SCRIPT and
>>>> -     * RESOURCE_STYLESHEET this is an URI path to the resource (a script file or
>>>> -     * an external stylesheet) that needs to be included. For RESOURCE_INLINECSS
>>>> -     * the resource should be something that can be added between
>>>> -     * &lt;style>&lt;/style> in the header file (commonheader.jsp). For
>>>> -     * RESOURCE_JSFUNCTION it is the name of the Javascript function that should
>>>> -     * be run at page load.
>>>> -     * <p>
>>>> -     * The IncludeResourceTag inserts code in the template files, which is then
>>>> -     * filled by the WikiFilter after the request has been rendered but not yet
>>>> -     * sent to the recipient.
>>>> -     * <p>
>>>> -     * Note that ALL resource requests get rendered, so this method does not
>>>> -     * check if the request already exists in the resources. Therefore, if you
>>>> -     * have a plugin which makes a new resource request every time, you'll end
>>>> -     * up with multiple resource requests rendered. It's thus a good idea to
>>>> -     * make this request only once during the page life cycle.
>>>> -     *
>>>> -     * @param ctx The current wiki context
>>>> -     * @param type What kind of a request should be added?
>>>> -     * @param resource The resource to add.
>>>> -     * @deprecated use the Stripes <code>layout-component</code> tags instead
>>>> -     */
>>>> -    @SuppressWarnings( "unchecked" )
>>>> -    public static void addResourceRequest( WikiContext ctx, String type, String resource )
>>>> -    {
>>>> -        HashMap<String, Vector<String>> resourcemap = (HashMap<String, Vector<String>>) ctx.getVariable( RESOURCE_INCLUDES );
>>>> -
>>>> -        if( resourcemap == null )
>>>> -        {
>>>> -            resourcemap = new HashMap<String, Vector<String>>();
>>>> -        }
>>>> -
>>>> -        Vector<String> resources = resourcemap.get( type );
>>>> -
>>>> -        if( resources == null )
>>>> -        {
>>>> -            resources = new Vector<String>();
>>>> -        }
>>>> -
>>>> -        String resourceString = null;
>>>> -
>>>> -        if( type.equals( RESOURCE_SCRIPT ) )
>>>> -        {
>>>> -            resourceString = "<script type='text/javascript' src='" + resource + "'></script>";
>>>> -        }
>>>> -        else if( type.equals( RESOURCE_STYLESHEET ) )
>>>> -        {
>>>> -            resourceString = "<link rel='stylesheet' type='text/css' href='" + resource + "' />";
>>>> -        }
>>>> -        else if( type.equals( RESOURCE_INLINECSS ) )
>>>> -        {
>>>> -            resourceString = "<style type='text/css'>\n" + resource + "\n</style>\n";
>>>> -        }
>>>> -        else if( type.equals( RESOURCE_JSFUNCTION ) )
>>>> -        {
>>>> -            resourceString = resource;
>>>> -        }
>>>> -        else if( type.equals( RESOURCE_HTTPHEADER ) )
>>>> -        {
>>>> -            resourceString = resource;
>>>> -        }
>>>> -
>>>> -        if( resourceString != null )
>>>> -        {
>>>> -            resources.add( resourceString );
>>>> -        }
>>>> -
>>>> -        log.debug( "Request to add a resource: " + resourceString );
>>>> -
>>>> -        resourcemap.put( type, resources );
>>>> -        ctx.setVariable( RESOURCE_INCLUDES, resourcemap );
>>>> -    }
>>>> -
>>>> -    /**
>>>> -     * Returns resource requests for a particular type. If there are no
>>>> -     * resources, returns an empty array.
>>>> -     *
>>>> -     * @param ctx WikiContext
>>>> -     * @param type The resource request type
>>>> -     * @return a String array for the resource requests
>>>> -     * @deprecated use the Stripes <code>layout-component</code> tags instead
>>>> -     */
>>>> -    @SuppressWarnings( "unchecked" )
>>>> -    public static String[] getResourceRequests( WikiContext ctx, String type )
>>>> -    {
>>>> -        HashMap<String, Vector<String>> hm = (HashMap<String, Vector<String>>) ctx.getVariable( RESOURCE_INCLUDES );
>>>> -
>>>> -        if( hm == null )
>>>> -            return new String[0];
>>>> -
>>>> -        Vector<String> resources = hm.get( type );
>>>> -
>>>> -        if( resources == null )
>>>> -            return new String[0];
>>>> -
>>>> -        String[] res = new String[resources.size()];
>>>> -
>>>> -        return resources.toArray( res );
>>>> -    }
>>>> -
>>>> -    /**
>>>> -     * Returns all those types that have been requested so far.
>>>> -     *
>>>> -     * @param ctx the wiki context
>>>> -     * @return the array of types requested
>>>> -     * @deprecated use the Stripes <code>layout-component</code> tags instead
>>>> -     */
>>>> -    @SuppressWarnings( "unchecked" )
>>>> -    public static String[] getResourceTypes( WikiContext ctx )
>>>> -    {
>>>> -        String[] res = new String[0];
>>>> -
>>>> -        if( ctx != null )
>>>> -        {
>>>> -            HashMap<String, String> hm = (HashMap<String, String>) ctx.getVariable( RESOURCE_INCLUDES );
>>>> -
>>>> -            if( hm != null )
>>>> -            {
>>>> -                Set<String> keys = hm.keySet();
>>>> -
>>>> -                res = keys.toArray( res );
>>>> -            }
>>>> -        }
>>>> -
>>>> -        return res;
>>>> -    }
>>>> -
>>>> +
>>>>     /**
>>>>      * Returns an empty collection, since at the moment the TemplateManager does
>>>>      * not manage any modules.
>>>> @@ -631,50 +346,6 @@
>>>>      */
>>>>     public Collection<WikiModuleInfo> modules()
>>>>     {
>>>> -        return EMPTY_MODULE_LIST;
>>>> -    }
>>>> -
>>>> -    /**
>>>> -     * Adds all of the resources under a specified path prefix to the
>>>> -     * resource resolver map, with the "short name" of the path as the
>>>> -     * key, and the full path as the value. The short name is the portion
>>>> -     * of the path after the prefix. If a resource with that short name
>>>> -     * has already been added to the resource map, it will not be added
>>>> -     * again. Any resources ending in {@code /} (i.e., a directory path)
>>>> -     * will be processed recursively.
>>>> -     * @param context the servlet context
>>>> -     * @param resolver the resource resolver map
>>>> -     * @param prefix the path prefix that the search initiates from
>>>> -     * @param dir the directory to search relative to the path prefix. If not
>>>> -     * supplied, the path prefix directory itself will be searched
>>>> -     */
>>>> -    @SuppressWarnings("unchecked")
>>>> -    private static void addResources( ServletContext context, Map<String,String> resolver, String prefix, String dir )
>>>> -    {
>>>> -        String searchPath = dir == null ? prefix : prefix + dir;
>>>> -        Set<String> resources = context.getResourcePaths( searchPath );
>>>> -        if ( resources != null )
>>>> -        {
>>>> -            for ( String resource : resources )
>>>> -            {
>>>> -                String shortName = resource.substring( prefix.length() );
>>>> -
>>>> -                // Directory: process these entries too
>>>> -                if ( shortName.endsWith( "/" ) )
>>>> -                {
>>>> -                    addResources( context, resolver, prefix, shortName );
>>>> -                }
>>>> -
>>>> -                // Regular resource: add it if we don't have it already
>>>> -                else
>>>> -                {
>>>> -                    boolean alreadyProcessed = resolver.containsKey( shortName );
>>>> -                    if ( !alreadyProcessed )
>>>> -                    {
>>>> -                        resolver.put( shortName, resource );
>>>> -                    }
>>>> -                }
>>>> -            }
>>>> -        }
>>>> +        return Collections.emptyList();
>>>>     }
>>>> }
>>>> 
>>>> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/TemplateResolution.java
>>>> URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/TemplateResolution.java?rev=917390&r1=917389&r2=917390&view=diff
>>>> ==============================================================================
>>>> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/TemplateResolution.java (original)
>>>> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/TemplateResolution.java Mon Mar  1 05:23:10 2010
>>>> @@ -22,6 +22,8 @@
>>>> {
>>>>     private static final Logger LOG = LoggerFactory.getLogger( TemplateResolution.class );
>>>> 
>>>> +    private static final String DEFAULT_PATH_PREFIX = "/" + TemplateManager.TEMPLATE_DIR + "/" + TemplateManager.DEFAULT_TEMPLATE + "/";
>>>> +
>>>>     /**
>>>>      * Constructs a new TemplateResolution
>>>>      *
>>>> @@ -41,7 +43,7 @@
>>>>         String path = TemplateManager.getResourceResolver( servletContext ).get( getPath() );
>>>>         if( path == null )
>>>>         {
>>>> -            path = "/templates/" + TemplateManager.DEFAULT_TEMPLATE + "/" + getPath();
>>>> +            path = DEFAULT_PATH_PREFIX + getPath();
>>>>         }
>>>>         setPath( path );
>>>> 
>>>> 
>>> 
>>> 
>> 


Mime
View raw message