You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by dl...@apache.org on 2002/04/03 18:07:33 UTC

cvs commit: jakarta-velocity/src/java/org/apache/velocity/servlet VelocityServlet.java

dlr         02/04/03 08:07:33

  Modified:    src/java/org/apache/velocity/servlet VelocityServlet.java
  Log:
  Changed from "properties" to "org.apache.velocity.properties" to add
  namespace protection for the global hash key INIT_PROPS_KEY.
  Introduced a private OLD_INIT_PROPS_KEY member to provide backwards
  compatibility for the deprecated "properties" key.
  
  I'm unsure what the right way to handle the logging of a deprecation
  warning is, as the Velocity logger has not yet been initialized at the
  time we want to log the warning.  Ideas welcome.
  
  Revision  Changes    Path
  1.45      +36 -7     jakarta-velocity/src/java/org/apache/velocity/servlet/VelocityServlet.java
  
  Index: VelocityServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/servlet/VelocityServlet.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -u -r1.44 -r1.45
  --- VelocityServlet.java	6 Feb 2002 23:42:01 -0000	1.44
  +++ VelocityServlet.java	3 Apr 2002 16:07:33 -0000	1.45
  @@ -127,7 +127,8 @@
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
    * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
    * @author <a href="kjohnson@transparent.com">Kent Johnson</a>
  - * $Id: VelocityServlet.java,v 1.44 2002/02/06 23:42:01 dlr Exp $
  + * @author <a href="dlr@finemaltcoding.com">Daniel Rall</a>
  + * $Id: VelocityServlet.java,v 1.45 2002/04/03 16:07:33 dlr Exp $
    */
   public abstract class VelocityServlet extends HttpServlet
   {
  @@ -169,9 +170,16 @@
   
       /**
        * This is the string that is looked for when getInitParameter is
  -     * called.
  +     * called (<code>org.apache.velocity.properties</code>).
        */
  -    protected static final String INIT_PROPS_KEY = "properties";
  +    protected static final String INIT_PROPS_KEY =
  +        "org.apache.velocity.properties";
  +
  +    /**
  +     * Use of this properties key has been deprecated, and will be
  +     * removed in Velocity version 1.5.
  +     */
  +    private static final String OLD_INIT_PROPS_KEY = "properties";
   
       /**
        * Cache of writers
  @@ -256,7 +264,7 @@
        *      &lt;servlet-name&gt; YourServlet &lt/servlet-name&gt;
        *      &lt;servlet-class&gt; your.package.YourServlet &lt;/servlet-class&gt;
        *      &lt;init-param&gt;
  -     *         &lt;param-name&gt; properties &lt;/param-name&gt;
  +     *         &lt;param-name&gt; org.apache.velocity.properties &lt;/param-name&gt;
        *         &lt;param-value&gt; velocity.properties &lt;/param-value&gt;
        *      &lt;/init-param&gt;
        *    &lt;/servlet&gt;
  @@ -267,7 +275,7 @@
        *  <br>
        *  <pre>
        *    &lt;context-param&gt;
  -     *       &lt;param-name&gt; properties &lt;/param-name&gt;
  +     *       &lt;param-name&gt; org.apache.velocity.properties &lt;/param-name&gt;
        *       &lt;param-value&gt; velocity.properties &lt;/param-value&gt;
        *       &lt;description&gt; Path to Velocity configuration &lt;/description&gt;
        *    &lt;/context-param&gt;
  @@ -290,11 +298,32 @@
       protected Properties loadConfiguration(ServletConfig config )
           throws IOException, FileNotFoundException
       {
  +        // This is a little overly complex because of legacy support
  +        // for the initialization properties key "properties".
  +        // References to OLD_INIT_PROPS_KEY should be removed at
  +        // Velocity version 1.5.
           String propsFile = config.getInitParameter(INIT_PROPS_KEY);
           if (propsFile == null || propsFile.length() == 0)
           {
  -            propsFile = config.getServletContext()
  -                .getInitParameter(INIT_PROPS_KEY);
  +            propsFile = config.getInitParameter(OLD_INIT_PROPS_KEY);
  +            if (propsFile == null || propsFile.length() == 0)
  +            {
  +                propsFile = config.getServletContext()
  +                    .getInitParameter(INIT_PROPS_KEY);
  +                if (propsFile == null || propsFile.length() == 0)
  +                {
  +                    propsFile = config.getServletContext()
  +                        .getInitParameter(OLD_INIT_PROPS_KEY);
  +                }
  +                else
  +                {
  +                    // TODO: Log deprecation warning.
  +                }
  +            }
  +            else
  +            {
  +                // TODO: Log deprecation warning.
  +            }
           }
           
           /*
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-velocity/src/java/org/apache/velocity/servlet VelocityServlet.java

Posted by Daniel Rall <dl...@finemaltcoding.com>.
"Geir Magnusson Jr." <ge...@optonline.net> writes:

> On 4/3/02 11:49 AM, "Daniel Rall" <dl...@finemaltcoding.com> wrote:
>
>> I can't nest the block comments.  I can use XEmacs to insert a whole
>> list of line comments in front of existing code, but I prefer to use
>> block comments for debugging.
>> 
>> I guess there's just no accounting for taste.  ;-)
>> 
>
> Or lack of... :)
>
> The nice thing about using line comments for debugging and commenting out
> code blocks is that it doesn't matter what the underlying code is... It just
> works.  Methods, javadoc, line comments, block comments, etc...
>
> The other way means that *everyone* else has to switch, and anytime someone
> deviates, it screws it up....  It also means you can't comment out entire
> methods (including the javadoc comments...)...

Good points.

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-velocity/src/java/org/apache/velocity/servlet VelocityServlet.java

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 4/3/02 11:49 AM, "Daniel Rall" <dl...@finemaltcoding.com> wrote:

> I can't nest the block comments.  I can use XEmacs to insert a whole
> list of line comments in front of existing code, but I prefer to use
> block comments for debugging.
> 
> I guess there's just no accounting for taste.  ;-)
> 

Or lack of... :)

The nice thing about using line comments for debugging and commenting out
code blocks is that it doesn't matter what the underlying code is... It just
works.  Methods, javadoc, line comments, block comments, etc...

The other way means that *everyone* else has to switch, and anytime someone
deviates, it screws it up....  It also means you can't comment out entire
methods (including the javadoc comments...)...


-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"He who throws mud only loses ground." - Fat Albert


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-velocity/src/java/org/apache/velocity/servlet VelocityServlet.java

Posted by Daniel Rall <dl...@finemaltcoding.com>.
"Geir Magnusson Jr." <ge...@optonline.net> writes:

> On 4/3/02 11:26 AM, "Daniel Rall" <dl...@finemaltcoding.com> wrote:
>
>> "Geir Magnusson Jr." <ge...@optonline.net> writes:
>> 
>>> Oh, btw, icky comment style :)
>> 
>> Hah!  While we're on the subject, let me mention why I hate the use
>> block comments in implementations.
>> 
>> When you're debugging, and want to comment out a large block of code
>> at once, the presence of pre-existing block comments inhibits your
>> ability to do so (they confuse the compiler).
>
> What compiler?
>
> I can do 
>
> public class Comment
> {
>         public Comment()
>         {
> //              /*
> //                 *  I am a block comment
> //                 */
>         }
> }
>
> And my compiler handles it just fine...
>
> Is that what you meant?


public static void main(String[] argv)
{
    /*
     *
     * I am a big block comment!
     *
     */

    if (1 + 1 == 2)
    {
        System.out.println("hi");
        System.out.println("bye");
    }

    System.out.println("---");
}

The above compiles fine inside a test class.  Now say I wanted to debug:

public static void main(String[] argv)
{
/*
    /*
     *
     * I am a big block comment!
     *
     */

    if (1 + 1 == 2)
    {
        System.out.println("hi");
        System.out.println("bye");
    }
*/

    System.out.println("---");
}

dlr@despot:dlr$ javac test.java
test.java:19: illegal start of expression
*/
^
1 error

I can't nest the block comments.  I can use XEmacs to insert a whole
list of line comments in front of existing code, but I prefer to use
block comments for debugging.

I guess there's just no accounting for taste.  ;-)

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-velocity/src/java/org/apache/velocity/servlet VelocityServlet.java

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 4/3/02 11:26 AM, "Daniel Rall" <dl...@finemaltcoding.com> wrote:

> "Geir Magnusson Jr." <ge...@optonline.net> writes:
> 
>> Oh, btw, icky comment style :)
> 
> Hah!  While we're on the subject, let me mention why I hate the use
> block comments in implementations.
> 
> When you're debugging, and want to comment out a large block of code
> at once, the presence of pre-existing block comments inhibits your
> ability to do so (they confuse the compiler).

What compiler?

I can do 

public class Comment
{
        public Comment()
        {
//              /*
//                 *  I am a block comment
//                 */
        }
}

And my compiler handles it just fine...

Is that what you meant?


> Sure, you could just
> throw an if (false) {} block around the section you wanted commented
> out, but that's what block comments are for in the first place!!!  Use
> of line comments avoids this problem entirely.  XEmacs M-q will take
> one or more line comments and rejigger them into a list of neatly
> formatted line comments in a single key stroke.
> 
> - Dan
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
POC lives!


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-velocity/src/java/org/apache/velocity/servlet VelocityServlet.java

Posted by Daniel Rall <dl...@finemaltcoding.com>.
"Geir Magnusson Jr." <ge...@optonline.net> writes:

> Oh, btw, icky comment style :)

Hah!  While we're on the subject, let me mention why I hate the use
block comments in implementations.

When you're debugging, and want to comment out a large block of code
at once, the presence of pre-existing block comments inhibits your
ability to do so (they confuse the compiler).  Sure, you could just
throw an if (false) {} block around the section you wanted commented
out, but that's what block comments are for in the first place!!!  Use
of line comments avoids this problem entirely.  XEmacs M-q will take
one or more line comments and rejigger them into a list of neatly
formatted line comments in a single key stroke.

- Dan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-velocity/src/java/org/apache/velocity/servlet VelocityServlet.java

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 4/3/02 11:07 AM, "dlr@apache.org" <dl...@apache.org> wrote:

> dlr         02/04/03 08:07:33
> 
> Modified:    src/java/org/apache/velocity/servlet VelocityServlet.java
> Log:
> Changed from "properties" to "org.apache.velocity.properties" to add
> namespace protection for the global hash key INIT_PROPS_KEY.
> Introduced a private OLD_INIT_PROPS_KEY member to provide backwards
> compatibility for the deprecated "properties" key.
> 
> I'm unsure what the right way to handle the logging of a deprecation
> warning is, as the Velocity logger has not yet been initialized at the
> time we want to log the warning.  Ideas welcome.

Heh.  Your are in the servlet, so you could just fire into the servlet log.

Also, the Velocity servlet could / should be able to accept and hold log
messages until the real logger gets configured.

The only problem is that if there is a failure in that part - I think the
safest is to just babble to the servlet log.

Oh, btw, icky comment style :)

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"We will be judged not by the monuments we build, but by the monuments we
destroy" - Ada Louise Huxtable


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>