dlr         2002/10/10 10:10:30

  Modified:    src/java/org/apache/velocity/runtime/directive Include.java
                        Parse.java
  Added:       src/java/org/apache/velocity/runtime/directive
                        InputBase.java
  Log:
  Introduced new abstract InputBase class to encapsulate
  common operations for directives which perform input.
  
  Revision  Changes    Path
  1.25      +3 -23     
jakarta-velocity/src/java/org/apache/velocity/runtime/directive/Include.java
  
  Index: Include.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/directive/Include.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -u -r1.24 -r1.25
  --- Include.java      10 Oct 2002 16:30:54 -0000      1.24
  +++ Include.java      10 Oct 2002 17:10:30 -0000      1.25
  @@ -104,7 +104,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Kasper Nielsen</a>
    * @version $Id$
    */
  -public class Include extends Directive
  +public class Include extends InputBase
   {
       private String outputMsgStart = "";
       private String outputMsgEnd = "";
  @@ -227,29 +227,9 @@
   
           Resource resource = null;
   
  -        Resource current = context.getCurrentResource();
  -
           try
           {
  -            /*
  -             *  get the resource, and assume that we use the encoding
  -             *  of the current template the 'current resource' can be
  -             *  null if we are processing a stream....
  -             */
  -
  -            String encoding = null;
  -
  -            if ( current != null)
  -            {
  -                encoding = current.getEncoding();
  -            }
  -            else
  -            {
  -                encoding =
  -                    (String) rsvc.getProperty(RuntimeConstants.INPUT_ENCODING);
  -            }
  -
  -            resource = rsvc.getContent(arg, encoding);
  +            resource = rsvc.getContent(arg, getInputEncoding(context));
           }
           catch ( ResourceNotFoundException rnfe )
           {
  
  
  
  1.26      +3 -23     
jakarta-velocity/src/java/org/apache/velocity/runtime/directive/Parse.java
  
  Index: Parse.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/directive/Parse.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -u -r1.25 -r1.26
  --- Parse.java        10 Oct 2002 16:47:54 -0000      1.25
  +++ Parse.java        10 Oct 2002 17:10:30 -0000      1.26
  @@ -94,7 +94,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph Reck</a>
    * @version $Id$
    */
  -public class Parse extends Directive
  +public class Parse extends InputBase
   {
       private boolean ready = false;
   
  @@ -171,26 +171,6 @@
               return false;
           }
   
  -        Resource current = context.getCurrentResource();
  -
  -        /*
  -         *  get the resource, and assume that we use the encoding of
  -         *  the current template the 'current resource' can be null if
  -         *  we are processing a stream....
  -         */
  -
  -        String encoding = null;
  -
  -        if ( current != null)
  -        {
  -            encoding = current.getEncoding();
  -        }
  -        else
  -        {
  -            encoding =
  -                (String) rsvc.getProperty(RuntimeConstants.INPUT_ENCODING);
  -        }
  -
           /*
            *  now use the Runtime resource loader to get the template
            */
  @@ -199,7 +179,7 @@
   
           try 
           {
  -            t = rsvc.getTemplate( arg, encoding );   
  +            t = rsvc.getTemplate( arg, getInputEncoding(context) );
           }
           catch ( ResourceNotFoundException rnfe )
           {
  
  
  
  1.1                  
jakarta-velocity/src/java/org/apache/velocity/runtime/directive/InputBase.java
  
  Index: InputBase.java
  ===================================================================
  package org.apache.velocity.runtime.directive;
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS 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/>.
   */
  
  import org.apache.velocity.context.InternalContextAdapter;
  import org.apache.velocity.runtime.RuntimeConstants;
  import org.apache.velocity.runtime.resource.Resource;
  
  /**
   * Base class for directives which do input operations
   * (e.g. <code>#include()</code>, <code>#parse()</code>, etc.).
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
   * @since 1.4
   */
  public abstract class InputBase extends Directive
  {
      /**
       * Decides the encoding used during input processing of this
       * directive.
       *
       * Get the resource, and assume that we use the encoding of the
       * current template the 'current resource' can be
       * <code>null</code> if we are processing a stream....
       *
       * @param context The context to derive the default input encoding
       * from.
       * @return The encoding to use when processing this directive.     
       */
      protected String getInputEncoding(InternalContextAdapter context)
      {
          Resource current = context.getCurrentResource();
          if (current != null)
          {
              return current.getEncoding();
          }
          else
          {
              return (String) rsvc.getProperty(RuntimeConstants.INPUT_ENCODING);
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to