├── velocity-tools-view ├── src │ ├── test │ │ ├── resources │ │ │ ├── inclasspath.json │ │ │ ├── charset-test.vm │ │ │ ├── webapp_mocking │ │ │ │ ├── inwebapp.json │ │ │ │ └── inwebapp.xml │ │ │ ├── inclasspath.xml │ │ │ ├── VM_global_library.vm │ │ │ └── WEB-INF │ │ │ │ └── velocity.properties │ │ └── java │ │ │ └── org │ │ │ └── apache │ │ │ └── velocity │ │ │ └── tools │ │ │ ├── test │ │ │ └── blackbox │ │ │ │ ├── BreadcrumbToolTests.java │ │ │ │ ├── BaseToolTests.java │ │ │ │ ├── TestURLHandler.java │ │ │ │ ├── ResponseAdaptor.java │ │ │ │ └── ServletContextAdaptor.java │ │ │ └── view │ │ │ └── BaseWebappMockTest.java │ └── main │ │ ├── resources │ │ └── org │ │ │ └── apache │ │ │ └── velocity │ │ │ └── tools │ │ │ └── view │ │ │ ├── velocity.properties │ │ │ └── tools.xml │ │ └── java │ │ └── org │ │ └── apache │ │ └── velocity │ │ └── tools │ │ └── view │ │ ├── package.html │ │ ├── JeeContextConfig.java │ │ ├── JeeFilterConfig.java │ │ ├── JeeServletConfig.java │ │ ├── XmlTool.java │ │ ├── JeeConfig.java │ │ ├── ImportTool.java │ │ └── ViewContext.java └── pom.xml ├── velocity-tools-generic ├── src │ ├── test │ │ ├── resources │ │ │ ├── foo.json │ │ │ ├── resources2.properties │ │ │ ├── resources_en.properties │ │ │ ├── resources_fr.properties │ │ │ ├── file.xml │ │ │ ├── tools.properties │ │ │ ├── tools.test.properties │ │ │ ├── tools.xml │ │ │ ├── tools.test.xml │ │ │ ├── whiteboxtest-toolbox.xml │ │ │ └── toolbox.test.xml │ │ └── java │ │ │ ├── org │ │ │ └── apache │ │ │ │ └── velocity │ │ │ │ └── tools │ │ │ │ └── generic │ │ │ │ ├── CollectionToolTests.java │ │ │ │ ├── MathToolTests.java │ │ │ │ ├── JsonToolTests.java │ │ │ │ └── Veltools128Tests.java │ │ │ └── tools.java │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── velocity │ │ │ └── tools │ │ │ ├── config │ │ │ ├── Property.java │ │ │ ├── ValidScope.java │ │ │ ├── InvalidScope.java │ │ │ ├── NullKeyException.java │ │ │ ├── DefaultKey.java │ │ │ ├── SkipSetters.java │ │ │ ├── InvalidScopeException.java │ │ │ └── ConfigurationException.java │ │ │ ├── generic │ │ │ ├── package.html │ │ │ ├── FormatConfig.java │ │ │ ├── LogTool.java │ │ │ └── LocaleConfig.java │ │ │ └── Scope.java │ │ └── resources │ │ └── org │ │ └── apache │ │ └── velocity │ │ └── tools │ │ └── generic │ │ ├── times.properties │ │ └── tools.xml └── pom.xml ├── velocity-tools-examples ├── velocity-tools-examples-showcase │ └── src │ │ └── main │ │ ├── webapp │ │ ├── WEB-INF │ │ │ ├── included │ │ │ │ ├── test-xinclude3.txt │ │ │ │ ├── test-xinclude1.xml │ │ │ │ └── test-xinclude2.xml │ │ │ ├── velocity.properties │ │ │ ├── tools.xml │ │ │ └── web.xml │ │ ├── nolayout │ │ │ └── xinclude.txt │ │ ├── footer.vm │ │ ├── post_json.vm │ │ ├── layout │ │ │ ├── Print.vm │ │ │ ├── Simple.vm │ │ │ ├── Table.vm │ │ │ └── Default.vm │ │ ├── index.vm │ │ ├── json.vm │ │ ├── collection.vm │ │ ├── layoutmenu.vm │ │ ├── header.vm │ │ ├── include.vm │ │ ├── xml.vm │ │ ├── class.vm │ │ ├── field.vm │ │ ├── loop.vm │ │ ├── sorter.vm │ │ ├── context.vm │ │ ├── convert.vm │ │ ├── cookies.vm │ │ ├── Error.vm │ │ ├── alternator.vm │ │ ├── import.vm │ │ ├── display.vm │ │ ├── template.txt │ │ ├── mill.vm │ │ ├── toolmenu.vm │ │ ├── render.vm │ │ ├── fullDemo.vm │ │ ├── lists.vm │ │ ├── text.vm │ │ └── number.vm │ │ ├── resources │ │ ├── NOTICE │ │ ├── otherStuff.properties │ │ ├── resources_de.properties │ │ ├── resources_fr.properties │ │ └── file.xml │ │ └── java │ │ └── org │ │ └── apache │ │ └── velocity │ │ └── tools │ │ └── examples │ │ └── showcase │ │ ├── sample │ │ ├── Person.java │ │ └── SampleListInitializer.java │ │ ├── ShowcaseLayoutServlet.java │ │ └── tool │ │ └── LayoutLinkTool.java ├── velocity-tools-examples-simple │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── velocity │ │ │ │ └── tools │ │ │ │ └── examples │ │ │ │ └── simple │ │ │ │ └── tool │ │ │ │ └── ToyTool.java │ │ │ └── webapp │ │ │ ├── WEB-INF │ │ │ ├── tools.xml │ │ │ └── web.xml │ │ │ ├── index.vm │ │ │ └── index.jsp │ └── pom.xml └── pom.xml ├── .gitignore ├── NOTICE ├── README.md └── velocity-tools-view-jsp ├── src ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── velocity │ │ └── tools │ │ └── view │ │ └── jsp │ │ ├── package-info.java │ │ ├── jspimpl │ │ ├── package-info.java │ │ ├── VelocityToolsJspException.java │ │ ├── ExternalWriterHttpServletResponse.java │ │ └── VelocityJspFragment.java │ │ └── JspToolContext.java └── test │ └── java │ └── org │ └── apache │ └── velocity │ └── tools │ └── view │ └── jsp │ └── jspimpl │ ├── ExternalWriterHttpServletResponseTest.java │ └── VelocityJspFragmentTest.java └── pom.xml /velocity-tools-view/src/test/resources/inclasspath.json: -------------------------------------------------------------------------------- 1 | {"hey" : "brother" } 2 | -------------------------------------------------------------------------------- /velocity-tools-view/src/test/resources/charset-test.vm: -------------------------------------------------------------------------------- 1 | Questo è il momento della verità. 2 | -------------------------------------------------------------------------------- /velocity-tools-view/src/test/resources/webapp_mocking/inwebapp.json: -------------------------------------------------------------------------------- 1 | {"hey" : "there" } 2 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/resources/foo.json: -------------------------------------------------------------------------------- 1 | { "foo": "bar", "array": [ "foo1", "foo2"] } 2 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/WEB-INF/included/test-xinclude3.txt: -------------------------------------------------------------------------------- 1 | success 2 | -------------------------------------------------------------------------------- /velocity-tools-view/src/test/resources/inclasspath.xml: -------------------------------------------------------------------------------- 1 | 2 | brother 3 | 4 | -------------------------------------------------------------------------------- /velocity-tools-view/src/test/resources/webapp_mocking/inwebapp.xml: -------------------------------------------------------------------------------- 1 | 2 | there 3 | 4 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/nolayout/xinclude.txt: -------------------------------------------------------------------------------- 1 | $xinclude_1 $xinclude_2 $xinclude_3 2 | 3 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/WEB-INF/included/test-xinclude1.xml: -------------------------------------------------------------------------------- 1 | success 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #maven 2 | target 3 | 4 | #idea 5 | *.iml 6 | .idea 7 | 8 | #eclipse 9 | bin 10 | .project 11 | .classpath 12 | .settings 13 | 14 | # OSX 15 | .DS_Store 16 | 17 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/WEB-INF/included/test-xinclude2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | success 4 | 5 | 6 | -------------------------------------------------------------------------------- /velocity-tools-view/src/test/resources/VM_global_library.vm: -------------------------------------------------------------------------------- 1 | #macro( quietnull $a) 2 | #if($a)$a#end 3 | #end 4 | 5 | #macro( recurse $a ) 6 | global recurse $a 7 | #set( $a = $a - 1) 8 | #if ($a > 0) 9 | #recurse( $a ) 10 | #end 11 | #end 12 | 13 | #macro( callrecurse ) 14 | #set( $count = 5) 15 | #recurse( $count ) 16 | #end 17 | 18 | #macro( testbool $b ) 19 | #if($b) 20 | arg true 21 | #end 22 | #if( ! $b ) 23 | arg false 24 | #end 25 | #end 26 | 27 | 28 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache Velocity Tools 2 | 3 | Copyright (C) 2000-2007 The Apache Software Foundation 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). 7 | 8 | Support for using SSL with Struts is provided using 9 | the sslext library package, which is open source software 10 | under the Apache Software License 1.1 with copyright attributed 11 | to The Apache Software Foundation. 12 | This software is available from http://sslext.sourceforge.net/ 13 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/resources/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Velocity Tools 2 | Showcase application 3 | 4 | Copyright (C) 2000-2010 The Apache Software Foundation 5 | 6 | This product includes software developed at 7 | The Apache Software Foundation (http://www.apache.org/). 8 | 9 | Support for using SSL with Struts is provided using 10 | the sslext library package, which is open source software 11 | under the Apache Software License 1.1 with copyright attributed 12 | to The Apache Software Foundation. 13 | This software is available from http://sslext.sourceforge.net/ 14 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/java/org/apache/velocity/tools/examples/showcase/sample/Person.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.examples.showcase.sample; 2 | 3 | public class Person 4 | { 5 | 6 | private String name; 7 | 8 | private String surname; 9 | 10 | private String role; 11 | 12 | public Person(String name, String surname, String role) 13 | { 14 | this.name = name; 15 | this.surname = surname; 16 | this.role = role; 17 | } 18 | 19 | public String getName() 20 | { 21 | return name; 22 | } 23 | 24 | public String getSurname() 25 | { 26 | return surname; 27 | } 28 | 29 | public String getRole() 30 | { 31 | return role; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Title: Apache Velocity Tools 2 | 3 | # Apache Velocity Tools 4 | 5 | Welcome to the VelocityTools projects. This is a subproject of the 6 | Apache Velocity project hosted at https://velocity.apache.org/ 7 | 8 | The VelocityTools project contains several subprojects: 9 | 10 | velocity-tools-generic/ A collection of general purpose tools 11 | velocity-tools-view/ Tools servlets and filters for use in a webapp 12 | velocity-tools-jsp/ Tools for a JEE JSP context 13 | velocity-tools-examples/ 14 | velocity-tools-examples-simple/ Simple examples 15 | velocity-tools-examples-showcase/ A full webapp demonstrating tools 16 | 17 | Apache Velocity Tools require at least Java 8 to run. 18 | 19 | ## Feedback 20 | 21 | We welcome your feedback to user@velocity.apache.org. 22 | 23 | - The Apache Velocity Team 24 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/CollectionToolTests.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.generic; 2 | 3 | import org.junit.Test; 4 | import static org.junit.Assert.assertEquals; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public class CollectionToolTests 10 | { 11 | public @Test 12 | void testNullElements() 13 | { 14 | CollectionTool tool = new CollectionTool(); 15 | 16 | List lst = Arrays.asList("b", null, "a"); 17 | List sorted = (List)tool.sort(lst); 18 | assertEquals(2, sorted.size()); 19 | assertEquals("a", sorted.get(0)); 20 | assertEquals("b", sorted.get(1)); 21 | 22 | String arr[] = new String[] { "foo", null, "bar"}; 23 | sorted = (List)tool.sort(arr); 24 | assertEquals(2, sorted.size()); 25 | assertEquals("bar", sorted.get(0)); 26 | assertEquals("foo", sorted.get(1)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/resources/resources2.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | foo = woogie 19 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/footer.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | 18 | 19 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/resources/resources_en.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | foo = bar 19 | hello.whoever = Hello {0}! 20 | world = World 21 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/resources/resources_fr.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | foo = barre 19 | hello.whoever = Bonjour {0}! 20 | world = Monde 21 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/java/org/apache/velocity/tools/examples/showcase/ShowcaseLayoutServlet.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.examples.showcase; 2 | 3 | import org.apache.velocity.tools.view.VelocityLayoutServlet; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | 7 | public class ShowcaseLayoutServlet extends VelocityLayoutServlet 8 | { 9 | private static final long serialVersionUID = -8743195198276764930L; 10 | 11 | /** 12 | * Searches for a non-default layout to be used for this request. 13 | * This implementation checks the request parameters and attributes. 14 | */ 15 | protected String findLayout(HttpServletRequest request) 16 | { 17 | // check if an alternate layout has been specified 18 | // by way of the request parameters 19 | String layout = request.getParameter(KEY_LAYOUT); 20 | return layout == null ? super.findLayout(request) : layout; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/resources/otherStuff.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | foo= woogie 19 | baz= The args are {0} and {1}. 20 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/resources/resources_de.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | foo = Stab 19 | hello.whoever = Hallo {0}! 20 | world = Welt 21 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/resources/file.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | woogie 23 | wiggie 24 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/resources/resources_fr.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | foo = barre 19 | hello.whoever = Bonjour {0}! 20 | world = Monde 21 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/post_json.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'JsonTool test template' ) 18 | $json.foo 19 | -------------------------------------------------------------------------------- /velocity-tools-view/src/test/resources/WEB-INF/velocity.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | input.encoding=UTF-8 19 | resource.loaders = clazz 20 | resource.loader.clazz.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader 21 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/resources/file.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | woogie 23 | wiggie 24 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/layout/Print.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | 18 | #parse( 'header.vm' ) 19 |

20 | $text.appname: $text.print.name 21 |

22 |

23 | $screen_content 24 |

25 | #parse( 'footer.vm' ) 26 | -------------------------------------------------------------------------------- /velocity-tools-view-jsp/src/main/java/org/apache/velocity/tools/view/jsp/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: package-info.java 1044659 2010-12-11 14:16:04Z apetrelli $ 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | /** 22 | * JSP support of Velocity (and vice-versa). 23 | */ 24 | package org.apache.velocity.tools.view.jsp; 25 | 26 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/index.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #set( $index = $text.index ) 18 |

$index.greeting!

19 | 20 |

$index.explanation*

21 | 22 |

$index.start

23 | 24 |
25 | *$index.asterisk 26 |
27 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/json.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'JsonTool' ) 18 |

19 | $text.demo.thisPage.insert("#doclink( 'JsonTool' true )"). 20 |

21 |

22 | $text.json.intro 23 |

24 | 25 | #demoTableStart() 26 | 27 | #demo1( 'json' 'parse' 5 'parse JSON string' ) 28 | 29 | 30 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/layout/Simple.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | 18 | #parse( 'header.vm' ) 19 | 20 |
21 | $text.appname: $text.simple.name 22 |
23 | 24 |
25 | $screen_content 26 |
27 | 28 | 32 | 33 | #parse( 'footer.vm' ) 34 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/collection.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'CollectionTool' ) 18 |

19 | $text.demo.thisPage.insert("#doclink( 'CollectionTool' true )"). 20 |

21 |

22 | $text.collection.intro 23 |

24 | 25 | #demoTableStart() 26 | 27 | #demo1( 'collection' 'split' 5 'split string' ) 28 | #demoCustom( "sorter.sort(['b','c','a'])" ) 29 | 30 | 31 | -------------------------------------------------------------------------------- /velocity-tools-view-jsp/src/main/java/org/apache/velocity/tools/view/jsp/jspimpl/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: package-info.java 1044659 2010-12-11 14:16:04Z apetrelli $ 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | /** 22 | * Contains JSP-simulating classes that allows the use of a Velocity environment 23 | * under JSP specific classes, like tags. 24 | */ 25 | package org.apache.velocity.tools.view.jsp.jspimpl; 26 | 27 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/layoutmenu.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #set( $slink = $link.self ) 18 | #set( $layouts = $text.layouts ) 19 |

$layouts.header:

20 |
26 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/resources/tools.properties: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | 18 | tools.toolbox = request,application 19 | tools.data.version = 2.0 20 | tools.data.version.type = number 21 | tools.request.property.locale = en_US 22 | tools.request.text = org.apache.velocity.tools.generic.ResourceTool 23 | tools.application.calc = org.apache.velocity.tools.generic.MathTool 24 | tools.application.number = org.apache.velocity.tools.generic.NumberTool 25 | tools.application.number.locale = fr 26 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/resources/tools.test.properties: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | 18 | tools.toolbox = request,application 19 | tools.data.version = 2.0 20 | tools.data.version.type = number 21 | tools.request.property.locale = en_US 22 | tools.request.text = org.apache.velocity.tools.generic.ResourceTool 23 | tools.application.calc = org.apache.velocity.tools.generic.MathTool 24 | tools.application.number = org.apache.velocity.tools.generic.NumberTool 25 | tools.application.number.locale = fr 26 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/header.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | 18 | 19 | VelocityTools - $text.appname#if( $page_title ) - $page_title#end 20 | #if( $stylesheet ) 21 | 22 | #end 23 | #if( $displayTagStylesheet ) 24 | 25 | #end 26 | 27 | 28 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/resources/tools.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/resources/tools.test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/include.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'IncludeTool' ) 18 |

19 | $text.demo.thisPage.insert("#doclink( 'IncludeTool' false )"). 20 | $text.get('include.intro') 21 |

22 | 23 | #set( $toolname = 'include' ) 24 | #set( $toolclass = $include.class ) 25 | #set( $toollink = $doclink ) 26 | #set( $toolDemo = 27 | "${esc.d}include.exists('include.vm') 28 | ${esc.d}include.exists('foo.vm') 29 | ${esc.h}${esc.h}this demo is currently poor because we don't have i18n templates!" 30 | ) 31 | 32 | #parse( 'demo.vm' ) 33 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/xml.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'XmlTool' ) 18 |

19 | $text.demo.thisPage.insert("#doclink( 'XmlTool' true )"). 20 | $text.get('xml.intro') 21 |

22 | 23 | #set( $toolname = 'xml' ) 24 | #set( $toolclass = $xml.class ) 25 | #set( $toollink = $doclink ) 26 | #set( $toolDemo = 27 | "Document: ${esc.d}esc.xml(${esc.d}xml) 28 | 29 | bar text: ${esc.d}xml.bar.text 30 | 31 | baz attr value: ${esc.d}xml.a.baz 32 | 33 | last bar xml: ${esc.d}esc.xml(${esc.d}xml.bar.last)" 34 | ) 35 | 36 | #parse( 'demo.vm' ) 37 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/class.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'ClassTool' ) 18 |

19 | $text.demo.thisPage.insert("#doclink( 'ClassTool' true )"). 20 |

21 |

22 | $text.get('class.intro') 23 |

24 | 25 | #set( $toolname = 'class' ) 26 | #set( $toolclass = $class.class ) 27 | #set( $toollink = $doclink ) 28 | #set( $toolDemo = 29 | "${esc.h}set( ${esc.d}classTool = ${esc.d}class.inspect(${esc.d}class) ) 30 | ${esc.h}foreach( ${esc.d}method in ${esc.d}classTool.methods ) 31 | ${esc.d}method.javadocRef 32 | ${esc.h}end" 33 | ) 34 | 35 | #parse( 'demo.vm' ) 36 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/field.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'FieldTool' ) 18 |

19 | $text.demo.thisPage.insert("#doclink( 'FieldTool' true )"). 20 |

21 |

22 | $text.field.intro 23 |

24 | 25 | ## The demo.vm template expects the following values to be set 26 | #set( $toolname = 'field' ) 27 | #set( $toolclass = $field.class ) 28 | #set( $toollink = $doclink ) 29 | #set( $toolDemo = 30 | "${esc.d}field.in(0).MIN_VALUE 31 | ${esc.h}${esc.h} once a class's fields have been searched, they remain available 32 | ${esc.d}field.MAX_VALUE" 33 | ) 34 | 35 | #parse( 'demo.vm' ) 36 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-simple/src/main/java/org/apache/velocity/tools/examples/simple/tool/ToyTool.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.examples.simple.tool; 2 | /* 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | public class ToyTool 22 | { 23 | private String message = "Hello from ToyTool!"; 24 | 25 | public String getMessage() 26 | { 27 | return message; 28 | } 29 | 30 | public void setMessage(String m) 31 | { 32 | message = m; 33 | } 34 | 35 | /** To test exception handling in templates. */ 36 | public boolean whine() { 37 | throw new IllegalArgumentException(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/Property.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.config; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | /** 23 | * Simple extension of {@link Data} that treats "name" as an alias 24 | * for "key". See {@link Data} for a description and feature list. 25 | * 26 | * @author Nathan Bubna 27 | * @version $Id: Property.java 511959 2007-02-26 19:24:39Z nbubna $ 28 | */ 29 | public class Property extends Data 30 | { 31 | public void setName(String name) 32 | { 33 | setKey(name); 34 | } 35 | 36 | public String getName() 37 | { 38 | return getKey(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-simple/src/main/webapp/WEB-INF/tools.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 23 | 24 | 25 | 26 | this is foo 27 | this is bar. 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/layout/Table.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | 18 | 20 | 21 | #parse( 'header.vm' ) 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 34 | 37 | 38 |
$text.appname: $text.table.name
30 | #parse( 'toolmenu.vm' ) 31 | $screen_content 35 | #parse( 'layoutmenu.vm' ) 36 |
39 | #parse( 'footer.vm' ) 40 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/loop.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'LoopTool' ) 18 |

19 | $text.demo.thisPage.insert("#doclink( 'LoopTool' true )"). 20 |

21 |

22 | $text.loop.intro 23 |

24 | 25 | #set( $fullDemo = 26 | '#set( $numbers = [1..5] ) 27 | #set( $letters = ["A","B","C"] ) 28 | #set( $symbols = ["!", "@"] ) 29 | #foreach( $l in $loop.watch($letters, "l").sync($symbols, "s") ) 30 | #foreach( $n in $loop.watch($numbers).exclude(3) ) 31 | #if( $loop.first )$l$loop.s[#end## 32 | $n## 33 | #if( $loop.last )] #else, #end## 34 | #if( $l == "B" )$loop.stop("l")#end## stop the letter loop after B 35 | #end 36 | #end' 37 | ) 38 | 39 | #parse( 'fullDemo.vm' ) 40 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/sorter.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'SortTool' ) 18 |

19 | #set( $demo = $text.demo ) 20 | $demo.thisPage.insert("#doclink( 'SortTool' true )"). 21 |

22 | 23 | #demoTableStart() 24 | 25 | #set( $quote = '' ) 26 | 27 | #set( $desc = 'Sorts the values of the specified Collection, Map, or array of Objects according to their natural ordering' ) 28 | #demo1( 'sorter' 'sort' 3 $desc) 29 | 30 | #set( $desc = "Sorts the values of the specified Collection, Map, or array of Objects according to the values returned by the specified property or list of properties" ) 31 | #demo2( 'sorter' 'sort' 5 $desc ) 32 | 33 | #demoCustom( "sorter.sort(['b','c','a'])" ) 34 | 35 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/resources/whiteboxtest-toolbox.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 23 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/WEB-INF/velocity.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # 19 | # These are the default properties. So, this file is essentially 20 | # unnecessary here, but is included just to demonstrate that these 21 | # can be changed. 22 | # 23 | 24 | # Filepath for error template, relative to web application root directory 25 | tools.view.servlet.error.template = Error.vm 26 | 27 | # Directory for layout templates, relative to web application root directory 28 | tools.view.servlet.layout.directory = layout/ 29 | 30 | # Filepath of the default layout template 31 | # relative to the layout directory 32 | # NOT relative to the root directory of the webapp! 33 | tools.view.servlet.layout.default.template = Default.vm 34 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/context.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'ContextTool' ) 18 |

19 | $text.demo.thisPage.insert("#doclink( 'ViewContextTool' false )"). 20 |

21 |

22 | $text.get('context.intro') 23 |

24 | 25 | #set( $toolname = 'context' ) 26 | ## all the interesting methods are actually in the superclass 27 | ## since ViewContextTool only adds request/session/app attributes 28 | ## and not any additional methods 29 | #set( $toolclass = $context.class.superclass ) 30 | #set( $toollink = $doclink ) 31 | #set( $toolDemo = 32 | "${esc.h}foreach( ${esc.d}key in ${esc.d}context.keys ) 33 | ${esc.d}key = ${esc.d}context.get(${esc.d}key) 34 | ${esc.h}end" 35 | ) 36 | 37 | #parse( 'demo.vm' ) 38 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/ValidScope.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.config; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.lang.annotation.Documented; 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Inherited; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | /** 30 | * 31 | * 32 | * @author Nathan Bubna 33 | * @version $Id: ValidScope.java 511959 2007-02-26 19:24:39Z nbubna $ 34 | */ 35 | @Documented 36 | @Inherited 37 | @Target(ElementType.TYPE) 38 | @Retention(RetentionPolicy.RUNTIME) 39 | public @interface ValidScope 40 | { 41 | String[] value(); 42 | } 43 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/resources/toolbox.test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 23 | version 24 | 2.0 25 | 26 | 27 | org.apache.velocity.tools.generic.ResourceTool 28 | text 29 | 30 | 31 | org.apache.velocity.tools.generic.MathTool 32 | calc 33 | application 34 | 35 | 36 | org.apache.velocity.tools.generic.NumberTool 37 | number 38 | application 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/InvalidScope.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.config; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.lang.annotation.Documented; 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Inherited; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | /** 30 | * 31 | * 32 | * @author Nathan Bubna 33 | * @version $Id: InvalidScope.java 511959 2007-02-26 19:24:39Z nbubna $ 34 | */ 35 | @Documented 36 | @Inherited 37 | @Target(ElementType.TYPE) 38 | @Retention(RetentionPolicy.RUNTIME) 39 | public @interface InvalidScope 40 | { 41 | String[] value(); 42 | } 43 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/java/org/apache/velocity/tools/examples/showcase/sample/SampleListInitializer.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.examples.showcase.sample; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import javax.servlet.ServletContextEvent; 7 | import javax.servlet.ServletContextListener; 8 | 9 | public class SampleListInitializer implements ServletContextListener 10 | { 11 | 12 | public void contextInitialized(ServletContextEvent event) 13 | { 14 | List people = new ArrayList(); 15 | people.add(new Person("Claude", "Brisson", "PMC Member")); 16 | people.add(new Person("Nathan", "Bubna", "PMC Member")); 17 | people.add(new Person("Will", "Glass-Husain", "PMC Chair")); 18 | people.add(new Person("Marinó A.", "Jónsson", "PMC Member")); 19 | people.add(new Person("Geir", "Magnusson Jr.", "PMC Member")); 20 | people.add(new Person("Daniel", "Rall", "PMC Member")); 21 | people.add(new Person("Henning P.", "Schmiedehausen", "PMC Member")); 22 | people.add(new Person("Jon S.", "Stevens", "Emeritus")); 23 | people.add(new Person("Jason", "van Zyl", "Emeritus")); 24 | people.add(new Person("Christopher", "Schultz", "Java developer")); 25 | people.add(new Person("Antonio", "Petrelli", "PMC Member")); 26 | event.getServletContext().setAttribute("people", people); 27 | } 28 | 29 | public void contextDestroyed(ServletContextEvent event) 30 | { 31 | // It does nothing. 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/MathToolTests.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.generic; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import org.apache.velocity.VelocityContext; 23 | 24 | /** 25 | * This 26 | */ 27 | public class MathToolTests extends BaseTestCase 28 | { 29 | public MathToolTests(String name) 30 | { 31 | super(name); 32 | } 33 | 34 | protected void setUpContext(VelocityContext context) 35 | { 36 | context.put("math", new MathTool()); 37 | } 38 | 39 | public void testMax() 40 | { 41 | assertEvalEquals("4.0", "$math.max(4,3.5)"); 42 | assertEvalEquals("4.0", "$math.max(4,3.5,3)"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/convert.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'ConversionTool' ) 18 |

19 | $text.demo.thisPage.insert("#doclink( 'ConversionTool' true )"). 20 | $text.convert.intro 21 |

22 | 23 | ## The demo.vm template expects the following values to be set 24 | #set( $toollink = $doclink ) 25 | #set( $toolname = 'convert' ) 26 | #set( $toolclass = $convert.class ) 27 | #set( $toolDemo = 28 | "" 29 | ) 30 | 31 | #set( $skip = [ 32 | 'parseDate_StringString', 33 | 'parseNumber_StringString', 34 | 'toBooleans_Collection', 35 | 'toNumbers_Collection', 36 | 'toCalendars_Collection', 37 | 'toDates_Collection', 38 | 'toLocales_Collection', 39 | 'toString_Collection' 40 | ] ) 41 | #parse( 'demo.vm' ) 42 | -------------------------------------------------------------------------------- /velocity-tools-view/src/main/resources/org/apache/velocity/tools/view/velocity.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # by default, load resources with webapp resource loader and string resource loader (in that order) 19 | resource.loaders = webapp,string 20 | resource.loader.webapp.class = org.apache.velocity.tools.view.WebappResourceLoader 21 | resource.loader.string.class = org.apache.velocity.runtime.resource.loader.StringResourceLoader 22 | 23 | # allows getting and setting $request, $session and $application attributes using Velocity syntax, 24 | # like in #set($session.foo = 'bar'), instead of $session.setAttribute('foo','bar') 25 | introspector.uberspect.class = org.apache.velocity.util.introspection.UberspectImpl,org.apache.velocity.tools.view.WebappUberspector 26 | 27 | # HTTP charset 28 | output.encoding = UTF-8 29 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/NullKeyException.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.config; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | /** 23 | * 24 | * 25 | * @author Nathan Bubna 26 | * @version $Id: NullKeyException.java 511959 2007-02-26 19:24:39Z nbubna $ 27 | */ 28 | public class NullKeyException extends ConfigurationException 29 | { 30 | private static final long serialVersionUID = -3939817560016273430L; 31 | 32 | public NullKeyException(Data data) 33 | { 34 | super(data, "Key is null for data with value of '"+data.getValue()+'\''); 35 | } 36 | 37 | public NullKeyException(ToolConfiguration tool) 38 | { 39 | super(tool, "Key is null for tool whose class is '"+tool.getClassname()+'\''); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-simple/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 25 | 26 | velocity 27 | org.apache.velocity.tools.view.VelocityViewServlet 28 | 29 | 30 | velocity 31 | *.vm 32 | 33 | 34 | index.vm 35 | 36 | 37 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/JsonToolTests.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.generic; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import org.junit.Test; 23 | 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | import static org.junit.Assert.assertEquals; 28 | 29 | /** 30 | *

Tests for {@link JsonTool}

31 | * 32 | * @author Claude Brisson 33 | * @since VelocityTools 3.0 34 | * @version $Id$ 35 | */ 36 | public class JsonToolTests 37 | { 38 | 39 | public @Test void testJson() throws Exception 40 | { 41 | Map config = new HashMap(); 42 | config.put("resource", "foo.json"); 43 | JsonTool jsonTool = new JsonTool(); 44 | jsonTool.configure(config); 45 | assertEquals(jsonTool.get("foo"), "bar"); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/layout/Default.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | 18 | 20 | 21 | #set( $stylesheet = '/layout/layout.css' ) 22 | #set( $css = $text.css ) 23 | #parse( 'header.vm' ) 24 | 25 |
26 |

$text.appname: $css.name

27 |

$screen_content

28 |
29 | 30 | 39 | 40 | 48 | 49 | 50 | 51 | #parse( 'footer.vm' ) 52 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/cookies.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'CookieTool' ) 18 |

19 | $text.demo.thisPage.insert("#doclink( 'CookieTool' false )"). 20 | $text.cookies.intro 21 |

22 | 23 | ## The demo.vm template expects the following values to be set 24 | #set( $toollink = $doclink ) 25 | #set( $toolname = 'cookies' ) 26 | #set( $toolclass = $cookies.class ) 27 | #set( $toolDemo = 28 | "${esc.h}foreach( ${esc.d}cookie in ${esc.d}cookies.all ) 29 | ${esc.d}cookie.name = ${esc.d}cookie.value 30 | Expiry ${esc.d}cookie.maxAge 31 | Domain ${esc.d}cookie.domain 32 | Comment ${esc.d}cookie.comment 33 | Version ${esc.d}cookie.version 34 | Secure ${esc.d}cookie.secure 35 | ${esc.h}end" ) 36 | 37 | #set( $skipAll = [ 'setRequest', 'setResponse', 'setLog' ] ) 38 | #parse( 'demo.vm' ) 39 | 40 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/DefaultKey.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.config; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.lang.annotation.Documented; 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Inherited; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | /** 30 | * Annotation specifying the default key to use for a tool class in the 31 | * case none was specified. 32 | * 33 | * @author Nathan Bubna 34 | * @version $Id: DefaultKey.java 511959 2007-02-26 19:24:39Z nbubna $ 35 | */ 36 | @Documented 37 | @Target(ElementType.TYPE) 38 | @Retention(RetentionPolicy.RUNTIME) 39 | @Inherited 40 | public @interface DefaultKey 41 | { 42 | String value(); 43 | } 44 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/Error.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | 18 | ## Force use of default layout (so req params don't override it) 19 | #set( $layout = "Default.vm" ) 20 | #title( "Error - $!cause.class.name" ) 21 | 22 |
23 |

$text.error.header

24 |
25 | 26 | #if( $invocation_exception ) 27 | $!invocation_exception.message 28 | #else 29 | $!cause.message 30 | #end 31 | 32 |
33 |
34 |
35 | #if( $invocation_exception )
36 | oh joy! it's a MethodInvocationException!
37 | 
38 | Reference name: $invocation_exception.referenceName
39 | Method name: $invocation_exception.methodName
40 | #end
41 | 
42 | Alright, here's the stack.  Good luck.
43 | 
44 | $stack_trace
45 | 
46 |
47 |

$text.error.sorry

48 |
49 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/alternator.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'AlternatorTool' ) 18 |

19 | $text.demo.thisPage.insert("#doclink( 'AlternatorTool' true )"). 20 | #set( $toollink = $doclink ) 21 | $text.alternator.intro.insert("#doclink( 'Alternator' true )") 22 |

23 | 24 | ## The demo.vm template expects the following values to be set 25 | #set( $toolname = 'alternator' ) 26 | #set( $toolclass = $alternator.class ) 27 | #set( $toolDemo = 28 | "${esc.h}set( ${esc.d}color = ${esc.d}alternator.auto('red', 'blue') ) 29 | ${esc.h}${esc.h} use manual alternation for this one 30 | ${esc.h}set( ${esc.d}style = ${esc.d}alternator.manual(['hip','fly','groovy']) ) 31 | ${esc.h}foreach( ${esc.d}i in [1..5] ) 32 | Number ${esc.d}i is ${esc.d}color and ${esc.d}style. I dig $style.next numbers. 33 | ${esc.h}end" 34 | ) 35 | 36 | #parse( 'demo.vm' ) 37 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/import.vm: -------------------------------------------------------------------------------- 1 | ## regarding copyright ownership. The ASF licenses this file 2 | ## to you under the Apache License, Version 2.0 (the 3 | ## "License"); you may not use this file except in compliance 4 | ## with the License. You may obtain a copy of the License at 5 | ## 6 | ## http://www.apache.org/licenses/LICENSE-2.0 7 | ## 8 | ## Unless required by applicable law or agreed to in writing, 9 | ## software distributed under the License is distributed on an 10 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 | ## KIND, either express or implied. See the License for the 12 | ## specific language governing permissions and limitations 13 | ## under the License. 14 | #title( 'ImportTool' ) 15 |

16 | #set( $demo = $text.demo ) 17 | $demo.thisPage.insert("#doclink( 'ImportTool' false )"). 18 |

19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 41 | 42 | 43 | 44 | 45 | #demoCustom( 'import' ) 46 |
$demo.function$demo.result$demo.description
29 | ${esc.d}import.read('') 30 | 32 | #if( $params.read ) 33 | $esc.html($import.read($params.read)) 34 | #else 35 | 36 |
37 | Please note that the results will be html-escaped by the 38 | EscapeTool for the purposes of this demo. 39 | #end 40 |
Returns the content read from the specified URL
47 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/display.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'DisplayTool' ) 18 |

19 | $text.demo.thisPage.insert("#doclink( 'DisplayTool' true )"). 20 | $text.get('display.intro') 21 |

22 | 23 | #set( $toolname = 'display' ) 24 | #set( $toolclass = $display.class ) 25 | #set( $toollink = $doclink ) 26 | #set( $toolDemo = 27 | "${esc.h}set( ${esc.d}primes = [1, 2, 3, 5, 7, 11] ) 28 | ${esc.d}display.list(${esc.d}primes) 29 | ${esc.d}display.truncate('This sentence should be truncated at 30 characters.') 30 | ${esc.d}display.truncate('This will be cut at 15.', 15) 31 | ${esc.d}display.alt(${esc.d}primes) 32 | ${esc.d}display.alt(${esc.d}null, '--') 33 | ${esc.h}set( ${esc.d}demoSize = ${esc.d}display.measure(${esc.d}toolDemo) ) 34 | This demo is ${esc.d}demoSize.height lines with a max length of ${esc.d}demoSize.width chars." 35 | ) 36 | 37 | #parse( 'demo.vm' ) 38 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/Veltools128Tests.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.generic; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import org.apache.velocity.VelocityContext; 23 | 24 | /** 25 | * This class tests VELOCITY-762. 26 | */ 27 | public class Veltools128Tests extends BaseTestCase 28 | { 29 | public Veltools128Tests(String name) 30 | { 31 | super(name); 32 | } 33 | 34 | protected void setUpContext(VelocityContext context) 35 | { 36 | context.put("loop", new LoopTool()); 37 | } 38 | 39 | public void testLoopToolSync() 40 | { 41 | String template = 42 | "#foreach( $item in $loop.watch([1..3]).sync([3..5], 'other') )"+ 43 | "$item:$loop.other "+ 44 | "#end"; 45 | assertEvalEquals("1:3 2:4 3:5 ", template); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /velocity-tools-examples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 4.0.0 24 | 25 | 26 | org.apache.velocity.tools 27 | velocity-tools-parent 28 | 3.3-SNAPSHOT 29 | 30 | 31 | velocity-tools-examples 32 | pom 33 | 34 | Apache Velocity Tools - Examples 35 | Examples to show how to use Velocity Tools 36 | 37 | 38 | velocity-tools-examples-showcase 39 | velocity-tools-examples-simple 40 | 41 | 42 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/SkipSetters.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.config; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.lang.annotation.Documented; 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Inherited; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | /** 30 | * Annotation specifying that {@link org.apache.velocity.tools.ToolInfo} 31 | * should only use the public void configure(Map) method for configuration of 32 | * a tool, and skip over the step of trying to find individual 33 | * property setters. 34 | * 35 | * @author Nathan Bubna 36 | * @version $Id: SkipSetters.java 511959 2007-02-26 19:24:39Z nbubna $ 37 | */ 38 | @Documented 39 | @Target(ElementType.TYPE) 40 | @Retention(RetentionPolicy.RUNTIME) 41 | @Inherited 42 | public @interface SkipSetters 43 | { 44 | } 45 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-simple/src/main/webapp/index.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | 18 | 19 | 20 | 21 | I'm a velocity template processed using the VelocityViewServlet. 22 | 23 | #if( $XHTML ) 24 | #set( $br = "
" ) 25 | #else 26 | #set( $br = "
" ) 27 | #end 28 | 29 | $br 30 | $br 31 | 32 | Here we use a custom tool: $toytool.message 33 | 34 | $br 35 | $br 36 | 37 | Lets count : #foreach($i in [1..5])$i #end 38 | 39 | $br 40 | $br 41 | 42 | Let's play with a hashmap:$br 43 | first add foo: $map.put("foo",$foo)$br 44 | then add bar: $map.put("bar",$bar)$br 45 | $br 46 | and that gives us $map 47 | 48 | $br 49 | $br 50 | 51 | Here we get the date from the DateTool: $date.medium 52 | 53 | $br 54 | $br 55 | 56 | #if( $isSimple ) 57 | This is simple#if( $XHTML ) xhtml#end app version ${version}. 58 | #end 59 | 60 | $br 61 | $br 62 | 63 | Click here to see the VelocityViewTag handle the same VTL markup. 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-simple/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@taglib prefix="velocity" uri="http://velocity.apache.org/velocity-view" %> 2 | <%-- 3 | Licensed to the Apache Software Foundation (ASF) under one 4 | or more contributor license agreements. See the NOTICE file 5 | distributed with this work for additional information 6 | regarding copyright ownership. The ASF licenses this file 7 | to you under the Apache License, Version 2.0 (the 8 | "License"); you may not use this file except in compliance 9 | with the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, 14 | software distributed under the License is distributed on an 15 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | KIND, either express or implied. See the License for the 17 | specific language governing permissions and limitations 18 | under the License. 19 | --%> 20 | 21 | 22 | 23 | I'm a JSP file that uses the VelocityViewTag. 24 | 25 | 26 | #if( $XHTML ) 27 | #set( $br = "
" ) 28 | #else 29 | #set( $br = "
" ) 30 | #end 31 | 32 | $br 33 | $br 34 | 35 | Here we use a custom tool: $toytool.message 36 | 37 | $br 38 | $br 39 | 40 | Lets count : #foreach($i in [1..5])$i #end 41 | 42 | $br 43 | $br 44 | 45 | Let's play with a hashmap:$br 46 | first add foo: $map.put("foo",$foo)$br 47 | then add bar: $map.put("bar",$bar)$br 48 | $br 49 | and that gives us $map 50 | 51 | $br 52 | $br 53 | 54 | Here we get the date from the DateTool: $date.medium 55 | 56 | $br 57 | $br 58 | 59 | #if( $isSimple ) 60 | This is simple#if( $XHTML ) xhtml#end app version ${version}. 61 | #end 62 | 63 | $br 64 | $br 65 | 66 | Click here to see this VTL markup as a normal template. 67 | 68 |
69 | 70 | 71 | -------------------------------------------------------------------------------- /velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/BreadcrumbToolTests.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.test.blackbox; 2 | 3 | import org.apache.velocity.tools.view.BreadcrumbTool; 4 | import org.junit.Test; 5 | 6 | import java.lang.reflect.InvocationHandler; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | /** 11 | * Breadcrumb tool tool tests 12 | * 13 | * @version $$ 14 | * @author Claude Brisson 15 | * @since 3.1 16 | */ 17 | 18 | public class BreadcrumbToolTests extends BaseToolTests 19 | { 20 | private BreadcrumbTool newBreadcrumbTool(String uri) throws Exception 21 | { 22 | return newBreadcrumbTool(new RequestAdaptor("", uri, null), new ResponseAdaptor()); 23 | } 24 | 25 | private BreadcrumbTool newBreadcrumbTool(InvocationHandler requestHandler, InvocationHandler responseHandler) throws Exception 26 | { 27 | return newTool(BreadcrumbTool.class, requestHandler, responseHandler); 28 | } 29 | 30 | @Test 31 | public void testBreadcrumb() throws Exception 32 | { 33 | Map params = new HashMap<>(); 34 | BreadcrumbTool bc = newBreadcrumbTool("/colors/red/nuances.vhtml"); 35 | bc.configure(params); 36 | assertEquals("home > colors > red > nuances", bc.toString()); 37 | 38 | params.put("home.name", "index"); 39 | params.put("home.url", "/welcome.vhtml"); 40 | params.put("nuances.name", "shades"); 41 | bc = newBreadcrumbTool("/colors/red/nuances.vhtml"); 42 | bc.configure(params); 43 | assertEquals("index > colors > red > shades", bc.toString()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/resources/org/apache/velocity/tools/generic/times.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | after=later 19 | before=earlier 20 | equal=same time 21 | zero=0 milliseconds 22 | current.after=away 23 | current.after.day=tomorrow 24 | current.before=ago 25 | current.before.day=yesterday 26 | current.equal=now 27 | 28 | millisecond=millisecond 29 | milliseconds=milliseconds 30 | second=second 31 | seconds=seconds 32 | minute=minute 33 | minutes=minutes 34 | hour=hour 35 | hours=hours 36 | day=day 37 | days=days 38 | week=week 39 | weeks=weeks 40 | month=month 41 | months=months 42 | year=year 43 | years=years 44 | 45 | 46 | # abbreviations 47 | after.abbr=later 48 | before.abbr=earlier 49 | equal.abbr=same 50 | zero.abbr=0 ms 51 | current.after.abbr=away 52 | current.before.abbr=ago 53 | current.equal.abbr=now 54 | 55 | millisecond.abbr=ms 56 | milliseconds.abbr=ms 57 | second.abbr=s 58 | seconds.abbr=s 59 | minute.abbr=min 60 | minutes.abbr=min 61 | hour.abbr=h 62 | hours.abbr=h 63 | day.abbr=d 64 | days.abbr=d 65 | week.abbr=w 66 | weeks.abbr=w 67 | month.abbr=m 68 | months.abbr=m 69 | year.abbr=y 70 | years.abbr=y 71 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/InvalidScopeException.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.config; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | /** 23 | * 24 | * 25 | * @author Nathan Bubna 26 | * @version $Id: InvalidScopeException.java 511959 2007-02-26 19:24:39Z nbubna $ 27 | */ 28 | public class InvalidScopeException extends ConfigurationException 29 | { 30 | private static final long serialVersionUID = -8551578237473304915L; 31 | 32 | // this isn't crucial to keep around if the exception is serialized 33 | private final transient ToolConfiguration tool; 34 | 35 | public InvalidScopeException(ToolboxConfiguration toolbox, 36 | ToolConfiguration tool) 37 | { 38 | super(toolbox, "Toolbox with scope '" + 39 | toolbox.getScope() + 40 | "' may not contain a " + 41 | tool.getClassname() + '.'); 42 | this.tool = tool; 43 | } 44 | 45 | public ToolConfiguration getToolConfiguration() 46 | { 47 | return tool; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/test/java/tools.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | import java.util.Locale; 21 | import org.apache.velocity.tools.config.EasyFactoryConfiguration; 22 | import org.apache.velocity.tools.config.FactoryConfiguration; 23 | import org.apache.velocity.tools.generic.MathTool; 24 | import org.apache.velocity.tools.generic.NumberTool; 25 | import org.apache.velocity.tools.generic.ResourceTool; 26 | 27 | /** 28 | * Test java configuration class 29 | * 30 | * @author Nathan Bubna 31 | * @version $Id: tools.java 511959 2007-02-26 19:24:39Z nbubna $ 32 | */ 33 | public class tools 34 | { 35 | public static FactoryConfiguration getConfiguration() 36 | { 37 | EasyFactoryConfiguration easy = new EasyFactoryConfiguration(); 38 | easy.number("version", 2.0); 39 | easy.toolbox("request") 40 | .property("locale", Locale.US) 41 | .tool(ResourceTool.class); 42 | easy.toolbox("application") 43 | .tool("calc", MathTool.class) 44 | .tool(NumberTool.class) 45 | .property("locale", Locale.FRENCH); 46 | return easy; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/template.txt: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | 18 |

19 | #set( $demo = $text.demo ) 20 | $demo.thisPage.insert("#doclink( 'FooTool' true )"). 21 |

22 | 23 | #demoTableStart() 24 | 25 | #set( $quote = '' ) 26 | #set( $desc = "" ) 27 | #demo( 'foo' '' $desc ) 28 | 29 | #set( $desc = '' ) 30 | #demo1( 'foo' '' 3 $desc) 31 | 32 | #set( $desc = "" ) 33 | #demo2( 'foo' '' 5 $desc ) 34 | 35 | #demoCustom( 'foo' ) 36 | 37 | 38 |
39 |

$demo.mainExampleHeader

40 |
41 | 50 |
51 | 52 | #if( $params.layout ) 53 | 54 | #end 55 |
56 | 57 | #if( $params.demo ) 58 | $demo.mainResultsIntro: 59 |
60 |   $render.eval($params.demo)
61 | 
62 | #end 63 |
64 | 65 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/mill.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'IteratorTool' ) 18 |

19 | #set( $demo = $text.demo ) 20 | $demo.thisPage.insert("#doclink( 'IteratorTool' true )"). 21 | This tool is a convenience tool to use with ${esc.h}foreach loops. It wraps a 22 | list to let the designer specify a condition to terminate the loop, 23 | and reuse the same list in different loops. 24 |

25 | 26 |
27 | 41 | 42 | #if( $params.layout ) 43 | 44 | #end 45 |
46 | 47 | #if( $params.demo ) 48 | $demo.mainResultsIntro: 49 |
50 |   $render.eval($params.demo)
51 | 
52 | #end 53 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/toolmenu.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #if( $params.layout ) 18 | #set( $llink = $link.layout($params.layout) ) 19 | #else 20 | #set( $llink = $link) 21 | #end 22 | #set( $tools = $text.tools ) 23 |

$tools.header:

24 |
    25 | #toolMenuItem( $llink 'alternator' ) 26 | #toolMenuItem( $llink 'browser' ) 27 | #toolMenuItem( $llink 'class' ) 28 | #toolMenuItem( $llink 'collection' ) 29 | #toolMenuItem( $llink 'context' ) 30 | #toolMenuItem( $llink 'convert' ) 31 | #toolMenuItem( $llink 'cookies' ) 32 | #toolMenuItem( $llink 'date' ) 33 | #toolMenuItem( $llink 'display' ) 34 | #toolMenuItem( $llink 'esc' ) 35 | #toolMenuItem( $llink 'field' ) 36 | #toolMenuItem( $llink 'import' ) 37 | #toolMenuItem( $llink 'include' ) 38 | #toolMenuItem( $llink 'json' ) 39 | #toolMenuItem( $llink 'jsp' ) 40 | #toolMenuItem( $llink 'link' ) 41 | #toolMenuItem( $llink 'loop' ) 42 | #toolMenuItem( $llink 'math' ) 43 | #toolMenuItem( $llink 'number' ) 44 | #toolMenuItem( $llink 'pager' ) 45 | #toolMenuItem( $llink 'params' ) 46 | #toolMenuItem( $llink 'render' ) 47 | #toolMenuItem( $llink 'text' ) 48 | #toolMenuItem( $llink 'search' ) 49 | #toolMenuItem( $llink 'sorter' ) 50 | #toolMenuItem( $llink 'xml' ) 51 |
52 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/package.html: -------------------------------------------------------------------------------- 1 | 19 | 20 | 21 | 22 | 27 | 28 | 29 | 30 | Contains a collection of reusable, general-purpose "tools" for Velocity. 31 | These tools are independent of the VelocityView classes and may be used 32 | in any context. 33 | 34 | 40 | 41 |

Package Specification

42 | 43 | 49 | 50 |

Related Documentation

51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /velocity-tools-view/src/main/java/org/apache/velocity/tools/view/package.html: -------------------------------------------------------------------------------- 1 | 19 | 20 | 21 | 22 | 27 | 28 | 29 | 30 | Contains tools and supporting infrastructure for using 31 | those tools in a servlet environment as well as general 32 | use classes to support use of Velocity as (or in) the 33 | view layer of web applications. 34 | 35 | 41 | 42 |

Package Specification

43 | 44 | 50 | 51 |

Related Documentation

52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/java/org/apache/velocity/tools/examples/showcase/tool/LayoutLinkTool.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.examples.showcase.tool; 2 | /* 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | import org.apache.velocity.tools.view.LinkTool; 22 | import org.apache.velocity.tools.view.VelocityLayoutServlet; 23 | 24 | /** 25 | * This is meant to demonstrate how to extend the LinkTool to 26 | * avoid the manual use of "magic" or common query parameters. 27 | * So instead of doing $link.param('layout', 'Table.vm') in your 28 | * template, you would just do $link.layout('Table'). 29 | * 30 | * @author Nathan Bubna 31 | * @version $Id: LayoutLinkTool.java 479724 2006-11-27 18:49:37Z nbubna $ 32 | */ 33 | public class LayoutLinkTool extends LinkTool 34 | { 35 | 36 | private static final long serialVersionUID = -3140621321122037963L; 37 | 38 | public LayoutLinkTool layout(Object obj) 39 | { 40 | if (obj == null) 41 | { 42 | return null; 43 | } 44 | return layout(obj.toString()); 45 | } 46 | 47 | public LayoutLinkTool layout(String layout) 48 | { 49 | if (layout != null && !layout.endsWith(".vm")) 50 | { 51 | layout += ".vm"; 52 | } 53 | return (LayoutLinkTool)param(VelocityLayoutServlet.KEY_LAYOUT, layout); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /velocity-tools-view-jsp/src/main/java/org/apache/velocity/tools/view/jsp/jspimpl/VelocityToolsJspException.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.view.jsp.jspimpl; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | /** 23 | * An exception thrown when something bad happens in JSP support for Velocity. 24 | * 25 | */ 26 | public class VelocityToolsJspException extends RuntimeException 27 | { 28 | 29 | /** 30 | * The serial version UID. 31 | */ 32 | private static final long serialVersionUID = 7627800888526325645L; 33 | 34 | /** 35 | * Constructor. 36 | */ 37 | public VelocityToolsJspException() 38 | { 39 | } 40 | 41 | /** 42 | * Constructor. 43 | * 44 | * @param message The message of the exception. 45 | */ 46 | public VelocityToolsJspException(String message) 47 | { 48 | super(message); 49 | } 50 | 51 | /** 52 | * Constructor. 53 | * 54 | * @param cause The cause. 55 | */ 56 | public VelocityToolsJspException(Throwable cause) 57 | { 58 | super(cause); 59 | } 60 | 61 | /** 62 | * Constructor. 63 | * 64 | * @param message The message of the exception. 65 | * @param cause The cause. 66 | */ 67 | public VelocityToolsJspException(String message, Throwable cause) 68 | { 69 | super(message, cause); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /velocity-tools-view/src/main/resources/org/apache/velocity/tools/view/tools.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /velocity-tools-view-jsp/src/main/java/org/apache/velocity/tools/view/jsp/jspimpl/ExternalWriterHttpServletResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: ExternalWriterHttpServletResponse.java 892369 2009-12-18 20:21:36Z apetrelli $ 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.apache.velocity.tools.view.jsp.jspimpl; 23 | 24 | import java.io.PrintWriter; 25 | 26 | import javax.servlet.http.HttpServletResponse; 27 | import javax.servlet.http.HttpServletResponseWrapper; 28 | 29 | /** 30 | * Copied from Tiles Request sandbox. 31 | * 32 | * Wraps an HTTP response and overrides its print writer. 33 | * 34 | * @version $Rev: 892369 $ $Date: 2009-12-18 21:21:36 +0100 (ven, 18 dic 2009) $ 35 | * @since 2.2.0 36 | */ 37 | public class ExternalWriterHttpServletResponse extends 38 | HttpServletResponseWrapper { 39 | 40 | /** 41 | * The print writer to use, instead of the response's one. 42 | */ 43 | private PrintWriter writer; 44 | 45 | /** 46 | * Constructor. 47 | * 48 | * @param response The response to wrap. 49 | * @param writer The print writer to use, instead of the response's one. 50 | * @since 2.2.0 51 | */ 52 | public ExternalWriterHttpServletResponse(HttpServletResponse response, PrintWriter writer) { 53 | super(response); 54 | this.writer = writer; 55 | } 56 | 57 | /** {@inheritDoc} */ 58 | @Override 59 | public PrintWriter getWriter() { 60 | return writer; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /velocity-tools-view-jsp/src/test/java/org/apache/velocity/tools/view/jsp/jspimpl/ExternalWriterHttpServletResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: ExternalWriterHttpServletResponseTest.java 892369 2009-12-18 20:21:36Z apetrelli $ 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package org.apache.velocity.tools.view.jsp.jspimpl; 23 | 24 | import static org.junit.Assert.*; 25 | import static org.easymock.EasyMock.*; 26 | 27 | import java.io.IOException; 28 | import java.io.PrintWriter; 29 | import java.io.StringWriter; 30 | import java.io.Writer; 31 | 32 | import javax.servlet.http.HttpServletResponse; 33 | 34 | import org.junit.Test; 35 | 36 | /** 37 | * Tests {@link ExternalWriterHttpServletResponse}. 38 | */ 39 | public class ExternalWriterHttpServletResponseTest { 40 | 41 | /** 42 | * Test method for {@link org.apache.tiles.request.servlet.ExternalWriterHttpServletResponse#getWriter()}. 43 | * @throws IOException If something goes wrong. 44 | */ 45 | @Test 46 | public void testGetWriter() { 47 | HttpServletResponse wrappedResponse = createMock(HttpServletResponse.class); 48 | Writer writer = new StringWriter(); 49 | PrintWriter printWriter = new PrintWriter(writer); 50 | replay(wrappedResponse); 51 | ExternalWriterHttpServletResponse response = new ExternalWriterHttpServletResponse( 52 | wrappedResponse, printWriter); 53 | assertEquals(printWriter, response.getWriter()); 54 | verify(wrappedResponse); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/WEB-INF/tools.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 23 | Nathan Bubna 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /velocity-tools-view/src/main/java/org/apache/velocity/tools/view/JeeContextConfig.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.view; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.util.Enumeration; 23 | import javax.servlet.ServletContext; 24 | 25 | /** 26 | * Implements {@link JeeConfig} with only a {@link ServletContext}. 27 | * 28 | * @version $Id$ 29 | * @since 2.0 30 | */ 31 | public class JeeContextConfig implements JeeConfig 32 | { 33 | protected ServletContext context; 34 | 35 | public JeeContextConfig(ServletContext context) 36 | { 37 | if (context == null) 38 | { 39 | throw new NullPointerException("ServletContext should not be null; there must be a way to get a ServletContext"); 40 | } 41 | this.context = context; 42 | } 43 | 44 | /** {@inheritDoc} */ 45 | public String getInitParameter(String name) 46 | { 47 | return null; 48 | } 49 | 50 | /** 51 | * Only checks the {@link ServletContext}'s init-params 52 | * for the specified parameter. 53 | */ 54 | public String findInitParameter(String key) 55 | { 56 | return context.getInitParameter(key); 57 | } 58 | 59 | /** {@inheritDoc} */ 60 | public Enumeration getInitParameterNames() 61 | { 62 | return null; 63 | } 64 | 65 | /** {@inheritDoc} */ 66 | public String getName() 67 | { 68 | return null; 69 | } 70 | 71 | /** {@inheritDoc} */ 72 | public ServletContext getServletContext() 73 | { 74 | return context; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/render.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'ViewRenderTool' ) 18 |

19 | #set( $demo = $text.demo ) 20 | $demo.thisPage.insert("#doclink( 'RenderTool' true )"). 21 |

22 | 23 | #demoTableStart() 24 | 25 | #set( $quote = "'" ) 26 | #set( $desc = 'Evaluates a String containing VTL using the current context, and returns the result as a String.' ) 27 | #demo1( 'render' 'eval' 15 $desc) 28 | 29 | #set( $desc = 'Recursively evaluates a String containing VTL using the current context, and returns the result as a String.' ) 30 | #demo1( 'render' 'recurse' 15 $desc ) 31 | 32 | #demoCustom( 'render' ) 33 | 34 | 35 |
36 |

$demo.mainExampleHeader

37 |
38 | 55 |
56 | 57 | #if( $params.layout ) 58 | 59 | #end 60 |
61 | 62 | #if( $params.demo ) 63 | $demo.mainResultsIntro: 64 |
65 |   $render.eval($params.demo)
66 | 
67 | #end 68 |
69 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/fullDemo.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | 18 | ## make sure we have access to demo resources 19 | #if( !$demo ) 20 | #set( $demo = $text.demo ) 21 | #end 22 | 23 | ## look for a full demo in the params 24 | #set( $fullDemo = $params.fullDemo ) 25 | #if( !$fullDemo ) 26 | ## see if one was set in the parent template 27 | #if( $toolDemo ) 28 | #set( $fullDemo = $toolDemo ) 29 | #else 30 | ## ok, try looking for one in the resources 31 | #set( $fullDemo = $text.get("${toolname}.fullDemo") ) 32 | #if( !$fullDemo.exists ) 33 | ## give up and hide the full demo 34 | #set( $fullDemo = false ) 35 | #end 36 | #end 37 | #end 38 | 39 | #if( $fullDemo ) 40 | #set( $dims = $display.measure($fullDemo) ) 41 |
42 |

$demo.mainExampleHeader

43 |
44 | 45 |
46 | 47 | ## maintain params for all the other demos 48 | #foreach( $param in $params.all.keySet() ) 49 | #if( $param != 'fullDemo' ) 50 | #foreach( $value in $params.getStrings($param) ) 51 | 52 | #end 53 | #end 54 | #end 55 |
56 | ## evaluate and display results if they hit submit 57 | #if( $params.fullDemo ) 58 | $demo.mainResultsIntro: 59 |
60 |         $render.eval($params.fullDemo)
61 |       
62 | #end 63 |
64 | #end 65 | -------------------------------------------------------------------------------- /velocity-tools-view/src/main/java/org/apache/velocity/tools/view/JeeFilterConfig.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.view; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.util.Enumeration; 23 | import javax.servlet.FilterConfig; 24 | import javax.servlet.ServletContext; 25 | 26 | /** 27 | * Implements {@link JeeConfig} with a {@link FilterConfig}. 28 | * 29 | * @version $Id$ 30 | * @since 2.0 31 | */ 32 | public class JeeFilterConfig implements JeeConfig 33 | { 34 | protected FilterConfig filter; 35 | 36 | public JeeFilterConfig(FilterConfig filter) 37 | { 38 | if (filter == null) 39 | { 40 | throw new NullPointerException("FilterConfig should not be null; there must be a way to get a ServletContext"); 41 | } 42 | this.filter = filter; 43 | } 44 | 45 | /** {@inheritDoc} */ 46 | public String getInitParameter(String name) 47 | { 48 | return filter.getInitParameter(name); 49 | } 50 | 51 | /** {@inheritDoc} */ 52 | public String findInitParameter(String key) 53 | { 54 | String param = getInitParameter(key); 55 | if (param == null) 56 | { 57 | param = getServletContext().getInitParameter(key); 58 | } 59 | return param; 60 | } 61 | 62 | /** {@inheritDoc} */ 63 | public Enumeration getInitParameterNames() 64 | { 65 | return filter.getInitParameterNames(); 66 | } 67 | 68 | /** {@inheritDoc} */ 69 | public String getName() 70 | { 71 | return filter.getFilterName(); 72 | } 73 | 74 | /** {@inheritDoc} */ 75 | public ServletContext getServletContext() 76 | { 77 | return filter.getServletContext(); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /velocity-tools-view-jsp/src/main/java/org/apache/velocity/tools/view/jsp/jspimpl/VelocityJspFragment.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.view.jsp.jspimpl; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.io.IOException; 23 | import java.io.Writer; 24 | 25 | import javax.servlet.jsp.JspContext; 26 | import javax.servlet.jsp.JspException; 27 | import javax.servlet.jsp.PageContext; 28 | import javax.servlet.jsp.tagext.JspFragment; 29 | 30 | import org.apache.velocity.context.InternalContextAdapter; 31 | import org.apache.velocity.runtime.parser.node.ASTBlock; 32 | 33 | /** 34 | * Exposes a directive body block as a {@link JspFragment}, i.e. the body of SimpleTag. 35 | * 36 | */ 37 | public class VelocityJspFragment extends JspFragment 38 | { 39 | 40 | /** 41 | * The JSP page context. 42 | */ 43 | private PageContext pageContext; 44 | 45 | /** 46 | * The block to wrap. 47 | */ 48 | private ASTBlock block; 49 | 50 | /** 51 | * The directive context. 52 | */ 53 | private InternalContextAdapter context; 54 | 55 | /** 56 | * Constructor. 57 | * 58 | * @param pageContext The page context to use. 59 | * @param block The block to wrap. 60 | * @param context The directive context. 61 | */ 62 | public VelocityJspFragment(PageContext pageContext, ASTBlock block, 63 | InternalContextAdapter context) 64 | { 65 | this.pageContext = pageContext; 66 | this.block = block; 67 | this.context = context; 68 | } 69 | 70 | @Override 71 | public void invoke(Writer out) throws JspException, IOException 72 | { 73 | block.render(context, out); 74 | } 75 | 76 | @Override 77 | public JspContext getJspContext() 78 | { 79 | return pageContext; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/FormatConfig.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.generic; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | /** 23 | * Implements common logic and constants for tools which allow their 24 | * default format to be configured. 25 | * 26 | * @author Nathan Bubna 27 | * @since VelocityTools 2.0 28 | */ 29 | public class FormatConfig extends LocaleConfig 30 | { 31 | /** 32 | * The default format to be used when none is specified. 33 | */ 34 | public static final String DEFAULT_FORMAT = "default"; 35 | 36 | /** 37 | * The key used for specifying a default format via tool configuration. 38 | */ 39 | public static final String FORMAT_KEY = "format"; 40 | 41 | private String format = DEFAULT_FORMAT; 42 | 43 | /** 44 | * Does the actual configuration. This is protected, so 45 | * subclasses may share the same ValueParser and call configure 46 | * at any time, while preventing templates from doing so when 47 | * configure(Map) is locked. 48 | */ 49 | protected void configure(ValueParser values) 50 | { 51 | super.configure(values); 52 | 53 | String format = values.getString(FORMAT_KEY); 54 | if (format != null) 55 | { 56 | setFormat(format); 57 | } 58 | } 59 | 60 | /** 61 | * This returns the configured default format for this tool. 62 | * 63 | * @return the default {@link String} 64 | */ 65 | public String getFormat() 66 | { 67 | return this.format; 68 | } 69 | 70 | /** 71 | * Sets the default format for this instance. 72 | * @param format default format 73 | */ 74 | protected void setFormat(String format) 75 | { 76 | this.format = format; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /velocity-tools-view/src/main/java/org/apache/velocity/tools/view/JeeServletConfig.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.view; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.util.Enumeration; 23 | import javax.servlet.ServletConfig; 24 | import javax.servlet.ServletContext; 25 | 26 | /** 27 | * Implements {@link JeeConfig} with a {@link ServletConfig}. 28 | * 29 | * @version $Id$ 30 | * @since 2.0 31 | */ 32 | public class JeeServletConfig implements JeeConfig 33 | { 34 | protected ServletConfig servlet; 35 | 36 | public JeeServletConfig(ServletConfig servlet) 37 | { 38 | if (servlet == null) 39 | { 40 | throw new NullPointerException("ServletConfig should not be null; there must be a way to get a ServletContext"); 41 | } 42 | this.servlet = servlet; 43 | } 44 | 45 | /** {@inheritDoc} */ 46 | public String getInitParameter(String name) 47 | { 48 | return servlet.getInitParameter(name); 49 | } 50 | 51 | /** {@inheritDoc} */ 52 | public String findInitParameter(String key) 53 | { 54 | String param = getInitParameter(key); 55 | if (param == null) 56 | { 57 | param = getServletContext().getInitParameter(key); 58 | } 59 | return param; 60 | } 61 | 62 | /** {@inheritDoc} */ 63 | public Enumeration getInitParameterNames() 64 | { 65 | return servlet.getInitParameterNames(); 66 | } 67 | 68 | /** {@inheritDoc} */ 69 | public String getName() 70 | { 71 | return servlet.getServletName(); 72 | } 73 | 74 | /** {@inheritDoc} */ 75 | public ServletContext getServletContext() 76 | { 77 | return servlet.getServletContext(); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-simple/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 4.0.0 24 | 25 | 26 | org.apache.velocity.tools 27 | velocity-tools-examples 28 | 3.3-SNAPSHOT 29 | 30 | 31 | velocity-tools-examples-simple 32 | war 33 | 34 | Apache Velocity Tools Examples - Simple 35 | Simple webapp based on Velocity Tools 36 | 37 | 38 | 39 | javax.servlet 40 | javax.servlet-api 41 | provided 42 | 43 | 44 | javax.servlet.jsp 45 | javax.servlet.jsp-api 46 | provided 47 | 48 | 49 | org.apache.velocity.tools 50 | velocity-tools-view 51 | ${project.version} 52 | runtime 53 | 54 | 55 | org.apache.velocity.tools 56 | velocity-tools-view-jsp 57 | ${project.version} 58 | runtime 59 | 60 | 61 | org.slf4j 62 | slf4j-simple 63 | runtime 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/ConfigurationException.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.config; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | /** 23 | * 24 | * 25 | * @author Nathan Bubna 26 | * @version $Id: ConfigurationException.java 511959 2007-02-26 19:24:39Z nbubna $ 27 | */ 28 | public class ConfigurationException extends RuntimeException 29 | { 30 | private static final long serialVersionUID = -561545916548921830L; 31 | 32 | private final Object source; 33 | 34 | public ConfigurationException(String message) 35 | { 36 | super(message); 37 | source = null; 38 | } 39 | 40 | public ConfigurationException(String message, Throwable cause) 41 | { 42 | super(message, cause); 43 | source = null; 44 | } 45 | 46 | public ConfigurationException(Data data, Throwable cause) 47 | { 48 | super(cause); 49 | this.source = data; 50 | } 51 | 52 | public ConfigurationException(Data data, String message) 53 | { 54 | super(message); 55 | this.source = data; 56 | } 57 | 58 | public ConfigurationException(Data data, String message, Throwable cause) 59 | { 60 | super(message, cause); 61 | this.source = data; 62 | } 63 | 64 | public ConfigurationException(Configuration config, Throwable cause) 65 | { 66 | super(cause); 67 | this.source = config; 68 | } 69 | 70 | public ConfigurationException(Configuration config, String message) 71 | { 72 | super(message); 73 | this.source = config; 74 | } 75 | 76 | public ConfigurationException(Configuration config, String message, Throwable cause) 77 | { 78 | super(message, cause); 79 | this.source = config; 80 | } 81 | 82 | public Object getSource() 83 | { 84 | return source; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 25 | 26 | 27 | velocity 28 | org.apache.velocity.tools.examples.showcase.ShowcaseLayoutServlet 29 | 30 | 31 | velocity-standard 32 | org.apache.velocity.tools.view.VelocityViewServlet 33 | 34 | 35 | 36 | velocity-standard 37 | nolayout/* 38 | 39 | 40 | velocity 41 | *.vm 42 | 43 | 44 | 45 | org.apache.velocity.tools.loadDefaults 46 | true 47 | 48 | 49 | org.apache.velocity.tools.cleanConfiguration 50 | true 51 | 52 | 53 | org.apache.velocity.tools.userCanOverwriteTools 54 | false 55 | 56 | 57 | 58 | index.vm 59 | 60 | 61 | 62 | org.apache.velocity.tools.examples.showcase.sample.SampleListInitializer 63 | 64 | 65 | -------------------------------------------------------------------------------- /velocity-tools-view-jsp/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 4.0.0 24 | 25 | 26 | org.apache.velocity.tools 27 | velocity-tools-parent 28 | 3.3-SNAPSHOT 29 | 30 | 31 | velocity-tools-view-jsp 32 | 33 | Apache Velocity Tools - JSP support 34 | Enables the use of Velocity under a JSP environment. 35 | 36 | 37 | 38 | javax.servlet 39 | javax.servlet-api 40 | provided 41 | 42 | 43 | javax.servlet.jsp 44 | javax.servlet.jsp-api 45 | provided 46 | 47 | 48 | javax.el 49 | javax.el-api 50 | provided 51 | 52 | 53 | org.apache.velocity 54 | velocity-engine-core 55 | 56 | 57 | org.apache.velocity.tools 58 | velocity-tools-view 59 | ${project.version} 60 | 61 | 62 | junit 63 | junit 64 | test 65 | 66 | 67 | org.easymock 68 | easymock 69 | test 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /velocity-tools-view-jsp/src/main/java/org/apache/velocity/tools/view/jsp/JspToolContext.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.view.jsp; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | import javax.servlet.jsp.PageContext; 25 | import org.apache.velocity.app.VelocityEngine; 26 | import org.apache.velocity.tools.view.ViewToolContext; 27 | 28 | /** 29 | *

Velocity context implementation specific to the JSP environment.

30 | * 31 | * @author Nathan Bubna 32 | * @version $Id: ViewContext.java 514727 2007-03-05 16:49:03Z nbubna $ 33 | */ 34 | public class JspToolContext extends ViewToolContext 35 | { 36 | public static final String PAGE_CONTEXT_KEY = "pageContext"; 37 | 38 | private final PageContext pageContext; 39 | 40 | public JspToolContext(VelocityEngine velocity, 41 | PageContext pageContext) 42 | { 43 | super(velocity, 44 | (HttpServletRequest)pageContext.getRequest(), 45 | (HttpServletResponse)pageContext.getResponse(), 46 | pageContext.getServletContext()); 47 | 48 | this.pageContext = pageContext; 49 | } 50 | 51 | protected void putToolProperties() 52 | { 53 | putToolProperty(PAGE_CONTEXT_KEY, getPageContext()); 54 | 55 | super.putToolProperties(); 56 | } 57 | 58 | public PageContext getPageContext() 59 | { 60 | return this.pageContext; 61 | } 62 | 63 | protected Object getServletApi(String key) 64 | { 65 | if (key.equals(PAGE_CONTEXT_KEY)) 66 | { 67 | return getPageContext(); 68 | } 69 | return super.getServletApi(key); 70 | } 71 | 72 | public Object getAttribute(String key) 73 | { 74 | Object o = getPageContext().getAttribute(key); 75 | if (o == null) 76 | { 77 | o = super.getAttribute(key); 78 | } 79 | return o; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /velocity-tools-generic/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 4.0.0 24 | 25 | 26 | org.apache.velocity.tools 27 | velocity-tools-parent 28 | 3.3-SNAPSHOT 29 | 30 | 31 | velocity-tools-generic 32 | 33 | Apache Velocity Tools - Generic tools 34 | Generic tools that can be used in any context. 35 | 36 | 37 | 38 | org.apache.velocity 39 | velocity-engine-core 40 | 41 | 42 | commons-beanutils 43 | commons-beanutils 44 | 1.9.4 45 | 46 | 47 | org.apache.commons 48 | commons-digester3 49 | 50 | 51 | org.apache.commons 52 | commons-lang3 53 | 54 | 55 | org.slf4j 56 | slf4j-api 57 | 58 | 59 | com.github.cliftonlabs 60 | json-simple 61 | 4.0.1 62 | 63 | 64 | junit 65 | junit 66 | test 67 | 68 | 69 | org.slf4j 70 | slf4j-simple 71 | test 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/BaseToolTests.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.test.blackbox; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import org.apache.velocity.tools.ClassUtils; 23 | import org.junit.Assert; 24 | 25 | import javax.servlet.http.HttpServletRequest; 26 | import javax.servlet.http.HttpServletResponse; 27 | import java.lang.reflect.InvocationHandler; 28 | import java.lang.reflect.Method; 29 | import java.lang.reflect.Proxy; 30 | 31 | /** 32 | * A base class for blackbox tools testing 33 | * 34 | * @version $$ 35 | * @author Claude Brisson 36 | * @since 3.1 37 | */ 38 | 39 | public class BaseToolTests extends Assert 40 | { 41 | protected static T newTool(Class clazz, InvocationHandler requestHandler, InvocationHandler responseHandler) throws Exception 42 | { 43 | ClassLoader classLoader = BaseToolTests.class.getClassLoader(); 44 | Object requestProxy 45 | = Proxy.newProxyInstance(classLoader, 46 | new Class[] { HttpServletRequest.class }, 47 | requestHandler); 48 | 49 | Object responseProxy 50 | = Proxy.newProxyInstance(classLoader, 51 | new Class[] { HttpServletResponse.class }, 52 | responseHandler); 53 | 54 | HttpServletRequest request = (HttpServletRequest)requestProxy; 55 | HttpServletResponse response = (HttpServletResponse)responseProxy; 56 | 57 | T tool = clazz.getConstructor(new Class[] {}).newInstance(); 58 | invokeMethodOrNOP(tool, "setRequest", request, HttpServletRequest.class); 59 | invokeMethodOrNOP(tool, "setResponse", response, HttpServletResponse.class); 60 | return tool; 61 | } 62 | 63 | private static void invokeMethodOrNOP(Object tool, String methodName, Object singleArg, Class singleArgClass) throws Exception 64 | { 65 | Method method = ClassUtils.findMethod(tool.getClass(), methodName, new Class[] { singleArgClass }); 66 | if (method != null) 67 | { 68 | method.invoke(tool, new Object[] { singleArg }); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LogTool.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.generic; 2 | /* 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | import java.io.Serializable; 22 | import org.apache.velocity.tools.Scope; 23 | import org.apache.velocity.tools.config.DefaultKey; 24 | import org.apache.velocity.tools.config.ValidScope; 25 | 26 | /** 27 | *

28 | * This tool is used to log from within templates. 29 | *

30 | *

31 | * Of course, the desired log level must have been configured, using the method specific 32 | * to the SLF4J implementation you are using. For instance, when using the webapp-slf4j-logger, 33 | * you will use the following snippet of code in you /WEB-INF/web.xml file:

34 | *
35 |  * <context-param>
36 |  *   <param-name>webapp-slf4j-logger.level</param-name>
37 |  *   <param-value>debug</param-value>
38 |  * </context-param>
39 |  * 
40 | * 41 | *

You can optionnaly specify the logger name in the config (the default is to re-use the engine logger):

42 | *
43 |  * <tools>
44 |  *   <toolbox scope="application">
45 |  *     <tool class="org.apache.velocity.tools.generic.LogTool"/>
46 |  *   </toolbox>
47 |  * </tools>
48 |  * 
49 | * 50 | * @author Claude Brisson 51 | * @since VelocityTools 3.0 52 | * @version $Id: $ 53 | */ 54 | 55 | @DefaultKey("log") 56 | @ValidScope(Scope.APPLICATION) 57 | public class LogTool extends SafeConfig implements Serializable 58 | { 59 | private static final long serialVersionUID = 2081207016220808266L; 60 | 61 | public void error(String message) 62 | { 63 | getLog().error(message); 64 | } 65 | 66 | public void warn(String message) 67 | { 68 | getLog().warn(message); 69 | } 70 | 71 | public void info(String message) 72 | { 73 | getLog().info(message); 74 | } 75 | 76 | public void debug(String message) 77 | { 78 | getLog().debug(message); 79 | } 80 | 81 | public void trace(String message) 82 | { 83 | getLog().trace(message); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /velocity-tools-view/src/main/java/org/apache/velocity/tools/view/XmlTool.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.view; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import org.apache.velocity.tools.XmlUtils; 23 | import org.apache.velocity.tools.generic.ValueParser; 24 | 25 | import javax.servlet.ServletRequest; 26 | 27 | /** 28 | * View version of {@link org.apache.velocity.tools.generic.XmlTool}. It adds an automatic parsing of the HTTP query 29 | * body content, if it is found to be of JSON type. 30 | * 31 | * @author Claude Brisson 32 | * @since VelocityTools 3.0 33 | * @version $Id:$ 34 | */ 35 | 36 | public class XmlTool extends org.apache.velocity.tools.generic.XmlTool 37 | { 38 | private static final long serialVersionUID = 8975478801777360304L; 39 | 40 | /** 41 | * ImportSupport initialization. 42 | * @param config configuration values 43 | */ 44 | @Override 45 | protected synchronized void initializeImportSupport(ValueParser config) 46 | { 47 | if (importSupport == null) 48 | { 49 | importSupport = new ViewImportSupport(); 50 | importSupport.configure(config); 51 | } 52 | } 53 | 54 | /** 55 | * Configuration. Parses request body if appropriate. 56 | * @param values configuration values 57 | */ 58 | protected void configure(ValueParser values) 59 | { 60 | super.configure(values); 61 | if (isEmpty()) 62 | { 63 | ServletRequest request = (ServletRequest)values.get(ViewContext.REQUEST); 64 | if (request.getContentLength() > 0) 65 | { 66 | String mimeType = request.getContentType(); 67 | if (XmlUtils.isXmlMimeType(mimeType)) 68 | { 69 | try 70 | { 71 | setRoot(XmlUtils.parse(request.getReader())); 72 | } 73 | catch (Exception e) 74 | { 75 | getLog().error("could not parse given XML string", e); 76 | } 77 | } 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/resources/org/apache/velocity/tools/generic/tools.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/lists.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'ListTool' ) 18 |

19 | #set( $demo = $text.demo ) 20 | $demo.thisPage.insert("#doclink( 'ListTool' true )"). 21 | Once Velocity 1.6 is released, this tool will be obsolete since 22 | Velocity 1.6 now allows all List methods to be called directly on arrays 23 | within templates. 24 |

25 | 26 | #demoTableStart() 27 | 28 | ## set quote character to empty string so values are not treated as strings 29 | #set( $quote = '' ) 30 | 31 | #set( $desc = 'Checks if a List/array contains a certain element.' ) 32 | #demo2( 'lists' 'contains' 5 $desc ) 33 | 34 | #set( $desc = 'Gets the specified element of a List/array.' ) 35 | #demo2( 'lists' 'get' 5 $desc ) 36 | 37 | #set( $desc = 'Checks if an object is an array.' ) 38 | #demo1( 'lists' 'isArray' 3 $desc) 39 | 40 | #set( $desc = 'Checks if a List/array is empty.' ) 41 | #demo1( 'lists' 'isEmpty' 3 $desc) 42 | 43 | #set( $desc = 'Checks if an object is a List.' ) 44 | #demo1( 'lists' 'isList' 3 $desc) 45 | 46 | #set( $desc = 'Sets the specified element of a List/array.' ) 47 | #demo3( 'lists' 'set' 5 $desc ) 48 | 49 | #set( $desc = 'Gets the size of a List/array.' ) 50 | #demo1( 'lists' 'size' 3 $desc) 51 | 52 | #demoCustom( 'lists' ) 53 | 54 | 55 | #set( $primes = [1, 2, 3, 5, 7, 11] ) 56 |
57 |

$demo.mainExampleHeader

58 |
59 | 72 |
73 | 74 | #if( $params.layout ) 75 | 76 | #end 77 |
78 | 79 | #if( $params.demo ) 80 | $demo.mainResultsIntro: 81 |
82 |   $render.eval($params.demo)
83 | 
84 | #end 85 |
86 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/java/org/apache/velocity/tools/Scope.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.util.ArrayList; 23 | import java.util.Collections; 24 | import java.util.List; 25 | 26 | /** 27 | * A specialized constants class to provide some compile-time typo checking and 28 | * runtime validation for scopes specified in annotations, toolbox configs, etc. 29 | * 30 | * @author Nathan Bubna 31 | * @version $Id: Toolbox.java 511959 2007-02-26 19:24:39Z nbubna $ 32 | */ 33 | public final class Scope 34 | { 35 | public static final String REQUEST = "request"; 36 | public static final String SESSION = "session"; 37 | public static final String APPLICATION = "application"; 38 | 39 | private static final List VALUES; 40 | static 41 | { 42 | List defaults = new ArrayList(3); 43 | defaults.add(REQUEST); 44 | defaults.add(SESSION); 45 | defaults.add(APPLICATION); 46 | VALUES = Collections.synchronizedList(defaults); 47 | } 48 | 49 | // keep an instance available in case someone wants to 50 | // drop this into a template for some reason 51 | private static final Scope INSTANCE = new Scope(); 52 | 53 | public static final Scope getInstance() 54 | { 55 | return INSTANCE; 56 | } 57 | 58 | public static final void add(String newScope) 59 | { 60 | // keep everything lower case 61 | newScope = newScope.toLowerCase(); 62 | // complain if it already exists 63 | if (VALUES.contains(newScope)) 64 | { 65 | throw new IllegalArgumentException("Scope '"+newScope+"' has already been registered."); 66 | } 67 | VALUES.add(newScope); 68 | } 69 | 70 | public static final boolean exists(String scope) 71 | { 72 | // keep everything lower case 73 | scope = scope.toLowerCase(); 74 | return VALUES.contains(scope); 75 | } 76 | 77 | public static final List values() 78 | { 79 | return Collections.unmodifiableList(VALUES); 80 | } 81 | 82 | private Scope() 83 | { 84 | // keep constructor private, this is a singleton 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /velocity-tools-view/src/main/java/org/apache/velocity/tools/view/JeeConfig.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.view; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.util.Enumeration; 23 | import javax.servlet.ServletContext; 24 | 25 | /** 26 | *

Because sometimes you don't care about the difference between a 27 | * servlet and a filter. Why isn't there a common interface for 28 | * {@link JeeFilterConfig} and {@link JeeServletConfig} already? Sheesh.

29 | *

30 | * Anyway, this also adds the ability to fake everything if you don't have 31 | * either a FilterConfig or a ServletConfig handy. Just implement it and 32 | * override the methods that return things you care about. Oh, and if you don't 33 | * have any init-params at all, just use {@link JeeContextConfig} as 34 | * {@link ServletContext} is the only really essential thing for creating a 35 | * {@link VelocityView}.

36 | * 37 | * @version $Id$ 38 | * @since 2.0 39 | */ 40 | public interface JeeConfig 41 | { 42 | /** 43 | * Returns an initialization parameter. 44 | * 45 | * @param name The name of the initialization parameter. 46 | * @return The value of the parameter. 47 | */ 48 | String getInitParameter(String name); 49 | 50 | /** 51 | * Looks for the specified init-param in the servlet/filter config 52 | * (i.e. calls {@link #getInitParameter}). If no such init-param is 53 | * found there, it checks the {@link ServletContext}'s init-params 54 | * for the specified parameter. 55 | * 56 | * @param key The name of the initialization parameter. 57 | * @return The value of the initialization parameter. 58 | */ 59 | String findInitParameter(String key); 60 | 61 | /** 62 | * Returns all the parameter names. 63 | * 64 | * @return The enumeration containing the parameter names. 65 | */ 66 | @SuppressWarnings("unchecked") 67 | Enumeration getInitParameterNames(); 68 | 69 | /** 70 | * Returns the name of the servlet (or filter) being used. 71 | * 72 | * @return The name of the configuration. 73 | */ 74 | String getName(); 75 | 76 | /** 77 | * Returns the servlet context. 78 | * 79 | * @return The servlet context. 80 | */ 81 | ServletContext getServletContext(); 82 | 83 | } 84 | -------------------------------------------------------------------------------- /velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LocaleConfig.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.generic; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.util.Locale; 23 | 24 | import org.apache.velocity.tools.ConversionUtils; 25 | import org.apache.velocity.tools.ToolContext; 26 | 27 | /** 28 | * Implements common logic and constants for tools which allow their 29 | * default {@link Locale} to be configured. 30 | * 31 | * @author Nathan Bubna 32 | * @since VelocityTools 2.0 33 | */ 34 | public class LocaleConfig extends SafeConfig 35 | { 36 | /** 37 | * The default {@link Locale} to be used when none is specified. 38 | */ 39 | public static final Locale DEFAULT_LOCALE = Locale.getDefault(); 40 | 41 | private Locale locale = DEFAULT_LOCALE; 42 | 43 | /** 44 | * Does the actual configuration. This is protected, so 45 | * subclasses may share the same ValueParser and call configure 46 | * at any time, while preventing templates from doing so when 47 | * configure(Map) is locked. 48 | */ 49 | protected void configure(ValueParser values) 50 | { 51 | Locale locale = values.getLocale(ToolContext.LOCALE_KEY); 52 | if (locale != null) 53 | { 54 | setLocale(locale); 55 | } 56 | } 57 | 58 | /** 59 | * This returns the configured default {@link Locale} for this tool. 60 | * 61 | * @return the default {@link Locale} 62 | */ 63 | public Locale getLocale() 64 | { 65 | return this.locale; 66 | } 67 | 68 | /** 69 | * Sets the default locale for this instance. 70 | * @param locale default locale to use 71 | */ 72 | protected void setLocale(Locale locale) 73 | { 74 | this.locale = locale; 75 | } 76 | 77 | /** 78 | * @param value the object to be converted 79 | * @return a {@link Locale} for the specified value or 80 | * null if the value is null or the conversion failed 81 | * @since VelocityTools 3.0 82 | */ 83 | public Locale toLocale(Object value) 84 | { 85 | if (value == null) 86 | { 87 | return null; 88 | } 89 | else if (value instanceof Locale) 90 | { 91 | return (Locale)value; 92 | } 93 | return ConversionUtils.toLocale(String.valueOf(value)); 94 | } 95 | 96 | 97 | } 98 | -------------------------------------------------------------------------------- /velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/TestURLHandler.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.test.blackbox; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.io.ByteArrayInputStream; 23 | import java.io.IOException; 24 | import java.io.InputStream; 25 | import java.net.*; 26 | import java.nio.charset.StandardCharsets; 27 | import java.util.Map; 28 | import java.util.concurrent.ConcurrentHashMap; 29 | 30 | public class TestURLHandler 31 | { 32 | static final String TEST_PROTOCOL = "veltest"; 33 | static Map contentMap; 34 | static 35 | { 36 | contentMap = new ConcurrentHashMap(); 37 | URLStreamHandlerFactory factory = new URLStreamHandlerFactory() 38 | { 39 | @Override 40 | public URLStreamHandler createURLStreamHandler(String protocol) 41 | { 42 | URLStreamHandler handler = null; 43 | if (TEST_PROTOCOL.equals(protocol)) 44 | { 45 | handler = new URLStreamHandler() 46 | { 47 | @Override 48 | protected URLConnection openConnection(URL url) throws IOException 49 | { 50 | return new URLConnection(url) 51 | { 52 | @Override 53 | public void connect() throws IOException 54 | { 55 | } 56 | 57 | @Override 58 | public InputStream getInputStream() throws IOException 59 | { 60 | InputStream inputStream = null; 61 | String path = getURL().getPath(); 62 | String content = contentMap.get(path); 63 | if (content != null) 64 | { 65 | inputStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)); 66 | } 67 | return inputStream; 68 | } 69 | }; 70 | } 71 | }; 72 | } 73 | return handler; 74 | } 75 | }; 76 | // this call may fail in non-fork mode if someone made it sooner (it's allowed only once) 77 | URL.setURLStreamHandlerFactory(factory); 78 | } 79 | 80 | public static void registerTestURL(String path, String content) 81 | { 82 | if (path == null) path = "/"; 83 | else if (!path.startsWith("/")) path = "/" + path; 84 | contentMap.put(path, content); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportTool.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.view; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import org.apache.velocity.tools.Scope; 23 | import org.apache.velocity.tools.config.DefaultKey; 24 | import org.apache.velocity.tools.config.ValidScope; 25 | import org.apache.velocity.tools.generic.ValueParser; 26 | 27 | /** 28 | * General-purpose text-importing view tool for templates. 29 | *

Usage:
30 | * Just call $import.read("http://www.foo.com/bleh.jsp?sneh=bar") to insert the contents of the named 31 | * resource into the template. 32 | *

33 | *
34 |  * Toolbox configuration:
35 |  * <tools>
36 |  *   <toolbox scope="request">
37 |  *     <tool class="org.apache.velocity.tools.view.ImportTool"/>
38 |  *   </toolbox>
39 |  * </tools>
40 |  * 
41 | * 42 | * @author Marino A. Jonsson 43 | * @since VelocityTools 2.0 44 | * @version $Revision$ $Date$ 45 | */ 46 | 47 | @DefaultKey("import") 48 | @ValidScope(Scope.REQUEST) 49 | public class ImportTool extends org.apache.velocity.tools.generic.ImportTool 50 | { 51 | private static final long serialVersionUID = 9071583951325800486L; 52 | 53 | protected synchronized void initializeImportSupport(ValueParser config) 54 | { 55 | if (importSupport == null) 56 | { 57 | importSupport = new ViewImportSupport(); 58 | importSupport.configure(config); 59 | } 60 | } 61 | 62 | protected void configure(ValueParser values) 63 | { 64 | super.configure(values); 65 | } 66 | 67 | /** 68 | * Returns the supplied URL rendered as a String. 69 | * 70 | * @param obj the URL to import 71 | * @return the URL as a string 72 | */ 73 | public String read(Object obj) { 74 | if (obj == null) 75 | { 76 | getLog().warn("URL is null!"); 77 | return null; 78 | } 79 | String url = String.valueOf(obj).trim(); 80 | if (url.length() == 0) 81 | { 82 | getLog().warn("URL is empty string!"); 83 | return null; 84 | } 85 | try 86 | { 87 | return importSupport.acquireString(url); 88 | } 89 | catch (Exception ex) 90 | { 91 | getLog().error("Exception while acquiring '{}'", url, ex); 92 | return null; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/text.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'ResourceTool' ) 18 |

19 | #set( $demo = $text.demo ) 20 | $demo.thisPage.insert("#doclink( 'ResourceTool' true )"). This tool 21 | is similar to the LinkTool in that most methods 22 | return a new object that has mostly the same methods as the original, allowing you 23 | to build up parameters elegantly and simply, rather than try to remember how to use 24 | methods with many parameters that must be in a specific order. So, you can access a 25 | resource with the key 'hello.whoever' in the 'otherStuff' bundle with one message 26 | argument like this: 27 |

28 |   ${esc.d}text.hello.whoever.bundle('otherStuff').insert('World')
29 | 
30 | instead of like this: 31 |
32 |   ${esc.d}text.get('hello.whoever','otherStuff', $null, 'World')
33 | 
34 | While the former is somewhat longer, it is much more understandable and flexible. 35 |

36 | 37 | #demoTableStart() 38 | 39 | #set( $desc = 'Returns the resource with the specified name, if it exists.' ) 40 | #demo1( 'text' 'get' 9 $desc ) 41 | 42 | #set( $desc = 'Returns a list of the available keys.' ) 43 | #demo( 'text' 'hello.keys' $desc ) 44 | 45 | #set( $desc = 'Returns a new $text that will search only the specified bundle (if it exists) for the resource "foo".' ) 46 | #demo1( 'text.foo' 'bundle' 9 $desc ) 47 | 48 | #set( $quote = '' ) 49 | #set( $desc = 'Returns a new $text that will try to find the resource "foo" for the specified Locale.' ) 50 | #demo1( 'text.foo' 'locale' 9 $desc ) 51 | 52 | #set( $quote = '"' ) 53 | #set( $desc = 'Returns the resource "hello.whoever" with the specified value inserted.' ) 54 | #demo1( 'text.hello.whoever' 'insert' 9 $desc ) 55 | 56 | #set( $desc = 'Returns the resource "baz" with the specified values inserted.' ) 57 | #demo2( 'text.baz' 'insert' 9 $desc ) 58 | 59 | #demoCustom( 'text' ) 60 | 61 | 62 |
63 |

$demo.mainExampleHeader

64 |
65 | 75 |
76 | 77 | #if( $params.layout ) 78 | 79 | #end 80 |
81 | 82 | #if( $params.demo ) 83 | $demo.mainResultsIntro: 84 |
85 |   $render.eval($params.demo)
86 | 
87 | #end 88 |
89 | -------------------------------------------------------------------------------- /velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/number.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | #title( 'NumberTool' ) 18 |

19 | #set( $demo = $text.demo ) 20 | $demo.thisPage.insert("#doclink( 'NumberTool' true )"). 21 |

22 | 23 | #demoTableStart() 24 | 25 | #set( $desc = 'Convenience method equivalent to $number.format("currency", $foo).' ) 26 | #demo1( 'number' 'currency' 4 $desc ) 27 | 28 | #set( $desc = 'Converts the specified object to a number and formats it according to the pattern or style returned by $number.format.' ) 29 | #demo1( 'number' 'format' 4 $desc ) 30 | 31 | #set( $desc = 'Converts the specified object to a number and returns a formatted string representing that number in the locale returned by $number.locale.' ) 32 | #demo2( 'number' 'format' 4 $desc ) 33 | 34 | #set( $quote = '' ) 35 | #set( $desc = 'Converts the specified object to a number and returns a formatted string representing that number in the specified Locale.' ) 36 | #demo3( 'number' 'format' 4 $desc ) 37 | 38 | #set( $quote = '"' ) 39 | #set( $desc = 'Return the pattern or style to be used for formatting numbers when none is specified.' ) 40 | #demo( 'number' 'format' $desc ) 41 | 42 | #set( $desc = 'This implementation returns the default locale.' ) 43 | #demo( 'number' 'locale' $desc ) 44 | 45 | #set( $quote = '' ) 46 | #set( $desc = 'Returns a NumberFormat instance for the specified format and Locale.' ) 47 | #demo2( 'number' 'getNumberFormat' 4 $desc ) 48 | 49 | #set( $quote = '"' ) 50 | #set( $desc = 'Convenience method equivalent to $number.format("integer", $foo).' ) 51 | #demo1( 'number' 'integer' 4 $desc ) 52 | 53 | #set( $desc = 'Convenience method equivalent to $number.format("number", $foo).' ) 54 | #demo1( 'number' 'number' 4 $desc ) 55 | 56 | #set( $desc = 'Convenience method equivalent to $number.format("percent", $foo).' ) 57 | #demo1( 'number' 'percent' 4 $desc ) 58 | 59 | #set( $desc = 'Converts an object to an instance of Number using the format returned by $number.format and the Locale returned by $number.locale if the object is not already an instance of Number.' ) 60 | #demo1( 'number' 'toNumber' 4 $desc ) 61 | 62 | #set( $desc = 'Converts an object to an instance of Number using the specified format and the Locale returned by $number.locale if the object is not already an instance of Number.' ) 63 | #demo2( 'number' 'toNumber' 4 $desc ) 64 | 65 | #set( $quote = '' ) 66 | #set( $desc = 'Converts an object to an instance of Number using the specified format and Localeif the object is not already an instance of Number.' ) 67 | #demo3( 'number' 'toNumber' 4 $desc ) 68 | 69 | #set( $desc = 'Converts an object to an instance of Boolean if the object is not already an instance of Boolean.' ) 70 | #demo1( 'number' 'toBoolean' 4 $desc ) 71 | 72 | #demoCustom( 'number' ) 73 | 74 | -------------------------------------------------------------------------------- /velocity-tools-view/src/test/java/org/apache/velocity/tools/view/BaseWebappMockTest.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.view; 2 | 3 | import org.easymock.EasyMockRule; 4 | import org.easymock.IAnswer; 5 | import org.easymock.Mock; 6 | import org.junit.Rule; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import javax.servlet.FilterChain; 11 | import javax.servlet.FilterConfig; 12 | import javax.servlet.ServletContext; 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | import javax.servlet.http.HttpSession; 16 | 17 | import static org.easymock.EasyMock.replay; 18 | 19 | public class BaseWebappMockTest 20 | { 21 | protected static Logger logger = LoggerFactory.getLogger("webapp-mock"); 22 | /** 23 | * Unique point of passage for non-void calls 24 | * @param value value to return 25 | * @param type of returned value 26 | * @return value 27 | */ 28 | protected static IAnswer eval(final T value) 29 | { 30 | return new IAnswer() 31 | { 32 | public T answer() throws Throwable 33 | { 34 | String caller = null; 35 | String mocked = null; 36 | String test = null; 37 | StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); 38 | for (StackTraceElement line : stackTrace) 39 | { 40 | String at = line.toString(); 41 | if (mocked == null) 42 | { 43 | if (at.startsWith("com.sun.proxy")) 44 | { 45 | int dot = at.lastIndexOf('.'); 46 | dot = at.lastIndexOf('.', dot - 1); 47 | int par = at.indexOf('(', dot + 1); 48 | mocked = at.substring(dot + 1, par) + "()"; 49 | } 50 | } 51 | if (at.startsWith("org.apache")) 52 | { 53 | if (at.contains("Test")) 54 | { 55 | if (test == null && !at.contains(".answer(") && !(at.contains("$"))) 56 | { 57 | test = at.replaceAll("\\b[a-z]+\\.|\\(.*\\)", ""); 58 | } 59 | } 60 | else if (caller == null) 61 | { 62 | caller = at; 63 | } 64 | } 65 | } 66 | // good place for a breakpoint 67 | logger.trace("XXX [{}] mocked {} called from {}, returning {}", test, mocked, caller, value); 68 | return value; 69 | } 70 | }; 71 | } 72 | 73 | @Rule 74 | public EasyMockRule rule = new EasyMockRule(this); 75 | 76 | @Mock 77 | protected FilterConfig filterConfig; 78 | 79 | @Mock 80 | protected ServletContext servletContext; 81 | 82 | @Mock 83 | protected HttpServletRequest request; 84 | 85 | @Mock 86 | protected HttpServletResponse response; 87 | 88 | @Mock 89 | protected FilterChain filterChain; 90 | 91 | @Mock 92 | protected HttpSession httpSession; 93 | 94 | protected void replayAll() 95 | { 96 | replay(filterConfig, servletContext, request, response, filterChain, httpSession); 97 | } 98 | 99 | 100 | } 101 | -------------------------------------------------------------------------------- /velocity-tools-view-jsp/src/test/java/org/apache/velocity/tools/view/jsp/jspimpl/VelocityJspFragmentTest.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.view.jsp.jspimpl; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import static org.easymock.EasyMock.*; 23 | import static org.junit.Assert.*; 24 | 25 | import java.io.IOException; 26 | import java.io.Writer; 27 | 28 | import javax.servlet.jsp.JspException; 29 | import javax.servlet.jsp.PageContext; 30 | 31 | import org.apache.velocity.context.InternalContextAdapter; 32 | import org.apache.velocity.exception.MethodInvocationException; 33 | import org.apache.velocity.exception.ParseErrorException; 34 | import org.apache.velocity.exception.ResourceNotFoundException; 35 | import org.apache.velocity.runtime.parser.node.ASTBlock; 36 | import org.junit.Test; 37 | 38 | /** 39 | * Tests {@link VelocityJspFragment}. 40 | * 41 | */ 42 | public class VelocityJspFragmentTest 43 | { 44 | 45 | /** 46 | * Test method for {@link org.apache.velocity.tools.view.jsp.jspimpl.VelocityJspFragment#invoke(java.io.Writer)}. 47 | * @throws IOException If something goes wrong. 48 | * @throws ParseErrorException If something goes wrong. 49 | * @throws ResourceNotFoundException If something goes wrong. 50 | * @throws MethodInvocationException If something goes wrong. 51 | * @throws JspException If something goes wrong. 52 | */ 53 | @Test 54 | public void testInvokeWriter() throws MethodInvocationException, ResourceNotFoundException, ParseErrorException, IOException, JspException 55 | { 56 | PageContext pageContext = createMock(PageContext.class); 57 | ASTBlock block = createMock(ASTBlock.class); 58 | InternalContextAdapter context = createMock(InternalContextAdapter.class); 59 | Writer writer = createMock(Writer.class); 60 | expect(block.render(context, writer)).andReturn(true); 61 | 62 | replay(pageContext, block, context, writer); 63 | VelocityJspFragment fragment = new VelocityJspFragment(pageContext, block, context); 64 | fragment.invoke(writer); 65 | verify(pageContext, block, context, writer); 66 | } 67 | 68 | /** 69 | * Test method for {@link org.apache.velocity.tools.view.jsp.jspimpl.VelocityJspFragment#getJspContext()}. 70 | */ 71 | @Test 72 | public void testGetJspContext() 73 | { 74 | PageContext pageContext = createMock(PageContext.class); 75 | ASTBlock block = createMock(ASTBlock.class); 76 | InternalContextAdapter context = createMock(InternalContextAdapter.class); 77 | 78 | replay(pageContext, block, context); 79 | VelocityJspFragment fragment = new VelocityJspFragment(pageContext, block, context); 80 | assertSame(pageContext, fragment.getJspContext()); 81 | verify(pageContext, block, context); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ResponseAdaptor.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.test.blackbox; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import javax.servlet.http.Cookie; 23 | import javax.servlet.http.HttpServletResponse; 24 | import java.lang.reflect.InvocationHandler; 25 | import java.lang.reflect.Method; 26 | import java.util.HashMap; 27 | import java.util.Map; 28 | 29 | /** 30 | *

Helper class for LinkToolTests class

31 | * 32 | * @author Christopher Schultz 33 | * @version $Id$ 34 | */ 35 | public class ResponseAdaptor implements InvocationHandler 36 | { 37 | // the params now also serve as a cookie jar for CookieToolTests 38 | private Map _params; 39 | 40 | public ResponseAdaptor() 41 | { 42 | this(null); 43 | } 44 | 45 | public ResponseAdaptor(Map params) 46 | { 47 | _params = params; 48 | 49 | if(null == _params) 50 | { 51 | _params = new HashMap(); 52 | } 53 | } 54 | 55 | public Object invoke(Object proxy, 56 | Method method, 57 | Object[] args) 58 | { 59 | Class clazz = method.getDeclaringClass(); 60 | 61 | if(clazz.isAssignableFrom(HttpServletResponse.class)) 62 | { 63 | return response(proxy, method, args); 64 | } 65 | else 66 | { 67 | throw new IllegalStateException("Unexpected proxy interface: " 68 | + clazz.getName()); 69 | } 70 | } 71 | 72 | protected Object response(Object proxy, 73 | Method method, 74 | Object[] args) 75 | { 76 | String methodName = method.getName(); 77 | 78 | if("encodeURL".equals(methodName) 79 | || "encodeUrl".equals(methodName)) 80 | { 81 | // Don't worry about adding ";jsessionid" or anything. 82 | return args[0]; 83 | } 84 | else if ("addCookie".equals(methodName)) 85 | { 86 | Cookie c = (Cookie)args[0]; 87 | if (c.getMaxAge() == 0) 88 | { 89 | _params.remove(c.getName()); 90 | } 91 | else 92 | { 93 | _params.put(c.getName(), c); 94 | } 95 | return null; 96 | } 97 | else if ("getCharacterEncoding".equals(methodName)) 98 | { 99 | return "UTF-8"; 100 | } 101 | else if ("toString".equals(methodName)) 102 | { 103 | return toString(); 104 | } 105 | else 106 | { 107 | throw new IllegalStateException("Unexpected method call: " 108 | + method); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /velocity-tools-view/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 4.0.0 24 | 25 | 26 | org.apache.velocity.tools 27 | velocity-tools-parent 28 | 3.3-SNAPSHOT 29 | 30 | 31 | velocity-tools-view 32 | 33 | Apache Velocity Tools - View tools 34 | Tools to be used in a servlet context. 35 | 36 | 37 | 38 | javax.servlet 39 | javax.servlet-api 40 | provided 41 | 42 | 43 | org.apache.velocity 44 | velocity-engine-core 45 | 46 | 47 | org.apache.velocity.tools 48 | velocity-tools-generic 49 | ${project.version} 50 | 51 | 52 | org.slf4j 53 | slf4j-api 54 | 55 | 56 | org.apache.commons 57 | commons-lang3 58 | 59 | 60 | org.apache.commons 61 | commons-digester3 62 | 63 | 64 | junit 65 | junit 66 | test 67 | 68 | 69 | org.easymock 70 | easymock 71 | test 72 | 73 | 74 | org.slf4j 75 | slf4j-simple 76 | test 77 | 78 | 79 | 80 | 81 | 82 | 83 | org.apache.maven.plugins 84 | maven-surefire-plugin 85 | 86 | 87 | 88 | test.output.dir 89 | ${project.build.testOutputDirectory} 90 | 91 | 92 | org.slf4j.simpleLogger.defaultLogLevel 93 | info 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ViewContext.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.view; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | import javax.servlet.ServletContext; 25 | import org.apache.velocity.app.VelocityEngine; 26 | import org.apache.velocity.context.Context; 27 | 28 | /** 29 | *

This interface provides view tools in a servlet environment 30 | * access to relevant context information, like servlet request, servlet 31 | * context and the velocity context.

32 | *

The standard implementation is {@link ViewToolContext}.

33 | * 34 | * @author Gabe Sidler 35 | * @author Geir Magnusson Jr. 36 | * @author Nathan Bubna 37 | * @version $Id$ 38 | */ 39 | public interface ViewContext 40 | { 41 | /** Key used for the HTTP request object. */ 42 | public static final String REQUEST = "request"; 43 | 44 | /** Key used for the HTTP response object. */ 45 | public static final String RESPONSE = "response"; 46 | 47 | /** Key used for the HTTP session object. */ 48 | public static final String SESSION = "session"; 49 | 50 | /** Key used for the servlet context object in templates. */ 51 | public static final String APPLICATION = "application"; 52 | 53 | /** Key used for the servlet context object in tool properties. */ 54 | public static final String SERVLET_CONTEXT_KEY = "servletContext"; 55 | 56 | /** Default key used to store toolboxes in request/session/application attributes. */ 57 | public static final String DEFAULT_TOOLBOX_KEY = 58 | VelocityView.DEFAULT_TOOLBOX_KEY; 59 | 60 | 61 | /** 62 | * @return the instance of {@link HttpServletRequest} for this request. 63 | */ 64 | public HttpServletRequest getRequest(); 65 | 66 | 67 | /** 68 | * @return the instance of {@link HttpServletResponse} for this request. 69 | */ 70 | public HttpServletResponse getResponse(); 71 | 72 | 73 | /** 74 | * @return the instance of {@link ServletContext} for this request. 75 | */ 76 | public ServletContext getServletContext(); 77 | 78 | 79 | /** 80 | *

Searches for the named attribute in request, session (if valid), 81 | * and application scope(s) in order and returns the value associated 82 | * or null.

83 | * @param key attribute key 84 | * @return attribute value or null 85 | * @since VelocityTools 1.1 86 | */ 87 | public Object getAttribute(String key); 88 | 89 | 90 | /** 91 | * @return a reference to the current Velocity context. 92 | */ 93 | public Context getVelocityContext(); 94 | 95 | 96 | /** 97 | * @return the current VelocityEngine instance. 98 | */ 99 | public VelocityEngine getVelocityEngine(); 100 | 101 | } 102 | -------------------------------------------------------------------------------- /velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletContextAdaptor.java: -------------------------------------------------------------------------------- 1 | package org.apache.velocity.tools.test.blackbox; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import javax.servlet.RequestDispatcher; 23 | import javax.servlet.ServletContext; 24 | import java.io.InputStream; 25 | import java.lang.reflect.InvocationHandler; 26 | import java.lang.reflect.Method; 27 | import java.net.URL; 28 | 29 | /** 30 | *

Helper class for LinkToolTests class

31 | * 32 | * @author Christopher Schultz 33 | * @version $Id$ 34 | */ 35 | public class ServletContextAdaptor implements InvocationHandler 36 | { 37 | private String _contextPath; 38 | 39 | public ServletContextAdaptor() 40 | { 41 | this(null); 42 | } 43 | 44 | public ServletContextAdaptor(String contextPath) 45 | { 46 | _contextPath = contextPath; 47 | if(null == _contextPath) 48 | { 49 | _contextPath = ""; 50 | } 51 | } 52 | 53 | public Object invoke(Object proxy, 54 | Method method, 55 | Object[] args) 56 | { 57 | Class clazz = method.getDeclaringClass(); 58 | if(clazz.isAssignableFrom(ServletContext.class)) 59 | { 60 | return context(proxy, method, args); 61 | } 62 | else 63 | { 64 | throw new IllegalStateException("Unexpected proxy interface: " 65 | + clazz.getName()); 66 | } 67 | } 68 | 69 | protected Object context(Object proxy, 70 | Method method, 71 | Object[] args) 72 | { 73 | String methodName = method.getName(); 74 | 75 | if("getContextPath".equals(methodName)) 76 | { 77 | return _contextPath; 78 | } 79 | else if ("getResource".equals(methodName)) 80 | { 81 | return getResource((String)args[0]); 82 | } 83 | else if ("getResourceAsStream".equals(methodName)) 84 | { 85 | return getResourceAsStream((String)args[0]); 86 | } 87 | else if ("getRequestDispatcher".equals(methodName)) 88 | { 89 | return getRequestDispatcher((String)args[0]); 90 | } 91 | else if ("toString".equals(methodName)) 92 | { 93 | return toString(); 94 | } 95 | else 96 | { 97 | throw new IllegalStateException("Unexpected method call: " 98 | + methodName); 99 | } 100 | } 101 | 102 | protected URL getResource(String path) 103 | { 104 | return null; 105 | } 106 | 107 | protected InputStream getResourceAsStream(String path) 108 | { 109 | return null; 110 | } 111 | 112 | protected RequestDispatcher getRequestDispatcher(String url) 113 | { 114 | return null; 115 | } 116 | } 117 | --------------------------------------------------------------------------------