jvanzyl     2002/06/01 15:05:28

  Added:       src/java/org/apache/turbine/tool ContentURI.java
                        IntakeTool.java LocalizationTool.java
                        RelativeTemplateLink.java TemplateLink.java
                        TemplateLinkWithSlash.java
                        TemplatePageAttributes.java UIManager.java
  Log:
  Tools are now in the same source tree with the rest of the code for
  now.
  
  Revision  Changes    Path
  1.1                  
jakarta-turbine-3/src/java/org/apache/turbine/tool/ContentURI.java
  
  Index: ContentURI.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 [EMAIL PROTECTED]
   *
   * 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 java.lang.reflect.Method;
  import org.apache.turbine.RunData;
  import org.apache.turbine.DynamicURI;
  import org.apache.turbine.services.pull.ApplicationTool;
  
  /**
   * Utility class to allow the easy inclusion of
   * images in templates: &lt;img src="$content.getURI("image.jpg")">
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Cameron Riley</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Jason van Zyl</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Jon S. Stevens</a>
   * @version $Id: ContentURI.java,v 1.1 2002/06/01 22:05:28 jvanzyl Exp $
   */
  public class ContentURI
      extends DynamicURI
      implements ApplicationTool
  {
      /** stores the context path for servlet 2.1+ compliant containers */
      private String contextPath;
  
      /**
       * Constructor
       *
       * @param data a RunData instance
       */
      public ContentURI (RunData data)
      {
          super(data);
          init(data);
      }
  
      /**
       * Default constructor
       */
      public ContentURI ()
      {
      }
  
      /**
       * Initialize this object using the data given (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 another type is appropriate.
          init((RunData)data);
      }
  
      /**
       * Refresh method - does nothing
       */
      public void refresh()
      {
          // empty
      }
  
      /**
       * Initialize this object using the given RunData object
       *
       * @param data a RunData instance
       */
      public void init(RunData data)
      {
          super.init(data);
          try
          {
              Class runDataClass = RunData.class;
              Method meth = runDataClass.getDeclaredMethod("getContextPath", null);
              contextPath = (String)meth.invoke(data, null);
          }
          catch (Exception e)
          {
              /*
               * Ignore a NoSuchMethodException because it means we are
               * using Servlet API 2.0.  Make sure scriptName is not
               * null.
               */
              contextPath = "";
          }
      }
  
      /**
       * Returns a URI pointing to the given content (where content is a
       * path relative to the webapp root.
       *
       * @param pathToContent a path relative to the webapp root
       */
      public String getURI(String pathToContent)
      {
          StringBuffer sb = new StringBuffer();
          sb.append (getServerScheme()); //http
          sb.append ("://");
          sb.append (getServerName()); //www.foo.com
          sb.append (':');
          sb.append (getServerPort()); //port webserver running on (8080 for TDK)
          //the context for tomcat adds a / so no need to add another
          sb.append (contextPath); //the tomcat context
          sb.append ('/');
          sb.append (pathToContent);
          return (sb.toString());
      }
  }
  
  
  
  1.1                  
jakarta-turbine-3/src/java/org/apache/turbine/tool/IntakeTool.java
  
  Index: IntakeTool.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 [EMAIL PROTECTED]
   *
   * 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.fulcrum.intake.Intake;
  import org.apache.turbine.RunData;
  import org.apache.turbine.services.pull.ApplicationTool;
  
  /**
   * A Pull tool to make intake objects available to a template
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>John D. McNally</a>
   * @version $Id: IntakeTool.java,v 1.1 2002/06/01 22:05:28 jvanzyl Exp $
   */
  public class IntakeTool extends Intake
      implements ApplicationTool
  {
      public IntakeTool()
      {
          super();
      }
  
      /**
       * Prepares intake for a single request
       */
      public void init(Object runData)
      {
          super.init( ((RunData)runData).getParameters() );
      }
  
  
      /**
       * Implementation of ApplicationTool interface is not needed for this
       * tool as it is request scoped
       */
      public void refresh()
      {
          // empty
      }
  
  }
  
  
  
  
  
  
  
  
  
  1.1                  
jakarta-turbine-3/src/java/org/apache/turbine/tool/LocalizationTool.java
  
  Index: LocalizationTool.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 [EMAIL PROTECTED]
   *
   * 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 java.util.ArrayList;
  import java.util.List;
  import java.util.Locale;
  import java.util.MissingResourceException;
  import java.util.ResourceBundle;
  
  import org.apache.fulcrum.localization.Localization;
  
  import org.apache.turbine.RunData;
  import org.apache.turbine.services.pull.ApplicationTool;
  
  /**
   * A pull tool which provides lookups for localized text by delegating
   * to the configured <code>LocalizationService</code>.
   *
   * <p><ul>Enhancement(s) suggested by Daniel Rall and Jacopo
   * Cappellato &lt;[EMAIL PROTECTED]>:
   *
   * <li><ol>Add Language negotiation overrides the following order
   * <li>user temporary language</li>
   * <li>user permanent language</li>
   * <li>application context language</li>
   * <li>automatic language negotiation (already supported)</li>
   * </ol></li>
   *
   * <li>Missing key message format pulled from TR.props.</li>
   *
   * </ul></p>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Jon Stevens</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Leonard Richardson</a>
   */
  public class LocalizationTool implements ApplicationTool
  {
      /**
       * The language and country information parsed from the request's
       * <code>Accept-Language</code> header.  Reset on each request.
       */
      private Locale locale;
  
      /**
       * The name of the bundle for this tool to use.
       */
      private String bundleName;
  
      /**
       * The prefix to prepend to localization keys.
       */
      private String keyPrefix;
  
      /**
       * Creates a new instance.  Used by <code>PullService</code>.
       */
      public LocalizationTool()
      {
      }
  
      /**
       * <p>Performs text lookups for localization.</p>
       *
       * <p>Assuming there is a instance of this class with a HTTP
       * request set in your template's context named <code>l10n</code>,
       * the VTL <code>$l10n.HELLO</code> would render to
       * <code>hello</code> for English requests and <code>hola</code>
       * in Spanish (depending on the value of the HTTP request's
       * <code>Accept-Language</code> header).</p>
       *
       * @param key The identifier for the localized text to retrieve,
       * prepended by key prefix returned by {@link #getPrefix(String)}
       * (if not <code>null</code>).
       * @return The localized text.
       * @see #get(String, String)
       */
      public String get(String key)
      {
          return get(null, key);
      }
  
      /**
       * @param prefix A key prefix override which is passed to {@link
       * #getPrefix(String)}.
       * @param key The identifier for the localized text to retrieve,
       * prepended by key prefix (if not <code>null</code>).
       * @return The localized text.
       * @see #get(String)
       */
      public String get(String prefix, String key)
      {
          // Determine prefix, and prepend to key (if necessary).
          key = applyPrefix(prefix, key);
  
          try
          {
              return Localization.getString(getBundleName(), getLocale(), key);
          }
          catch (MissingResourceException noKey)
          {
              return formatErrorMessage(key, noKey);
          }
      }
  
      /**
       * Gets the current locale.
       *
       * @return The locale currently in use.
       */
      public Locale getLocale()
      {
          return locale;
      }
  
      /**
       * Formats a localized value using the provided object.
       *
       * @param key The identifier for the localized text to retrieve,
       * @param arg1 The object to use as {0} when formatting the localized text.
       * @return Formatted localized text.
       * @see #format(String, List)
       */
      public String format(String key, Object arg1)
      {
          key = applyPrefix(null, key);
          return Localization.format(getBundleName(), getLocale(), key, arg1);
      }
  
      /**
       * Formats a localized value using the provided objects.
       *
       * @param key The identifier for the localized text to retrieve,
       * @param arg1 The object to use as {0} when formatting the localized text.
       * @param arg2 The object to use as {1} when formatting the localized text.
       * @return Formatted localized text.
       * @see #format(String, List)
       */
      public String format(String key, Object arg1, Object arg2)
      {
          key = applyPrefix(null, key);
          return Localization.format(getBundleName(), getLocale(), key,
                                     arg1, arg2);
      }
  
      /**
       * Formats a localized value using the provided objects.
       *
       * @param key The identifier for the localized text to retrieve,
       * @param args The <code>MessageFormat</code> data used when
       * formatting the localized text.
       * @return Formatted localized text.
       * @see #format(String, List)
       */
      public String format(String key, Object[] args)
      {
          key = applyPrefix(null, key);
          return Localization.format(getBundleName(), getLocale(), key, args);
      }
  
      /**
       * <p>Formats a localized value using the provided objects.</p>
       *
       * <p>ResourceBundle:
       * <blockquote><code><pre>
       * VelocityUsersNotWrong={0} out of {1} users can't be wrong!
       * </pre></code></blockquote>
       *
       * Template:
       * <blockquote><code><pre>
       * $l10n.format("VelocityUsersNotWrong", ["9", "10"])
       * </pre></code></blockquote>
       *
       * Result:
       * <blockquote><code><pre>
       * 9 out of 10 Velocity users can't be wrong!
       * </pre></code></blockquote></p>
       *
       * @param key The identifier for the localized text to retrieve,
       * @param args The objects to use as {0}, {1}, etc. when
       *             formatting the localized text.
       * @return Formatted localized text.
       */
      public String format(String key, List args)
      {
          key = applyPrefix(null, key);
          return Localization.format(getBundleName(), getLocale(), key,
                                     args.toArray());
      }
  
      /**
       * The return value of this method is used to set the name of the
       * bundle used by this tool.  Useful as a hook for using a
       * different bundle than specifed in your
       * <code>LocalizationService</code> configuration.
       *
       * @param data The inputs passed from {@link #init(Object)}.
       * (ignored by this implementation).
       */
      protected String determineBundleName(Object data)
      {
          return Localization.getDefaultBundleName();
      }
  
      /**
       * Returns the name of the bundle currently in use.
       *
       * @param The resource bundle name.
       */
      protected String getBundleName()
      {
          return bundleName;
      }
  
      /**
       * Returns the prefix prepended to keys used to retrieve localized
       * text.  This method could be overridden to introduce separator
       * text between prefix and key (i.e. <code>prefix__key</code>).
       *
       * @param override Overrides the key prefix set for this instance,
       * or ignored if <code>null</code>.
       * @return The prefix to prepend to localization keys.
       */
      protected String getPrefix(String override)
      {
          return (override == null ? keyPrefix : override);
      }
  
      /**
       * Appends the current prefix (if any) to the supplied key.
       *
       * @param prefix An override for the current prefix.
       * @param key The key to apply a prefix to.
       * @return The prefixed key, or the same key if no prefix.
       */
      private String applyPrefix(String prefix, String key)
      {
          prefix = getPrefix(prefix);
          if (prefix != null)
          {
              key = prefix + key;
          }
          return key;
      }
  
      /**
       * Sets the prefix prepended to keys used to retrieve localized
       * text.  Subclasses may wish to call this method in {@link
       * #init(Object)} to auto-negotiate a call to this method (thus
       * automatically setting up the key prefix).
       *
       * @param keyPrefix The prefix to prepend to localization keys, or
       * <code>null</code> for no prefix.
       */
      public void setPrefix(String keyPrefix)
      {
          this.keyPrefix = keyPrefix;
      }
  
      /**
       * Returns <code>null</code> by default, which causes Velocity to
       * render your reference literally (i.e. <code>$l10n.FooKey</code>
       * will render as exactly that).  Useful as a hook for providing a
       * formatted error message.
       *
       * <p>TODO: Pull alternate error text from a TR.props value, or
       * return <code>null</code> if not available.</p>
       *
       * @param key The name of the key whose attempted retrieval caused
       * an error.
       * @param e The exception thrown when the named key was not
       * available.
       */
      protected String formatErrorMessage(String key, MissingResourceException e)
      {
          return null;
      }
  
  
      // ------ ApplicationTool implementation -------------------------------
  
      /**
       * Sets the request to get the <code>Accept-Language</code> header
       * from (reset on each request).
       */
      public void init(Object data)
      {
          if (data instanceof RunData)
          {
              // Request-scoped initialization.  Pull necessary
              // information out of RunData while we have a reference to
              // it.
              locale = Localization.getLocale( ((RunData) data).getRequest() );
          }
          bundleName = determineBundleName(data);
      }
  
      /**
       * Zero everything out.
       */
      public void refresh()
      {
          locale = null;
          bundleName = null;
          setPrefix(null);
      }
  }
  
  
  
  1.1                  
jakarta-turbine-3/src/java/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 [EMAIL PROTECTED]
   *
   * 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.DynamicURI;
  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="[EMAIL PROTECTED]">John D. McNally</a>
   * @author see the authors of TemplateLink
   * @version $Id: RelativeTemplateLink.java,v 1.1 2002/06/01 22:05:28 jvanzyl Exp $
   */
  public class RelativeTemplateLink
      extends DynamicURI
      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()
      {
          setRelative(true);
      }
  
      /**
       * Constructor.
       *
       * @param data a Turbine RunData object.
       */
      public RelativeTemplateLink(RunData data)
      {
          super(data);
          setRelative(true);
      }
  
      /**
       * 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-3/src/java/org/apache/turbine/tool/TemplateLink.java
  
  Index: TemplateLink.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 [EMAIL PROTECTED]
   *
   * 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.DynamicURI;
  import org.apache.turbine.RunData;
  import org.apache.turbine.services.pull.ApplicationTool;
  
  /**
   * A customized version of the DynamicURI to be used in Templates.
   * This is automatically inserted into the template context by the
   * appropriate templating service so page authors can create links
   * in templates.  Here's an example of its Velocity/WebMacro use:
   *
   * <p><code>
   * $link.setPage("index.wm").addPathInfo("hello","world")
   * This would return: http://foo.com/Turbine/template/index.wm/hello/world
   * </code>
   *
   * @author <a href="[EMAIL PROTECTED]">Dave Bryson</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Jon S. Stevens</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Henning P. Schmiedehausen</a>
   * @version $Id: TemplateLink.java,v 1.1 2002/06/01 22:05:28 jvanzyl Exp $
   */
  public class TemplateLink
      extends DynamicURI
      implements ApplicationTool
  {
      /** the pathinfo key stored in the DynamicURI */
      public 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 TemplateLink()
      {
      }
  
      /**
       * Constructor.
       *
       * @param data a Turbine RunData object.
       */
      public TemplateLink(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(). This is useful 
       * for cases where you don't want to see the session information
       */
      public TemplateLink setEncodeURLOff()
      {
          setEncodeUrl(false);
          return this;
      }
  
      /**
       * Sets the template variable used by the Template Service.
       *
       * @param t A String with the template name.
       * @return A TemplateLink.
       */
      public TemplateLink 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;
      }
  
      /**
       * Set to false to skip the scheme, host, and port sections of the url.
       * The default is to return absolute url's from the toString method.
       *
       * @param b a <code>boolean</code> value
       * @return a <code>TemplateLink</code> value
       */
      public TemplateLink setAbsolute(boolean b)
      {
          setRelative(!b);
          return this;
      }
  
      /**
       * 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();
          setEncodeUrl(true);
          setAbsolute(true);
  
          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-3/src/java/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 [EMAIL PROTECTED]
   *
   * 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;
  
  /**
   * 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="[EMAIL PROTECTED]">John D. McNally</a>
   * @version $Id: TemplateLinkWithSlash.java,v 1.1 2002/06/01 22:05:28 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-3/src/java/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 [EMAIL PROTECTED]
   *
   * 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:[EMAIL PROTECTED]";>Sean Legassick</a>
   * @version $Id: TemplatePageAttributes.java,v 1.1 2002/06/01 22:05:28 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 title 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 bgColor the background color.
       * @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 "";
      }
  }
  
  
  
  1.1                  
jakarta-turbine-3/src/java/org/apache/turbine/tool/UIManager.java
  
  Index: UIManager.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 [EMAIL PROTECTED]
   *
   * 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 java.io.FileInputStream;
  import java.util.Properties;
  import org.apache.turbine.Turbine;
  import org.apache.turbine.RunData;
  import org.apache.turbine.services.pull.ApplicationTool;
  import org.apache.turbine.services.pull.TurbinePull;
  import org.apache.fulcrum.security.entity.User;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * UIManager.java
   * <br>
   * Manages all UI elements for a Turbine Application. Any
   * UI element can be accessed in any template using the
   * $ui handle (assuming you use the default PullService
   * configuration). So, for example, you could access
   * the background colour for your pages by using
   * $ui.bgcolor
   * <p>
   * <h3>Questions:</h3>
   * What is the best way to allow an application
   * to be skinned. And how to allow the flexible
   * altering of a particular UI element in certain
   * parts of the template hierarchy. For example
   * on one section of your site you might like
   * a certain bgcolor, on another part of your
   * site you might want another. How can be let
   * the designer specify these properties and
   * still use the single $app.ui.bgcolor in
   * all the templates.
   * <p>
   * It would also be very cool to use some form
   * of inheritence for UI elements. Say a $ui.bgcolor
   * is used in a template where the bgcolor is not
   * set for that part of hierarch, it would be cool
   * if it could find the setting for the bgcolor
   * in the parent directory. So you could override
   * a UI element where you wanted and the system
   * would fall back to the parent when necessary.
   * <p>
   * How to specify skins, how to deal with images,
   * how could this be handled with a web app.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Jason van Zyl</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Coltman</a>
   * @version $Id: UIManager.java,v 1.1 2002/06/01 22:05:28 jvanzyl Exp $
   */
  public class UIManager implements ApplicationTool
  {
      private static final Log log = LogFactory.getLog( UIManager.class );
  
      /**
       * The location of the skins within the application
       * resources directory.
       */
      private static final String SKINS_DIRECTORY = "/ui/skins";
  
      /**
       * The name of the directory where images are
       * stored for this skin.
       */
      private static final String IMAGES_DIRECTORY = "/images";
  
  
      /**
       * Property tag for the skin that is to be
       * used for the web application.
       */
      private static final String SKIN_PROPERTY = "tool.ui.skin";
  
      /**
       * Default skin name. This name actually represents
       * a directory in the WEBAPP/resources/ui/skins
       * directory. There is a file called skin.props
       * which actually contains the name/value pairs.
       */
      private static final String SKIN_PROPERTY_DEFAULT = "default";
  
      /**
       * Attribute name of skinName value in User's temp hashmap.
       */
      private static final String SKIN_ATTRIBUTE =
          "org.apache.fulcrum.pull.util.UIManager.skin";
  
      /**
       * The actual skin being used for the webapp.
       */
      private String skinName;
  
      /**
       * The skins directory.
       */
      private static String skinsDirectory;
  
      /**
       * The file within the skin directory that actually
       * contains the name/value pairs for the skin.
       */
      private static final String SKIN_PROPS_FILE = "skin.props";
  
      /**
       * The file name for the skin style sheet.
       */
      private static final String SKIN_CSS_FILE = "skin.css";
  
      /**
       * This the resources directory relative to the
       * webapp context. Used for constructing correct
       * URIs for retrieving images in image().
       */
      private static String resourcesDirectory;
  
      /**
       * Properties to hold the name/value pairs
       * for the skin.
       */
      private static Properties skinProperties;
  
      /**
       * Initialize the UIManager object.
       *
       * @param data This is null, RunData or User depending upon specified tool scope.
       */
      public void init(Object data)
      {
          /**
           * Store the resources directory for use in image().
           */
          resourcesDirectory = TurbinePull.getResourcesDirectory();
  
          if (data == null)
          {
              log.debug("UI Manager scope is global");
              setSkin();
          }
          else if (data instanceof RunData)
          {
              log.debug("UI Manager scope is request");
              setSkin((RunData) data);
          }
          else if (data instanceof User)
          {
              log.debug("UI Manager scope is session");
              setSkin((User) data);
          }
  
          skinsDirectory =
              TurbinePull.getAbsolutePathToResourcesDirectory() + SKINS_DIRECTORY;
  
          loadSkin();
      }
  
      /**
       * This lets the tool know that it should be
       * refreshed. The tool can perform whatever actions
       * are necessary to refresh itself. This is necessary
       * for sane development where you probably want the
       * tools to refresh themselves on every request.
       */
      public void refresh()
      {
          log.debug("Refreshing UI manager");
  
          loadSkin();
      }
  
      /**
       * Retrieve a property from the properties held
       * within the properties file for this skin.
       */
      public String get(String key)
      {
          return skinProperties.getProperty(key);
      }
  
      /**
       * Retrieve the skin name.
       */
      public String getSkin()
      {
          return skinName;
      }
  
      /**
       * Retrieve the URL for an image that is part
       * of a skin. The images are stored in the
       * WEBAPP/resources/ui/skins/<SKIN>/images
       * directory.
       *
       * Use this if for some reason your server name,
       * server scheme, or server port change on a
       * per request basis. I'm not sure if this
       * would happend in a load balanced situation.
       * I think in most cases the image(String image)
       * method would probably be enough, but I'm not
       * absolutely positive.
       */
      public String image(String imageId, RunData data)
      {
          ContentURI cu = new ContentURI(data);
          StringBuffer sb = new StringBuffer();
  
          sb.append(resourcesDirectory).
             append(SKINS_DIRECTORY).
             append("/").
             append(getSkin()).
             append(IMAGES_DIRECTORY).
             append("/").
             append(imageId);
  
          return cu.getURI(sb.toString());
      }
  
      /**
       * Retrieve the URL for an image that is part
       * of a skin. The images are stored in the
       * WEBAPP/resources/ui/skins/<SKIN>/images
       * directory.
       */
      public String image(String imageId)
      {
          StringBuffer sb = new StringBuffer();
  
          sb.append(Turbine.getServerScheme()).
             append("://").
             append(Turbine.getServerName()).
             append(":").
             append(Turbine.getServerPort()).
             append(Turbine.getApplicationRoot()).
             append("/").
             append(resourcesDirectory).
             append(SKINS_DIRECTORY).
             append("/").
             append(getSkin()).
             append(IMAGES_DIRECTORY).
             append("/").
             append(imageId);
  
          return sb.toString();
      }
  
      /**
       * Retrieve the URL for the style sheet that is part
       * of a skin. The style is stored in the
       * WEBAPP/resources/ui/skins/<SKIN> directory with the
       * filename skin.css
       *
       * Use this if for some reason your server name,
       * server scheme, or server port change on a
       * per request basis. I'm not sure if this
       * would happend in a load balanced situation.
       * I think in most cases the style()
       * method would probably be enough, but I'm not
       * absolutely positive.
       */
      public String getStylecss(RunData data)
      {
          ContentURI cu = new ContentURI(data);
          StringBuffer sb = new StringBuffer();
  
          sb.append(resourcesDirectory).
             append(SKINS_DIRECTORY).
             append("/").
             append(getSkin()).
             append("/").
             append(SKIN_CSS_FILE);
  
          return cu.getURI(sb.toString());
      }
  
      /**
       * Retrieve the URL for the style sheet that is part
       * of a skin. The style is stored in the
       * WEBAPP/resources/ui/skins/<SKIN> directory with the
       * filename skin.css
       */
      public String getStylecss()
      {
          StringBuffer sb = new StringBuffer();
  
          sb.append(Turbine.getServerScheme()).
             append("://").
             append(Turbine.getServerName()).
             append(":").
             append(Turbine.getServerPort()).
             append(Turbine.getApplicationRoot()).
             append("/").
             append(resourcesDirectory).
             append(SKINS_DIRECTORY).
             append("/").
             append(getSkin()).
             append("/").
             append(SKIN_CSS_FILE);
  
          return sb.toString();
      }
  
      /**
       * Load the specified skin. In development mode
       * this may occur frequently as the skin properties
       * are being changed.
       */
      private void loadSkin()
      {
          skinProperties = new Properties();
  
          try
          {
              FileInputStream is = new FileInputStream(
                  skinsDirectory + "/" + getSkin() + "/" + SKIN_PROPS_FILE);
  
              skinProperties.load(is);
          }
          catch (Exception e)
          {
              log.error("Cannot load skin: " + skinName);
          }
      }
  
      /**
       * Set the skin name to the skin from the TR.props
       * file. If the property is not present use the
       * default skin.
       */
      public void setSkin()
      {
          this.skinName = Turbine.getConfiguration().getString(SKIN_PROPERTY,
                  SKIN_PROPERTY_DEFAULT);
      }
  
      /**
       * Set the skin name to the specified skin.
       *
       * @param skinName the skin name to use.
       */
      public void setSkin(String skinName)
      {
          this.skinName = skinName;
      }
  
      /**
       * Set the skin name when the tool is configured to be
       * loaded on a per-request basis. By default it calls getSkin
       * to return the skin specified in TR.properties. Developers can
       * write a subclass of UIManager that overrides this method to
       * determine the skin to use based on information held in the request.
       *
       * @param data a RunData instance
       */
      protected void setSkin(RunData data)
      {
          setSkin();
      }
  
      /**
       * Set the skin name when the tool is configured to be
       * loaded on a per-session basis. It the user's temp hashmap contains
       * a value in the attribute specified by the String constant SKIN_ATTRIBUTE
       * then that is returned. Otherwise it calls getSkin to return the skin
       * specified in TR.properties.
       *
       * @param user a User instance
       */
      protected void setSkin(User user)
      {
          if (user.getTemp(SKIN_ATTRIBUTE) == null)
          {
              setSkin();
          }
          else
          {
              setSkin((String) user.getTemp(SKIN_ATTRIBUTE));
          }
      }
  
      /**
       * Set the skin name user's temp hashmap for the current session.
       *
       * @param user a User instance
       * @param skin the skin name for the session
       */
      public static void setSkin(User user, String skin)
      {
          user.setTemp(SKIN_ATTRIBUTE, skin);
      }
  }
  
  
  

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

Reply via email to