- User area: Added Add Term include and term-related classes - Clean-up: + WEB-INF/web.xml: Fixed markup + Added Hibernate3-core sources link (for Javadoc) + Removed bogus Struts2Hubernate source attachment + Changed indentation size to 2 spaces + Formatted all source code (automatically)
/trunk/src/struts.xml |
---|
3,82 → 3,96 |
"http://struts.apache.org/dtds/struts-2.0.dtd"> |
<struts> |
<constant name="struts.devMode" value="true" /> <!-- activates debugging output --> |
<!-- User environment --> |
<package name="user" namespace="/user" extends="hibernate-default"> |
<constant name="struts.devMode" value="true" /> <!-- activates debugging output --> |
<!-- User environment --> |
<package name="user" namespace="/user" extends="hibernate-default"> |
<!-- Term management --> |
<action name="termAddForm"> |
<result>/user/termAddForm.jsp</result> |
</action> |
</package> |
<!-- Admin environment --> |
<package name="admin" namespace="/admin" extends="hibernate-default"> |
<!-- User management --> |
<action name="userAddForm"> |
<result>/admin/userAddForm.jsp</result> |
</action> |
<action name="doUserAdd" method="addOrUpdate" class="ch.ffhs.webE.action.UserAction"> |
<result name="success">/admin/userAdd.jsp</result> |
</action> |
<action name="userList" method="list" class="ch.ffhs.webE.action.UserAction"> |
<result name="success">/admin/userList.jsp</result> |
</action> |
<action name="deleteUser" method="delete" class="ch.ffhs.webE.action.UserAction"> |
<result name="success" type="redirect">/admin/userList</result> |
</action> |
<action name="editUser" method="edit" class="ch.ffhs.webE.action.UserAction"> |
<result name="success">/admin/userAddForm.jsp</result> |
</action> |
<!-- Relationship Type management --> |
<action name="relTypeList" method="list" class="ch.ffhs.webE.action.RelationshipTypeAction"> |
<result name="success">/admin/relTypeList.jsp</result> |
</action> |
<action name="relTypeAddForm"> |
<result>/admin/relTypeAddForm.jsp</result> |
</action> |
<action name="doRelTypeAdd" method="addOrUpdate" class="ch.ffhs.webE.action.RelationshipTypeAction"> |
<result name="success" type="redirect">/admin/relTypeList</result> |
</action> |
<action name="deleteRelType" method="delete" class="ch.ffhs.webE.action.RelationshipTypeAction"> |
<result name="success" type="redirect">/admin/relTypeList</result> |
</action> |
<action name="editRelType" method="edit" class="ch.ffhs.webE.action.RelationshipTypeAction"> |
<result name="success">/admin/relTypeAddForm.jsp</result> |
<result name="error">/admin/adminError.jsp</result> |
</action> |
</package> |
<!-- Remaining environment of the session--> |
<package name="default" namespace="" extends="hibernate-default"> |
<!-- Login --> |
<action name="Login" method="doLogin" class="ch.ffhs.webE.action.LoginAction"> |
<result name="admin" type="redirect">/admin/main.jsp</result> |
<result name="user" type="redirect">/user/main.jsp</result> |
<result name="error" type="redirect">/index.jsp</result> |
</action> |
<action name="Logout" method="doLogout" class="ch.ffhs.webE.action.LoginAction"> |
<result name="success" type="redirect">/index.jsp</result> |
</action> |
</package> |
<action name="doTermAdd" method="addOrUpdate" |
class="ch.ffhs.webE.action.TermAction"> |
<result name="success">/user/termAdd.jsp</result> |
</action> |
</package> |
<!-- Admin environment --> |
<package name="admin" namespace="/admin" extends="hibernate-default"> |
<!-- User management --> |
<action name="userAddForm"> |
<result>/admin/userAddForm.jsp</result> |
</action> |
<action name="doUserAdd" method="addOrUpdate" |
class="ch.ffhs.webE.action.UserAction"> |
<result name="success">/admin/userAdd.jsp</result> |
</action> |
<action name="userList" method="list" |
class="ch.ffhs.webE.action.UserAction"> |
<result name="success">/admin/userList.jsp</result> |
</action> |
<action name="deleteUser" method="delete" |
class="ch.ffhs.webE.action.UserAction"> |
<result name="success" type="redirect">/admin/userList</result> |
</action> |
<action name="editUser" method="edit" |
class="ch.ffhs.webE.action.UserAction"> |
<result name="success">/admin/userAddForm.jsp</result> |
</action> |
<!-- Relationship Type management --> |
<action name="relTypeList" method="list" |
class="ch.ffhs.webE.action.RelationshipTypeAction"> |
<result name="success">/admin/relTypeList.jsp</result> |
</action> |
<action name="relTypeAddForm"> |
<result>/admin/relTypeAddForm.jsp</result> |
</action> |
<action name="doRelTypeAdd" method="addOrUpdate" |
class="ch.ffhs.webE.action.RelationshipTypeAction"> |
<result name="success" type="redirect">/admin/relTypeList</result> |
</action> |
<action name="deleteRelType" method="delete" |
class="ch.ffhs.webE.action.RelationshipTypeAction"> |
<result name="success" type="redirect">/admin/relTypeList</result> |
</action> |
<action name="editRelType" method="edit" |
class="ch.ffhs.webE.action.RelationshipTypeAction"> |
<result name="success">/admin/relTypeAddForm.jsp</result> |
<result name="error">/admin/adminError.jsp</result> |
</action> |
</package> |
<!-- Remaining environment of the session --> |
<package name="default" namespace="" extends="hibernate-default"> |
<!-- Login --> |
<action name="Login" method="doLogin" class="ch.ffhs.webE.action.LoginAction"> |
<result name="admin" type="redirect">/admin/main.jsp</result> |
<result name="user" type="redirect">/user/main.jsp</result> |
<result name="error" type="redirect">/index.jsp</result> |
</action> |
<action name="Logout" method="doLogout" |
class="ch.ffhs.webE.action.LoginAction"> |
<result name="success" type="redirect">/index.jsp</result> |
</action> |
</package> |
</struts> |
/trunk/src/ch/ffhs/webE/dao/TermDAO.java |
---|
0,0 → 1,46 |
package ch.ffhs.webE.dao; |
import java.util.List; |
import ch.ffhs.webE.domain.Term; |
/** |
* Defines methods all term DAO implementations must implement |
* |
* @author pelinux |
*/ |
public interface TermDAO |
{ |
/** |
* @return |
*/ |
List<Term> listTerm(); |
/** |
* @param termName |
* @return |
*/ |
Term searchTerm(String termName); |
/** |
* Delete a term |
* |
* @param termId |
* Term ID |
*/ |
void deleteTerm(int termId); |
/** |
* @param termId |
* @return |
*/ |
Term listTermById(int termId); |
/** |
* Executes the query to save the term |
* |
* @param term |
* Domain object to be saved |
*/ |
void saveOrUpdate(Term term); |
} |
Property changes: |
Added: svn:mime-type |
## -0,0 +1 ## |
+text/plain |
\ No newline at end of property |
Index: ch/ffhs/webE/dao/TermDAOImpl.java |
=================================================================== |
--- ch/ffhs/webE/dao/TermDAOImpl.java (nonexistent) |
+++ ch/ffhs/webE/dao/TermDAOImpl.java (revision 31) |
@@ -0,0 +1,145 @@ |
+package ch.ffhs.webE.dao; |
+ |
+import java.util.ArrayList; |
+import java.util.List; |
+ |
+import org.hibernate.Session; |
+import org.hibernate.Transaction; |
+ |
+import ch.ffhs.webE.domain.Term; |
+ |
+import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget; |
+import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget; |
+ |
+/** |
+ * Implements the Database Access Object for terms |
+ * |
+ * @author Thomas Lahn |
+ */ |
+public class TermDAOImpl implements TermDAO |
+{ |
+ /** |
+ * Database session |
+ */ |
+ @SessionTarget |
+ Session session; |
+ |
+ /** |
+ * Database transaction |
+ */ |
+ @TransactionTarget |
+ Transaction transaction; |
+ |
+ /** |
+ * Creates a list of all terms |
+ * |
+ * @return an ArrayList with all the users - in case of a problem, an empty |
+ * list is returned |
+ */ |
+ @SuppressWarnings("unchecked") |
+ public List<Term> listTerm() |
+ { |
+ List<Term> term = null; |
+ try |
+ { |
+ term = this.session.createQuery("FROM term").list(); //$NON-NLS-1$ |
+ } |
+ catch (Exception e) |
+ { |
+ e.printStackTrace(); |
+ } |
+ |
+ /* |
+ * If no term was checked, return an empty list to mitigate null pointer |
+ * exceptions |
+ */ |
+ if (term == null) |
+ { |
+ term = new ArrayList<Term>(); |
+ } |
+ return term; |
+ } |
+ |
+ /* |
+ * (non-Javadoc) |
+ * |
+ * @see ch.ffhs.webE.dao.TermDAO#saveOrUpdate(ch.ffhs.webE.domain.Term) |
+ */ |
+ public void saveOrUpdate(Term term) |
+ { |
+ try |
+ { |
+ this.session.saveOrUpdate(term); |
+ } |
+ catch (Exception e) |
+ { |
+ this.transaction.rollback(); |
+ e.printStackTrace(); |
+ } |
+ } |
+ |
+ /* |
+ * (non-Javadoc) |
+ * |
+ * @see ch.ffhs.webE.dao.TermDAO#deleteTerm(int) |
+ */ |
+ public void deleteTerm(int termId) |
+ { |
+ try |
+ { |
+ Term user = (Term) this.session.get(Term.class, termId); |
+ this.session.delete(user); |
+ } |
+ catch (Exception e) |
+ { |
+ this.transaction.rollback(); |
+ e.printStackTrace(); |
+ } |
+ } |
+ |
+ /** |
+ * Returns a single user with this user name (used for login) |
+ * |
+ * @param termName |
+ * Term name |
+ * @return User: Returns a user object if something is found. If not, null is |
+ * returned |
+ */ |
+ public Term searchTerm(String termName) |
+ { |
+ Term term = null; |
+ |
+ /* Exec query */ |
+ try |
+ { |
+ term = (Term) this.session |
+ .createQuery("FROM User " + "WHERE username = :username") //$NON-NLS-1$ //$NON-NLS-2$ |
+ .setParameter("username", termName).uniqueResult(); //$NON-NLS-1$ |
+ } |
+ catch (Exception e) |
+ { |
+ /* TODO: Log error */ |
+ } |
+ return term; |
+ } |
+ |
+ /** |
+ * List a term by ID |
+ * |
+ * @param termId |
+ * @return |
+ */ |
+ public Term listTermById(int termId) |
+ { |
+ Term term = null; |
+ try |
+ { |
+ term = (Term) this.session.get(Term.class, termId); |
+ } |
+ catch (Exception e) |
+ { |
+ e.printStackTrace(); |
+ } |
+ return term; |
+ } |
+} |
\ No newline at end of file |
/ch/ffhs/webE/dao/TermDAOImpl.java |
---|
Property changes: |
Added: svn:mime-type |
## -0,0 +1 ## |
+text/plain |
\ No newline at end of property |
Index: ch/ffhs/webE/action/TermAction.java |
=================================================================== |
--- ch/ffhs/webE/action/TermAction.java (nonexistent) |
+++ ch/ffhs/webE/action/TermAction.java (revision 31) |
@@ -0,0 +1,166 @@ |
+package ch.ffhs.webE.action; |
+ |
+import java.util.ArrayList; |
+import java.util.List; |
+ |
+import javax.servlet.http.HttpServletRequest; |
+ |
+import org.apache.struts2.StrutsStatics; |
+ |
+import ch.ffhs.webE.dao.TermDAO; |
+import ch.ffhs.webE.dao.TermDAOImpl; |
+import ch.ffhs.webE.domain.Term; |
+ |
+import com.opensymphony.xwork2.Action; |
+import com.opensymphony.xwork2.ActionContext; |
+import com.opensymphony.xwork2.ActionSupport; |
+import com.opensymphony.xwork2.ModelDriven; |
+ |
+/** |
+ * Implements actions applicable to term editing |
+ * |
+ * @author Thomas Lahn |
+ */ |
+public class TermAction extends ActionSupport implements ModelDriven<Term> |
+{ |
+ private static final long serialVersionUID = -6659925652584240539L; |
+ |
+ private Term term = new Term(); |
+ private List<Term> termList = new ArrayList<Term>(); |
+ private final TermDAO termDAO = new TermDAOImpl(); |
+ |
+ /* |
+ * (non-Javadoc) |
+ * |
+ * @see com.opensymphony.xwork2.ModelDriven#getModel() |
+ */ |
+ public Term getModel() |
+ { |
+ return this.term; |
+ } |
+ |
+ /** |
+ * Executes the DB query to save the user |
+ * |
+ * @return {@link Action#SUCCESS} |
+ */ |
+ public String addOrUpdate() |
+ { |
+ this.termDAO.saveOrUpdate(this.term); |
+ return Action.SUCCESS; |
+ } |
+ |
+ /** |
+ * DB query for userList |
+ * |
+ * @return SUCCESS |
+ */ |
+ public String list() |
+ { |
+ this.termList = this.termDAO.listTerm(); |
+ return Action.SUCCESS; |
+ } |
+ |
+ /** |
+ * @return {@link Action#SUCCESS} if <var>id</var> > 0, {@link Action#ERROR} |
+ * otherwise |
+ */ |
+ public String edit() |
+ { |
+ int id = this.getIdParameter(); |
+ |
+ if (id > 0) |
+ { |
+ this.term = this.termDAO.listTermById(id); |
+ return Action.SUCCESS; |
+ } |
+ else |
+ { |
+ return Action.ERROR; |
+ } |
+ } |
+ |
+ /** |
+ * Gets the ID Parameter for update / delete requests |
+ * |
+ * @return int from the ID request. If not set or wrong, it gives back -1 |
+ */ |
+ private int getIdParameter() |
+ { |
+ HttpServletRequest request = (HttpServletRequest) ActionContext |
+ .getContext().get(StrutsStatics.HTTP_REQUEST); |
+ |
+ int id = -1; |
+ try |
+ { |
+ id = Integer.parseInt(request.getParameter("id")); //$NON-NLS-1$ |
+ } |
+ catch (Exception e) |
+ { |
+ /* TODO: Logging - wrong parameter set */ |
+ } |
+ |
+ return id; |
+ } |
+ |
+ /** |
+ * deletes a user, gets the ID from the "id" parameter that was submitted with |
+ * the HTTP request |
+ * |
+ * @return String - either SUCCESS or ERROR constant |
+ */ |
+ public String delete() |
+ { |
+ |
+ int id = this.getIdParameter(); |
+ |
+ /* Check for malicious ID values */ |
+ if (id > 0) |
+ { |
+ this.termDAO.deleteTerm(id); |
+ return Action.SUCCESS; |
+ } |
+ else |
+ { |
+ return Action.ERROR; |
+ } |
+ } |
+ |
+ /* |
+ * Standard getters and setters |
+ */ |
+ |
+ /** |
+ * @return The term edited with this instance |
+ */ |
+ public Term getTerm() |
+ { |
+ return this.term; |
+ } |
+ |
+ /** |
+ * @param term |
+ * The term edited with this instance |
+ */ |
+ public void setTerm(Term term) |
+ { |
+ this.term = term; |
+ } |
+ |
+ /** |
+ * @return The list of terms edited with this instance |
+ */ |
+ public List<Term> getTermList() |
+ { |
+ return this.termList; |
+ } |
+ |
+ /** |
+ * @param termList |
+ * The list of terms edited with this instance |
+ */ |
+ public void setTermList(List<Term> termList) |
+ { |
+ this.termList = termList; |
+ } |
+} |
/ch/ffhs/webE/action/TermAction.java |
---|
Property changes: |
Added: svn:mime-type |
## -0,0 +1 ## |
+text/plain |
\ No newline at end of property |
Index: hibernate.cfg.xml |
=================================================================== |
--- hibernate.cfg.xml (revision 30) |
+++ hibernate.cfg.xml (revision 31) |
@@ -3,38 +3,36 @@ |
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" |
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> |
<hibernate-configuration> |
- <session-factory> |
- <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> |
- |
- <property name="hibernate.connection.url">jdbc:mysql://localhost/webengineering</property> |
- <property name="hibernate.connection.username">webEngineering</property> |
- <property name="connection.password">ontologie</property> |
- |
- <property name="connection.pool_size">1</property> |
- <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> |
- |
- <!-- Print all generated SQL to the console --> |
- <property name="show_sql">true</property> |
- <property name="format_sql">true</property> |
- <!-- |
- <property name="connection.provider_class"> |
- org.hibernate.connection.C3P0ConnectionProvider |
- </property>--> |
- <!-- C3P0 connection pool --> |
- <property name="hibernate.c3p0.min_size">5</property> |
- <property name="hibernate.c3p0.max_size">20</property> |
- <property name="hibernate.c3p0.timeout">300</property> |
- <property name="hibernate.c3p0.max_statements">50 </property> |
- <property name="hibernate.c3p0.idle_test_period">3000 </property> |
- |
- <!--<property name="hbm2ddl.auto">create</property>--> |
- <mapping class="ch.ffhs.webE.domain.ActionType" /> |
- <mapping class="ch.ffhs.webE.domain.History" /> |
- <mapping class="ch.ffhs.webE.domain.Object" /> |
- <mapping class="ch.ffhs.webE.domain.ObjectType" /> |
- <mapping class="ch.ffhs.webE.domain.Relationship" /> |
- <mapping class="ch.ffhs.webE.domain.RelationshipType" /> |
- <mapping class="ch.ffhs.webE.domain.Term" /> |
- <mapping class="ch.ffhs.webE.domain.User" /> |
- </session-factory> |
+ <session-factory> |
+ <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> |
+ |
+ <property name="hibernate.connection.url">jdbc:mysql://localhost/webengineering</property> |
+ <property name="hibernate.connection.username">webEngineering</property> |
+ <property name="connection.password">ontologie</property> |
+ |
+ <property name="connection.pool_size">1</property> |
+ <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> |
+ |
+ <!-- Print all generated SQL to the console --> |
+ <property name="show_sql">true</property> |
+ <property name="format_sql">true</property> |
+ <!-- <property name="connection.provider_class"> org.hibernate.connection.C3P0ConnectionProvider |
+ </property> --> |
+ <!-- C3P0 connection pool --> |
+ <property name="hibernate.c3p0.min_size">5</property> |
+ <property name="hibernate.c3p0.max_size">20</property> |
+ <property name="hibernate.c3p0.timeout">300</property> |
+ <property name="hibernate.c3p0.max_statements">50 </property> |
+ <property name="hibernate.c3p0.idle_test_period">3000 </property> |
+ |
+ <!--<property name="hbm2ddl.auto">create</property> --> |
+ <mapping class="ch.ffhs.webE.domain.ActionType" /> |
+ <mapping class="ch.ffhs.webE.domain.History" /> |
+ <mapping class="ch.ffhs.webE.domain.Object" /> |
+ <mapping class="ch.ffhs.webE.domain.ObjectType" /> |
+ <mapping class="ch.ffhs.webE.domain.Relationship" /> |
+ <mapping class="ch.ffhs.webE.domain.RelationshipType" /> |
+ <mapping class="ch.ffhs.webE.domain.Term" /> |
+ <mapping class="ch.ffhs.webE.domain.User" /> |
+ </session-factory> |
</hibernate-configuration> |