Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Olexiy Prokhorenko committed Apr 19, 2009
0 parents commit dd97f5d
Show file tree
Hide file tree
Showing 17 changed files with 522 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
nbproject/
war/WEB-INF/lib/
war/WEB-INF/classes/com/

95 changes: 95 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<project name="alexqwe3-1" default="datanucleusenhance">
<property name="sdk.dir" location="/usr/local/appengine" />
<property name="struts.dir" location="/usr/local/jars/struts-2.1.6" />

<import file="${sdk.dir}/config/user/ant-macros.xml" />

<path id="project.classpath">
<pathelement path="war/WEB-INF/classes" />
<fileset dir="war/WEB-INF/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="${sdk.dir}/lib">
<include name="shared/**/*.jar" />
</fileset>
</path>

<target name="copyjars"
description="Copies the App Engine JARs to the WAR.">
<mkdir dir="war/WEB-INF/lib" />
<copy
todir="war/WEB-INF/lib"
flatten="true">
<fileset dir="${sdk.dir}/lib/user">
<include name="**/*.jar" />
</fileset>
</copy>
<!-- struts -->
<copy todir="war/WEB-INF/lib" flatten="true">
<fileset dir="${struts.dir}">
<include name="lib/commons-beanutils-*.jar"/> <!-- 1.7.0 -->
<include name="lib/commons-logging-*.jar"/> <!-- 1.0.4 -->
<include name="lib/commons-fileupload-*.jar"/> <!-- 1.2.1 -->
<include name="lib/freemarker-*.jar"/> <!-- 2.3.13 -->
<include name="lib/ognl-*.jar"/> <!-- 2.6.11 -->
<include name="lib/struts2-core-*.jar"/> <!-- 2.0.8 -->
<include name="lib/struts2-sitemesh-plugin-*.jar"/> <!-- 2.1.6 -->
<include name="lib/xwork-*.jar"/> <!-- 2.1.2 -->
</fileset>
</copy>
</target>

<target name="compile" depends="copyjars"
description="Compiles Java source and copies other source files to the WAR.">
<mkdir dir="war/WEB-INF/classes" />
<copy todir="war/WEB-INF/classes">
<fileset dir="src">
<exclude name="**/*.java" />
</fileset>
</copy>
<javac
srcdir="src"
destdir="war/WEB-INF/classes"
classpathref="project.classpath"
debug="on" />
</target>

<target name="datanucleusenhance" depends="compile"
description="Performs JDO enhancement on compiled data classes.">
<enhance_war war="war" />
</target>

<target name="runserver" depends="datanucleusenhance"
description="Starts the development server.">
<dev_appserver war="war" />
</target>

<target name="update" depends="datanucleusenhance"
description="Uploads the application to App Engine.">
<appcfg action="update" war="war" />
</target>

<target name="update_indexes" depends="datanucleusenhance"
description="Uploads just the datastore index configuration to App Engine.">
<appcfg action="update_indexes" war="war" />
</target>

<target name="rollback" depends="datanucleusenhance"
description="Rolls back an interrupted application update.">
<appcfg action="rollback" war="war" />
</target>

<target name="request_logs"
description="Downloads log data from App Engine for the application.">
<appcfg action="request_logs" war="war">
<options>
<arg value="--num_days=5"/>
</options>
<args>
<arg value="logs.txt"/>
</args>
</appcfg>
</target>

</project>

65 changes: 65 additions & 0 deletions src/com/qwe3/sandbox/action/RecordAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.qwe3.sandbox.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.qwe3.sandbox.base.PMF;
import com.qwe3.sandbox.model.Profile;

import javax.jdo.PersistenceManager;

public class RecordAction extends ActionSupport implements Preparable {

private Profile profile;
private List profiles;

public String doSave() {
if (profile.getId() == null) {
PMF.get().getPersistenceManager().makePersistent(profile);
} else {
PersistenceManager pm = PMF.get().getPersistenceManager();
Profile profileOld = pm.getObjectById(Profile.class, profile.getId());
profileOld.setEmail( profile.getEmail() );
profileOld.setName( profile.getName() );
pm.makePersistent(profileOld);
pm.close(); // important!!!
}
return SUCCESS;
}

public String doDelete() {
PersistenceManager pm = PMF.get().getPersistenceManager();
profile = pm.getObjectById(Profile.class, profile.getId());
pm.deletePersistent(profile);
return SUCCESS;
}

public String doList() {
profiles = (List) PMF.get().getPersistenceManager().newQuery(Profile.class).execute();
return SUCCESS;
}

public String doInput() {
return INPUT;
}

public Profile getProfile() {
return profile;
}

public void setProfile(Profile profile) {
this.profile = profile;
}

public List getProfiles() {
return profiles;
}

public void prepare() throws Exception {
if (profile != null && profile.getId() != null) {
profile = PMF.get().getPersistenceManager().getObjectById(Profile.class, profile.getId());
}
}

}
37 changes: 37 additions & 0 deletions src/com/qwe3/sandbox/base/InitListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.qwe3.sandbox.base;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import ognl.OgnlRuntime;

public class InitListener implements ServletContextListener, HttpSessionListener, HttpSessionAttributeListener {

public InitListener() {
}

public void contextInitialized(ServletContextEvent sce) {
OgnlRuntime.setSecurityManager(null);
}

public void contextDestroyed(ServletContextEvent arg0) {
}

public void sessionCreated(HttpSessionEvent arg0) {
}

public void sessionDestroyed(HttpSessionEvent arg0) {
}

public void attributeAdded(HttpSessionBindingEvent arg0) {
}

public void attributeRemoved(HttpSessionBindingEvent arg0) {
}

public void attributeReplaced(HttpSessionBindingEvent arg0) {
}
}
16 changes: 16 additions & 0 deletions src/com/qwe3/sandbox/base/PMF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.qwe3.sandbox.base;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;

public final class PMF {
private static final PersistenceManagerFactory pmfInstance =
JDOHelper.getPersistenceManagerFactory("transactions-optional");

private PMF() {
}

public static PersistenceManagerFactory get() {
return pmfInstance;
}
}
64 changes: 64 additions & 0 deletions src/com/qwe3/sandbox/model/Profile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.qwe3.sandbox.model;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Profile {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private String name;
@Persistent
private String email;

public Profile() {
this.name = "";
this.email = "";
}

public Profile(String email) {
this.name = "";
this.email = email;
}

public Profile(String name, String email) {
this.name = name;
this.email = email;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

@Override
public String toString() {
return "id: " + this.getId() + " [Name: " + this.getName() + " Email: " + this.getEmail() + "]";
}

}
5 changes: 5 additions & 0 deletions war/WEB-INF/appengine-web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>alexqwe3-1</application>
<sessions-enabled>false</sessions-enabled>
<version>1</version>
</appengine-web-app>
14 changes: 14 additions & 0 deletions war/WEB-INF/classes/META-INF/jdoconfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
<persistence-manager-factory name="transactions-optional">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/>
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
<property name="javax.jdo.option.RetainValues" value="true"/>
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
</persistence-manager-factory>
</jdoconfig>
20 changes: 20 additions & 0 deletions war/WEB-INF/classes/demo.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#labels
application.title=Profile Maintenance Application
label.profiles=Profiles
label.delete=Delete
label.edit=Edit
label.profile.edit=Edit Profile
label.profile.add=Add Profile
label.name=Name
label.email=Email

#button labels
button.label.submit=Submit
button.label.cancel=Cancel

##-- errors
errors.prefix=<span style="color:red;font-weight:bold;">
errors.suffix=</span>
errors.general=An Error Has Occcured
errors.required.name=Name is required.
errors.required.email=Email is required.
1 change: 1 addition & 0 deletions war/WEB-INF/classes/struts.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
struts.custom.i18n.resources=demo
24 changes: 24 additions & 0 deletions war/WEB-INF/classes/struts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- Include webwork default (from the Struts JAR). -->
<include file="struts-default.xml"/>

<!-- Configuration for the default package. -->
<package name="default" extends="struts-default">

<!-- Default interceptor stack. -->
<default-interceptor-ref name="paramsPrepareParamsStack"/>
<action name="index" class="com.qwe3.sandbox.action.RecordAction" method="list">
<result name="success">/WEB-INF/jsp/profiles.jsp</result>
<!-- we don't need the full stack here -->
<interceptor-ref name="basicStack"/>
</action>
<action name="crud" class="com.qwe3.sandbox.action.RecordAction" method="input">
<result name="success" type="redirectAction">index</result>
<result name="input">/WEB-INF/jsp/profileForm.jsp</result>
<result name="error">/WEB-INF/jsp/error.jsp</result>
</action>
</package>
</struts>
18 changes: 18 additions & 0 deletions war/WEB-INF/jsp/error.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Error Page</title>
<link href="<s:url value='/css/main.css'/>" rel="stylesheet" type="text/css"/>
</head>
<body>
<s:actionerror/>
<br/>
In order that the development team can address this error, please report what you were doing that caused this error.
<br/><br/>
The following information can help the development
team find where the error happened and what can be done to prevent it from
happening in the future.

</body>
</html>
Loading

0 comments on commit dd97f5d

Please sign in to comment.