You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by jo...@apache.org on 2012/10/19 20:49:48 UTC
svn commit: r1400220 [2/9] - in /struts/struts2/trunk/apps/showcase: ./
src/main/java/org/apache/struts2/showcase/
src/main/java/org/apache/struts2/showcase/action/
src/main/java/org/apache/struts2/showcase/actionchaining/
src/main/java/org/apache/stru...
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/action/JSPEvalAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/action/JSPEvalAction.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/action/JSPEvalAction.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/action/JSPEvalAction.java Fri Oct 19 18:49:39 2012
@@ -20,58 +20,52 @@
*/
package org.apache.struts2.showcase.action;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.net.URL;
-
-import org.apache.struts2.ServletActionContext;
-
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.interceptor.annotations.After;
+import org.apache.struts2.ServletActionContext;
+
+import java.io.*;
+import java.net.URL;
/**
* Will only work on containers that unzip war files
- *
*/
public class JSPEvalAction extends ExampleAction {
- private String jsp;
- private final static String FILE = "/interactive/demo.jsp";
+ private String jsp;
+ private final static String FILE = "/interactive/demo.jsp";
- public String execute() throws IOException {
- if (jsp != null) {
- //write it to file
- URL url = ServletActionContext.getServletContext().getResource(FILE);
- BufferedWriter writer = new BufferedWriter(new FileWriter(new File(url
- .getFile())));
- try {
- //directive
- writer.write("<%@ taglib prefix=\"s\" uri=\"/struts-tags\" %>");
- writer.write(jsp);
- } finally {
- if (writer != null)
- writer.close();
- }
- }
- return Action.SUCCESS;
- }
-
- @After
- public void cleanUp() throws IOException {
- URL url = ServletActionContext.getServletContext().getResource(FILE);
- FileOutputStream out = new FileOutputStream(new File(url.getFile()));
- try {
- out.getChannel().truncate(0);
- } finally {
- if (out != null)
- out.close();
- }
- }
-
- public void setJsp(String jsp) {
- this.jsp = jsp;
- }
+ public String execute() throws IOException {
+ if (jsp != null) {
+ //write it to file
+ URL url = ServletActionContext.getServletContext().getResource(FILE);
+ BufferedWriter writer = new BufferedWriter(new FileWriter(new File(url
+ .getFile())));
+ try {
+ //directive
+ writer.write("<%@ taglib prefix=\"s\" uri=\"/struts-tags\" %>");
+ writer.write(jsp);
+ } finally {
+ if (writer != null)
+ writer.close();
+ }
+ }
+ return Action.SUCCESS;
+ }
+
+ @After
+ public void cleanUp() throws IOException {
+ URL url = ServletActionContext.getServletContext().getResource(FILE);
+ FileOutputStream out = new FileOutputStream(new File(url.getFile()));
+ try {
+ out.getChannel().truncate(0);
+ } finally {
+ if (out != null)
+ out.close();
+ }
+ }
+
+ public void setJsp(String jsp) {
+ this.jsp = jsp;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/action/SkillAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/action/SkillAction.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/action/SkillAction.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/action/SkillAction.java Fri Oct 19 18:49:39 2012
@@ -20,70 +20,64 @@
*/
package org.apache.struts2.showcase.action;
+import com.opensymphony.xwork2.Preparable;
import org.apache.log4j.Logger;
import org.apache.struts2.showcase.dao.Dao;
import org.apache.struts2.showcase.dao.SkillDao;
import org.apache.struts2.showcase.model.Skill;
-
-import com.opensymphony.xwork2.Preparable;
+import org.springframework.beans.factory.annotation.Autowired;
/**
* SkillAction.
- *
*/
public class SkillAction extends AbstractCRUDAction implements Preparable {
- private static final Logger log = Logger.getLogger(SkillAction.class);
+ private static final Logger log = Logger.getLogger(SkillAction.class);
+
+ @Autowired
+ private SkillDao skillDao;
+
+ private String skillName;
+ private Skill currentSkill;
- private String skillName;
- protected SkillDao skillDao;
- private Skill currentSkill;
-
- public String getSkillName() {
- return skillName;
- }
-
- public void setSkillName(String skillName) {
- this.skillName = skillName;
- }
-
- protected Dao getDao() {
- return skillDao;
- }
-
- public void setSkillDao(SkillDao skillDao) {
- if (log.isDebugEnabled()) {
- log.debug("SkillAction - [setSkillDao]: skillDao injected.");
- }
- this.skillDao = skillDao;
- }
-
- public Skill getCurrentSkill() {
- return currentSkill;
- }
-
- public void setCurrentSkill(Skill currentSkill) {
- this.currentSkill = currentSkill;
- }
-
- /**
- * This method is called to allow the action to prepare itself.
- *
- * @throws Exception thrown if a system level exception occurs.
- */
- public void prepare() throws Exception {
- Skill preFetched = (Skill) fetch(getSkillName(), getCurrentSkill());
- if (preFetched != null) {
- setCurrentSkill(preFetched);
- }
- }
-
- public String save() throws Exception {
- if (getCurrentSkill() != null) {
- setSkillName((String) skillDao.merge(getCurrentSkill()));
- }
- return SUCCESS;
- }
+ /**
+ * This method is called to allow the action to prepare itself.
+ *
+ * @throws Exception thrown if a system level exception occurs.
+ */
+ public void prepare() throws Exception {
+ Skill preFetched = (Skill) fetch(getSkillName(), getCurrentSkill());
+ if (preFetched != null) {
+ setCurrentSkill(preFetched);
+ }
+ }
+
+ public String save() throws Exception {
+ if (getCurrentSkill() != null) {
+ setSkillName((String) skillDao.merge(getCurrentSkill()));
+ }
+ return SUCCESS;
+ }
+
+ public String getSkillName() {
+ return skillName;
+ }
+
+ public void setSkillName(String skillName) {
+ this.skillName = skillName;
+ }
+
+ protected Dao getDao() {
+ return skillDao;
+ }
+
+ public Skill getCurrentSkill() {
+ return currentSkill;
+ }
+
+ public void setCurrentSkill(Skill currentSkill) {
+ this.currentSkill = currentSkill;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain1.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain1.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain1.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain1.java Fri Oct 19 18:49:39 2012
@@ -22,24 +22,21 @@ package org.apache.struts2.showcase.acti
import com.opensymphony.xwork2.ActionSupport;
-/**
- *
- */
public class ActionChain1 extends ActionSupport {
- private static final long serialVersionUID = -6811701750042275153L;
+ private static final long serialVersionUID = -6811701750042275153L;
- private String actionChain1Property1 = "Property Set In Action Chain 1";
+ private String actionChain1Property1 = "Property Set In Action Chain 1";
- public String getActionChain1Property1() {
- return actionChain1Property1;
- }
- public void setActionChain1Property1(String actionChain1Property1) {
- this.actionChain1Property1 = actionChain1Property1;
- }
+ public String input() throws Exception {
+ return SUCCESS;
+ }
+ public String getActionChain1Property1() {
+ return actionChain1Property1;
+ }
- public String input() throws Exception {
- return SUCCESS;
- }
+ public void setActionChain1Property1(String actionChain1Property1) {
+ this.actionChain1Property1 = actionChain1Property1;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain2.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain2.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain2.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain2.java Fri Oct 19 18:49:39 2012
@@ -22,37 +22,31 @@ package org.apache.struts2.showcase.acti
import com.opensymphony.xwork2.ActionSupport;
-/**
- *
- */
public class ActionChain2 extends ActionSupport {
- private static final long serialVersionUID = 3951745956044674809L;
+ private static final long serialVersionUID = 3951745956044674809L;
- private String actionChain1Property1;
- private String actionChain2Property1 = "Property Set in Action Chain 2";
+ private String actionChain1Property1;
+ private String actionChain2Property1 = "Property Set in Action Chain 2";
+ public String execute() throws Exception {
+ return SUCCESS;
+ }
- public String getActionChain1Property1() {
- return actionChain1Property1;
- }
- public void setActionChain1Property1(String actionChain1Property1) {
- this.actionChain1Property1 = actionChain1Property1;
- }
+ public String getActionChain1Property1() {
+ return actionChain1Property1;
+ }
+ public void setActionChain1Property1(String actionChain1Property1) {
+ this.actionChain1Property1 = actionChain1Property1;
+ }
- public String getActionChain2Property1() {
- return actionChain2Property1;
- }
- public void setActionChain2Property1(String actionChain2Property1) {
- this.actionChain2Property1 = actionChain2Property1;
- }
+ public String getActionChain2Property1() {
+ return actionChain2Property1;
+ }
-
-
-
- public String execute() throws Exception {
- return SUCCESS;
- }
+ public void setActionChain2Property1(String actionChain2Property1) {
+ this.actionChain2Property1 = actionChain2Property1;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain3.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain3.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain3.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/actionchaining/ActionChain3.java Fri Oct 19 18:49:39 2012
@@ -22,47 +22,42 @@ package org.apache.struts2.showcase.acti
import com.opensymphony.xwork2.ActionSupport;
-/**
- *
- */
public class ActionChain3 extends ActionSupport {
- private static final long serialVersionUID = -1456568865075250621L;
+ private static final long serialVersionUID = -1456568865075250621L;
- private String actionChain1Property1;
- private String actionChain2Property1;
- private String actionChain3Property1 = "Property set in Action Chain 3";
+ private String actionChain1Property1;
+ private String actionChain2Property1;
+ private String actionChain3Property1 = "Property set in Action Chain 3";
- public String getActionChain1Property1() {
- return actionChain1Property1;
- }
- public void setActionChain1Property1(String actionChain1Property1) {
- this.actionChain1Property1 = actionChain1Property1;
- }
+ public String execute() throws Exception {
+ return SUCCESS;
+ }
+ public String getActionChain1Property1() {
+ return actionChain1Property1;
+ }
+ public void setActionChain1Property1(String actionChain1Property1) {
+ this.actionChain1Property1 = actionChain1Property1;
+ }
- public String getActionChain2Property1() {
- return actionChain2Property1;
- }
- public void setActionChain2Property1(String actionChain2Property1) {
- this.actionChain2Property1 = actionChain2Property1;
- }
+ public String getActionChain2Property1() {
+ return actionChain2Property1;
+ }
+ public void setActionChain2Property1(String actionChain2Property1) {
+ this.actionChain2Property1 = actionChain2Property1;
+ }
- public String getActionChain3Property1() {
- return actionChain3Property1;
- }
- public void setActionChain3Property1(String actionChain3Property1) {
- this.actionChain3Property1 = actionChain3Property1;
- }
+ public String getActionChain3Property1() {
+ return actionChain3Property1;
+ }
-
-
- public String execute() throws Exception {
- return SUCCESS;
- }
+ public void setActionChain3Property1(String actionChain3Property1) {
+ this.actionChain3Property1 = actionChain3Property1;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AjaxTestAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AjaxTestAction.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AjaxTestAction.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AjaxTestAction.java Fri Oct 19 18:49:39 2012
@@ -25,30 +25,28 @@ import com.opensymphony.xwork2.Action;
import java.io.Serializable;
-/**
- */
public class AjaxTestAction implements Action, Serializable {
- private static int counter = 0;
- private String data;
+ private static int counter = 0;
+ private String data;
- public long getServerTime() {
- return System.currentTimeMillis();
- }
-
- public int getCount() {
- return ++counter;
- }
-
- public String getData() {
- return data;
- }
-
- public void setData(String data) {
- this.data = data;
- }
-
- public String execute() throws Exception {
- return SUCCESS;
- }
+ public String execute() throws Exception {
+ return SUCCESS;
+ }
+
+ public long getServerTime() {
+ return System.currentTimeMillis();
+ }
+
+ public int getCount() {
+ return ++counter;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AutocompleterExampleAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AutocompleterExampleAction.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AutocompleterExampleAction.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/AutocompleterExampleAction.java Fri Oct 19 18:49:39 2012
@@ -20,40 +20,40 @@
*/
package org.apache.struts2.showcase.ajax;
+import com.opensymphony.xwork2.ActionSupport;
+
import java.util.ArrayList;
import java.util.List;
-import com.opensymphony.xwork2.ActionSupport;
-
public class AutocompleterExampleAction extends ActionSupport {
- private String select;
- private List<String> options = new ArrayList<String>();
+ private String select;
+ private List<String> options = new ArrayList<String>();
- private static final long serialVersionUID = -8481638176160014396L;
+ private static final long serialVersionUID = -8481638176160014396L;
- public String execute() throws Exception {
- if ("fruits".equals(select)) {
- options.add("apple");
- options.add("banana");
- options.add("grape");
- options.add("pear");
- } else if ("colors".equals(select)) {
- options.add("red");
- options.add("green");
- options.add("blue");
- }
- return SUCCESS;
- }
-
- public String getSelect() {
- return select;
- }
-
- public void setSelect(String select) {
- this.select = select;
- }
-
- public List<String> getOptions() {
- return options;
- }
+ public String execute() throws Exception {
+ if ("fruits".equals(select)) {
+ options.add("apple");
+ options.add("banana");
+ options.add("grape");
+ options.add("pear");
+ } else if ("colors".equals(select)) {
+ options.add("red");
+ options.add("green");
+ options.add("blue");
+ }
+ return SUCCESS;
+ }
+
+ public String getSelect() {
+ return select;
+ }
+
+ public void setSelect(String select) {
+ this.select = select;
+ }
+
+ public List<String> getOptions() {
+ return options;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example4ShowPanelAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example4ShowPanelAction.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example4ShowPanelAction.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example4ShowPanelAction.java Fri Oct 19 18:49:39 2012
@@ -20,56 +20,56 @@
*/
package org.apache.struts2.showcase.ajax;
+import com.opensymphony.xwork2.ActionSupport;
+
import java.text.SimpleDateFormat;
import java.util.Date;
-import com.opensymphony.xwork2.ActionSupport;
-
/**
* @version $Date$ $Id$
*/
public class Example4ShowPanelAction extends ActionSupport {
- private String name;
- private String gender;
+ private String name;
+ private String gender;
- private static final long serialVersionUID = 7751976335066456596L;
+ private static final long serialVersionUID = 7751976335066456596L;
- public String panel1() throws Exception {
- return SUCCESS;
- }
-
- public String panel2() throws Exception {
- return SUCCESS;
- }
-
- public String panel3() throws Exception {
- return SUCCESS;
- }
-
- public String getGender() {
- return gender;
- }
-
- public void setGender(String gender) {
- this.gender = gender;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getTodayDate() {
- SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMM-yyyy");
- return sdf.format(new Date());
- }
-
- public String getTodayTime() {
- SimpleDateFormat sdf = new SimpleDateFormat("kk:mm:ss");
- return sdf.format(new Date());
- }
+ public String panel1() throws Exception {
+ return SUCCESS;
+ }
+
+ public String panel2() throws Exception {
+ return SUCCESS;
+ }
+
+ public String panel3() throws Exception {
+ return SUCCESS;
+ }
+
+ public String getGender() {
+ return gender;
+ }
+
+ public void setGender(String gender) {
+ this.gender = gender;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getTodayDate() {
+ SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMM-yyyy");
+ return sdf.format(new Date());
+ }
+
+ public String getTodayTime() {
+ SimpleDateFormat sdf = new SimpleDateFormat("kk:mm:ss");
+ return sdf.format(new Date());
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example5Action.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example5Action.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example5Action.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/Example5Action.java Fri Oct 19 18:49:39 2012
@@ -24,20 +24,28 @@ import com.opensymphony.xwork2.ActionSup
public class Example5Action extends ActionSupport {
- private static final long serialVersionUID = 2111967621952300611L;
+ private static final long serialVersionUID = 2111967621952300611L;
- private String name;
- private Integer age;
+ private String name;
+ private Integer age;
-
- public String getName() { return name; }
- public void setName(String name) { this.name = name; }
-
- public Integer getAge() { return age; }
- public void setAge(Integer age) { this.age = age; }
-
- @Override
- public String execute() throws Exception {
- return SUCCESS;
- }
+ public String execute() throws Exception {
+ return SUCCESS;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Integer getAge() {
+ return age;
+ }
+
+ public void setAge(Integer age) {
+ this.age = age;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/Category.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/Category.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/Category.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/Category.java Fri Oct 19 18:49:39 2012
@@ -28,77 +28,77 @@ import java.util.Map;
/**
*/
public class Category {
- private static Map<Long, Category> catMap = new HashMap<Long, Category>();
+ private static Map<Long, Category> catMap = new HashMap<Long, Category>();
- static {
- new Category(1, "Root",
- new Category(2, "Java",
- new Category(3, "Web Frameworks",
- new Category(4, "Struts"),
- new Category(7, "Stripes"),
- new Category(8, "Rife")),
- new Category(9, "Persistence",
- new Category(10, "iBatis"),
- new Category(11, "Hibernate"),
- new Category(12, "JDO"),
- new Category(13, "JDBC"))),
- new Category(14, "JavaScript",
- new Category(15, "Dojo"),
- new Category(16, "Prototype"),
- new Category(17, "Scriptaculous"),
- new Category(18, "OpenRico"),
- new Category(19, "DWR")));
- }
-
- public static Category getById(long id) {
- return catMap.get(id);
- }
-
- private long id;
- private String name;
- private List<Category> children;
- private boolean toggle;
-
- public Category(long id, String name, Category... children) {
- this.id = id;
- this.name = name;
- this.children = new ArrayList<Category>();
- for (Category child : children) {
- this.children.add(child);
- }
-
- catMap.put(id, this);
- }
-
- public long getId() {
- return id;
- }
-
- public void setId(long id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public List<Category> getChildren() {
- return children;
- }
-
- public void setChildren(List<Category> children) {
- this.children = children;
- }
-
- public void toggle() {
- toggle = !toggle;
- }
-
- public boolean isToggle() {
- return toggle;
- }
+ static {
+ new Category(1, "Root",
+ new Category(2, "Java",
+ new Category(3, "Web Frameworks",
+ new Category(4, "Struts"),
+ new Category(7, "Stripes"),
+ new Category(8, "Rife")),
+ new Category(9, "Persistence",
+ new Category(10, "iBatis"),
+ new Category(11, "Hibernate"),
+ new Category(12, "JDO"),
+ new Category(13, "JDBC"))),
+ new Category(14, "JavaScript",
+ new Category(15, "Dojo"),
+ new Category(16, "Prototype"),
+ new Category(17, "Scriptaculous"),
+ new Category(18, "OpenRico"),
+ new Category(19, "DWR")));
+ }
+
+ public static Category getById(long id) {
+ return catMap.get(id);
+ }
+
+ private long id;
+ private String name;
+ private List<Category> children;
+ private boolean toggle;
+
+ public Category(long id, String name, Category... children) {
+ this.id = id;
+ this.name = name;
+ this.children = new ArrayList<Category>();
+ for (Category child : children) {
+ this.children.add(child);
+ }
+
+ catMap.put(id, this);
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List<Category> getChildren() {
+ return children;
+ }
+
+ public void setChildren(List<Category> children) {
+ this.children = children;
+ }
+
+ public void toggle() {
+ toggle = !toggle;
+ }
+
+ public boolean isToggle() {
+ return toggle;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/GetCategory.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/GetCategory.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/GetCategory.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/GetCategory.java Fri Oct 19 18:49:39 2012
@@ -25,25 +25,25 @@ import com.opensymphony.xwork2.ActionSup
/**
*/
public class GetCategory extends ActionSupport {
- private long catId;
- private Category category;
+ private long catId;
+ private Category category;
- public String execute() throws Exception {
- if (catId < 1) {
- // force the root
- catId = 1;
- }
+ public String execute() throws Exception {
+ if (catId < 1) {
+ // force the root
+ catId = 1;
+ }
- category = Category.getById(catId);
+ category = Category.getById(catId);
- return SUCCESS;
- }
+ return SUCCESS;
+ }
- public void setCatId(long catId) {
- this.catId = catId;
- }
+ public void setCatId(long catId) {
+ this.catId = catId;
+ }
- public Category getCategory() {
- return category;
- }
+ public Category getCategory() {
+ return category;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/Toggle.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/Toggle.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/Toggle.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/ajax/tree/Toggle.java Fri Oct 19 18:49:39 2012
@@ -24,11 +24,11 @@ package org.apache.struts2.showcase.ajax
/**
*/
public class Toggle extends GetCategory {
- public String execute() throws Exception {
- super.execute();
+ public String execute() throws Exception {
+ super.execute();
- getCategory().toggle();
+ getCategory().toggle();
- return SUCCESS;
- }
+ return SUCCESS;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/application/MemoryStorage.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/application/MemoryStorage.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/application/MemoryStorage.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/application/MemoryStorage.java Fri Oct 19 18:49:39 2012
@@ -20,123 +20,126 @@
*/
package org.apache.struts2.showcase.application;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.struts2.showcase.exception.CreateException;
import org.apache.struts2.showcase.exception.DuplicateKeyException;
import org.apache.struts2.showcase.exception.StorageException;
import org.apache.struts2.showcase.exception.UpdateException;
import org.apache.struts2.showcase.model.IdEntity;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Repository;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
/**
* MemoryStorage.
* Very simple in-memory persistence emulation.
- *
*/
+@Repository
+@Scope("singleton")
public class MemoryStorage implements Storage {
- private static final long serialVersionUID = 8611213748834904125L;
+ private static final long serialVersionUID = 8611213748834904125L;
- private Map memory = new HashMap();
+ private Map memory = new HashMap();
- private Map getEntityMap ( Class entityClass ) {
- if (entityClass != null) {
- Map tryMap = (Map) memory.get(entityClass);
- if (tryMap == null) {
- synchronized(memory) {
- tryMap = new HashMap();
- memory.put(entityClass, tryMap);
- }
- }
- return tryMap;
- } else {
- return null;
- }
- }
-
- private IdEntity intStore( Class entityClass, IdEntity object ) {
- getEntityMap(entityClass).put(object.getId(), object);
- return object;
- }
-
- public IdEntity get( Class entityClass, Serializable id ) {
- if (entityClass != null && id != null) {
- return (IdEntity) getEntityMap(entityClass).get(id);
- } else {
- return null;
- }
- }
-
- public Serializable create ( IdEntity object ) throws CreateException {
- if (object == null) {
- throw new CreateException("Either given class or object was null");
- }
- if (object.getId() == null) {
- throw new CreateException("Cannot store object with null id");
- }
- if (get(object.getClass(), object.getId()) != null) {
- throw new DuplicateKeyException("Object with this id already exists.");
- }
- return intStore(object.getClass(), object).getId();
- }
-
- public IdEntity update ( IdEntity object ) throws UpdateException {
- if (object == null) {
- throw new UpdateException("Cannot update null object.");
- }
- if ( get(object.getClass(), object.getId())==null ) {
- throw new UpdateException("Object to update not found.");
- }
- return intStore(object.getClass(), object);
- }
-
- public Serializable merge ( IdEntity object ) throws StorageException {
- if (object == null) {
- throw new StorageException("Cannot merge null object");
- }
- if (object.getId() == null || get(object.getClass(), object.getId())==null) {
- return create(object);
- } else {
- return update(object).getId();
- }
- }
-
- public int delete( Class entityClass, Serializable id ) throws CreateException {
- try {
- if (get(entityClass, id) != null) {
- getEntityMap(entityClass).remove(id);
- return 1;
- } else {
- return 0;
- }
- } catch (Exception e) {
- throw new CreateException(e);
- }
- }
-
- public int delete( IdEntity object ) throws CreateException {
- if (object == null) {
- throw new CreateException("Cannot delete null object");
- }
- return delete(object.getClass(), object.getId());
- }
-
- public Collection findAll( Class entityClass ) {
- if (entityClass != null) {
- return getEntityMap(entityClass).values();
- } else {
- return new ArrayList();
- }
- }
-
- public void reset() {
- this.memory = new HashMap();
- }
+ private Map getEntityMap(Class entityClass) {
+ if (entityClass != null) {
+ Map tryMap = (Map) memory.get(entityClass);
+ if (tryMap == null) {
+ synchronized (memory) {
+ tryMap = new HashMap();
+ memory.put(entityClass, tryMap);
+ }
+ }
+ return tryMap;
+ } else {
+ return null;
+ }
+ }
+
+ private IdEntity intStore(Class entityClass, IdEntity object) {
+ getEntityMap(entityClass).put(object.getId(), object);
+ return object;
+ }
+
+ public IdEntity get(Class entityClass, Serializable id) {
+ if (entityClass != null && id != null) {
+ return (IdEntity) getEntityMap(entityClass).get(id);
+ } else {
+ return null;
+ }
+ }
+
+ public Serializable create(IdEntity object) throws CreateException {
+ if (object == null) {
+ throw new CreateException("Either given class or object was null");
+ }
+ if (object.getId() == null) {
+ throw new CreateException("Cannot store object with null id");
+ }
+ if (get(object.getClass(), object.getId()) != null) {
+ throw new DuplicateKeyException("Object with this id already exists.");
+ }
+ return intStore(object.getClass(), object).getId();
+ }
+
+ public IdEntity update(IdEntity object) throws UpdateException {
+ if (object == null) {
+ throw new UpdateException("Cannot update null object.");
+ }
+ if (get(object.getClass(), object.getId()) == null) {
+ throw new UpdateException("Object to update not found.");
+ }
+ return intStore(object.getClass(), object);
+ }
+
+ public Serializable merge(IdEntity object) throws StorageException {
+ if (object == null) {
+ throw new StorageException("Cannot merge null object");
+ }
+ if (object.getId() == null || get(object.getClass(), object.getId()) == null) {
+ return create(object);
+ } else {
+ return update(object).getId();
+ }
+ }
+
+ public int delete(Class entityClass, Serializable id) throws CreateException {
+ try {
+ if (get(entityClass, id) != null) {
+ getEntityMap(entityClass).remove(id);
+ return 1;
+ } else {
+ return 0;
+ }
+ } catch (Exception e) {
+ throw new CreateException(e);
+ }
+ }
+
+ public int delete(IdEntity object) throws CreateException {
+ if (object == null) {
+ throw new CreateException("Cannot delete null object");
+ }
+ return delete(object.getClass(), object.getId());
+ }
+
+ public Collection findAll(Class entityClass) {
+ if (entityClass != null) {
+ return getEntityMap(entityClass).values();
+ } else {
+ return new ArrayList();
+ }
+ }
+
+ public void reset() {
+ this.memory = new HashMap();
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/application/Storage.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/application/Storage.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/application/Storage.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/application/Storage.java Fri Oct 19 18:49:39 2012
@@ -20,31 +20,30 @@
*/
package org.apache.struts2.showcase.application;
-import java.io.Serializable;
-import java.util.Collection;
-
import org.apache.struts2.showcase.exception.CreateException;
import org.apache.struts2.showcase.exception.StorageException;
import org.apache.struts2.showcase.exception.UpdateException;
import org.apache.struts2.showcase.model.IdEntity;
+import java.io.Serializable;
+import java.util.Collection;
+
/**
* Storage. Interface.
- *
*/
public interface Storage extends Serializable {
- IdEntity get( Class entityClass, Serializable id );
+ IdEntity get(Class entityClass, Serializable id);
- Serializable create ( IdEntity object ) throws CreateException;
+ Serializable create(IdEntity object) throws CreateException;
- IdEntity update ( IdEntity object ) throws UpdateException;
+ IdEntity update(IdEntity object) throws UpdateException;
- Serializable merge ( IdEntity object ) throws StorageException;
+ Serializable merge(IdEntity object) throws StorageException;
- int delete( Class entityClass, Serializable id ) throws CreateException;
+ int delete(Class entityClass, Serializable id) throws CreateException;
- int delete( IdEntity object ) throws CreateException;
+ int delete(IdEntity object) throws CreateException;
- Collection findAll( Class entityClass );
+ Collection findAll(Class entityClass);
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/application/TestDataProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/application/TestDataProvider.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/application/TestDataProvider.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/application/TestDataProvider.java Fri Oct 19 18:49:39 2012
@@ -20,10 +20,6 @@
*/
package org.apache.struts2.showcase.application;
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Date;
-
import org.apache.log4j.Logger;
import org.apache.struts2.showcase.dao.EmployeeDao;
import org.apache.struts2.showcase.dao.SkillDao;
@@ -31,88 +27,87 @@ import org.apache.struts2.showcase.excep
import org.apache.struts2.showcase.model.Employee;
import org.apache.struts2.showcase.model.Skill;
import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Date;
/**
* TestDataProvider.
- *
*/
-
+@Service
public class TestDataProvider implements Serializable, InitializingBean {
- private static final long serialVersionUID = 1L;
-
- private static final Logger log = Logger.getLogger(TestDataProvider.class);
+ private static final long serialVersionUID = 1L;
+ private static final Logger log = Logger.getLogger(TestDataProvider.class);
- public static final String[] POSITIONS = {
- "Developer",
- "System Architect",
- "Sales Manager",
- "CEO"
- };
-
- public static final String[] LEVELS = {
- "Junior",
- "Senior",
- "Master"
- };
-
- private static final Skill[] TEST_SKILLS = {
- new Skill("WW-SEN", "Struts Senior Developer"),
- new Skill("WW-JUN", "Struts Junior Developer"),
- new Skill("SPRING-DEV", "Spring Developer")
- };
-
- public static final Employee[] TEST_EMPLOYEES = {
- new Employee(new Long(1), "Alan", "Smithee", new Date(), new Float(2000f), true, POSITIONS[0],
- TEST_SKILLS[0], null, "alan", LEVELS[0], "Nice guy"),
- new Employee(new Long(2), "Robert", "Robson", new Date(), new Float(10000f), false, POSITIONS[1],
- TEST_SKILLS[1], Arrays.asList(TEST_SKILLS).subList(1,TEST_SKILLS.length), "rob", LEVELS[1], "Smart guy")
- };
-
- private SkillDao skillDao;
- private EmployeeDao employeeDao;
-
- public void setSkillDao(SkillDao skillDao) {
- this.skillDao = skillDao;
- }
-
- public void setEmployeeDao(EmployeeDao employeeDao) {
- this.employeeDao = employeeDao;
- }
-
- protected void addTestSkills() {
- try {
- for (int i = 0, j = TEST_SKILLS.length; i < j; i++) {
- skillDao.merge(TEST_SKILLS[i]);
- }
- if (log.isInfoEnabled()) {
- log.info("TestDataProvider - [addTestSkills]: Added test skill data.");
- }
- } catch (StorageException e) {
- log.error("TestDataProvider - [addTestSkills]: Exception catched: " + e.getMessage());
- }
- }
-
- protected void addTestEmployees() {
- try {
- for (int i = 0, j = TEST_EMPLOYEES.length; i < j; i++) {
- employeeDao.merge(TEST_EMPLOYEES[i]);
- }
- if (log.isInfoEnabled()) {
- log.info("TestDataProvider - [addTestEmployees]: Added test employee data.");
- }
- } catch (StorageException e) {
- log.error("TestDataProvider - [addTestEmployees]: Exception catched: " + e.getMessage());
- }
- }
-
- protected void addTestData() {
- addTestSkills();
- addTestEmployees();
- }
-
- public void afterPropertiesSet() throws Exception {
- addTestData();
- }
+ public static final String[] POSITIONS = {
+ "Developer",
+ "System Architect",
+ "Sales Manager",
+ "CEO"
+ };
+
+ public static final String[] LEVELS = {
+ "Junior",
+ "Senior",
+ "Master"
+ };
+
+ private static final Skill[] TEST_SKILLS = {
+ new Skill("WW-SEN", "Struts Senior Developer"),
+ new Skill("WW-JUN", "Struts Junior Developer"),
+ new Skill("SPRING-DEV", "Spring Developer")
+ };
+
+ public static final Employee[] TEST_EMPLOYEES = {
+ new Employee(new Long(1), "Alan", "Smithee", new Date(), new Float(2000f), true, POSITIONS[0],
+ TEST_SKILLS[0], null, "alan", LEVELS[0], "Nice guy"),
+ new Employee(new Long(2), "Robert", "Robson", new Date(), new Float(10000f), false, POSITIONS[1],
+ TEST_SKILLS[1], Arrays.asList(TEST_SKILLS).subList(1, TEST_SKILLS.length), "rob", LEVELS[1], "Smart guy")
+ };
+
+ @Autowired
+ private SkillDao skillDao;
+
+ @Autowired
+ private EmployeeDao employeeDao;
+
+ protected void addTestSkills() {
+ try {
+ for (int i = 0, j = TEST_SKILLS.length; i < j; i++) {
+ skillDao.merge(TEST_SKILLS[i]);
+ }
+ if (log.isInfoEnabled()) {
+ log.info("TestDataProvider - [addTestSkills]: Added test skill data.");
+ }
+ } catch (StorageException e) {
+ log.error("TestDataProvider - [addTestSkills]: Exception catched: " + e.getMessage());
+ }
+ }
+
+ protected void addTestEmployees() {
+ try {
+ for (int i = 0, j = TEST_EMPLOYEES.length; i < j; i++) {
+ employeeDao.merge(TEST_EMPLOYEES[i]);
+ }
+ if (log.isInfoEnabled()) {
+ log.info("TestDataProvider - [addTestEmployees]: Added test employee data.");
+ }
+ } catch (StorageException e) {
+ log.error("TestDataProvider - [addTestEmployees]: Exception catched: " + e.getMessage());
+ }
+ }
+
+ protected void addTestData() {
+ addTestSkills();
+ addTestEmployees();
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ addTestData();
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatAuthenticationInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatAuthenticationInterceptor.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatAuthenticationInterceptor.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatAuthenticationInterceptor.java Fri Oct 19 18:49:39 2012
@@ -21,40 +21,37 @@
package org.apache.struts2.showcase.chat;
-import org.apache.struts2.dispatcher.SessionMap;
-
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import org.apache.struts2.dispatcher.SessionMap;
public class ChatAuthenticationInterceptor implements Interceptor {
- private static final long serialVersionUID = 1L;
-
- private static final Logger LOG = LoggerFactory.getLogger(ChatAuthenticationInterceptor.class);
-
- public static final String USER_SESSION_KEY = "chatUserSessionKey";
+ private static final long serialVersionUID = 1L;
+ private static final Logger LOG = LoggerFactory.getLogger(ChatAuthenticationInterceptor.class);
+ public static final String USER_SESSION_KEY = "chatUserSessionKey";
- public void destroy() {
- }
+ public void destroy() {
+ }
- public void init() {
- }
+ public void init() {
+ }
- public String intercept(ActionInvocation invocation) throws Exception {
+ public String intercept(ActionInvocation invocation) throws Exception {
- LOG.debug("Authenticating chat user");
+ LOG.debug("Authenticating chat user");
- SessionMap session = (SessionMap) ActionContext.getContext().get(ActionContext.SESSION);
- User user = (User) session.get(USER_SESSION_KEY);
+ SessionMap session = (SessionMap) ActionContext.getContext().get(ActionContext.SESSION);
+ User user = (User) session.get(USER_SESSION_KEY);
- if (user == null) {
- return Action.LOGIN;
- }
- return invocation.invoke();
- }
+ if (user == null) {
+ return Action.LOGIN;
+ }
+ return invocation.invoke();
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatException.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatException.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatException.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatException.java Fri Oct 19 18:49:39 2012
@@ -22,15 +22,15 @@ package org.apache.struts2.showcase.chat
public class ChatException extends RuntimeException {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- public enum ErrorType {
- ROOM_ALREADY_EXISTS,
- USER_ALREADY_EXISTS,
- NO_SUCH_ROOM_EXISTS
- }
+ public enum ErrorType {
+ ROOM_ALREADY_EXISTS,
+ USER_ALREADY_EXISTS,
+ NO_SUCH_ROOM_EXISTS
+ }
- public ChatException(String description, ErrorType type) {
- super(description);
- }
+ public ChatException(String description, ErrorType type) {
+ super(description);
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatInterceptor.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatInterceptor.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatInterceptor.java Fri Oct 19 18:49:39 2012
@@ -20,8 +20,6 @@
*/
package org.apache.struts2.showcase.chat;
-import javax.servlet.http.HttpSession;
-
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
@@ -29,32 +27,34 @@ import com.opensymphony.xwork2.intercept
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import javax.servlet.http.HttpSession;
+
/**
* Authenticate showcase chat example, make sure everyone have a username.
*/
public class ChatInterceptor implements Interceptor {
- private static final Logger LOG = LoggerFactory.getLogger(ChatInterceptor.class);
+ private static final Logger LOG = LoggerFactory.getLogger(ChatInterceptor.class);
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- public static final String CHAT_USER_SESSION_KEY = "ChatUserSessionKey";
+ public static final String CHAT_USER_SESSION_KEY = "ChatUserSessionKey";
- public void destroy() {
- }
+ public void destroy() {
+ }
- public void init() {
- }
-
- public String intercept(ActionInvocation invocation) throws Exception {
- HttpSession session = (HttpSession) ActionContext.getContext().get(ActionContext.SESSION);
- User chatUser = (User) session.getAttribute(CHAT_USER_SESSION_KEY);
- if (chatUser == null) {
- LOG.debug("Chat user not logged in");
- return Action.LOGIN;
- }
- return invocation.invoke();
- }
+ public void init() {
+ }
+
+ public String intercept(ActionInvocation invocation) throws Exception {
+ HttpSession session = (HttpSession) ActionContext.getContext().get(ActionContext.SESSION);
+ User chatUser = (User) session.getAttribute(CHAT_USER_SESSION_KEY);
+ if (chatUser == null) {
+ LOG.debug("Chat user not logged in");
+ return Action.LOGIN;
+ }
+ return invocation.invoke();
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatLoginAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatLoginAction.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatLoginAction.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatLoginAction.java Fri Oct 19 18:49:39 2012
@@ -20,49 +20,48 @@
*/
package org.apache.struts2.showcase.chat;
-import java.util.Map;
-
+import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.interceptor.SessionAware;
-import com.opensymphony.xwork2.ActionSupport;
+import java.util.Map;
public class ChatLoginAction extends ActionSupport implements SessionAware {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private ChatService chatService;
- private Map session;
+ private ChatService chatService;
+ private Map session;
- private String name;
+ private String name;
- public ChatLoginAction(ChatService chatService) {
- this.chatService = chatService;
- }
-
- public String getName() {
- return this.name;
- }
- public void setName(String name) {
- this.name = name;
- }
-
-
- public String execute() throws Exception {
- try {
- chatService.login(new User(name));
- session.put(ChatAuthenticationInterceptor.USER_SESSION_KEY, new User(name));
- }
- catch(ChatException e) {
- e.printStackTrace();
- addActionError(e.getMessage());
- return INPUT;
- }
- return SUCCESS;
- }
-
-
- // === SessionAware ===
- public void setSession(Map session) {
- this.session = session;
- }
+ public ChatLoginAction(ChatService chatService) {
+ this.chatService = chatService;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+ public String execute() throws Exception {
+ try {
+ chatService.login(new User(name));
+ session.put(ChatAuthenticationInterceptor.USER_SESSION_KEY, new User(name));
+ } catch (ChatException e) {
+ e.printStackTrace();
+ addActionError(e.getMessage());
+ return INPUT;
+ }
+ return SUCCESS;
+ }
+
+
+ // === SessionAware ===
+ public void setSession(Map session) {
+ this.session = session;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatLogoutAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatLogoutAction.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatLogoutAction.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatLogoutAction.java Fri Oct 19 18:49:39 2012
@@ -20,39 +20,38 @@
*/
package org.apache.struts2.showcase.chat;
-import java.util.Map;
-
+import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.interceptor.SessionAware;
-import com.opensymphony.xwork2.ActionSupport;
+import java.util.Map;
public class ChatLogoutAction extends ActionSupport implements SessionAware {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private ChatService chatService;
+ private ChatService chatService;
- private Map session;
+ private Map session;
- public ChatLogoutAction(ChatService chatService) {
- this.chatService = chatService;
- }
+ public ChatLogoutAction(ChatService chatService) {
+ this.chatService = chatService;
+ }
- public String execute() throws Exception {
+ public String execute() throws Exception {
- User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY);
- if (user != null) {
- chatService.logout(user.getName());
- session.remove(ChatAuthenticationInterceptor.USER_SESSION_KEY);
- }
+ User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY);
+ if (user != null) {
+ chatService.logout(user.getName());
+ session.remove(ChatAuthenticationInterceptor.USER_SESSION_KEY);
+ }
- return SUCCESS;
- }
+ return SUCCESS;
+ }
- // === SessionAware ===
- public void setSession(Map session) {
- this.session = session;
- }
+ // === SessionAware ===
+ public void setSession(Map session) {
+ this.session = session;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatMessage.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatMessage.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatMessage.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatMessage.java Fri Oct 19 18:49:39 2012
@@ -24,26 +24,28 @@ import java.util.Date;
public class ChatMessage {
- private Date creationDate;
- private String message;
- private User creator;
-
- public ChatMessage(String message, User creator) {
- assert(message != null);
- assert(creator != null);
-
- this.creationDate = new Date(System.currentTimeMillis());
- this.message = message;
- this.creator = creator;
- }
-
- public Date getCreationDate() {
- return creationDate;
- }
- public User getCreator() {
- return creator;
- }
- public String getMessage() {
- return message;
- }
+ private Date creationDate;
+ private String message;
+ private User creator;
+
+ public ChatMessage(String message, User creator) {
+ assert (message != null);
+ assert (creator != null);
+
+ this.creationDate = new Date(System.currentTimeMillis());
+ this.message = message;
+ this.creator = creator;
+ }
+
+ public Date getCreationDate() {
+ return creationDate;
+ }
+
+ public User getCreator() {
+ return creator;
+ }
+
+ public String getMessage() {
+ return message;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatService.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatService.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatService.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatService.java Fri Oct 19 18:49:39 2012
@@ -23,15 +23,23 @@ package org.apache.struts2.showcase.chat
import java.util.List;
public interface ChatService {
- List<User> getAvailableUsers();
- void login(User user);
- void logout(String name);
-
- List<Room> getAvailableRooms();
- void addRoom(Room room);
- void enterRoom(User user, String roomName);
- void exitRoom(String userName, String roomName);
- List<ChatMessage> getMessagesInRoom(String roomName);
- void sendMessageToRoom(String roomName, User user, String message);
- List<User> getUsersAvailableInRoom(String roomName);
+ List<User> getAvailableUsers();
+
+ void login(User user);
+
+ void logout(String name);
+
+ List<Room> getAvailableRooms();
+
+ void addRoom(Room room);
+
+ void enterRoom(User user, String roomName);
+
+ void exitRoom(String userName, String roomName);
+
+ List<ChatMessage> getMessagesInRoom(String roomName);
+
+ void sendMessageToRoom(String roomName, User user, String message);
+
+ List<User> getUsersAvailableInRoom(String roomName);
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatServiceImpl.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatServiceImpl.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatServiceImpl.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatServiceImpl.java Fri Oct 19 18:49:39 2012
@@ -27,89 +27,89 @@ import java.util.Map;
public class ChatServiceImpl implements ChatService {
- private Map<String, User> availableUsers = new LinkedHashMap<String, User>();
- private Map<String, Room> availableRooms = new LinkedHashMap<String, Room>();
+ private Map<String, User> availableUsers = new LinkedHashMap<String, User>();
+ private Map<String, Room> availableRooms = new LinkedHashMap<String, Room>();
- public List<User> getAvailableUsers() {
- return new ArrayList<User>(availableUsers.values());
- }
-
- public List<Room> getAvailableRooms() {
- return new ArrayList<Room>(availableRooms.values());
- }
-
- public void addRoom(Room room) {
- if (availableRooms.containsKey(room.getName())) {
- throw new ChatException("room ["+room.getName()+"] is already available", ChatException.ErrorType.valueOf("ROOM_ALREADY_EXISTS"));
- }
- availableRooms.put(room.getName(), room);
- }
-
- public void login(User user) {
- assert(user != null);
- if (availableUsers.containsKey(user.getName())) {
- throw new ChatException("User ["+user.getName()+"] already exists", ChatException.ErrorType.valueOf("USER_ALREADY_EXISTS"));
- }
- availableUsers.put(user.getName(), user);
- }
-
- public void logout(String name) {
- assert(name != null);
- assert(name.trim().length() > 0);
- availableUsers.remove(name);
- for (Room room : availableRooms.values()) {
- if (room.hasMember(name)) {
- room.memberExit(name);
- }
- }
- }
-
- public void exitRoom(String userName, String roomName) {
- assert(roomName != null);
- assert(roomName.trim().length()> 0);
-
- if (availableRooms.containsKey(roomName)) {
- Room room = availableRooms.get(roomName);
- room.memberExit(userName);
- }
- }
-
- public void enterRoom(User user, String roomName) {
- assert(roomName != null);
- assert(roomName.trim().length() > 0);
- if (! availableRooms.containsKey(roomName)) {
- throw new ChatException("No such room exists ["+roomName+"]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
- }
- Room room = availableRooms.get(roomName);
- room.memberEnter(user);
- }
-
- public List<ChatMessage> getMessagesInRoom(String roomName) {
- assert(roomName != null);
- assert(roomName.trim().length() > 0);
- if (! availableRooms.containsKey(roomName)) {
- throw new ChatException("No such room exists ["+roomName+"]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
- }
- Room room = availableRooms.get(roomName);
- return room.getChatMessages();
- }
-
- public void sendMessageToRoom(String roomName, User user, String message) {
- assert(roomName != null);
- if (! availableRooms.containsKey(roomName)) {
- throw new ChatException("No such room exists ["+roomName+"]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
- }
- Room room = availableRooms.get(roomName);
- room.addMessage(new ChatMessage(message, user));
- }
-
- public List<User> getUsersAvailableInRoom(String roomName) {
- assert(roomName != null);
- if (! availableRooms.containsKey(roomName)) {
- throw new ChatException("No such room exists ["+roomName+"]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
- }
- Room room = availableRooms.get(roomName);
- return room.getMembers();
- }
+ public List<User> getAvailableUsers() {
+ return new ArrayList<User>(availableUsers.values());
+ }
+
+ public List<Room> getAvailableRooms() {
+ return new ArrayList<Room>(availableRooms.values());
+ }
+
+ public void addRoom(Room room) {
+ if (availableRooms.containsKey(room.getName())) {
+ throw new ChatException("room [" + room.getName() + "] is already available", ChatException.ErrorType.valueOf("ROOM_ALREADY_EXISTS"));
+ }
+ availableRooms.put(room.getName(), room);
+ }
+
+ public void login(User user) {
+ assert (user != null);
+ if (availableUsers.containsKey(user.getName())) {
+ throw new ChatException("User [" + user.getName() + "] already exists", ChatException.ErrorType.valueOf("USER_ALREADY_EXISTS"));
+ }
+ availableUsers.put(user.getName(), user);
+ }
+
+ public void logout(String name) {
+ assert (name != null);
+ assert (name.trim().length() > 0);
+ availableUsers.remove(name);
+ for (Room room : availableRooms.values()) {
+ if (room.hasMember(name)) {
+ room.memberExit(name);
+ }
+ }
+ }
+
+ public void exitRoom(String userName, String roomName) {
+ assert (roomName != null);
+ assert (roomName.trim().length() > 0);
+
+ if (availableRooms.containsKey(roomName)) {
+ Room room = availableRooms.get(roomName);
+ room.memberExit(userName);
+ }
+ }
+
+ public void enterRoom(User user, String roomName) {
+ assert (roomName != null);
+ assert (roomName.trim().length() > 0);
+ if (!availableRooms.containsKey(roomName)) {
+ throw new ChatException("No such room exists [" + roomName + "]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
+ }
+ Room room = availableRooms.get(roomName);
+ room.memberEnter(user);
+ }
+
+ public List<ChatMessage> getMessagesInRoom(String roomName) {
+ assert (roomName != null);
+ assert (roomName.trim().length() > 0);
+ if (!availableRooms.containsKey(roomName)) {
+ throw new ChatException("No such room exists [" + roomName + "]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
+ }
+ Room room = availableRooms.get(roomName);
+ return room.getChatMessages();
+ }
+
+ public void sendMessageToRoom(String roomName, User user, String message) {
+ assert (roomName != null);
+ if (!availableRooms.containsKey(roomName)) {
+ throw new ChatException("No such room exists [" + roomName + "]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
+ }
+ Room room = availableRooms.get(roomName);
+ room.addMessage(new ChatMessage(message, user));
+ }
+
+ public List<User> getUsersAvailableInRoom(String roomName) {
+ assert (roomName != null);
+ if (!availableRooms.containsKey(roomName)) {
+ throw new ChatException("No such room exists [" + roomName + "]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
+ }
+ Room room = availableRooms.get(roomName);
+ return room.getMembers();
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatSessionListener.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatSessionListener.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatSessionListener.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ChatSessionListener.java Fri Oct 19 18:49:39 2012
@@ -20,35 +20,34 @@
*/
package org.apache.struts2.showcase.chat;
-import javax.servlet.http.HttpSession;
-import javax.servlet.http.HttpSessionEvent;
-import javax.servlet.http.HttpSessionListener;
-
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
-import com.opensymphony.xwork2.util.logging.Logger;
-import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
public class ChatSessionListener implements HttpSessionListener {
- private static final Logger LOG = LoggerFactory.getLogger(ChatSessionListener.class);
+ private static final Logger LOG = LoggerFactory.getLogger(ChatSessionListener.class);
- public void sessionCreated(HttpSessionEvent event) {
- }
+ public void sessionCreated(HttpSessionEvent event) {
+ }
- public void sessionDestroyed(HttpSessionEvent event) {
- HttpSession session = event.getSession();
- WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(session.getServletContext());
- if (context != null) {
- User user = (User) session.getAttribute(ChatInterceptor.CHAT_USER_SESSION_KEY);
- if (user != null) {
- ChatService service = (ChatService) context.getBean("chatService");
- service.logout(user.getName());
-
- LOG.info("session expired, logged user ["+user.getName()+"] out");
- }
- }
- }
+ public void sessionDestroyed(HttpSessionEvent event) {
+ HttpSession session = event.getSession();
+ WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(session.getServletContext());
+ if (context != null) {
+ User user = (User) session.getAttribute(ChatInterceptor.CHAT_USER_SESSION_KEY);
+ if (user != null) {
+ ChatService service = (ChatService) context.getBean("chatService");
+ service.logout(user.getName());
+
+ LOG.info("session expired, logged user [" + user.getName() + "] out");
+ }
+ }
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/Constants.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/Constants.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/Constants.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/Constants.java Fri Oct 19 18:49:39 2012
@@ -21,5 +21,5 @@
package org.apache.struts2.showcase.chat;
public class Constants {
- public static String UPDATE_FREQ = "5000";
+ public static String UPDATE_FREQ = "5000";
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/CrudRoomAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/CrudRoomAction.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/CrudRoomAction.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/CrudRoomAction.java Fri Oct 19 18:49:39 2012
@@ -24,41 +24,40 @@ import com.opensymphony.xwork2.ActionSup
public class CrudRoomAction extends ActionSupport {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private ChatService chatService;
+ private ChatService chatService;
- private String name;
- private String description;
+ private String name;
+ private String description;
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public CrudRoomAction(ChatService chatService) {
- this.chatService = chatService;
- }
-
- public String create() throws Exception {
- try {
- chatService.addRoom(new Room(name, description));
- }
- catch(ChatException e) {
- addActionError(e.getMessage());
- }
- return SUCCESS;
- }
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public CrudRoomAction(ChatService chatService) {
+ this.chatService = chatService;
+ }
+
+ public String create() throws Exception {
+ try {
+ chatService.addRoom(new Room(name, description));
+ } catch (ChatException e) {
+ addActionError(e.getMessage());
+ }
+ return SUCCESS;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/DateConverter.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/DateConverter.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/DateConverter.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/DateConverter.java Fri Oct 19 18:49:39 2012
@@ -20,41 +20,39 @@
*/
package org.apache.struts2.showcase.chat;
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import org.apache.struts2.util.StrutsTypeConverter;
+
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
-import org.apache.struts2.util.StrutsTypeConverter;
-
-import com.opensymphony.xwork2.util.logging.Logger;
-import com.opensymphony.xwork2.util.logging.LoggerFactory;
-
public class DateConverter extends StrutsTypeConverter {
- private static final Logger LOG = LoggerFactory.getLogger(DateConverter.class);
+ private static final Logger LOG = LoggerFactory.getLogger(DateConverter.class);
- public Object convertFromString(Map context, String[] values, Class toClass) {
+ public Object convertFromString(Map context, String[] values, Class toClass) {
- if (values.length > 0 && values[0] != null && values[0].trim().length() > 0) {
- SimpleDateFormat sdf = new SimpleDateFormat();
- try {
- return sdf.parse(values[0]);
- }
- catch(ParseException e) {
- LOG.error("error converting value ["+values[0]+"] to Date ", e);
- }
- }
- return null;
- }
-
- public String convertToString(Map context, Object o) {
-
- if (o instanceof Date) {
- SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
- return sdf.format((Date) o);
- }
- return "";
- }
+ if (values.length > 0 && values[0] != null && values[0].trim().length() > 0) {
+ SimpleDateFormat sdf = new SimpleDateFormat();
+ try {
+ return sdf.parse(values[0]);
+ } catch (ParseException e) {
+ LOG.error("error converting value [" + values[0] + "] to Date ", e);
+ }
+ }
+ return null;
+ }
+
+ public String convertToString(Map context, Object o) {
+
+ if (o instanceof Date) {
+ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
+ return sdf.format((Date) o);
+ }
+ return "";
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/EnterRoomAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/EnterRoomAction.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/EnterRoomAction.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/EnterRoomAction.java Fri Oct 19 18:49:39 2012
@@ -20,43 +20,46 @@
*/
package org.apache.struts2.showcase.chat;
-import java.util.Map;
-
+import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.interceptor.SessionAware;
-import com.opensymphony.xwork2.ActionSupport;
+import java.util.Map;
public class EnterRoomAction extends ActionSupport implements SessionAware {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private ChatService chatService;
- private Map session;
- private String roomName;
-
- public String getRoomName() { return this.roomName; }
- public void setRoomName(String roomName) { this.roomName = roomName; }
-
- public EnterRoomAction(ChatService chatService) {
- this.chatService = chatService;
- }
-
- public String execute() throws Exception {
-
- User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY);
- try {
- chatService.enterRoom(user, roomName);
- }
- catch(Exception e) {
- addActionError(e.getMessage());
- }
- return SUCCESS;
- }
-
-
- // === SessionAware ===
- public void setSession(Map session) {
- this.session = session;
- }
+ private ChatService chatService;
+ private Map session;
+ private String roomName;
+
+ public String getRoomName() {
+ return this.roomName;
+ }
+
+ public void setRoomName(String roomName) {
+ this.roomName = roomName;
+ }
+
+ public EnterRoomAction(ChatService chatService) {
+ this.chatService = chatService;
+ }
+
+ public String execute() throws Exception {
+
+ User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY);
+ try {
+ chatService.enterRoom(user, roomName);
+ } catch (Exception e) {
+ addActionError(e.getMessage());
+ }
+ return SUCCESS;
+ }
+
+
+ // === SessionAware ===
+ public void setSession(Map session) {
+ this.session = session;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ExitRoomAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ExitRoomAction.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ExitRoomAction.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/ExitRoomAction.java Fri Oct 19 18:49:39 2012
@@ -20,39 +20,43 @@
*/
package org.apache.struts2.showcase.chat;
-import java.util.Map;
-
+import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.interceptor.SessionAware;
-import com.opensymphony.xwork2.ActionSupport;
+import java.util.Map;
public class ExitRoomAction extends ActionSupport implements SessionAware {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
+
+ private String roomName;
- private String roomName;
+ private Map session;
- private Map session;
+ public String getRoomName() {
+ return roomName;
+ }
- public String getRoomName() { return roomName; }
- public void setRoomName(String roomName) { this.roomName = roomName; }
+ public void setRoomName(String roomName) {
+ this.roomName = roomName;
+ }
- private ChatService chatService;
+ private ChatService chatService;
- public ExitRoomAction(ChatService chatService) {
- this.chatService = chatService;
- }
+ public ExitRoomAction(ChatService chatService) {
+ this.chatService = chatService;
+ }
- public String execute() throws Exception {
- User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY);
- chatService.exitRoom(user.getName(), roomName);
+ public String execute() throws Exception {
+ User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY);
+ chatService.exitRoom(user.getName(), roomName);
- return SUCCESS;
- }
+ return SUCCESS;
+ }
- // === SessionAware ===
- public void setSession(Map session) {
- this.session = session;
- }
+ // === SessionAware ===
+ public void setSession(Map session) {
+ this.session = session;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/MessagesAvailableInRoomAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/MessagesAvailableInRoomAction.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/MessagesAvailableInRoomAction.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/MessagesAvailableInRoomAction.java Fri Oct 19 18:49:39 2012
@@ -20,40 +20,42 @@
*/
package org.apache.struts2.showcase.chat;
+import com.opensymphony.xwork2.ActionSupport;
+
import java.util.ArrayList;
import java.util.List;
-import com.opensymphony.xwork2.ActionSupport;
-
public class MessagesAvailableInRoomAction extends ActionSupport {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private String roomName;
- private ChatService chatService;
- private List<ChatMessage> messagesAvailableInRoom = new ArrayList<ChatMessage>();
-
- public String getRoomName() { return this.roomName; }
- public void setRoomName(String roomName) {
- this.roomName = roomName;
- }
-
- public List<ChatMessage> getMessagesAvailableInRoom() {
- return messagesAvailableInRoom;
- }
-
- public MessagesAvailableInRoomAction(ChatService chatService) {
- this.chatService = chatService;
- }
-
- public String execute() throws Exception {
- try {
- messagesAvailableInRoom = chatService.getMessagesInRoom(roomName);
- }
- catch(ChatException e) {
- addActionError(e.getMessage());
- }
- return SUCCESS;
- }
+ private String roomName;
+ private ChatService chatService;
+ private List<ChatMessage> messagesAvailableInRoom = new ArrayList<ChatMessage>();
+
+ public String getRoomName() {
+ return this.roomName;
+ }
+
+ public void setRoomName(String roomName) {
+ this.roomName = roomName;
+ }
+
+ public List<ChatMessage> getMessagesAvailableInRoom() {
+ return messagesAvailableInRoom;
+ }
+
+ public MessagesAvailableInRoomAction(ChatService chatService) {
+ this.chatService = chatService;
+ }
+
+ public String execute() throws Exception {
+ try {
+ messagesAvailableInRoom = chatService.getMessagesInRoom(roomName);
+ } catch (ChatException e) {
+ addActionError(e.getMessage());
+ }
+ return SUCCESS;
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/Room.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/Room.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/Room.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/Room.java Fri Oct 19 18:49:39 2012
@@ -20,82 +20,81 @@
*/
package org.apache.struts2.showcase.chat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class Room {
- private static final int MAX_CHAT_MESSAGES = 10;
+ private static final int MAX_CHAT_MESSAGES = 10;
- private String name;
- private String description;
- private Date creationDate;
-
- private List<ChatMessage> messages = new ArrayList<ChatMessage>();
-
- private Map<String, User> members = new LinkedHashMap<String, User>();
-
- public Room(String name, String description) {
- this.name = name;
- this.description = description;
- this.creationDate = new Date(System.currentTimeMillis());
- }
-
-
- // properties
- public Date getCreationDate() {
- return creationDate;
- }
-
- public String getDescription() {
- return description;
- }
-
- public String getName() {
- return name;
- }
-
-
- // (behaviour) members
- public List<User> getMembers() {
- return new ArrayList<User>(members.values());
- }
- public User findMember(String name) {
- assert(name != null);
- return members.get(name);
- }
- public boolean hasMember(String name) {
- assert(name != null);
- return members.containsKey(name);
- }
- public void memberEnter(User member) {
- assert(member != null);
- if (! hasMember(member.getName())) {
- members.put(member.getName(), member);
- }
- }
-
- public void memberExit(String memberName) {
- assert(memberName != null);
- assert(memberName.trim().length() > 0);
- members.remove(memberName);
- }
-
-
- // (behaviour) chat messags
- public void addMessage(ChatMessage chatMessage) {
- if (messages.size() > MAX_CHAT_MESSAGES) {
- // messages.remove(messages.size() - 1);
- messages.remove(0);
- }
- messages.add(chatMessage);
- }
-
- public List<ChatMessage> getChatMessages() {
- return new ArrayList<ChatMessage>(messages);
- }
+ private String name;
+ private String description;
+ private Date creationDate;
+
+ private List<ChatMessage> messages = new ArrayList<ChatMessage>();
+
+ private Map<String, User> members = new LinkedHashMap<String, User>();
+
+ public Room(String name, String description) {
+ this.name = name;
+ this.description = description;
+ this.creationDate = new Date(System.currentTimeMillis());
+ }
+
+
+ // properties
+ public Date getCreationDate() {
+ return creationDate;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+
+ // (behaviour) members
+ public List<User> getMembers() {
+ return new ArrayList<User>(members.values());
+ }
+
+ public User findMember(String name) {
+ assert (name != null);
+ return members.get(name);
+ }
+
+ public boolean hasMember(String name) {
+ assert (name != null);
+ return members.containsKey(name);
+ }
+
+ public void memberEnter(User member) {
+ assert (member != null);
+ if (!hasMember(member.getName())) {
+ members.put(member.getName(), member);
+ }
+ }
+
+ public void memberExit(String memberName) {
+ assert (memberName != null);
+ assert (memberName.trim().length() > 0);
+ members.remove(memberName);
+ }
+
+
+ // (behaviour) chat messags
+ public void addMessage(ChatMessage chatMessage) {
+ if (messages.size() > MAX_CHAT_MESSAGES) {
+ // messages.remove(messages.size() - 1);
+ messages.remove(0);
+ }
+ messages.add(chatMessage);
+ }
+
+ public List<ChatMessage> getChatMessages() {
+ return new ArrayList<ChatMessage>(messages);
+ }
}
Modified: struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/RoomsAvailableAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/RoomsAvailableAction.java?rev=1400220&r1=1400219&r2=1400220&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/RoomsAvailableAction.java (original)
+++ struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/RoomsAvailableAction.java Fri Oct 19 18:49:39 2012
@@ -20,29 +20,29 @@
*/
package org.apache.struts2.showcase.chat;
+import com.opensymphony.xwork2.ActionSupport;
+
import java.util.ArrayList;
import java.util.List;
-import com.opensymphony.xwork2.ActionSupport;
-
public class RoomsAvailableAction extends ActionSupport {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private List<Room> availableRooms = new ArrayList<Room>();
+ private List<Room> availableRooms = new ArrayList<Room>();
- private ChatService chatService;
+ private ChatService chatService;
- public RoomsAvailableAction(ChatService chatService) {
- this.chatService = chatService;
- }
+ public RoomsAvailableAction(ChatService chatService) {
+ this.chatService = chatService;
+ }
- public String execute() throws Exception {
- availableRooms = chatService.getAvailableRooms();
- return SUCCESS;
- }
+ public String execute() throws Exception {
+ availableRooms = chatService.getAvailableRooms();
+ return SUCCESS;
+ }
- public List<Room> getAvailableRooms() {
- return availableRooms;
- }
+ public List<Room> getAvailableRooms() {
+ return availableRooms;
+ }
}