diff --git a/achetypes/struts2-archetype-dbportlet/README.txt b/achetypes/struts2-archetype-dbportlet/README.txt new file mode 100644 index 000000000..7c2a6a39c --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/README.txt @@ -0,0 +1,42 @@ +INFORMATION +=========== +- This is Struts 2's "Database Portlet" Maven Archetype +- To be used to create a simple portlet that displays information in a database and can be deployed as a webapp or JSR168 portlet. + + +USAGE +===== + +- change directory to where the portlet template is to be created, + for example, a 'projects' directory (which you may need to create): + + cd /home/tmjee/projects + +- run the following command to generate the sample portlet template, assuming :- + - root java package -> com.myCompany.myPortlet + + - the portlet war name -> myWebApp + + + mvn archetype:create -DgroupId=com.myCompany.myPortlet \ + -DartifactId=myWebApp \ + -DarchetypeGroupId=org.apache.struts \ + -DarchetypeArtifactId=struts2-archetype-dbportlet \ + -DarchetypeVersion=2.0.9-SNAPSHOT \ + -DremoteRepositories=http://people.apache.org/maven-snapshot-repository + +- to compile, execute + mvn compile + +- to run test cases execute + mvn test + +- to clean execute + mvn clean + +- to package execute + mvn package + +- to start it with jetty execute as a servlet + mvn jetty:run + diff --git a/achetypes/struts2-archetype-dbportlet/pom.xml b/achetypes/struts2-archetype-dbportlet/pom.xml new file mode 100644 index 000000000..cd84947a8 --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/pom.xml @@ -0,0 +1,44 @@ + + + + + org.apache.struts + struts2-parent + 2.2.0-SNAPSHOT + + + 4.0.0 + struts2-archetype-dbportlet + 2.2.0-SNAPSHOT + Struts 2 Archetypes - Database Portlet + + + scm:svn:http://svn.apache.org/repos/asf/struts/maven/trunk/struts2-archetype-dbportlet/ + scm:svn:https://svn.apache.org/repos/asf/struts/maven/trunk/struts2-archetype-dbportlet/ + http://svn.apache.org/viewcvs.cgi/struts/maven/trunk/struts2-archetype-dbportlet/ + + + + + release + + + + org.apache.maven.plugins + maven-gpg-plugin + + + sign-artifacts + verify + + sign + + + + + + + + + + diff --git a/achetypes/struts2-archetype-dbportlet/src/main/resources/META-INF/archetype.xml b/achetypes/struts2-archetype-dbportlet/src/main/resources/META-INF/archetype.xml new file mode 100644 index 000000000..a19db5e0a --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/src/main/resources/META-INF/archetype.xml @@ -0,0 +1,21 @@ + + + + struts2-archetype-dbblank + + src/main/java/view/IndexAction.java + src/main/java/edit/IndexAction.java + + + src/main/resources/struts.xml + src/main/webapp/index.jsp + src/main/webapp/WEB-INF/web.xml + src/main/webapp/WEB-INF/portlet.xml + src/main/webapp/WEB-INF/applicationContext.xml + src/main/webapp/WEB-INF/view/index.jsp + src/main/webapp/WEB-INF/help/index.jsp + src/main/webapp/WEB-INF/edit/index-input.jsp + src/main/webapp/WEB-INF/edit/index-success.jsp + + + diff --git a/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/pom.xml b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 000000000..8fda48ad4 --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,123 @@ + + + + 4.0.0 + ${groupId} + ${artifactId} + war + ${version} + Struts 2 Database Portlet + http://www.myComp.com + Struts 2 Database Portlet + + + 2.1.8.1 + + + + + + + junit + junit + 3.8.1 + test + + + + + org.apache.struts + struts2-core + ${struts2.version} + + + + org.apache.struts + struts2-portlet-plugin + ${struts2.version} + + + + org.apache.struts + struts2-convention-plugin + ${struts2.version} + + + + org.apache.struts + struts2-spring-plugin + ${struts2.version} + + + + org.apache.struts + struts2-config-browser-plugin + ${struts2.version} + + + + + org.springframework + spring-jdbc + 2.5.6 + + + + + hsqldb + hsqldb + 1.8.0.7 + + + + + javax.servlet + servlet-api + 2.4 + provided + + + + javax.servlet + jsp-api + 2.0 + provided + + + + portlet-api + portlet-api + 1.0 + provided + + + + + + ${artifactId} + + + maven-compiler-plugin + + 1.5 + 1.5 + + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.21 + + 10 + + + + portlet-api + portlet-api + 1.0 + + + + + + diff --git a/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/java/edit/IndexAction.java b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/java/edit/IndexAction.java new file mode 100644 index 000000000..4a553c100 --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/java/edit/IndexAction.java @@ -0,0 +1,46 @@ +package ${package}.edit; + +import org.apache.struts2.dispatcher.DefaultActionSupport; + +/** + * + */ +public class IndexAction extends DefaultActionSupport { + private String pref1; + private String pref2; + private boolean submit; + + public String execute() { + + if (submit) { + + // Save the preferences somehow + + return SUCCESS; + } else { + + // Preform any logic here + + return INPUT; + } + } + + public void setSubmit(String val) { + this.submit = (val != null); + } + + public String getPref1() { + return pref1; + } + public String getPref2() { + return pref2; + } + + public void setPref1(String pref) { + this.pref1 = pref; + } + + public void setPref2(String pref) { + this.pref2 = pref; + } +} diff --git a/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/java/view/IndexAction.java b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/java/view/IndexAction.java new file mode 100644 index 000000000..4ab7b32f8 --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/java/view/IndexAction.java @@ -0,0 +1,51 @@ +package ${package}.view; + +import org.apache.struts2.dispatcher.DefaultActionSupport; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; + +import javax.sql.DataSource; +import java.util.Map; +import java.util.List; + +/** + * Loads and displays the contents of a database table + */ +public class IndexAction extends DefaultActionSupport { + + private static boolean initialized = false; + private DataSource ds; + private static List> data; + private static long lastLoaded; + private static long CACHE_TIME = 1000 * 60; + + public void setDataSource(DataSource ds) { + + // Initializes the in-memory database (not necessary in production) + if (!initialized) { + SimpleJdbcTemplate jt = new SimpleJdbcTemplate(ds); + jt.update("CREATE TABLE sample_table ( id INTEGER IDENTITY, str_col VARCHAR(256), num_col INTEGER)"); + jt.update("INSERT INTO sample_table(str_col,num_col) VALUES('Ford', 100)"); + jt.update("INSERT INTO sample_table(str_col,num_col) VALUES('Toyota', 200)"); + jt.update("INSERT INTO sample_table(str_col,num_col) VALUES('Mazda', 300)"); + initialized = true; + } + this.ds = ds; + } + + public String execute() { + + // Only refresh the data every minute as needed + long now = System.currentTimeMillis(); + if (lastLoaded + CACHE_TIME < now) { + SimpleJdbcTemplate jt = new SimpleJdbcTemplate(ds); + data = jt.queryForList("SELECT * FROM sample_table"); + lastLoaded = now; + } + return SUCCESS; + } + + public List> getData() { + return data; + } +} + diff --git a/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/resources/struts.xml b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/resources/struts.xml new file mode 100644 index 000000000..8a49126a8 --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/resources/struts.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + index + /view + + + + diff --git a/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/applicationContext.xml b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/applicationContext.xml new file mode 100644 index 000000000..7b9650d15 --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/applicationContext.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + diff --git a/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/edit/index-input.jsp b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/edit/index-input.jsp new file mode 100644 index 000000000..9fdb02124 --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/edit/index-input.jsp @@ -0,0 +1,10 @@ +<%@ taglib prefix="s" uri="/struts-tags" %> +

StrutsPortlet

+This is the default edit page! +

+ + + + + + diff --git a/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/edit/index-success.jsp b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/edit/index-success.jsp new file mode 100644 index 000000000..fbbb56e67 --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/edit/index-success.jsp @@ -0,0 +1,22 @@ +<%@ taglib prefix="s" uri="/struts-tags" %> + +The preferences has been saved: + +

+ + + + + + + + + + + + + + +
NameValue
Preference 1
Preference 2
+ +">Back diff --git a/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/help/index.jsp b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/help/index.jsp new file mode 100644 index 000000000..c8fb774f7 --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/help/index.jsp @@ -0,0 +1 @@ +This is the default help page! diff --git a/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/portlet.xml b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/portlet.xml new file mode 100644 index 000000000..f9153019b --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/portlet.xml @@ -0,0 +1,63 @@ + + + Struts Database Portlet + StrutsDBPortlet + Struts Database Portlet + + org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher + + + actionPackages + ${package} + + + + viewNamespace + /view + + + + defaultViewAction + index + + + + editNamespace + /edit + + + + defaultEditAction + index + + + + helpNamespace + /help + + + + defaultHelpAction + index + + + 0 + + + text/html + edit + help + + + en + + + Struts Database Porlet + DB + struts,portlet,database + + + + diff --git a/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/view/index.jsp b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/view/index.jsp new file mode 100644 index 000000000..5cd1fef93 --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/view/index.jsp @@ -0,0 +1,20 @@ +<%@ taglib prefix="s" uri="/struts-tags" %> +

Welcome to the Struts data table portlet

+

+This a simple table showing the database data: + + + + + + + + + + + +
NameValue
+

diff --git a/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..7c8e596a3 --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,37 @@ + + + + + + contextConfigLocation + /WEB-INF/applicationContext*.xml + + + + struts + org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter + + + + struts + /* + + + + org.springframework.web.context.ContextLoaderListener + + + + org.apache.struts2.portlet.context.ServletContextHolderListener + + + + preparator + org.apache.struts2.portlet.context.PreparatorServlet + + + + index.jsp + + + diff --git a/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/index.jsp b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/index.jsp new file mode 100644 index 000000000..737c71f27 --- /dev/null +++ b/achetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/index.jsp @@ -0,0 +1,4 @@ +<% + String redirectURL = "view/index.action"; + response.sendRedirect(redirectURL); +%>