tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-tapestry/framework/src/org/apache/tapestry/engine NullTemplateSourceDelegate.java ITemplateSourceDelegate.java DefaultTemplateSource.java
Date Sun, 23 Mar 2003 01:28:15 GMT
hlship      2003/03/22 17:28:15

  Modified:    framework/src/org/apache/tapestry/engine
                        DefaultTemplateSource.java
  Added:       framework/src/org/apache/tapestry/engine
                        NullTemplateSourceDelegate.java
                        ITemplateSourceDelegate.java
  Log:
  Add new extensions for locating page and component specifications and templates (when not
found by the standard rules).
  
  Revision  Changes    Path
  1.3       +45 -6     jakarta-tapestry/framework/src/org/apache/tapestry/engine/DefaultTemplateSource.java
  
  Index: DefaultTemplateSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/engine/DefaultTemplateSource.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultTemplateSource.java	15 Mar 2003 21:22:20 -0000	1.2
  +++ DefaultTemplateSource.java	23 Mar 2003 01:28:15 -0000	1.3
  @@ -66,9 +66,13 @@
   import java.util.Locale;
   import java.util.Map;
   
  +import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   import org.apache.tapestry.ApplicationRuntimeException;
   import org.apache.tapestry.IAsset;
   import org.apache.tapestry.IComponent;
  +import org.apache.tapestry.IEngine;
   import org.apache.tapestry.IMarkupWriter;
   import org.apache.tapestry.INamespace;
   import org.apache.tapestry.IRequestCycle;
  @@ -82,11 +86,9 @@
   import org.apache.tapestry.parse.TemplateToken;
   import org.apache.tapestry.resolver.ComponentSpecificationResolver;
   import org.apache.tapestry.spec.ComponentSpecification;
  +import org.apache.tapestry.spec.IApplicationSpecification;
   import org.apache.tapestry.util.IRenderDescription;
   import org.apache.tapestry.util.MultiKey;
  -import org.apache.commons.lang.builder.ToStringBuilder;
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
   
   /**
    *  Default implementation of {@link ITemplateSource}.  Templates, once parsed,
  @@ -131,15 +133,21 @@
   
       private IResourceLocation _applicationRootLocation;
   
  +    /** @since 2.4 **/
  +
  +    private ITemplateSourceDelegate _delegate;
  +
       private static class ParserDelegate implements ITemplateParserDelegate
       {
           private IComponent _component;
           private ComponentSpecificationResolver _resolver;
  +        private IRequestCycle _cycle;
   
           ParserDelegate(IComponent component, IRequestCycle cycle)
           {
               _component = component;
               _resolver = new ComponentSpecificationResolver(cycle);
  +            _cycle = cycle;
           }
   
           public boolean getKnownComponent(String componentId)
  @@ -161,7 +169,7 @@
           {
               INamespace namespace = _component.getNamespace();
   
  -            _resolver.resolve(namespace, libraryId, type);
  +            _resolver.resolve(_cycle, namespace, libraryId, type);
   
               ComponentSpecification spec = _resolver.getSpecification();
   
  @@ -212,13 +220,21 @@
   
           if (result == null)
           {
  +            result = getTemplateFromDelegate(cycle, component, locale);
  +
  +            if (result != null)
  +                return result;
  +
               String stringKey =
                   component.getSpecification().isPageSpecification()
                       ? "DefaultTemplateSource.no-template-for-page"
                       : "DefaultTemplateSource.no-template-for-component";
   
               throw new ApplicationRuntimeException(
  -                Tapestry.getString(stringKey, component.getExtendedId(), locale));
  +                Tapestry.getString(stringKey, component.getExtendedId(), locale),
  +                component,
  +                component.getLocation(),
  +                null);
           }
   
           saveToCache(key, result);
  @@ -235,6 +251,29 @@
       {
           _cache.put(key, template);
   
  +    }
  +
  +    private ComponentTemplate getTemplateFromDelegate(
  +        IRequestCycle cycle,
  +        IComponent component,
  +        Locale locale)
  +    {
  +        if (_delegate == null)
  +        {
  +            IEngine engine = cycle.getEngine();
  +            IApplicationSpecification spec = engine.getSpecification();
  +
  +            if (spec.checkExtension(Tapestry.TEMPLATE_SOURCE_DELEGATE_EXTENSION_NAME))
  +                _delegate =
  +                    (ITemplateSourceDelegate) spec.getExtension(
  +                        Tapestry.TEMPLATE_SOURCE_DELEGATE_EXTENSION_NAME,
  +                        ITemplateSourceDelegate.class);
  +            else
  +                _delegate = NullTemplateSourceDelegate.getSharedInstance();
  +
  +        }
  +
  +        return _delegate.findTemplate(cycle, component, locale);
       }
   
       /**
  
  
  
  1.1                  jakarta-tapestry/framework/src/org/apache/tapestry/engine/NullTemplateSourceDelegate.java
  
  Index: NullTemplateSourceDelegate.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation", "Tapestry" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" 
   *    or "Tapestry", nor may "Apache" or "Tapestry" appear in their 
   *    name, without prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE TAPESTRY CONTRIBUTOR COMMUNITY
   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.tapestry.engine;
  
  import java.util.Locale;
  
  import org.apache.tapestry.IComponent;
  import org.apache.tapestry.IRequestCycle;
  import org.apache.tapestry.parse.ComponentTemplate;
  
  /**
   *  Null implementation of {@link org.apache.tapestry.engine.ITemplateSourceDelegate}. 
   *
   *  @author Howard Lewis Ship
   *  @version $Id: NullTemplateSourceDelegate.java,v 1.1 2003/03/23 01:28:15 hlship Exp $
   *  @since 2.4
   *
   **/
  
  public class NullTemplateSourceDelegate implements ITemplateSourceDelegate
  {
  	private static NullTemplateSourceDelegate _shared;
  	
  	/**
  	 *  Returns a shared instance of NullTemplateSourceDelegate.
  	 * 
  	 **/
  	
  	public static NullTemplateSourceDelegate getSharedInstance()
  	{
  		if (_shared == null)
  			_shared = new NullTemplateSourceDelegate();
  			
  		return _shared;
  	}
  
  	/**
  	 *  Simply returns null.
  	 * 
  	 **/
  	
      public ComponentTemplate findTemplate(IRequestCycle cycle, IComponent component, Locale
locale)
      {
          return null;
      }
  
  }
  
  
  
  1.1                  jakarta-tapestry/framework/src/org/apache/tapestry/engine/ITemplateSourceDelegate.java
  
  Index: ITemplateSourceDelegate.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation", "Tapestry" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" 
   *    or "Tapestry", nor may "Apache" or "Tapestry" appear in their 
   *    name, without prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE TAPESTRY CONTRIBUTOR COMMUNITY
   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.tapestry.engine;
  
  import java.util.Locale;
  
  import org.apache.tapestry.IComponent;
  import org.apache.tapestry.IRequestCycle;
  import org.apache.tapestry.parse.ComponentTemplate;
  
  /**
   *  Acts as a delegate to the {@link ITemplateSource}, providing access to
   *  page and component templates after the normal search mechanisms have failed.
   * 
   *  <p>
   *  The delegate must be threadsafe.
   *
   *  @author Howard Lewis Ship
   *  @version $Id: ITemplateSourceDelegate.java,v 1.1 2003/03/23 01:28:15 hlship Exp $
   *  @since 2.4
   *  @see org.apache.tapestry.engine.DefaultTemplateSource
   * 
   **/
  
  public interface ITemplateSourceDelegate
  {
  	/**
  	 *  Invoked by the {@link ITemplateSource} when a template can't be found
  	 *  by normal means (i.e., in the normal locations).  This method
  	 *  should find the template.  The result may be null.  The delegate
  	 *  is responsible for caching the result.
  	 * 
  	 *  @param cycle for access to Tapestry and Servlet API objects
  	 *  @param component component (or page) for which a template is needed
  	 *  @param locale the desired locale for the template
  	 * 
  	 **/
  	
  	public ComponentTemplate findTemplate(IRequestCycle cycle,
  	IComponent component,
  	Locale locale);
  }
  
  
  

Mime
View raw message