velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r599284 - in /velocity/tools/branches/2.x/examples/showcase: VM_global_library.vm WEB-INF/src/resources.properties class.vm demo.vm field.vm toolmenu.vm
Date Thu, 29 Nov 2007 05:51:24 GMT
Author: nbubna
Date: Wed Nov 28 21:51:19 2007
New Revision: 599284

URL: http://svn.apache.org/viewvc?rev=599284&view=rev
Log:
add new, simpler, superior demo pages for ClassTool and FieldTool

Added:
    velocity/tools/branches/2.x/examples/showcase/class.vm   (with props)
    velocity/tools/branches/2.x/examples/showcase/demo.vm   (with props)
    velocity/tools/branches/2.x/examples/showcase/field.vm   (with props)
Modified:
    velocity/tools/branches/2.x/examples/showcase/VM_global_library.vm
    velocity/tools/branches/2.x/examples/showcase/WEB-INF/src/resources.properties
    velocity/tools/branches/2.x/examples/showcase/toolmenu.vm

Modified: velocity/tools/branches/2.x/examples/showcase/VM_global_library.vm
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/examples/showcase/VM_global_library.vm?rev=599284&r1=599283&r2=599284&view=diff
==============================================================================
--- velocity/tools/branches/2.x/examples/showcase/VM_global_library.vm (original)
+++ velocity/tools/branches/2.x/examples/showcase/VM_global_library.vm Wed Nov 28 21:51:19
2007
@@ -26,9 +26,12 @@
  * Creates a link to the javadoc for the specified tool.
  *#
 #macro( doclink $toolname $generic )
-<a href="http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/##
+#set( $doclink = 
+"http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/##
 #if( $generic )generic/#else#**#view/#end##
-${toolname}.html">$toolname</a>#end
+${toolname}.html"
+)##
+<a href="$doclink">$toolname</a>#end
 
 #**
  * Creates a list item for the toolmenu.
@@ -37,7 +40,27 @@
   <li><a href="$menulink.relative("${tool}.vm")">$text.tools.get($tool)</a></li>
 #end
 
-
+#**
+ * Creates a smart default value for a demo field.
+ *#
+#macro( demoDefault $valuetype )
+#if( $valuetype.simpleName )
+  #set( $valuetype = $valuetype.simpleName )
+#end
+#if( $valuetype eq 'String' )
+'test'##
+#elseif( $valuetype eq 'int' or $valuetype eq 'Integer'
+        or $valuetype eq 'long' or $valuetype eq 'Long' )
+1##
+#elseif( $valuetype eq 'double' or $valuetype eq 'Double'
+        or $valuetype eq 'float' or $valuetype eq 'Float' )
+1.1##
+#elseif( $valuetype eq 'boolean' or $valuetype eq 'Boolean' )
+true##
+#elseif( $valuetype eq 'Class' )
+${esc.d}class.class##
+#end##
+#end
 
 #**
  * Creates the start tag and header row for a function demonstration table.

Modified: velocity/tools/branches/2.x/examples/showcase/WEB-INF/src/resources.properties
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/examples/showcase/WEB-INF/src/resources.properties?rev=599284&r1=599283&r2=599284&view=diff
==============================================================================
--- velocity/tools/branches/2.x/examples/showcase/WEB-INF/src/resources.properties (original)
+++ velocity/tools/branches/2.x/examples/showcase/WEB-INF/src/resources.properties Wed Nov
28 21:51:19 2007
@@ -48,12 +48,14 @@
 tools.header = Choose a tool
 tools.alternator = AlternatorTool
 tools.browser = BrowserTool
+tools.class = ClassTool
 tools.context = ContextTool
 tools.convert = ConversionTool
 tools.cookies = CookieTool
 tools.date = DateTool
 tools.display = DisplayTool
 tools.esc = EscapeTool
+tools.field = FieldTool
 tools.import = ImportTool
 tools.link = LinkTool
 tools.lists = ListTool
@@ -70,11 +72,63 @@
 ## demo common resources
 demo.function = Function
 demo.result = Demo Result
+demo.nullResult = null
 demo.clear = Clear All
 demo.description = Description
+demo.descriptionMissing = TODO
 demo.try = Try it!
 demo.tryAgain = Try Again!
 demo.tryAnything = Try any code out here.
 demo.thisPage = This page demonstrates functions of the {0}
 demo.mainExampleHeader = Example Display
 demo.mainResultsIntro = Your code returned the following results
+demo.toString = Returns a customized string representation of the tool.
+
+# class.vm resources
+class.intro = By default, the ClassTool is set to inspect \
+    <code>java.lang.Object</code>, though you may set the "inspect" \
+    property in your ClassTool configuration to point to any class on the classpath. \
+    Also, a new ClassTool instance can be created for any class you wish \
+    by a call to one of the inspect() methods. \
+    By default, the <code>safeMode</code> property is set to <code>true</code>
unless you \
+    configure it to be <code>false</code>. \
+    When <code>true</code>, safeMode will restrict ClassTool (or any instances
it creates) to \
+    only inspecting classes, methods, fields and constructors that were declared <code>public</code>.
+class.getConstructors = Returns a list of <code>ConstructorSub</code>s for each
constructor declared in the inspected class.
+class.getFields = Returns a list of <code>FieldSub</code>s for each field declared
in the inspected class.
+class.getFullName = Returns the fully qualified name of the class being inspected.
+class.getMethods = Returns a list of <code>MethodSub</code>s for each method
declared in the inspected class.
+class.getName = Returns the simple name of the class being inspected.
+class.getPackage = Returns the package name of the class being inspected.
+class.getType = Returns the actual <code>Class</code> being inspected.
+class.getTypes = Returns a <code>Set</code> of all <code>Class</code>es
that are part of the signatures (i.e. parameters or return types) of the inspected Class's
methods, constructors and fields.
+class.inspectSuper = Returns a new ClassTool instance that inspects the immediate superclass
of the class being inspected.
+class.inspect_Class = Returns a new ClassTool instance that inspects the specified Class.
+class.inspect_Class.param1 = $class.class
+class.inspect_Object = Returns a new ClassTool instance that inspects the Class of the specified
object.
+class.inspect_Object.param1 = $class
+class.inspect_String = Returns a new ClassTool instance that inspects the Class for the specified
class name \
+    or <code>null</code> if no class can be found for the specified name.
+class.inspect_String.param1 = 'org.apache.velocity.tools.generic.ClassTool'
+class.isAbstract = Returns <code>true</code> if the class being inspected is
abstract.
+class.isFinal = Returns <code>true</code> if the class being inspected is final.
+class.isInterface = Returns <code>true</code> if the class being inspected is
an interface.
+class.isPrivate = Returns <code>true</code> if the class being inspected is private.
+class.isProtected = Returns <code>true</code> if the class being inspected is
protected.
+class.isPublic = Returns <code>true</code> if the class being inspected is public.
+class.isStatic = Returns <code>true</code> if the class being inspected is static.
+class.isStrict = Returns <code>true</code> if the class being inspected is declared
strict.
+class.supportsNewInstance = Returns <code>true</code> if a new instance of the
class being inspected can be created via $class.type.newInstance().
+class.toString = Returns the result of $class.type.toString().
+
+# field.vm resources
+field.intro = This tool allows easy access to public static fields in classes,  such as string
constants.
+field.get_String = Returns the value of the field with the specified name, if found.
+field.get_String.param1 = 'java.lang.Boolean.FALSE'
+field.in_Class = Loads all public static fields in the specified class.
+field.in_Class.param1 = $date.class
+field.in_Object = Loads all public static fields in the Class of the specified object.
+field.in_Object.param1 = 1
+field.in_String = Looks for a class with the specified name; if found, loads all public static
fields.
+field.in_String.param1 = 'java.lang.Float'
+field.custom = $field.in($field).INCLUDE_KEY

Added: velocity/tools/branches/2.x/examples/showcase/class.vm
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/examples/showcase/class.vm?rev=599284&view=auto
==============================================================================
--- velocity/tools/branches/2.x/examples/showcase/class.vm (added)
+++ velocity/tools/branches/2.x/examples/showcase/class.vm Wed Nov 28 21:51:19 2007
@@ -0,0 +1,33 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##   http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied.  See the License for the
+## specific language governing permissions and limitations
+## under the License.
+#title( 'ClassTool' )
+<p>
+$text.demo.thisPage.insert("#doclink( 'ClassTool' true )").
+</p>
+<p>
+$text.get('class.intro')
+</p>
+
+#set( $toolname = 'class' )
+#set( $toolclass = $class.class )
+#set( $toolDemo = 
+"${esc.h}foreach( ${esc.d}method in ${esc.d}class.methods )
+${esc.d}method.javadocRef
+${esc.h}end"
+)
+
+#parse( 'demo.vm' )

Propchange: velocity/tools/branches/2.x/examples/showcase/class.vm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: velocity/tools/branches/2.x/examples/showcase/class.vm
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: velocity/tools/branches/2.x/examples/showcase/demo.vm
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/examples/showcase/demo.vm?rev=599284&view=auto
==============================================================================
--- velocity/tools/branches/2.x/examples/showcase/demo.vm (added)
+++ velocity/tools/branches/2.x/examples/showcase/demo.vm Wed Nov 28 21:51:19 2007
@@ -0,0 +1,118 @@
+#set( $demo = $text.demo )
+#set( $tool = $class.inspect($toolclass) )
+
+<table border="1" cellspacing="0" cellpadding="3">
+<tr>
+  <th>$demo.function</th>
+  <form method="get" action="$link.self">
+  <th nowrap="1">
+    $demo.result<br>
+    <input style="font-size: 8pt" type="submit" value="$demo.clear">
+  </th>
+  #if( $params.layout )
+    <input type="hidden" name="layout" value="$params.layout">
+  #end
+  </form>
+  <th>$demo.description</th>
+</tr>
+#foreach( $method in $tool.methods )
+  #set( $desc = $text.get("${toolname}.${method.uniqueName}") )
+  #set( $call = "${esc.d}${toolname}.#if( !$method.takesParameters() && $method.propertyName
)$method.propertyName#else$method.signature#end" )
+<tr>
+  <td valign="top" id="${method.javadocRef}"><a href="$doclink#$method.javadocRef">$call</a></td>
+  #if( !$method.takesParameters() )
+    #set( $result = $call )
+    #set( $result = $render.eval($call) )
+    <td valign="top">#if( $result == $call )$text.demo.nullResult#else$result#end</td>
+  #else
+    <form method="get" action="$link.self.anchor($method.javadocRef)"> ## HttpUnit
doesn't like anchor-only links
+    <td valign="top">
+    <nobr>
+      #foreach( $param in $method.parameters )
+        #set( $pname = "$method.uniqueName$velocityCount" )
+        #set( $pvalue = $params.get($pname, false) )
+        #set( $pdefault = $text.get("${toolname}.${method.uniqueName}.param$velocityCount")
)
+        #if( !$pdefault.exists )
+          #set( $pdefault = "#demoDefault( $param )" )
+        #end
+        #if( $velocityCount > 1 ), #end<input type="text" name="$pname" value="#if(
$pvalue )$pvalue#else$pdefault#end" size="$math.sub($math.idiv(24, $method.parameterCount),
$method.parameterCount)"/>
+      #end
+      <input type="submit" value="$text.demo.try">
+    </nobr>
+    #if( $params.get("${method.uniqueName}1") )
+      #set( $call = "${esc.d}${toolname}.${method.name}(#foreach( $param in $method.parameters
)#if( $velocityCount > 1 ), #end$!params.get($render.eval('$method.uniqueName$velocityCount'))#end)"
)
+      #set( $result = $call )
+      #set( $result = $render.eval($call) )
+      <br>
+      $call
+      =
+      <div>#if( $result == $call )$demo.nullResult#else$result#end</div>
+    #end
+    #foreach( $param in $params.all.keySet() )
+      #if( !$param.startsWith($method.uniqueName) )
+        #foreach( $value in $params.getStrings($param) )
+          <input type="hidden" name="$param" value="$esc.html($value)">
+        #end
+      #end
+    #end
+    </td>
+    </form>
+  #end
+  <td valign="top">#if( $desc.exists )$desc#elseif( $method.uniqueName eq 'toString'
)$demo.toString#else$demo.descriptionMissing#end</td>
+</tr>
+#end
+<tr>
+  <form method="get" action="$link.self.anchor('custom')">
+  <td valign="top" colspan="2" id="custom">
+    #set( $custom = $params.getValue('custom', false) )
+    #set( $default = $text.get("${toolname}.custom") )
+    #if( !$default.exists )
+      #set( $default = "$esc.d$toolname" )
+    #end
+    <input type="text" size="40" name="custom" value="#if( $custom )$custom#else$default#end">
+    <input type="submit" value="$text.demo.try">
+    #if( $params.custom )
+      #set( $result = $call )
+      #set( $result = $render.eval($params.custom) )
+      <br>
+      $params.custom
+      =
+      <div>#if( $result == $call )$demo.nullResult#else$result#end</div>
+    #end
+    #foreach( $param in $params.all.keySet() )
+      #if( $param != 'custom' )
+        #foreach( $value in $params.getStrings($param) )
+          <input type="hidden" name="$param" value="$esc.html($value)">
+        #end
+      #end
+    #end
+  </td>
+  </form>
+  <td>$text.demo.tryAnything</td>
+</tr>
+</table>
+
+<div align="center">
+  <a name="fullDemo"><h3>$demo.mainExampleHeader</h3></a>
+<form method="post" action="$link.self.anchor('fullDemo')">
+<textarea name="demo" rows="3" cols="65">##
+#if( $params.demo )##
+$params.demo##
+#else##
+$!toolDemo##
+#end##
+</textarea>
+  <br>
+  <input type="submit" value="$demo.try">
+  #if( $params.layout )
+  <input type="hidden" name="layout" value="$params.layout">
+  #end
+</form>
+
+#if( $params.demo )
+$demo.mainResultsIntro:
+<pre>
+  $render.eval($params.demo)
+</pre>
+#end
+</div>

Propchange: velocity/tools/branches/2.x/examples/showcase/demo.vm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: velocity/tools/branches/2.x/examples/showcase/demo.vm
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: velocity/tools/branches/2.x/examples/showcase/field.vm
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/examples/showcase/field.vm?rev=599284&view=auto
==============================================================================
--- velocity/tools/branches/2.x/examples/showcase/field.vm (added)
+++ velocity/tools/branches/2.x/examples/showcase/field.vm Wed Nov 28 21:51:19 2007
@@ -0,0 +1,34 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##   http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied.  See the License for the
+## specific language governing permissions and limitations
+## under the License.
+#title( 'FieldTool' )
+<p>
+$text.demo.thisPage.insert("#doclink( 'FieldTool' true )").
+</p>
+<p>
+$text.field.intro
+</p>
+
+## The demo.vm template expects the following values to be set
+#set( $toolname = 'field' )
+#set( $toolclass = $field.class )
+#set( $toolDemo = 
+"${esc.d}field.in(0).MIN_VALUE
+${esc.h}${esc.h} once a class's fields have been searched, they remain available
+${esc.d}field.MAX_VALUE"
+)
+
+#parse( 'demo.vm' )

Propchange: velocity/tools/branches/2.x/examples/showcase/field.vm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: velocity/tools/branches/2.x/examples/showcase/field.vm
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: velocity/tools/branches/2.x/examples/showcase/toolmenu.vm
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/examples/showcase/toolmenu.vm?rev=599284&r1=599283&r2=599284&view=diff
==============================================================================
--- velocity/tools/branches/2.x/examples/showcase/toolmenu.vm (original)
+++ velocity/tools/branches/2.x/examples/showcase/toolmenu.vm Wed Nov 28 21:51:19 2007
@@ -24,12 +24,14 @@
 <ul>
 #toolMenuItem( $llink 'alternator' )
 #toolMenuItem( $llink 'browser' )
+#toolMenuItem( $llink 'class' )
 #toolMenuItem( $llink 'context' )
 #toolMenuItem( $llink 'convert' )
 #toolMenuItem( $llink 'cookies' )
 #toolMenuItem( $llink 'date' )
 #toolMenuItem( $llink 'display' )
 #toolMenuItem( $llink 'esc' )
+#toolMenuItem( $llink 'field' )
 #toolMenuItem( $llink 'import' )
 #toolMenuItem( $llink 'link' )
 #toolMenuItem( $llink 'lists' )



Mime
View raw message