You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jv...@apache.org on 2001/08/09 13:48:42 UTC

cvs commit: jakarta-turbine/src/tool/org/apache/turbine/tool RelativeTemplateLink.java TemplateLinkWithSlash.java TemplatePageAttributes.java TemplateLink.java

jvanzyl     01/08/09 04:48:42

  Modified:    src/tool/org/apache/turbine/tool TemplateLink.java
  Added:       src/tool/org/apache/turbine/tool RelativeTemplateLink.java
                        TemplateLinkWithSlash.java
                        TemplatePageAttributes.java
  Log:
  - forgot to check in all the files that were in the util.template
    directory.
  
  Revision  Changes    Path
  1.4       +2 -4      jakarta-turbine/src/tool/org/apache/turbine/tool/TemplateLink.java
  
  Index: TemplateLink.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/tool/org/apache/turbine/tool/TemplateLink.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TemplateLink.java	2001/08/09 07:47:34	1.3
  +++ TemplateLink.java	2001/08/09 11:48:42	1.4
  @@ -55,11 +55,9 @@
    */
   
   import javax.servlet.http.HttpServletResponse;
  -
  -import org.apache.turbine.services.pull.ApplicationTool;
  -
   import org.apache.turbine.util.DynamicURI;
   import org.apache.turbine.RunData;
  +import org.apache.turbine.services.pull.ApplicationTool;
   
   /**
    * A customized version of the DynamicURI to be used in Templates.
  @@ -75,7 +73,7 @@
    * @author <a href="mbryson@mont.mindspring.com">Dave Bryson</a>
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
    * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
  - * @version $Id: TemplateLink.java,v 1.3 2001/08/09 07:47:34 jon Exp $
  + * @version $Id: TemplateLink.java,v 1.4 2001/08/09 11:48:42 jvanzyl Exp $
    */
   public class TemplateLink
       extends DynamicURI
  
  
  
  1.1                  jakarta-turbine/src/tool/org/apache/turbine/tool/RelativeTemplateLink.java
  
  Index: RelativeTemplateLink.java
  ===================================================================
  package org.apache.turbine.tool;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.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" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", nor may "Apache" 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 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 javax.servlet.http.HttpServletResponse;
  import org.apache.turbine.util.RelativeDynamicURI;
  import org.apache.turbine.RunData;
  import org.apache.turbine.services.pull.ApplicationTool;
  
  /**
   * A customized version of the RelativeDynamicURI to be used in Templates.
   * Here's an example of its Velocity/WebMacro use:
   *
   * <p><code>
   * $link.setPage("index.wm").addPathInfo("hello","world")
   * This would return: /myapp/servlet/myapp/template/index.wm/hello/world
   * </code>
   *
   * @author <a href="jmcnally@collab.net">John D. McNally</a>
   * @author see the authors of TemplateLink
   * @version $Id: RelativeTemplateLink.java,v 1.1 2001/08/09 11:48:42 jvanzyl Exp $
   */
  public class RelativeTemplateLink
      extends RelativeDynamicURI
      implements ApplicationTool
  {
      /** the pathinfo key stored in the DynamicURI */
      private static final String TEMPLATE_KEY = "template";
      /** cache of the template name for getPage() */
      private String template = null;
  
      /**
       * Default constructor
       * <p>
       * The init method must be called before use.
       */
      public RelativeTemplateLink()
      {
      }
      
      /**
       * Constructor.
       *
       * @param data a Turbine RunData object.
       */
      public RelativeTemplateLink(RunData data)
      {
          super(data);
      }
  
      /**
       * This will initialise a TemplateLink object that was
       * constructed with the default constructor (ApplicationTool
       * method).
       *
       * @param data assumed to be a RunData object
       */
      public void init(Object data)
      {
          // we just blithely cast to RunData as if another object
          // or null is passed in we'll throw an appropriate runtime
          // exception.
          super.init((RunData)data);
      }
  
      /**
       * Refresh method - does nothing
       */
      public void refresh()
      {
          // empty
      }
  
      /**
       * This will turn off the execution of res.encodeURL()
       * by making res == null. This is a hack for cases
       * where you don't want to see the session information
       */
      public RelativeTemplateLink setEncodeURLOff()
      {
          this.res = null;
          return this;
      }
  
      /**
       * Sets the template variable used by the Template Service.
       *
       * @param t A String with the template name.
       * @return A TemplateLink.
       */
      public RelativeTemplateLink setPage(String t)
      {
          template = t;
          addPathInfo(TEMPLATE_KEY,t);
          return this;
      }
  
      /**
       * Gets the template variable used by the Template Service.
       * It is only available after setPage() has been called.
       *
       * @return The template name.
       */
      public String getPage()
      {
          return template;
      }
  
      /**
       * Returns the URI. After rendering the URI, it clears the 
       * pathInfo and QueryString portions of the DynamicURI.
       *
       * @return A String with the URI in the form
       * http://foo.com/Turbine/template/index.wm/hello/world
       */
      public String toString()
      {
          String output = super.toString();
  
          // This was added to allow multilple $link variables in one
          // template.
          removePathInfo();
          removeQueryData();
  
          return output;
      }
  
      /**
       * Returns the URI leaving the source intact. Wraps directly to the
       * <code>DynamicURI.toString</code> method of the superclass
       * (avoiding the local toString implementation).
       *
       * @return A String with the URI in the form
       * http://foo.com/Turbine/template/index.wm/hello/world
       */
      public String getURI()
      {
          return super.toString();
      }
  }
  
  
  
  1.1                  jakarta-turbine/src/tool/org/apache/turbine/tool/TemplateLinkWithSlash.java
  
  Index: TemplateLinkWithSlash.java
  ===================================================================
  package org.apache.turbine.tool;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.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" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", nor may "Apache" 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 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 javax.servlet.http.HttpServletResponse;
  
  import org.apache.turbine.util.DynamicURI;
  import org.apache.turbine.RunData;
  
  /**
   * This class allows one to specify paths in the setPage method 
   * using '/' slash as opposed to the ',' used in TemplateLink.
   * It is less efficient as the '/' are converted to ',' to avoid
   * problems parsing the pathinfo after conversion in a web server. 
   * 
   * It is recommended that projects standardize on using the ',' 
   * separator and use TemplateLink.  But this class is available for
   * those who do not mind the inefficiency.
   *
   * @author <a href="jmcnally@collab.net">John D. McNally</a>
   * @version $Id: TemplateLinkWithSlash.java,v 1.1 2001/08/09 11:48:42 jvanzyl Exp $
   */
  public class TemplateLinkWithSlash
      extends TemplateLink
  {
      /**
       * Default constructor
       * <p>
       * The init method must be called before use.
       */
      public TemplateLinkWithSlash()
      {
      }
      
      /**
       * Constructor.
       *
       * @param data a Turbine RunData object.
       */
      public TemplateLinkWithSlash(RunData data)
      {
          super(data);
      }
  
      /**
       * Sets the template variable used by the Template Service.
       * This method allows slashes '/' as the path separator.
       *
       * @param t A String with the template name.
       * @return A TemplateLink.
       */
      public TemplateLink setPage(String t)
      {
          super.setPage( t.replace('/', ',') );
          return this;
      }
  }
  
  
  
  
  
  1.1                  jakarta-turbine/src/tool/org/apache/turbine/tool/TemplatePageAttributes.java
  
  Index: TemplatePageAttributes.java
  ===================================================================
  package org.apache.turbine.tool;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.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" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", nor may "Apache" 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 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.turbine.RunData;
  import org.apache.turbine.services.pull.ApplicationTool;
  
  /**
   * Template context tool that will set various attributes of the HTML
   * page.  It is automatically placed in the Template context as
   * '$page'.  Here's an example of some uses:
   *
   * <p>
   * $page.setBgColor("#ffffff");
   * $page.setBgColor("white");
   * $page.setBackground("/images/standardbg.jpeg");
   * $page.setTitle("This is the title!");
   * $page.setKeywords("turbine, cool, servlet framework");
   * $page.setStyleSheet("/style.css");
   *
   * This should become a general attribute storage class
   * for a page. We should have something general like:
   *
   * $page.setAttr("bgcolor", "#ffffff")
   *
   * Instead of set methods for HTML because we might want
   * to set attributes for WML output or anything else.
   *
   * @author <a href="mailto:sean@somacity.com">Sean Legassick</a>
   * @version $Id: TemplatePageAttributes.java,v 1.1 2001/08/09 11:48:42 jvanzyl Exp $
   */
  public class TemplatePageAttributes
      implements ApplicationTool
  {
      /** The RunData object. */
      private RunData data = null;
  
      /** The title. */
      private String title = null;
      private String bgColor = null;
  
      /**
       * Default constructor. The init method must be called before use
       */
      public TemplatePageAttributes()
      {
      }
      
      /**
       * Construct a new instance with the given RunData object.
       *
       * @param data a RunData instance
       */
      public TemplatePageAttributes(RunData data)
      {
          this.data = data;
      }
  
      /**
       * Initialise this instance with the given RunData object.
       * (ApplicationTool method)
       *
       * @param data Assumed to be a RunData instance
       */
      public void init(Object data)
      {
          // we blithely cast to RunData as the runtime error thrown
          // if data is null or not RunData is appropriate.
          data = (RunData)data;
  
          // clear cached title
          title = null;
          bgColor = null;
      }
  
      /**
       * Refresh method - does nothing
       */
      public void refresh()
      {
          // empty
      }
  
      /**
       * Set the title in the page.  This returns an empty String so
       * that the template doesn't complain about getting a null return
       * value.
       *
       * @param intitle A String with the title.
       */
      public TemplatePageAttributes setTitle(String title)
      {
          this.title = title;
          return this;
      }
  
      /**
       * Get the title in the page.  This returns an empty String if
       * empty so that the template doesn't complain about getting a null
       * return value.
       *
       * @return A String with the title.
       */
      public String getTitle()
      {
          return title;
      }
  
      /**
       * Set the background color for the BODY tag.  You can use either
       * color names or color values (e.g. "white" or "#ffffff" or
       * "ffffff").
       *
       * @param color A String.
       * @return A TemplatePageAttributes (self).
       */
      public TemplatePageAttributes setBgColor(String bgColor)
      {
          this.bgColor = bgColor;
          return this;
      }
  
      public String getBgColor()
      {
          return bgColor;
      }        
  
      /**
       * A dummy toString method that returns an empty string.
       *
       * @return An empty String ("").
       */
      public String toString()
      {
          return "";
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org