myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Marinschek <martin.marinsc...@gmail.com>
Subject Re: svn commit: r376085 [1/2] - in /myfaces: commons/trunk/src/main/java/org/apache/myfaces/config/ commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/ tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/util/ tomahawk
Date Thu, 09 Feb 2006 06:44:18 GMT
Yeah, sorry!

My applied patch didn't fix every occurence of AddResource. I fixed
that, but Sean was faster ;)

thanks Sean!

regards,

Martin

On 2/9/06, Mike Kienenberger <mkienenb@gmail.com> wrote:
> Martin,
>
> Did you break something?  This looks related to your change from an hour ago.
>
> The code that I had from a couple of days ago compiled so.....
>
> I still don't have my IDE working with the new layout, so it's
> difficult for me to investigate further, but searching the commit
> messages seems to indicate you did it :)
>
> -Mike
>
>
> E:\workspace311\current\tomahawk\sandbox\core\src\main\java\org\apache\myfaces\c
> ustom\dojo\DojoUtils.java:[90,45] cannot resolve symbol
> symbol  : method getInstance (javax.faces.context.FacesContext)
> location: interface org.apache.myfaces.renderkit.html.util.AddResource
>
> E:\workspace311\current\tomahawk\sandbox\core\src\main\java\org\apache\myfaces\c
> ustom\dojo\DojoUtils.java:[170,45] cannot resolve symbol
> symbol  : method getInstance (javax.faces.context.FacesContext)
> location: interface org.apache.myfaces.renderkit.html.util.AddResource
>
> On 2/8/06, mmarinschek@apache.org <mmarinschek@apache.org> wrote:
> > Author: mmarinschek
> > Date: Wed Feb  8 13:40:47 2006
> > New Revision: 376085
> >
> > URL: http://svn.apache.org/viewcvs?rev=376085&view=rev
> > Log:
> > fix for MYFACES-1034. Thanks to Peter Mahoney.
> >
> > Added:
> >     myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResourceFactory.java
> >     myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/DefaultAddResource.java
> >     myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/ResourcePosition.java
> > Modified:
> >     myfaces/commons/trunk/src/main/java/org/apache/myfaces/config/MyfacesConfig.java
> >     myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java
> >     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/util/ExtensionsFilter.java
> >     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java
> >     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/inputHtml/InputHtmlRenderer.java
> >     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java
> >     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/jslistener/JsValueChangeListenerRenderer.java
> >     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/navmenu/jscookmenu/HtmlJSCookMenuRenderer.java
> >     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/popup/HtmlPopupRenderer.java
> >     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/swapimage/HtmlSwapImageRenderer.java
> >     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tabbedpane/HtmlTabbedPaneRenderer.java
> >     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree/renderkit/html/HtmlTreeRenderer.java
> >     myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/HtmlTreeRenderer.java
> >     myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/renderkit/html/util/AddResourceTest.java
> >     myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/accordion/HtmlAccordionPanelRenderer.java
> >     myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/autoupdatedatatable/AutoUpdateDataTableRenderer.java
> >     myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dojo/DojoUtils.java
> >     myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/effect/EffectRenderer.java
> >     myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicRenderer.java
> >     myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/inputAjax/HtmlInputTextAjaxRenderer.java
> >     myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/inputAjax/HtmlSelectBooleanCheckboxAjaxRenderer.java
> >     myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/inputAjax/HtmlSelectManyCheckboxAjaxRenderer.java
> >     myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/inputAjax/HtmlSelectOneRadioAjaxRenderer.java
> >     myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/inputsuggestajax/InputSuggestAjaxRenderer.java
> >     myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/picklist/HtmlPicklistRenderer.java
> >     myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/AbstractScheduleRenderer.java
> >     myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/PlannerRenderer.java
> >     myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggest/InputSuggestRenderer.java
> >
> > Modified: myfaces/commons/trunk/src/main/java/org/apache/myfaces/config/MyfacesConfig.java
> > URL: http://svn.apache.org/viewcvs/myfaces/commons/trunk/src/main/java/org/apache/myfaces/config/MyfacesConfig.java?rev=376085&r1=376084&r2=376085&view=diff
> > ==============================================================================
> > --- myfaces/commons/trunk/src/main/java/org/apache/myfaces/config/MyfacesConfig.java (original)
> > +++ myfaces/commons/trunk/src/main/java/org/apache/myfaces/config/MyfacesConfig.java Wed Feb  8 13:40:47 2006
> > @@ -51,10 +51,13 @@
> >      private static final String  INIT_PARAM_AUTO_SCROLL = "org.apache.myfaces.AUTO_SCROLL";
> >      private static final boolean INIT_PARAM_AUTO_SCROLL_DEFAULT = false;
> >
> > +       private static final String INIT_PARAM_ADD_RESOURCE_CLASS = "org.apache.myfaces.ADD_RESOURCE_CLASS";
> > +
> >      private boolean _prettyHtml;
> >      private boolean _detectJavascript;
> >      private boolean _allowJavascript;
> >      private boolean _autoScroll;
> > +    private String _addResourceClass;
> >
> >      public static MyfacesConfig getCurrentInstance(ExternalContext extCtx)
> >      {
> > @@ -73,6 +76,8 @@
> >                                                                            INIT_PARAM_DETECT_JAVASCRIPT_DEFAULT));
> >          myfacesConfig.setAutoScroll(getBooleanInitParameter(extCtx, INIT_PARAM_AUTO_SCROLL,
> >                                                                      INIT_PARAM_AUTO_SCROLL_DEFAULT));
> > +        myfacesConfig.setAddResourceClass(extCtx.getInitParameter(INIT_PARAM_ADD_RESOURCE_CLASS));
> > +
> >          return myfacesConfig;
> >      }
> >
> > @@ -145,4 +150,14 @@
> >      {
> >          _autoScroll = autoScroll;
> >      }
> > +
> > +    public void setAddResourceClass(String addResourceClass)
> > +    {
> > +       _addResourceClass = addResourceClass;
> > +    }
> > +
> > +    public String getAddResourceClass()
> > +    {
> > +               return _addResourceClass;
> > +       }
> >  }
> >
> > Modified: myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java
> > URL: http://svn.apache.org/viewcvs/myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java?rev=376085&r1=376084&r2=376085&view=diff
> > ==============================================================================
> > --- myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java (original)
> > +++ myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java Wed Feb  8 13:40:47 2006
> > @@ -15,150 +15,28 @@
> >   */
> >  package org.apache.myfaces.renderkit.html.util;
> >
> > -import org.apache.commons.lang.builder.EqualsBuilder;
> > -import org.apache.commons.lang.builder.HashCodeBuilder;
> > -import org.apache.commons.logging.Log;
> > -import org.apache.commons.logging.LogFactory;
> > -import org.apache.myfaces.renderkit.html.HTML;
> > -import org.apache.myfaces.renderkit.html.HtmlRendererUtils;
> > -import org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl;
> > -
> > -import javax.faces.FacesException;
> >  import javax.faces.context.FacesContext;
> > -import javax.faces.context.ResponseWriter;
> >  import javax.servlet.ServletContext;
> >  import javax.servlet.http.HttpServletRequest;
> >  import javax.servlet.http.HttpServletResponse;
> >  import java.io.IOException;
> > -import java.util.*;
> >
> >  /**
> > - * This is a utility class to render link to resources used by custom components.
> > + * This interface defines methods necessary to render links to resources used
> > + * by custom components.
> >   * Mostly used to avoid having to include [script src="..."][/script]
> >   * in the head of the pages before using a component.
> > - * <p>
> > - * When used together with the ExtensionsFilter, this class can allow components
> > - * in the body of a page to emit script and stylesheet references into the page
> > - * head section. The relevant methods on this object simply queue the changes,
> > - * and when the page is complete the ExtensionsFilter calls back into this
> > - * class to allow it to insert the commands into the buffered response.
> > - * <p>
> > - * This class also works with the ExtensionsFilter to allow components to
> > - * emit references to javascript/css/etc which are bundled in the component's
> > - * jar file. Special URLs are generated which the ExtensionsFilter will later
> > - * handle by retrieving the specified resource from the classpath.
> > - * <p>
> > - * The special URL format is:
> > - * <pre>
> > - * {contextPath}/faces/myFacesExtensionResource/
> > - *    {resourceLoaderName}/{cacheKey}/{resourceURI}
> > - * </pre>
> > - * Where:
> > - * <ul>
> > - * <li> {contextPath} is the context path of the current webapp
> > - * <li> {resourceLoaderName} is the fully-qualified name of a class which
> > - *  implements the ResourceLoader interface. When a browser app sends a request
> > - *  for the specified resource, an instance of the specified ResourceLoader class
> > - *  will be created and passed the resourceURI part of the URL for resolving to the
> > - *  actual resource to be served back. The standard MyFaces ResourceLoader
> > - *  implementation only serves resources for files stored beneath path
> > - *  org/apache/myfaces/custom in the classpath but non-myfaces code can provide their
> > - *  own ResourceLoader implementations.
> > - * </ul>
> >   *
> >   * @author Sylvain Vieujot (latest modification by $Author$)
> >   * @version $Revision$ $Date$
> >   */
> > -public final class AddResource
> > +public interface AddResource
> >  {
> > -    private static final String PATH_SEPARATOR = "/";
> > -
> > -    protected static final Log log = LogFactory.getLog(AddResource.class);
> > -
> > -    private static final String RESOURCE_VIRTUAL_PATH = "/faces/myFacesExtensionResource";
> > -
> > -    private static final String HEADER_BEGIN_INFO_REQUEST_ATTRIBUTE_NAME = AddResource.class
> > -            .getName()
> > -            + ".HEADER_BEGIN_INFO";
> > -
> > -    private static final String BODY_END_INFO_REQUEST_ATTRIBUTE_NAME = AddResource.class.getName()
> > -            + ".BODY_END_INFO";
> > -
> > -    private static final String BODY_ONLOAD_INFO_REQUEST_ATTRIBUTE_NAME = AddResource.class
> > -            .getName()
> > -            + ".BODY_ONLOAD_INFO";
> > +       public static final ResourcePosition HEADER_BEGIN = new ResourcePosition(0);
> >
> > -    private static final String RESOURCES_CACHE_KEY = AddResource.class.getName() + ".CACHE_KEY";
> > -
> > -    protected final String _contextPath;
> > -
> > -    public static final Position HEADER_BEGIN = new Position(0);
> > -    public static final Position BODY_END = new Position(1);
> > -    public static final Position BODY_ONLOAD = new Position(2);
> > -
> > -    private StringBuffer originalResponse;
> > -    private boolean parserCalled = false;
> > -    private int headerInsertPosition = -1;
> > -    private int bodyInsertPosition = -1;
> > -    private int beforeBodyPosition = -1;
> > -    private int afterBodyContentInsertPosition = -1;
> > -    private int beforeBodyEndPosition = -1;
> > -
> > -    private AddResource(String contextPath)
> > -    {
> > -        _contextPath = contextPath;
> > -    }
> > -
> > -    /**
> > -     * Map of AddResource instances keyed by context path. This map will have
> > -     * more than one entry only if the myfaces library is in the "shared"
> > -     * classpath of a container where more than one webapp can see it
> > -     * simultaneously.
> > -     */
> > -    private static final Map _addResourceMap = new HashMap();
> > +       public static final ResourcePosition BODY_END = new ResourcePosition(1);
> >
> > -    /**
> > -     * Internal factory method.
> > -     * <p>
> > -     * Return an instance of AddResource keyed by context path, or create one
> > -     * if no such instance already exists. Note that the same AddResource object
> > -     * is shared among all threads servicing the same webapp, so all methods
> > -     * on this class are required to be threadsafe.
> > -     * <p>
> > -     * Note that this method is package-scope for the purposes of unit-testing only.
> > -     * This method should be treated as private by non-test code.
> > -     */
> > -    static AddResource getInstance(String contextPath)
> > -    {
> > -        // Yes, this method does use a variant of the "double locking" idiom
> > -        // which is well documented to be invalid for general use. However
> > -        // it is believed safe for use here because AddResource objects in
> > -        // _addResourceMap are never removed or replaced.
> > -        AddResource instance = (AddResource) _addResourceMap.get(contextPath);
> > -        if (instance == null)
> > -        {
> > -            synchronized (_addResourceMap)
> > -            {
> > -                instance = (AddResource) _addResourceMap.get(contextPath);
> > -                if (instance == null)
> > -                {
> > -                    instance = new AddResource(contextPath);
> > -                    _addResourceMap.put(contextPath, instance);
> > -                }
> > -            }
> > -        }
> > -        return instance;
> > -    }
> > -
> > -    public static AddResource getInstance(FacesContext context)
> > -    {
> > -        return getInstance(context.getExternalContext().getRequestContextPath());
> > -    }
> > -
> > -    public static AddResource getInstance(HttpServletRequest request)
> > -    {
> > -        return getInstance(request.getContextPath());
> > -    }
> > +       public static final ResourcePosition BODY_ONLOAD = new ResourcePosition(2);
> >
> >      // Methods to add resources
> >
> > @@ -172,10 +50,7 @@
> >       * "example/Widget/resource/script.js" in the classpath.
> >       */
> >      public void addJavaScriptHere(FacesContext context, Class myfacesCustomComponent,
> > -            String resourceName) throws IOException
> > -    {
> > -        addJavaScriptHere(context, new MyFacesResourceHandler(myfacesCustomComponent, resourceName));
> > -    }
> > +            String resourceName) throws IOException;
> >
> >      /**
> >       * Insert a [script src="url"] entry at the current location in the response.
> > @@ -183,16 +58,7 @@
> >       * @param uri is the location of the desired resource, relative to the base
> >       * directory of the webapp (ie its contextPath).
> >       */
> > -    public void addJavaScriptHere(FacesContext context, String uri) throws IOException
> > -    {
> > -        ResponseWriter writer = context.getResponseWriter();
> > -
> > -        writer.startElement(HTML.SCRIPT_ELEM, null);
> > -        writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
> > -        String src = context.getExternalContext().encodeResourceURL(getResourceUri(context, uri));
> > -        writer.writeURIAttribute(HTML.SRC_ATTR, src, null);
> > -        writer.endElement(HTML.SCRIPT_ELEM);
> > -    }
> > +    public void addJavaScriptHere(FacesContext context, String uri) throws IOException;
> >
> >      /**
> >       * Insert a [script src="url"] entry at the current location in the response.
> > @@ -206,61 +72,10 @@
> >       * @throws IOException
> >       */
> >      public void addJavaScriptHere(FacesContext context, ResourceHandler resourceHandler)
> > -            throws IOException
> > -    {
> > -        validateResourceHandler(resourceHandler);
> > -
> > -        ResponseWriter writer = context.getResponseWriter();
> > -
> > -        writer.startElement(HTML.SCRIPT_ELEM, null);
> > -        writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
> > -        String src = context.getExternalContext().encodeResourceURL(
> > -                getResourceUri(context, resourceHandler));
> > -        writer.writeURIAttribute(HTML.SRC_ATTR, src, null);
> > -        writer.endElement(HTML.SCRIPT_ELEM);
> > -    }
> > +            throws IOException;
> >
> >      public void addResourceHere(FacesContext context, ResourceHandler resourceHandler)
> > -            throws IOException
> > -    {
> > -        validateResourceHandler(resourceHandler);
> > -
> > -        String path = getResourceUri(context, resourceHandler);
> > -        ResponseWriter writer = context.getResponseWriter();
> > -        writer.write(context.getExternalContext().encodeResourceURL(path));
> > -    }
> > -
> > -    /**
> > -     * Verify that the resource handler is acceptable. Null is not
> > -     * valid, and the getResourceLoaderClass method must return a
> > -     * Class object whose instances implements the ResourceLoader
> > -     * interface.
> > -     *
> > -     * @param resourceHandler
> > -     */
> > -    protected void validateResourceHandler(ResourceHandler resourceHandler)
> > -    {
> > -        if (resourceHandler == null)
> > -        {
> > -            throw new IllegalArgumentException("ResourceHandler is null");
> > -        }
> > -        validateResourceLoader(resourceHandler.getResourceLoaderClass());
> > -    }
> > -
> > -    /**
> > -     * Given a Class object, verify that the instances of that class
> > -     * implement the ResourceLoader interface.
> > -     *
> > -     * @param resourceloader
> > -     */
> > -    protected void validateResourceLoader(Class resourceloader)
> > -    {
> > -        if (!ResourceLoader.class.isAssignableFrom(resourceloader))
> > -        {
> > -            throw new FacesException("Class " + resourceloader.getName() + " must implement "
> > -                    + ResourceLoader.class.getName());
> > -        }
> > -    }
> > +            throws IOException;
> >
> >      /**
> >       * Adds the given Javascript resource to the document header at the specified
> > @@ -278,11 +93,8 @@
> >       * the script is inserted into the buffered response by the ExtensionsFilter
> >       * after the page is complete.
> >       */
> > -    public void addJavaScriptAtPosition(FacesContext context, Position position,
> > -            ResourceHandler resourceHandler)
> > -    {
> > -        addJavaScriptAtPosition(context, position, resourceHandler, false);
> > -    }
> > +    public void addJavaScriptAtPosition(FacesContext context, ResourcePosition position,
> > +            ResourceHandler resourceHandler);
> >
> >      /**
> >       * Insert a [script src="url"] entry into the document header at the
> > @@ -296,12 +108,8 @@
> >       * resourceName is script.js, the resource will be retrieved from
> >       * "example/Widget/resource/script.js" in the classpath.
> >       */
> > -    public void addJavaScriptAtPosition(FacesContext context, Position position,
> > -            Class myfacesCustomComponent, String resourceName)
> > -    {
> > -        addJavaScriptAtPosition(context, position, new MyFacesResourceHandler(
> > -                myfacesCustomComponent, resourceName));
> > -    }
> > +    public void addJavaScriptAtPosition(FacesContext context, ResourcePosition position,
> > +            Class myfacesCustomComponent, String resourceName);
> >
> >      /**
> >       * Insert a [script src="url"] entry into the document header at the
> > @@ -313,12 +121,8 @@
> >       * processing the html page without waiting for the specified script to
> >       * load and be run.
> >       */
> > -    public void addJavaScriptAtPosition(FacesContext context, Position position,
> > -            Class myfacesCustomComponent, String resourceName, boolean defer)
> > -    {
> > -        addJavaScriptAtPosition(context, position, new MyFacesResourceHandler(
> > -                myfacesCustomComponent, resourceName), defer);
> > -    }
> > +    public void addJavaScriptAtPosition(FacesContext context, ResourcePosition position,
> > +            Class myfacesCustomComponent, String resourceName, boolean defer);
> >
> >      /**
> >       * Insert a [script src="url"] entry into the document header at the
> > @@ -326,399 +130,104 @@
> >       * referenced, it's added only once.
> >       *
> >       * @param uri is the location of the desired resource, relative to the base
> > -     * directory of the webapp (ie its contextPath).
> > +     * directory of the webapp (ie its contextPath).
> >       */
> > -    public void addJavaScriptAtPosition(FacesContext context, Position position, String uri)
> > -    {
> > -        addJavaScriptAtPosition(context, position, uri, false);
> > -    }
> > +    public void addJavaScriptAtPosition(FacesContext context, ResourcePosition position, String uri);
> >
> >      /**
> >       * Adds the given Javascript resource at the specified document position.
> >       * If the script has already been referenced, it's added only once.
> >       */
> > -    public void addJavaScriptAtPosition(FacesContext context, Position position, String uri,
> > -            boolean defer)
> > -    {
> > -        addPositionedInfo(context, position, getScriptInstance(context, uri, defer));
> > -    }
> > +    public void addJavaScriptAtPosition(FacesContext context, ResourcePosition position, String uri,
> > +            boolean defer);
> >
> >      public void addJavaScriptToBodyTag(FacesContext context, String javascriptEventName,
> > -            String addedJavaScript)
> > -    {
> > -        AttributeInfo info = new AttributeInfo();
> > -        info.setAttributeName(javascriptEventName);
> > -        info.setAttributeValue(addedJavaScript);
> > -
> > -        addPositionedInfo(context, BODY_ONLOAD, info);
> > -    }
> > +            String addedJavaScript);
> >
> >      /**
> >       * Adds the given Javascript resource at the specified document position.
> >       * If the script has already been referenced, it's added only once.
> >       */
> > -    public void addJavaScriptAtPosition(FacesContext context, Position position,
> > -            ResourceHandler resourceHandler, boolean defer)
> > -    {
> > -        validateResourceHandler(resourceHandler);
> > -        addPositionedInfo(context, position, getScriptInstance(context, resourceHandler, defer));
> > -    }
> > +    public void addJavaScriptAtPosition(FacesContext context, ResourcePosition position,
> > +            ResourceHandler resourceHandler, boolean defer);
> >
> >      /**
> >       * Adds the given Style Sheet at the specified document position.
> >       * If the style sheet has already been referenced, it's added only once.
> >       */
> > -    public void addStyleSheet(FacesContext context, Position position,
> > -            Class myfacesCustomComponent, String resourceName)
> > -    {
> > -        addStyleSheet(context, position, new MyFacesResourceHandler(myfacesCustomComponent,
> > -                resourceName));
> > -    }
> > +    public void addStyleSheet(FacesContext context, ResourcePosition position,
> > +            Class myfacesCustomComponent, String resourceName);
> >
> >      /**
> >       * Adds the given Style Sheet at the specified document position.
> >       * If the style sheet has already been referenced, it's added only once.
> >       */
> > -    public void addStyleSheet(FacesContext context, Position position, String uri)
> > -    {
> > -        addPositionedInfo(context, position, getStyleInstance(context, uri));
> > -    }
> > +    public void addStyleSheet(FacesContext context, ResourcePosition position, String uri);
> >
> >      /**
> >       * Adds the given Style Sheet at the specified document position.
> >       * If the style sheet has already been referenced, it's added only once.
> >       */
> > -    public void addStyleSheet(FacesContext context, Position position,
> > -            ResourceHandler resourceHandler)
> > -    {
> > -        validateResourceHandler(resourceHandler);
> > -        addPositionedInfo(context, position, getStyleInstance(context, resourceHandler));
> > -    }
> > +    public void addStyleSheet(FacesContext context, ResourcePosition position,
> > +            ResourceHandler resourceHandler);
> >
> >      /**
> >       * Adds the given Inline Style at the specified document position.
> >       */
> > -    public void addInlineStyleAtPosition(FacesContext context, Position position, String inlineStyle)
> > -    {
> > -        addPositionedInfo(context, position, getInlineStyleInstance(inlineStyle));
> > -    }
> > +    public void addInlineStyleAtPosition(FacesContext context, ResourcePosition position, String inlineStyle);
> >
> >      /**
> >       * Adds the given Inline Script at the specified document position.
> >       */
> > -    public void addInlineScriptAtPosition(FacesContext context, Position position,
> > -            String inlineScript)
> > -    {
> > -        addPositionedInfo(context, position, getInlineScriptInstance(inlineScript));
> > -    }
> > +    public void addInlineScriptAtPosition(FacesContext context, ResourcePosition position,
> > +            String inlineScript);
> >
> >      public String getResourceUri(FacesContext context, Class myfacesCustomComponent,
> > -            String resource, boolean withContextPath)
> > -    {
> > -        return getResourceUri(context,
> > -                new MyFacesResourceHandler(myfacesCustomComponent, resource), withContextPath);
> > -    }
> > -
> > -    public String getResourceUri(FacesContext context, Class myfacesCustomComponent, String resource)
> > -    {
> > -        return getResourceUri(context, new MyFacesResourceHandler(myfacesCustomComponent, resource));
> > -    }
> > +            String resource, boolean withContextPath);
> > +
> > +    public String getResourceUri(FacesContext context, Class myfacesCustomComponent, String resource);
> >
> >      /**
> >       * Get the Path used to retrieve an resource.
> >       */
> > -    public String getResourceUri(FacesContext context, ResourceHandler resourceHandler)
> > -    {
> > -        String uri = resourceHandler.getResourceUri(context);
> > -        if (uri == null)
> > -        {
> > -            return getResourceUri(context, resourceHandler.getResourceLoaderClass(), true);
> > -        }
> > -        return getResourceUri(context, resourceHandler.getResourceLoaderClass(), true) + uri;
> > -    }
> > +    public String getResourceUri(FacesContext context, ResourceHandler resourceHandler);
> >
> >      /**
> >       * Get the Path used to retrieve an resource.
> >       */
> >      public String getResourceUri(FacesContext context, ResourceHandler resourceHandler,
> > -            boolean withContextPath)
> > -    {
> > -        String uri = resourceHandler.getResourceUri(context);
> > -        if (uri == null)
> > -        {
> > -            return getResourceUri(context, resourceHandler.getResourceLoaderClass(),
> > -                    withContextPath);
> > -        }
> > -        return getResourceUri(context, resourceHandler.getResourceLoaderClass(), withContextPath)
> > -                + uri;
> > -    }
> > +            boolean withContextPath);
> >
> >      /**
> >       * Get the Path used to retrieve an resource.
> >       */
> > -    public String getResourceUri(FacesContext context, String uri)
> > -    {
> > -        return getResourceUri(context, uri, true);
> > -    }
> > +    public String getResourceUri(FacesContext context, String uri);
> >
> >      /**
> >       * Get the Path used to retrieve an resource.
> >       */
> > -    public String getResourceUri(FacesContext context, String uri, boolean withContextPath)
> > -    {
> > -        if (withContextPath)
> > -        {
> > -            return context.getApplication().getViewHandler().getResourceURL(context, uri);
> > -        }
> > -        return uri;
> > -    }
> > +    public String getResourceUri(FacesContext context, String uri, boolean withContextPath);
> >
> > -    /**
> > -     * Get the Path used to retrieve an resource.
> > -     */
> > -    protected String getResourceUri(FacesContext context, Class resourceLoader,
> > -            boolean withContextPath)
> > -    {
> > -        StringBuffer sb = new StringBuffer(200);
> > -        sb.append(RESOURCE_VIRTUAL_PATH);
> > -        sb.append(PATH_SEPARATOR);
> > -        sb.append(resourceLoader.getName());
> > -        sb.append(PATH_SEPARATOR);
> > -        sb.append(getCacheKey(context));
> > -        sb.append(PATH_SEPARATOR);
> > -        return getResourceUri(context, sb.toString(), withContextPath);
> > -    }
> >
> > -    /**
> > -     * Return a value used in the {cacheKey} part of a generated URL for a
> > -     * resource reference.
> > -     * <p>
> > -     * Caching in browsers normally works by having files served to them
> > -     * include last-modified and expiry-time http headers. Until the expiry
> > -     * time is reached, a browser will silently use its cached version. After
> > -     * the expiry time, it will send a "get if modified since {time}" message,
> > -     * where {time} is the last-modified header from the version it has cached.
> > -     * <p>
> > -     * Unfortunately this scheme only works well for resources represented as
> > -     * plain files on disk, where the webserver can easily and efficiently see
> > -     * the last-modified time of the resource file. When that query has to be
> > -     * processed by a servlet that doesn't scale well, even when it is possible
> > -     * to determine the resource's last-modified date from servlet code.
> > -     * <p>
> > -     * Fortunately, for the AddResource class a static resource is only ever
> > -     * accessed because a URL was embedded by this class in a dynamic page.
> > -     * This makes it possible to implement caching by instead marking every
> > -     * resource served with a very long expiry time, but forcing the URL that
> > -     * points to the resource to change whenever the old cached version becomes
> > -     * invalid; the browser effectively thinks it is fetching a different
> > -     * resource that it hasn't seen before. This is implemented by embedding
> > -     * a "cache key" in the generated URL.
> > -     * <p>
> > -     * Rather than using the actual modification date of a resource as the
> > -     * cache key, we simply use the webapp deployment time. This means that all
> > -     * data cached by browsers will become invalid after a webapp deploy (all
> > -     * the urls to the resources change). It also means that changes that occur
> > -     * to a resource <i>without</i> a webapp redeploy will not be seen by browsers.
> > -     */
> > -    protected long getCacheKey(FacesContext context)
> > -    {
> > -        // cache key is hold in application scope so it is recreated on redeploying the webapp.
> > -        Map applicationMap = context.getExternalContext().getApplicationMap();
> > -        Long cacheKey = (Long) applicationMap.get(RESOURCES_CACHE_KEY);
> > -        if (cacheKey == null)
> > -        {
> > -            cacheKey = new Long(System.currentTimeMillis() / 100000);
> > -            applicationMap.put(RESOURCES_CACHE_KEY, cacheKey);
> > -        }
> > -        return cacheKey.longValue();
> > -    }
> > -
> > -    public boolean isResourceUri(HttpServletRequest request)
> > -    {
> > -        String path;
> > -        if (_contextPath != null)
> > -        {
> > -            path = _contextPath + RESOURCE_VIRTUAL_PATH;
> > -        }
> > -        else
> > -        {
> > -            path = RESOURCE_VIRTUAL_PATH;
> > -        }
> > -        return request.getRequestURI().startsWith(path);
> > -    }
> > -
> > -    private Class getClass(String className) throws ClassNotFoundException
> > -    {
> > -        Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
> > -        validateResourceLoader(clazz);
> > -        return clazz;
> > -    }
> > +    public boolean isResourceUri(HttpServletRequest request);
> >
> >      public void serveResource(ServletContext context, HttpServletRequest request,
> > -            HttpServletResponse response) throws IOException
> > -    {
> > -        String pathInfo = request.getPathInfo();
> > -        String uri = request.getContextPath() + request.getServletPath()
> > -                + (pathInfo == null ? "" : pathInfo);
> > -        String classNameStartsAfter = RESOURCE_VIRTUAL_PATH + '/';
> > -
> > -        int posStartClassName = uri.indexOf(classNameStartsAfter) + classNameStartsAfter.length();
> > -        int posEndClassName = uri.indexOf(PATH_SEPARATOR, posStartClassName);
> > -        String className = uri.substring(posStartClassName, posEndClassName);
> > -        int posEndCacheKey = uri.indexOf(PATH_SEPARATOR, posEndClassName + 1);
> > -        String resourceUri = null;
> > -        if (posEndCacheKey + 1 < uri.length())
> > -        {
> > -            resourceUri = uri.substring(posEndCacheKey + 1);
> > -        }
> > -        try
> > -        {
> > -            Class resourceLoader = getClass(className);
> > -            validateResourceLoader(resourceLoader);
> > -            ((ResourceLoader) resourceLoader.newInstance()).serveResource(context, request,
> > -                    response, resourceUri);
> > -            response.flushBuffer();
> > -        }
> > -        catch (ClassNotFoundException e)
> > -        {
> > -            log.error("Could not find class for name: " + className, e);
> > -            response.sendError(HttpServletResponse.SC_NOT_FOUND,
> > -                    "Could not find resourceloader class for name: " + className);
> > -        }
> > -        catch (InstantiationException e)
> > -        {
> > -            log.error("Could not instantiate class for name: " + className, e);
> > -            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
> > -                    "Could not instantiate resourceloader class for name: " + className);
> > -        }
> > -        catch (IllegalAccessException e)
> > -        {
> > -            log.error("Could not access class for name: " + className, e);
> > -            response.sendError(HttpServletResponse.SC_FORBIDDEN,
> > -                    "Could not access resourceloader class for name: " + className);
> > -        }
> > -        catch (Throwable e)
> > -        {
> > -            log.error("Error while serving resource: " +resourceUri+", message : "+ e.getMessage(), e);
> > -            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
> > -        }
> > -    }
> > -
> > -    // Positioned stuffs
> > -
> > -    private Set getHeaderBeginInfos(HttpServletRequest request)
> > -    {
> > -        Set set = (Set) request.getAttribute(HEADER_BEGIN_INFO_REQUEST_ATTRIBUTE_NAME);
> > -        if (set == null)
> > -        {
> > -            set = new LinkedHashSet();
> > -            request.setAttribute(HEADER_BEGIN_INFO_REQUEST_ATTRIBUTE_NAME, set);
> > -        }
> > -        return set;
> > -    }
> > -
> > -    private Set getBodyEndInfos(HttpServletRequest request)
> > -    {
> > -        Set set = (Set) request.getAttribute(BODY_END_INFO_REQUEST_ATTRIBUTE_NAME);
> > -        if (set == null)
> > -        {
> > -            set = new LinkedHashSet();
> > -            request.setAttribute(BODY_END_INFO_REQUEST_ATTRIBUTE_NAME, set);
> > -        }
> > -        return set;
> > -    }
> > -
> > -    private Set getBodyOnloadInfos(HttpServletRequest request)
> > -    {
> > -        Set set = (Set) request.getAttribute(BODY_ONLOAD_INFO_REQUEST_ATTRIBUTE_NAME);
> > -        if (set == null)
> > -        {
> > -            set = new LinkedHashSet();
> > -            request.setAttribute(BODY_ONLOAD_INFO_REQUEST_ATTRIBUTE_NAME, set);
> > -        }
> > -        return set;
> > -    }
> > -
> > -    private void addPositionedInfo(FacesContext context, Position position, PositionedInfo info)
> > -    {
> > -        if (HEADER_BEGIN.equals(position))
> > -        {
> > -            //todo: fix this to work in PortletRequest as well
> > -            HttpServletRequest request = (HttpServletRequest) context.getExternalContext()
> > -                    .getRequest();
> > -            Set set = getHeaderBeginInfos(request);
> > -            set.add(info);
> > -        }
> > -        else if (BODY_END.equals(position))
> > -        {
> > -            //todo: fix this to work in PortletRequest as well
> > -            HttpServletRequest request = (HttpServletRequest) context.getExternalContext()
> > -                    .getRequest();
> > -            Set set = getBodyEndInfos(request);
> > -            set.add(info);
> > -
> > -        }
> > -        else if (BODY_ONLOAD.equals(position))
> > -        {
> > -            //todo: fix this to work in PortletRequest as well
> > -            HttpServletRequest request = (HttpServletRequest) context.getExternalContext()
> > -                    .getRequest();
> > -            Set set = getBodyOnloadInfos(request);
> > -            set.add(info);
> > -        }
> > -    }
> > -
> > -    public boolean hasHeaderBeginInfos(HttpServletRequest request)
> > -    {
> > -        return request.getAttribute(HEADER_BEGIN_INFO_REQUEST_ATTRIBUTE_NAME) != null;
> > -    }
> > +            HttpServletResponse response) throws IOException;
> > +
> > +
> > +    public boolean hasHeaderBeginInfos(HttpServletRequest request);
> >
> >      /**
> >       * Parses the response to mark the positions where code will be inserted
> >       */
> >      public void parseResponse(HttpServletRequest request, String bufferedResponse,
> > -            HttpServletResponse response)
> > -    {
> > -
> > -        originalResponse = new StringBuffer(bufferedResponse);
> > -
> > -        ParseCallbackListener l = new ParseCallbackListener();
> > -        ReducedHTMLParser.parse(originalResponse, l);
> > -
> > -        headerInsertPosition = l.getHeaderInsertPosition();
> > -        bodyInsertPosition = l.getBodyInsertPosition();
> > -        beforeBodyPosition = l.getBeforeBodyPosition();
> > -        afterBodyContentInsertPosition = l.getAfterBodyContentInsertPosition();
> > -        beforeBodyEndPosition = l.getAfterBodyEndPosition()-7;  // 7, which is the length of </body>
> > -
> > -        parserCalled = true;
> > -    }
> > +            HttpServletResponse response) throws IOException;
> >
> >      /**
> >       * Writes the javascript code necessary for myfaces in every page, just befode the closing &lt;/body&gt; tag
> >       */
> >      public void writeMyFacesJavascriptBeforeBodyEnd(HttpServletRequest request,
> > -            HttpServletResponse response) throws IOException
> > -    {
> > -         if (!parserCalled)
> > -         {
> > -            throw new IOException("Method parseResponse has to be called first");
> > -         }
> > -
> > -        if (beforeBodyEndPosition >= 0)
> > -        {
> > -            String myFacesJavascript = (String) request.getAttribute("org.apache.myfaces.myFacesJavascript");
> > -
> > -            if(myFacesJavascript != null)
> > -            {
> > -                originalResponse.insert(beforeBodyEndPosition, myFacesJavascript);
> > -            }
> > -            else
> > -            {
> > -                log.warn("MyFaces special javascript could not be retrieved from request-map.");
> > -            }
> > -        }
> > -    }
> > +            HttpServletResponse response) throws IOException;
> >
> >      /**
> >       * Add the resources to the &lt;head&gt; of the page.
> > @@ -728,464 +237,12 @@
> >       * The ordering is such that the user header CSS & JS override the MyFaces' ones.
> >       */
> >      public void writeWithFullHeader(HttpServletRequest request,
> > -            HttpServletResponse response) throws IOException
> > -    {
> > -        if (!parserCalled)
> > -        {
> > -            throw new IOException("Method parseResponse has to be called first");
> > -        }
> > -
> > -        boolean addHeaderTags = false;
> > -
> > -        if (headerInsertPosition == -1)
> > -        {
> > -            if (beforeBodyPosition != -1)
> > -            {
> > -                // The input html has a body start tag, but no head tags. We therefore
> > -                // need to insert head start/end tags for our content to live in.
> > -                addHeaderTags = true;
> > -                headerInsertPosition = beforeBodyPosition;
> > -            }
> > -            else
> > -            {
> > -                // neither head nor body tags in the input
> > -                log.warn("Response has no <head> or <body> tag:\n" + originalResponse);
> > -            }
> > -        }
> > -
> > -        ResponseWriter writer = new HtmlResponseWriterImpl(response.getWriter(), HtmlRendererUtils
> > -                .selectContentType(request.getHeader("accept")), null);
> > -
> > -        if (afterBodyContentInsertPosition >= 0)
> > -        {
> > -            // insert all the items that want to go immediately after the <body> tag.
> > -            HtmlBufferResponseWriterWrapper writerWrapper = HtmlBufferResponseWriterWrapper
> > -                    .getInstance(writer);
> > -
> > -            for (Iterator i = getBodyEndInfos(request).iterator(); i.hasNext();)
> > -            {
> > -                writerWrapper.write("\n");
> > -
> > -                PositionedInfo positionedInfo = (PositionedInfo) i.next();
> > -
> > -                if (!(positionedInfo instanceof WritablePositionedInfo))
> > -                    throw new IllegalStateException("positionedInfo of type : "
> > -                            + positionedInfo.getClass().getName());
> > -                ((WritablePositionedInfo) positionedInfo).writePositionedInfo(response,
> > -                        writerWrapper);
> > -            }
> > -
> > -            originalResponse.insert(headerInsertPosition, writerWrapper.toString());
> > -        }
> > -
> > -        if (bodyInsertPosition > 0)
> > -        {
> > -            StringBuffer buf = new StringBuffer();
> > -            Set bodyInfos = getBodyOnloadInfos(request);
> > -            if (bodyInfos.size() > 0)
> > -            {
> > -                int i = 0;
> > -                for (Iterator it = getBodyOnloadInfos(request).iterator(); it.hasNext();)
> > -                {
> > -                    AttributeInfo positionedInfo = (AttributeInfo) it.next();
> > -                    if (i == 0)
> > -                    {
> > -                        buf.append(positionedInfo.getAttributeName());
> > -                        buf.append("=\"");
> > -                    }
> > -                    buf.append(positionedInfo.getAttributeValue());
> > -
> > -                    i++;
> > -                }
> > -
> > -                buf.append("\"");
> > -                originalResponse.insert(bodyInsertPosition - 1, " " + buf.toString());
> > -            }
> > -        }
> > -
> > -        if (headerInsertPosition >= 0)
> > -        {
> > -            HtmlBufferResponseWriterWrapper writerWrapper = HtmlBufferResponseWriterWrapper
> > -                    .getInstance(writer);
> > -
> > -            if (addHeaderTags)
> > -                writerWrapper.write("<head>");
> > -
> > -            for (Iterator i = getHeaderBeginInfos(request).iterator(); i.hasNext();)
> > -            {
> > -                writerWrapper.write("\n");
> > -
> > -                PositionedInfo positionedInfo = (PositionedInfo) i.next();
> > -
> > -                if (!(positionedInfo instanceof WritablePositionedInfo))
> > -                    throw new IllegalStateException("positionedInfo of type : "
> > -                            + positionedInfo.getClass().getName());
> > -                ((WritablePositionedInfo) positionedInfo).writePositionedInfo(response,
> > -                        writerWrapper);
> > -            }
> > -
> > -            if (addHeaderTags)
> > -                writerWrapper.write("</head>");
> > -
> > -            originalResponse.insert(headerInsertPosition, writerWrapper.toString());
> > -
> > -        }
> > -
> > -    }
> > +            HttpServletResponse response) throws IOException;
> >
> >      /**
> >       * Writes the response
> >       */
> >      public void writeResponse(HttpServletRequest request,
> > -            HttpServletResponse response) throws IOException
> > -    {
> > -        ResponseWriter writer = new HtmlResponseWriterImpl(response.getWriter(), HtmlRendererUtils
> > -                .selectContentType(request.getHeader("accept")), null);
> > -        writer.write(originalResponse.toString());
> > -    }
> > -
> > -    private PositionedInfo getStyleInstance(FacesContext context, ResourceHandler resourceHandler)
> > -    {
> > -        return new StylePositionedInfo(getResourceUri(context, resourceHandler));
> > -    }
> > -
> > -    private PositionedInfo getScriptInstance(FacesContext context, ResourceHandler resourceHandler,
> > -            boolean defer)
> > -    {
> > -        return new ScriptPositionedInfo(getResourceUri(context, resourceHandler), defer);
> > -    }
> > -
> > -    private PositionedInfo getStyleInstance(FacesContext context, String uri)
> > -    {
> > -        return new StylePositionedInfo(getResourceUri(context, uri));
> > -    }
> > -
> > -    protected PositionedInfo getScriptInstance(FacesContext context, String uri, boolean defer)
> > -    {
> > -        return new ScriptPositionedInfo(getResourceUri(context, uri), defer);
> > -    }
> > -
> > -    private PositionedInfo getInlineScriptInstance(String inlineScript)
> > -    {
> > -        return new InlineScriptPositionedInfo(inlineScript);
> > -    }
> > -
> > -    private PositionedInfo getInlineStyleInstance(String inlineStyle)
> > -    {
> > -        return new InlineStylePositionedInfo(inlineStyle);
> > -    }
> > -
> > -    public static class Position
> > -    {
> > -        private final int _pos;
> > -
> > -        private Position(int pos)
> > -        {
> > -            _pos = pos;
> > -        }
> > -
> > -        public boolean equals(Object obj)
> > -        {
> > -            if (obj == null)
> > -            {
> > -                return false;
> > -            }
> > -            if (obj == this)
> > -            {
> > -                return true;
> > -            }
> > -            if (obj instanceof Position)
> > -            {
> > -                return ((Position) obj)._pos == _pos;
> > -            }
> > -            return false;
> > -        }
> > -
> > -        public int hashCode()
> > -        {
> > -            return _pos;
> > -        }
> > -    }
> > -
> > -    private interface PositionedInfo
> > -    {
> > -    }
> > -
> > -    private static class AttributeInfo implements PositionedInfo
> > -    {
> > -        private String _attributeName;
> > -        private String _attributeValue;
> > -
> > -        public String getAttributeName()
> > -        {
> > -            return _attributeName;
> > -        }
> > -
> > -        public void setAttributeName(String attributeName)
> > -        {
> > -            _attributeName = attributeName;
> > -        }
> > -
> > -        public String getAttributeValue()
> > -        {
> > -            return _attributeValue;
> > -        }
> > -
> > -        public void setAttributeValue(String attributeValue)
> > -        {
> > -            _attributeValue = attributeValue;
> > -        }
> > -    }
> > -
> > -    private interface WritablePositionedInfo extends PositionedInfo
> > -    {
> > -        public abstract void writePositionedInfo(HttpServletResponse response, ResponseWriter writer)
> > -                throws IOException;
> > -    }
> > -
> > -    private abstract class AbstractResourceUri
> > -    {
> > -        protected final String _resourceUri;
> > -
> > -        protected AbstractResourceUri(String resourceUri)
> > -        {
> > -            _resourceUri = resourceUri;
> > -        }
> > -
> > -        public int hashCode()
> > -        {
> > -            return _resourceUri.hashCode();
> > -        }
> > -
> > -        public boolean equals(Object obj)
> > -        {
> > -            if (obj == null)
> > -            {
> > -                return false;
> > -            }
> > -            if (obj == this)
> > -            {
> > -                return true;
> > -            }
> > -            if (obj instanceof AbstractResourceUri)
> > -            {
> > -                AbstractResourceUri other = (AbstractResourceUri) obj;
> > -                return _resourceUri.equals(other._resourceUri);
> > -            }
> > -            return false;
> > -        }
> > -
> > -        protected String getResourceUri()
> > -        {
> > -            return _resourceUri;
> > -        }
> > -    }
> > -
> > -    private class StylePositionedInfo extends AbstractResourceUri implements WritablePositionedInfo
> > -    {
> > -        protected StylePositionedInfo(String resourceUri)
> > -        {
> > -            super(resourceUri);
> > -        }
> > -
> > -        public void writePositionedInfo(HttpServletResponse response, ResponseWriter writer)
> > -                throws IOException
> > -        {
> > -            writer.startElement(HTML.LINK_ELEM, null);
> > -            writer.writeAttribute(HTML.REL_ATTR, HTML.STYLESHEET_VALUE, null);
> > -            writer.writeAttribute(HTML.HREF_ATTR, response.encodeURL(this.getResourceUri()), null);
> > -            writer.writeAttribute(HTML.TYPE_ATTR, HTML.STYLE_TYPE_TEXT_CSS, null);
> > -            writer.endElement(HTML.LINK_ELEM);
> > -        }
> > -    }
> > -
> > -    private class ScriptPositionedInfo extends AbstractResourceUri implements
> > -            WritablePositionedInfo
> > -    {
> > -        protected final boolean _defer;
> > -
> > -        public ScriptPositionedInfo(String resourceUri, boolean defer)
> > -        {
> > -            super(resourceUri);
> > -            _defer = defer;
> > -        }
> > -
> > -        public int hashCode()
> > -        {
> > -            return new HashCodeBuilder().append(this.getResourceUri()).append(_defer).toHashCode();
> > -        }
> > -
> > -        public boolean equals(Object obj)
> > -        {
> > -            if (super.equals(obj))
> > -            {
> > -                if (obj instanceof ScriptPositionedInfo)
> > -                {
> > -                    ScriptPositionedInfo other = (ScriptPositionedInfo) obj;
> > -                    return new EqualsBuilder().append(_defer, other._defer).isEquals();
> > -                }
> > -            }
> > -            return false;
> > -        }
> > -
> > -        public void writePositionedInfo(HttpServletResponse response, ResponseWriter writer)
> > -                throws IOException
> > -        {
> > -            writer.startElement(HTML.SCRIPT_ELEM, null);
> > -            writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
> > -            writer.writeAttribute(HTML.SRC_ATTR, response.encodeURL(this.getResourceUri()), null);
> > -
> > -            if (_defer)
> > -            {
> > -                writer.writeAttribute(HTML.SCRIPT_ELEM_DEFER_ATTR, "true", null);
> > -            }
> > -            writer.endElement(HTML.SCRIPT_ELEM);
> > -        }
> > -    }
> > -
> > -    private abstract class InlinePositionedInfo implements WritablePositionedInfo
> > -    {
> > -        private final String _inlineValue;
> > -
> > -        protected InlinePositionedInfo(String inlineValue)
> > -        {
> > -            _inlineValue = inlineValue;
> > -        }
> > -
> > -        public String getInlineValue()
> > -        {
> > -            return _inlineValue;
> > -        }
> > -
> > -        public int hashCode()
> > -        {
> > -            return new HashCodeBuilder().append(_inlineValue).toHashCode();
> > -        }
> > -
> > -        public boolean equals(Object obj)
> > -        {
> > -            if (obj == null)
> > -            {
> > -                return false;
> > -            }
> > -            if (obj == this)
> > -            {
> > -                return true;
> > -            }
> > -            if (obj instanceof InlinePositionedInfo)
> > -            {
> > -                InlinePositionedInfo other = (InlinePositionedInfo) obj;
> > -                return new EqualsBuilder().append(_inlineValue, other._inlineValue).isEquals();
> > -            }
> > -            return false;
> > -        }
> > -    }
> > -
> > -    private class InlineScriptPositionedInfo extends InlinePositionedInfo
> > -    {
> > -        protected InlineScriptPositionedInfo(String inlineScript)
> > -        {
> > -            super(inlineScript);
> > -        }
> > -
> > -        public void writePositionedInfo(HttpServletResponse response, ResponseWriter writer)
> > -                throws IOException
> > -        {
> > -            writer.startElement(HTML.SCRIPT_ELEM, null);
> > -            writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
> > -            writer.writeText(getInlineValue(), null);
> > -            writer.endElement(HTML.SCRIPT_ELEM);
> > -        }
> > -    }
> > -
> > -    private class InlineStylePositionedInfo extends InlinePositionedInfo
> > -    {
> > -        protected InlineStylePositionedInfo(String inlineStyle)
> > -        {
> > -            super(inlineStyle);
> > -        }
> > -
> > -        public void writePositionedInfo(HttpServletResponse response, ResponseWriter writer)
> > -                throws IOException
> > -        {
> > -            writer.startElement(HTML.STYLE_ELEM, null);
> > -            writer.writeAttribute(HTML.REL_ATTR, HTML.STYLESHEET_VALUE, null);
> > -            writer.writeAttribute(HTML.TYPE_ATTR, HTML.STYLE_TYPE_TEXT_CSS, null);
> > -            writer.writeText(getInlineValue(), null);
> > -            writer.endElement(HTML.STYLE_ELEM);
> > -        }
> > -    }
> > -
> > -    private static class ParseCallbackListener implements CallbackListener
> > -    {
> > -        private int headerInsertPosition = -1;
> > -        private int bodyInsertPosition = -1;
> > -        private int beforeBodyPosition = -1;
> > -        private int afterBodyContentInsertPosition = -1;
> > -        private int afterBodyEndPosition = -1;
> > -
> > -        public void openedStartTag(int charIndex, int tagIdentifier)
> > -        {
> > -            if (tagIdentifier == ReducedHTMLParser.BODY_TAG)
> > -            {
> > -                beforeBodyPosition = charIndex;
> > -            }
> > -        }
> > -
> > -        public void closedStartTag(int charIndex, int tagIdentifier)
> > -        {
> > -            if (tagIdentifier == ReducedHTMLParser.HEAD_TAG)
> > -            {
> > -                headerInsertPosition = charIndex;
> > -            }
> > -            else if (tagIdentifier == ReducedHTMLParser.BODY_TAG)
> > -            {
> > -                bodyInsertPosition = charIndex;
> > -            }
> > -        }
> > -
> > -        public void openedEndTag(int charIndex, int tagIdentifier)
> > -        {
> > -            if (tagIdentifier == ReducedHTMLParser.BODY_TAG)
> > -            {
> > -                afterBodyContentInsertPosition = charIndex;
> > -            }
> > -        }
> > -
> > -        public void closedEndTag(int charIndex, int tagIdentifier)
> > -        {
> > -            if (tagIdentifier == ReducedHTMLParser.BODY_TAG)
> > -            {
> > -                afterBodyEndPosition = charIndex;
> > -            }
> > -        }
> > -
> > -        public void attribute(int charIndex, int tagIdentifier, String key, String value)
> > -        {
> > -        }
> > -
> > -        public int getHeaderInsertPosition()
> > -        {
> > -            return headerInsertPosition;
> > -        }
> > -
> > -        public int getBodyInsertPosition()
> > -        {
> > -            return bodyInsertPosition;
> > -        }
> > -
> > -        public int getBeforeBodyPosition()
> > -        {
> > -            return beforeBodyPosition;
> > -        }
> > -
> > -        public int getAfterBodyContentInsertPosition()
> > -        {
> > -            return afterBodyContentInsertPosition;
> > -        }
> > -
> > -        public int getAfterBodyEndPosition() {
> > -            return afterBodyEndPosition;
> > -        }
> > -    }
> > +            HttpServletResponse response) throws IOException;
> > +
> >  }
> >
> > Added: myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResourceFactory.java
> > URL: http://svn.apache.org/viewcvs/myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResourceFactory.java?rev=376085&view=auto
> > ==============================================================================
> > --- myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResourceFactory.java (added)
> > +++ myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResourceFactory.java Wed Feb  8 13:40:47 2006
> > @@ -0,0 +1,164 @@
> > +/*
> > + * Copyright 2004-2006 The Apache Software Foundation.
> > + *
> > + * Licensed under the Apache License, Version 2.0 (the "License");
> > + * you may not use this file except in compliance with the License.
> > + * You may obtain a copy of the License at
> > + *
> > + *      http://www.apache.org/licenses/LICENSE-2.0
> > + *
> > + * Unless required by applicable law or agreed to in writing, software
> > + * distributed under the License is distributed on an "AS IS" BASIS,
> > + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> > + * See the License for the specific language governing permissions and
> > + * limitations under the License.
> > + */
> > +
> > +package org.apache.myfaces.renderkit.html.util;
> > +
> > +import java.lang.reflect.Constructor;
> > +import java.lang.reflect.InvocationTargetException;
> > +import java.util.HashMap;
> > +import java.util.Map;
> > +
> > +import javax.faces.context.FacesContext;
> > +
> > +import org.apache.commons.logging.Log;
> > +import org.apache.commons.logging.LogFactory;
> > +import org.apache.myfaces.config.MyfacesConfig;
> > +import org.apache.myfaces.util.ClassUtils;
> > +
> > +/**
> > + * This class provides the ability to instantiate AddResource objects.
> > + * By default, this class will instantiate instances of
> > + * org.apache.myfaces.component.html.util.DefaultAddResource.
> > + * However, the context parameter org.apache.myfaces.ADD_RESOURCE_CLASS
> > + * can specify an alternative implementation of the AddResource
> > + * interface. The class must have a constructor with a single String
> > + * argument, representing the context path.
> > + *
> > + * Mostly used to avoid having to include [script src="..."][/script]
> > + * in the head of the pages before using a component.
> > + *
> > + * @author Peter Mahoney
> > + * @author Sylvain Vieujot (latest modification by $Author: mmarinschek $)
> > + * @version $Revision: 358042 $ $Date: 2005-12-20 17:12:56 +0000 (Tue, 20 Dec 2005) $
> > + */
> > +public class AddResourceFactory
> > +{
> > +
> > +    protected static final Log log = LogFactory.getLog(AddResourceFactory.class);
> > +
> > +    /**
> > +     * Map of AddResource instances keyed by context path. This map will have
> > +     * more than one entry only if the myfaces library is in the "shared"
> > +     * classpath of a container where more than one webapp can see it
> > +     * simultaneously.
> > +     */
> > +    private static final Map _addResourceMap = new HashMap();
> > +
> > +    /**
> > +     * Internal factory method.
> > +     * <p>
> > +     * Return an instance of AddResource keyed by context path, or create one
> > +     * if no such instance already exists. Note that the same AddResource object
> > +     * is shared among all threads servicing the same webapp, so all methods
> > +     * on this class are required to be threadsafe.
> > +     * <p>
> > +     * Note that this method is package-scope for the purposes of unit-testing only.
> > +     * This method should be treated as private by non-test code.
> > +     */
> > +    static AddResource getInstance(String contextPath, String addResourceClassName)
> > +    {
> > +        // Yes, this method does use a variant of the "double locking" idiom
> > +        // which is well documented to be invalid for general use. However
> > +        // it is believed safe for use here because AddResource objects in
> > +        // _addResourceMap are never removed or replaced.
> > +        AddResource instance = (AddResource) _addResourceMap.get(contextPath);
> > +        if (instance == null)
> > +        {
> > +            synchronized (_addResourceMap)
> > +            {
> > +                instance = (AddResource) _addResourceMap.get(contextPath);
> > +                if (instance == null)
> > +                {
> > +                       if (addResourceClassName == null)
> > +                       {
> > +                               // For efficiency don't use reflection unless it is necessary
> > +                        instance = new DefaultAddResource(contextPath);
> > +                       }
> > +                       else
> > +                       {
> > +                               try
> > +                               {
> > +                                       Class addResourceClass = ClassUtils.classForName(addResourceClassName);
> > +
> > +                                       if (AddResource.class.isAssignableFrom(addResourceClass))
> > +                                       {
> > +                                               // Look for an appropriate constructor
> > +                                               Constructor[] constructors = addResourceClass.getDeclaredConstructors();
> > +
> > +                                               for (int i = 0; i < constructors.length; i++)
> > +                                               {
> > +                                                       Class[] parameters = constructors[i].getParameterTypes();
> > +
> > +                                                       if (parameters.length == 1 && String.class.isAssignableFrom(parameters[i]))
> > +                                                       {
> > +                                                               instance = (AddResource) constructors[i].newInstance(new String[] {contextPath});
> > +                                                               log.info("Found AddResource class '" + addResourceClass.getName() + "'");
> > +                                                               break;
> > +                                                       }
> > +                                               }
> > +
> > +                                               if (instance == null)
> > +                                               {
> > +                                               log.error("Invalid AddResource class (" + addResourceClass.getName()
> > +                                                       + "). Must include single argument (context path) constructor.");
> > +                                               }
> > +                                       }
> > +                                       else
> > +                                       {
> > +                                       log.error("Invalid AddResource class (" + addResourceClass.getName()
> > +                                                       + "). Must implement the AddResource interface.");
> > +                                       }
> > +                               }
> > +                               catch (ClassNotFoundException e)
> > +                               {
> > +                                       log.error("AddResource class not found. Using default class instead", e);
> > +                               }
> > +                               catch (IllegalArgumentException e) {
> > +                                       // This should not happen as the constructor has been checked
> > +                                       log.error(e);
> > +                                               }
> > +                               catch (InstantiationException e) {
> > +                                       log.error("Invalid AddResource class. Must be non-abstract", e);
> > +                                               }
> > +                               catch (IllegalAccessException e) {
> > +                                       log.error("Could not access AddResource class", e);
> > +                                               }
> > +                               catch (InvocationTargetException e) {
> > +                                       log.error(e);
> > +                                               }
> > +                                               finally
> > +                                               {
> > +                                                       // Ensure there is always an AddResource object available
> > +                                                       if (instance == null)
> > +                                                       {
> > +                                                               instance = new DefaultAddResource(contextPath);
> > +                                                       }
> > +                                               }
> > +                       }
> > +                    _addResourceMap.put(contextPath, instance);
> > +                }
> > +            }
> > +        }
> > +        return instance;
> > +    }
> > +
> > +    public static AddResource getInstance(FacesContext context)
> > +    {
> > +        return getInstance(context.getExternalContext().getRequestContextPath(),
> > +                       MyfacesConfig.getCurrentInstance(context.getExternalContext()).getAddResourceClass());
> > +    }
> > +
> > +}
> >
> >
> >
>
>


--

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Mime
View raw message