velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1857763 - in /velocity/tools/branches/model/velocity-tools-examples: ./ velocity-tools-examples-bookshelf/ velocity-tools-examples-bookshelf/src/ velocity-tools-examples-bookshelf/src/main/ velocity-tools-examples-bookshelf/src/main/java/ ...
Date Thu, 18 Apr 2019 15:45:11 GMT
Author: cbrisson
Date: Thu Apr 18 15:45:11 2019
New Revision: 1857763

URL: http://svn.apache.org/viewvc?rev=1857763&view=rev
Log:
[tools/model] Initial import: velocity-tools-examples-bookshelf example webapp

Added:
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/pom.xml
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/java/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/java/org/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/java/org/apache/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/java/org/apache/velocity/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/java/org/apache/velocity/tools/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/java/org/apache/velocity/tools/examples/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/java/org/apache/velocity/tools/examples/bookshelf/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/java/org/apache/velocity/tools/examples/bookshelf/DatabaseInitializer.java
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/jetty/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/jetty/showcase.policy
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/resources/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/bookshelf.sql
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/jetty-env.xml
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/model.xml
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/velocity.properties
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/web.xml
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/index.vhtml
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/test.vhtml
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/test/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/test/java/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/test/java/org/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/test/java/org/apache/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/test/java/org/apache/velocity/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/test/java/org/apache/velocity/examples/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/test/java/org/apache/velocity/examples/bookshelf/
    velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/test/java/org/apache/velocity/examples/bookshelf/BookshelfTestsIT.java
Modified:
    velocity/tools/branches/model/velocity-tools-examples/pom.xml

Modified: velocity/tools/branches/model/velocity-tools-examples/pom.xml
URL: http://svn.apache.org/viewvc/velocity/tools/branches/model/velocity-tools-examples/pom.xml?rev=1857763&r1=1857762&r2=1857763&view=diff
==============================================================================
--- velocity/tools/branches/model/velocity-tools-examples/pom.xml (original)
+++ velocity/tools/branches/model/velocity-tools-examples/pom.xml Thu Apr 18 15:45:11 2019
@@ -35,6 +35,7 @@
   <description>Examples to show how to use Velocity Tools</description>
 
   <modules>
+    <module>velocity-tools-examples-bookshelf</module>
     <module>velocity-tools-examples-showcase</module>
     <module>velocity-tools-examples-simple</module>
   </modules>

Added: velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/pom.xml
URL: http://svn.apache.org/viewvc/velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/pom.xml?rev=1857763&view=auto
==============================================================================
--- velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/pom.xml
(added)
+++ velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/pom.xml
Thu Apr 18 15:45:11 2019
@@ -0,0 +1,182 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.velocity.tools</groupId>
+    <artifactId>velocity-tools-examples</artifactId>
+    <version>3.1-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>velocity-tools-examples-bookshelf</artifactId>
+  <packaging>war</packaging>
+
+  <name>Apache Velocity Tools Examples - Bookshelf</name>
+  <description>Example Use of Velocity Tools Model</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>javax.servlet-api</artifactId>
+      <version>3.1.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.velocity.tools</groupId>
+      <artifactId>velocity-tools-view</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.velocity.tools</groupId>
+      <artifactId>velocity-tools-model</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.httpunit</groupId>
+      <artifactId>httpunit</artifactId>
+      <version>1.7.3</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.commons</groupId>
+        <artifactId>commons-dbcp2</artifactId>
+        <version>2.6.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.hsqldb</groupId>
+      <artifactId>hsqldb</artifactId>
+      <version>2.4.1</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-failsafe-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <goals>
+              <goal>integration-test</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>verify</id>
+            <goals>
+              <goal>verify</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.cargo</groupId>
+        <artifactId>cargo-maven2-plugin</artifactId>
+        <version>1.6.8</version>
+        <configuration>
+          <container>
+            <containerId>jetty9x</containerId>
+            <timeout>1800000</timeout> <!-- @@ for debugging -->
+            <dependencies>
+              <dependency>
+                <groupId>org.apache.commons</groupId>
+                <artifactId>commons-dbcp2</artifactId>
+              </dependency>
+              <dependency>
+                <groupId>org.hsqldb</groupId>
+                <artifactId>hsqldb</artifactId>
+              </dependency>
+            </dependencies>
+          </container>
+          <configuration>
+            <files>
+              <!-- policy file, disabled, see below
+              <copy>
+                <file>${project.basedir}/src/main/jetty/showcase.policy</file>
+                <todir>/</todir>
+                <configfile>true</configfile>
+              </copy>
+              -->
+            </files>
+            <properties>
+              <!-- variables referenced in the showcase policy file -->
+              <!-- commented since broken on windows due to a cargo bug like MNG-6386
+              <cargo.container>${project.build.directory}/cargo/installs</cargo.container>
+              <cargo.repository>${settings.localRepository}</cargo.repository>
+              <cargo.webapp>${project.build.directory}/${project.artifactId}</cargo.webapp>
+              <cargo.velocity-engine.version>${velocity.engine.version}</cargo.velocity-engine.version>
+              <cargo.velocity-tools.version>${project.version}</cargo.velocity-tools.version>
+              <cargo.slf4j.version>${slf4j.version}</cargo.slf4j.version>
+              <cargo.webapp-slf4j-logger.version>${webapp-slf4j-logger.version}</cargo.webapp-slf4j-logger.version>
+              -->
+              <cargo.jvmargs>
+                <!-- enable remote debugging
+                -agentlib:jdwp=transport=dt_socket,server=n,suspend=n,address=5006
+                -->
+
+                <!-- enable Jetty debug log
+                -Dorg.eclipse.jetty.LEVEL=DEBUG
+                -->
+
+                <!-- enable security manager
+                   (disabled for now, see above note about policy file)
+                -Djava.security.manager
+                -Djava.security.policy=${project.build.directory}/cargo/configurations/jetty9x/showcase.policy
+                 -->
+              </cargo.jvmargs>
+            </properties>
+          </configuration>
+        </configuration>
+        <executions>
+          <execution>
+            <configuration>
+              <wait>false</wait>
+            </configuration>
+            <id>start-server</id>
+            <goals>
+              <goal>start</goal>
+            </goals>
+            <phase>pre-integration-test</phase>
+          </execution>
+          <execution>
+            <id>stop-server</id>
+            <goals>
+              <goal>stop</goal>
+            </goals>
+            <phase>post-integration-test</phase>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/java/org/apache/velocity/tools/examples/bookshelf/DatabaseInitializer.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/java/org/apache/velocity/tools/examples/bookshelf/DatabaseInitializer.java?rev=1857763&view=auto
==============================================================================
--- velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/java/org/apache/velocity/tools/examples/bookshelf/DatabaseInitializer.java
(added)
+++ velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/java/org/apache/velocity/tools/examples/bookshelf/DatabaseInitializer.java
Thu Apr 18 15:45:11 2019
@@ -0,0 +1,45 @@
+package org.apache.velocity.tools.examples.bookshelf;
+
+import org.apache.velocity.tools.model.Model;
+import org.apache.velocity.tools.view.ServletUtils;
+import org.apache.velocity.tools.view.VelocityView;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import java.io.Reader;
+import java.sql.SQLException;
+
+public class DatabaseInitializer implements ServletContextListener
+{
+    protected static Logger logger = LoggerFactory.getLogger(DatabaseInitializer.class);
+
+    @Override
+    public void contextInitialized(ServletContextEvent sce)
+    {
+        try
+        {
+            logger.info("populating database");
+            initDatabase(sce.getServletContext());
+            logger.info("database populated");
+        }
+        catch (Exception sqle)
+        {
+            logger.error("could not initialize database", sqle);
+        }
+    }
+
+    @Override
+    public void contextDestroyed(ServletContextEvent sce)
+    {
+
+    }
+
+    private void initDatabase(ServletContext servletContext) throws Exception
+    {
+        Model model = new Model().initialize(servletContext.getResource("/WEB-INF/model.xml"));
+        model.perform("initBookshelf");
+    }
+}

Added: velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/jetty/showcase.policy
URL: http://svn.apache.org/viewvc/velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/jetty/showcase.policy?rev=1857763&view=auto
==============================================================================
--- velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/jetty/showcase.policy
(added)
+++ velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/jetty/showcase.policy
Thu Apr 18 15:45:11 2019
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+///////////////////////////////////////////////////
+//
+// Give Maven repository libs all permissions
+//
+///////////////////////////////////////////////////
+
+grant codeBase "file:@cargo.repository@/-"
+{
+    permission java.security.AllPermission "", "";
+};
+
+///////////////////////////////////////////////////
+//
+// Give Jetty libs all permissions
+//
+///////////////////////////////////////////////////
+
+grant codeBase "file:@cargo.container@/-"
+{
+    permission java.security.AllPermission "", "";
+};
+
+///////////////////////////////////////////////////
+//
+// Give anyone basic and reflection runtime rights
+//
+///////////////////////////////////////////////////
+
+grant
+{
+    permission java.lang.RuntimePermission "accessDeclaredMembers";
+    permission java.lang.RuntimePermission "getProtectionDomain";
+    permission java.lang.RuntimePermission "getClassLoader";
+};
+
+///////////////////////////////////////////////////
+//
+// Let webapp resolve classes dependencies
+//
+///////////////////////////////////////////////////
+
+grant codeBase "file:@cargo.webapp@/WEB-INF/classes/-"
+{
+    permission java.io.FilePermission "@cargo.webapp@/WEB-INF/lib/*", "read";
+    permission java.io.FilePermission "@cargo.webapp@/WEB-INF/classes/-", "read";
+};
+
+grant codeBase "file:@cargo.webapp@/WEB-INF/lib/*"
+{
+    permission java.io.FilePermission "@cargo.webapp@/WEB-INF/lib/*", "read";
+    permission java.io.FilePermission "@cargo.webapp@/WEB-INF/classes/-", "read";
+};
+
+
+///////////////////////////////////////////////////
+//
+// Give webapp-slf4j-logger all permissions
+//
+///////////////////////////////////////////////////
+
+// (since the logger will install an IPFilter tag, it's here in all calling stacks)
+
+grant codeBase "file:@cargo.webapp@/WEB-INF/lib/webapp-slf4j-logger-@cargo.webapp-slf4j-logger.version@.jar
+{
+    permission java.security.AllPermission "", "";
+};
+
+///////////////////////////////////////////////////
+//
+// Give slf4j permission to read its properties
+//
+///////////////////////////////////////////////////
+
+// all calling chain is needed
+
+grant codeBase "file:@cargo.webapp@/WEB-INF/lib/slf4j-api-@cargo.slf4j.version@.jar"
+{
+    permission java.util.PropertyPermission "slf4j.*", "read";
+};
+
+grant codeBase "file:@cargo.webapp@/WEB-INF/lib/velocity-engine-core-@cargo.velocity-engine.version@.jar"
+{
+    permission java.util.PropertyPermission "slf4j.*", "read";
+};
+
+grant codeBase "file:@cargo.webapp@/WEB-INF/lib/velocity-tools-view-@cargo.velocity-tools.version@.jar"
+{
+    permission java.util.PropertyPermission "slf4j.*", "read";
+};
+
+///////////////////////////////////////////////////
+//
+// Give velocity, velocity-tools-generic and velocity-tools-view only needed rights
+//
+///////////////////////////////////////////////////
+
+// engine
+
+grant codeBase "file:@cargo.webapp@/WEB-INF/lib/velocity-engine-core-@cargo.velocity-engine.version@.jar"
+{
+    // read default velocity.properties from velocity-engine-core jar
+    permission java.io.FilePermission "@cargo.webapp@/WEB-INF/lib/velocity-engine-core-@cargo.velocity-engine.version@.jar",
"read";
+};
+
+// generic tools
+
+grant codeBase "file:@cargo.webapp@/WEB-INF/lib/velocity-tools-generic-@cargo.velocity-tools.version@.jar"
+{
+    // read default velocity.properties and default toolbox from velocity-tools-view jar
+    permission java.io.FilePermission "@cargo.webapp@/WEB-INF/lib/velocity-tools-view-@cargo.velocity-tools.version@.jar",
"read";
+
+    // read default toolbox from velocity-tools-generic jar
+    permission java.io.FilePermission "@cargo.webapp@/WEB-INF/lib/velocity-tools-generic-@cargo.velocity-tools.version@.jar",
"read";
+};
+
+
+// view tools
+
+grant codeBase "file:@cargo.webapp@/WEB-INF/lib/velocity-tools-view-@cargo.velocity-tools.version@.jar"
+{
+    // read permissions on the webapp
+    permission java.io.FilePermission "@cargo.webapp@/-", "read";
+
+    // get request character encoding (specific to jetty)
+    permission java.util.PropertyPermission "org.eclipse.jetty.util.UrlEncoding.charset","read";
   
+};
+

Added: velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/bookshelf.sql
URL: http://svn.apache.org/viewvc/velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/bookshelf.sql?rev=1857763&view=auto
==============================================================================
--- velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/bookshelf.sql
(added)
+++ velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/bookshelf.sql
Thu Apr 18 15:45:11 2019
@@ -0,0 +1,62 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"). you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--   http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.    
+
+create table publisher
+(
+    publisher_id int not null,
+    name varchar(200) not null,
+    primary key (publisher_id)
+);
+
+create table author
+(
+    author_id int not null,
+    name varchar(200) not null,
+    primary key (author_id)
+);
+
+create table book
+(
+    book_id int not null,
+    title varchar(200) not null,
+    publisher_id int not null,
+    primary key (book_id),
+    foreign key (publisher_id) references publisher (publisher_id)
+);
+
+create table book_author
+(
+    book_id int not null,
+    author_id int not null,
+    primary key (book_id, author_id),
+    foreign key (book_id) references book (book_id),
+    foreign key (author_id) references author (author_id)
+);
+
+create table friend
+(
+    friend_id int not null,
+    login varchar(200) not null,
+    password varchar(200) not null,
+    primary key (friend_id)
+);
+
+insert into publisher values (1, 'Green Penguin Books'), (2, 'Serious Stuff Publishing');
+insert into book values (1, 'The Astonishing Life of Duncan Aston', 1), (2, 'Beyond the Surface
of Things', 2), (3, 'Seeds and Flowers', 2);
+insert into author values (1, 'Graham Brigovicz'), (2, 'Robert Willhelm'), (3, 'Vanessa Hopkins'),
(4, 'Kai Mattey');
+insert into book_author values (1, 1), (1, 2), (2, 3), (3, 4);
+insert into friend values (1, 'nestor', 'secret');

Added: velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/jetty-env.xml
URL: http://svn.apache.org/viewvc/velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/jetty-env.xml?rev=1857763&view=auto
==============================================================================
--- velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/jetty-env.xml
(added)
+++ velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/jetty-env.xml
Thu Apr 18 15:45:11 2019
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
+<Configure class="org.eclipse.jetty.webapp.WebAppContext">
+    <New id="bookshelf-database" class="org.eclipse.jetty.plus.jndi.Resource">
+        <Arg></Arg>
+        <Arg>jdbc/bookshelf</Arg>
+        <Arg>
+            <New class="org.apache.commons.dbcp2.BasicDataSource">
+                <Set name="Url">jdbc:hsqldb:.</Set>
+                <Set name="Username">sa</Set>
+                <Set name="Password"></Set>
+            </New>
+        </Arg>
+    </New>
+</Configure>

Added: velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/model.xml
URL: http://svn.apache.org/viewvc/velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/model.xml?rev=1857763&view=auto
==============================================================================
--- velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/model.xml
(added)
+++ velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/model.xml
Thu Apr 18 15:45:11 2019
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<model xmlns:xi="http://www.w3.org/2001/XInclude" dataSource="jdbc/bookshelf" reverse="extended">
+    <transaction name="initBookshelf">
+        <xi:include href="bookshelf.sql" parse="text"/>
+    </transaction>
+
+    <!-- no need to declare entities: entities, key columns and foreign keys will be reverse
enginered -->
+
+    <!--
+        Get user by credentials.
+        There is no encryption function in HSQL, otherwise, for instance with MySQL, you
would do:
+        select * from user where login = <login/> and password = sha2(<password/>,
256);
+     -->
+    <row name="user_by_credentials" result="user">
+        select * from friend where login = <login/> and password = <password/>;
+    </row>
+
+</model>

Added: velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/velocity.properties
URL: http://svn.apache.org/viewvc/velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/velocity.properties?rev=1857763&view=auto
==============================================================================
--- velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/velocity.properties
(added)
+++ velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/velocity.properties
Thu Apr 18 15:45:11 2019
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+runtime.introspector.uberspect = org.apache.velocity.tools.model.ModelUberspector, org.apache.velocity.util.introspection.UberspectImpl,
org.apache.velocity.tools.view.WebappUberspector
+
+model.identifiers.mapping.* = lowercase
+model.identifiers.mapping.*.* = lowercase
+
+auth.form.redirect.enable = true
+auth.form.uri.login = login.vhtml
+auth.form.uri.home = index.vhtml
+auth.form.success.redirect_get = true

Added: velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/web.xml?rev=1857763&view=auto
==============================================================================
--- velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/web.xml
(added)
+++ velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/WEB-INF/web.xml
Thu Apr 18 15:45:11 2019
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
+         version="3.1">
+  <!-- resources -->
+  <resource-ref>
+      <description>Bookshelf Database</description>
+      <res-ref-name>jdbc/bookshelf</res-ref-name>
+      <res-type>javax.sql.DataSource</res-type>
+      <res-auth>Container</res-auth>
+  </resource-ref>
+  <!-- context listeners -->
+  <listener>
+    <listener-class>org.apache.velocity.tools.examples.bookshelf.DatabaseInitializer</listener-class>
+  </listener>
+  <!-- servlets -->
+  <servlet>
+    <servlet-name>view</servlet-name>
+    <servlet-class>org.apache.velocity.tools.view.VelocityViewServlet</servlet-class>
+  </servlet>
+  <!-- servlet mappings -->
+  <servlet-mapping>
+    <servlet-name>view</servlet-name>
+    <url-pattern>*.vhtml</url-pattern>
+  </servlet-mapping>
+  <!-- context params -->
+  <context-param>
+    <param-name>org.apache.velocity.tools.loadDefaults</param-name>
+    <param-value>true</param-value>
+  </context-param>
+  <context-param>
+    <param-name>org.apache.velocity.tools.cleanConfiguration</param-name>
+    <param-value>true</param-value>
+  </context-param>
+  <context-param>
+    <param-name>org.apache.velocity.tools.userCanOverwriteTools</param-name>
+    <param-value>false</param-value>
+  </context-param>
+  <!-- welcome file -->
+  <welcome-file-list>
+    <welcome-file>index.vhtml</welcome-file>
+  </welcome-file-list>
+</web-app>

Added: velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/index.vhtml
URL: http://svn.apache.org/viewvc/velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/index.vhtml?rev=1857763&view=auto
==============================================================================
--- velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/index.vhtml
(added)
+++ velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/index.vhtml
Thu Apr 18 15:45:11 2019
@@ -0,0 +1,22 @@
+<html>
+  <head>
+    <title>Velocity Bookshelf Example</title>
+  </head>
+  <body>
+    <h1>Velocity Bookshelf Example</h1>
+    My bookshelf has $model.book.count books:
+    <ul>
+#foreach( $book in $model.book )
+      <li>
+        $book.title, written by
+  #foreach( $author in $book.authors )
+        $author.name#if($foreach.hasNext) and #end
+  #end
+        published by $book.publisher.name
+      </li>
+#else
+      <li>(no book)</li>
+#end
+    </ul>
+  </body>
+</html>

Added: velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/test.vhtml
URL: http://svn.apache.org/viewvc/velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/test.vhtml?rev=1857763&view=auto
==============================================================================
--- velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/test.vhtml
(added)
+++ velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/main/webapp/test.vhtml
Thu Apr 18 15:45:11 2019
@@ -0,0 +1 @@
+blabla

Added: velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/test/java/org/apache/velocity/examples/bookshelf/BookshelfTestsIT.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/test/java/org/apache/velocity/examples/bookshelf/BookshelfTestsIT.java?rev=1857763&view=auto
==============================================================================
--- velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/test/java/org/apache/velocity/examples/bookshelf/BookshelfTestsIT.java
(added)
+++ velocity/tools/branches/model/velocity-tools-examples/velocity-tools-examples-bookshelf/src/test/java/org/apache/velocity/examples/bookshelf/BookshelfTestsIT.java
Thu Apr 18 15:45:11 2019
@@ -0,0 +1,181 @@
+package org.apache.velocity.examples.showcase;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.HTMLElement;
+import com.meterware.httpunit.PostMethodWebRequest;
+import com.meterware.httpunit.WebConversation;
+import com.meterware.httpunit.WebForm;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+
+import static org.junit.Assert.*;
+
+/**
+ * <p>View tools blackbox tests.</p>
+ *
+ * @author <a href="mailto:cbrisson@apache.org">Claude Brisson</a>
+ * @since Velocity Tools 1.3
+ * @version $Id$
+ */
+
+
+public class BookshelfTestsIT
+{
+
+    private static final String ROOT_URL = "http://localhost:8080/velocity-tools-examples-bookshelf/";
+
+    public static @BeforeClass void initBookshelfTests() throws Exception {
+    }
+
+    /******* Helpers **********/
+
+    /**
+     * Utility function to check the text content of an HTML element
+     * @param resp web response
+     * @param id HTML element id
+     * @param text expected text
+     * @throws Exception
+     */
+    private void checkText(WebResponse resp,String id,String text) throws Exception {
+        HTMLElement element = resp.getElementWithID(id);
+        assertNotNull(element);
+        assertEquals(text,element.getText());
+    }
+
+    /**
+     * Utility function to check the text content of an HTML element
+     * @param resp web response
+     * @param id HTML element id
+     * @param text expected start of the text
+     * @throws Exception
+     */
+    private void checkTextStart(WebResponse resp,String id,String text) throws Exception
{
+        HTMLElement element = resp.getElementWithID(id);
+        assertNotNull(element);
+        assertTrue(element.getText().startsWith(text));
+    }
+
+    /**
+     * Utility function to check the text content of an HTML element
+     * @param resp web response
+     * @param id HTML element id
+     * @param start expected start of the text
+     * @param end expected end of the text
+     * @throws Exception
+     */
+    private void checkTextStartEnd(WebResponse resp,String id,String start,String end) throws
Exception {
+        HTMLElement element = resp.getElementWithID(id);
+        assertNotNull(element);
+        assertTrue(element.getText().startsWith(start));
+        assertTrue(element.getText().endsWith(end));
+    }
+
+    /**
+     * Utility function to check the text content of an HTML element
+     * @param resp web response
+     * @param id HTML element id
+     * @param text expected contained text
+     * @throws Exception
+     */
+    private void checkTextContent(WebResponse resp,String id,String text) throws Exception
{
+        HTMLElement element = resp.getElementWithID(id);
+        assertNotNull(element);
+        assertTrue(element.getText().indexOf(text) != -1);
+    }
+
+    /**
+     * Utility function to check the text content of an HTML element
+     * @param resp web response
+     * @param id HTML element id
+     * @param regex expected regex
+     * @throws Exception
+     */
+    private void checkTextRegex(WebResponse resp,String id,String regex) throws Exception
{
+        HTMLElement element = resp.getElementWithID(id);
+        assertNotNull(element);
+        Pattern pattern = Pattern.compile(regex);
+        // strip new lines from string to be tested
+        String text = element.getText().replace("\n","");
+        Matcher matcher = pattern.matcher(text);
+        if (!matcher.matches())
+        {
+            fail(element.getText()+" did not match "+regex);
+        }
+    }
+
+    /**
+     *
+     * @param orig original web response
+     * @param formname form name
+     * @param paramname parameter name
+     * @param value parameter value
+     * @return new web response
+     * @throws Exception
+     */
+    private WebResponse submitWithParam(WebResponse orig, String formname, String paramname,
String value) throws Exception {
+        WebForm form = orig.getFormWithName(formname);
+        form.setParameter(paramname, value);
+        return form.submit();
+    }
+
+    /**
+     * Used for debugging testcases
+     * @param resp webresponse
+     */
+    private void dump(WebResponse resp) {
+        try {
+            PrintWriter pw = new PrintWriter("/tmp/dump.html");
+            pw.println(resp.getText());
+            pw.flush();
+            pw.close();
+        } catch (IOException ioe) {
+
+        }
+    }
+
+
+    /******* Tests **********/
+
+    public @Test void testIndex() throws Exception
+    {
+
+        WebConversation conv = new WebConversation();
+        WebRequest req = new GetMethodWebRequest(ROOT_URL+"index.vhtml");
+        WebResponse resp = conv.getResponse(req);
+
+    }
+}



Mime
View raw message