Mercurial > dive4elements > gnv-client
changeset 8:65ff6fcfee0c
Some Basic Stuff for WebProjects
gnv/trunk@84 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Mon, 14 Sep 2009 13:56:03 +0000 |
parents | fe6a64545552 |
children | a4cb6d175a6e |
files | gnv/Changelog gnv/src/main/java/de/intevation/gnv/action/ArtifactDatabaseActionBase.java gnv/src/main/java/de/intevation/gnv/action/FetchArtifactFactoriesAction.java gnv/src/main/java/de/intevation/gnv/action/SelectArtifactFactoryAction.java gnv/src/main/java/de/intevation/gnv/action/sessionmodel/DefaultSessionModel.java gnv/src/main/java/de/intevation/gnv/action/sessionmodel/SessionModel.java gnv/src/main/java/de/intevation/gnv/action/sessionmodel/SessionModelFactory.java gnv/src/main/webapp/WEB-INF/config/struts-config.xml gnv/src/main/webapp/WEB-INF/jsp/index.jsp gnv/src/main/webapp/WEB-INF/web.xml |
diffstat | 10 files changed, 386 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv/Changelog Mon Sep 14 13:46:25 2009 +0000 +++ b/gnv/Changelog Mon Sep 14 13:56:03 2009 +0000 @@ -1,3 +1,27 @@ +2009-09-14 Tim Englich <tim.englich@intevation.de> + + * src/main/webapp/WEB-INF/config/struts-config.xml: + Added two ActionMappings: + One for showing all FIS (ArtifactFactories) in an View. + The other for selceting one ArtifactFactory an visualizing the First Step of an Artifact. + * src/main/webapp/WEB-INF/jsp/index.jsp Edited: + Added an Combobox for selecting an FIS + * src/main/webapp/WEB-INF/web.xml: + Added the Servletmapping for the Struts Framework + * src/main/java/de/intevation/gnv/action/SelectArtifactFactoryAction.java Added, + src/main/java/de/intevation/gnv/action/FetchArtifactFactoriesAction.java Added, + src/main/java/de/intevation/gnv/action/ArtifactDatabaseActionBase.java Edited: + Some ActionHandler added for Handling the different Requests of the GNV. + FetchArtifactFactoriesAction: Will provides the Controllerlogic for Queriing all Reachable ArtifactFactories. + SelectArtifactFactoryAction will select one Specific ArtifactFactory and will create + an Instance in the ArtifactDatabase. + + * src/main/java/de/intevation/gnv/action/sessionmodel/DefaultSessionModel.java Added,: + src/main/java/de/intevation/gnv/action/sessionmodel/SessionModelFactory.java Added, + src/main/java/de/intevation/gnv/action/sessionmodel/SessionModel.java Added: + Interface and Defaultimplementation of an Model which can store the Session-Specific Informations. + e.g. Reachable ArtifactFactories and the current Artifact which should be used. + 2009-09-14 Tim Englich <tim.englich@intevation.de> * src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java Edited:
--- a/gnv/src/main/java/de/intevation/gnv/action/ArtifactDatabaseActionBase.java Mon Sep 14 13:46:25 2009 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/ArtifactDatabaseActionBase.java Mon Sep 14 13:56:03 2009 +0000 @@ -3,8 +3,6 @@ */ package de.intevation.gnv.action; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -20,6 +18,7 @@ */ public class ArtifactDatabaseActionBase extends Action { + protected final static String SUCCSESS_FORWARD_ID = "success"; /** * the logger, used to log exceptions and additonaly information */ @@ -39,19 +38,8 @@ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { - log.debug("ArtifactDatabaseActionBase.execute 1"); - return super.execute(mapping, form, request, response); + log.debug("ArtifactDatabaseActionBase.execute"); + ActionForward lForward = mapping.findForward(SUCCSESS_FORWARD_ID); + return lForward; } - - /** - * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.ServletRequest, javax.servlet.ServletResponse) - */ - @Override - public ActionForward execute(ActionMapping mapping, ActionForm form, - ServletRequest request, ServletResponse response) throws Exception { - log.debug("ArtifactDatabaseActionBase.execute 2"); - return super.execute(mapping, form, request, response); - } - - }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/FetchArtifactFactoriesAction.java Mon Sep 14 13:56:03 2009 +0000 @@ -0,0 +1,53 @@ +/** + * + */ +package de.intevation.gnv.action; + +import java.util.Collection; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; + +import de.intevation.gnv.action.sessionmodel.SessionModel; +import de.intevation.gnv.action.sessionmodel.SessionModelFactory; +import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory; +import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class FetchArtifactFactoriesAction extends ArtifactDatabaseActionBase{ + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(FetchArtifactFactoriesAction.class); + + public FetchArtifactFactoriesAction() { + super(); + } + + /** + * @see de.intevation.gnv.action.ArtifactDatabaseActionBase#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public ActionForward execute(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) + throws Exception { + log.debug("ArtifactDatabaseActionBase.execute"); + + Collection<ArtifactObject> artifactFactories = ArtifactDatabaseClientFactory.getInstance().getArtifactDatabaseClient().getArtifactFactories(); + SessionModel sm = SessionModelFactory.getInstance().getSessionModel(request); + sm.setArtifacteFactories(artifactFactories); + + + ActionForward lForward = mapping.findForward(SUCCSESS_FORWARD_ID); + return lForward; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/SelectArtifactFactoryAction.java Mon Sep 14 13:56:03 2009 +0000 @@ -0,0 +1,61 @@ +/** + * + */ +package de.intevation.gnv.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; + +import de.intevation.gnv.action.sessionmodel.SessionModel; +import de.intevation.gnv.action.sessionmodel.SessionModelFactory; +import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient; +import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory; +import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class SelectArtifactFactoryAction extends ArtifactDatabaseActionBase { + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(SelectArtifactFactoryAction.class); + + /** + * @see de.intevation.gnv.action.ArtifactDatabaseActionBase#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public ActionForward execute(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) + throws Exception { + log.debug("SelectArtifactFactoryAction.execute"); + String selectedArtifactFactoryID = request.getParameter("artifactFactory"); + log.debug("Selected ArtifactFactory ==> "+selectedArtifactFactoryID); + + SessionModel sm = SessionModelFactory.getInstance().getSessionModel(request); + sm.selectArtifactFactory(selectedArtifactFactoryID); + + ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory.getInstance().getArtifactDatabaseClient(); + ArtifactObject artifact = adc.createNewArtifact(sm.getSelectedArtifactFactory()); + sm.setCurrentArtifact(artifact); + + // TODO Initiales Describe Abrufen + + + // return succsess + return super.execute(mapping, form, request, response); + } + + /** + * Constructor + */ + public SelectArtifactFactoryAction() { + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/sessionmodel/DefaultSessionModel.java Mon Sep 14 13:56:03 2009 +0000 @@ -0,0 +1,92 @@ +/** + * + */ +package de.intevation.gnv.action.sessionmodel; + +import java.util.Collection; +import java.util.Iterator; + +import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class DefaultSessionModel implements SessionModel{ + + + private Collection<ArtifactObject> artifactFactories = null; + + private ArtifactObject selectedArtifactFactory = null; + + private ArtifactObject currentArtifact =null; + + + /** + * Constructor + */ + public DefaultSessionModel() { + super(); + } + + /** + * @see de.intevation.gnv.action.sessionmodel.SessionModel#selectArtifactFactory(java.lang.String) + */ + public void selectArtifactFactory(String artiFactFactoryId) { + Collection<ArtifactObject> artifactObjects = this.getArtifactFactories(); + if (artifactObjects != null){ + Iterator<ArtifactObject> unselect = artifactObjects.iterator(); + this.selectedArtifactFactory = null; + while (unselect.hasNext()){ + unselect.next().setSelected(false); + } + Iterator<ArtifactObject> it = artifactObjects.iterator(); + while (it.hasNext()){ + ArtifactObject obj = it.next(); + if(obj.getId().equals(artiFactFactoryId)){ + obj.setSelected(true); + this.selectedArtifactFactory = obj; + break; + } + } + } + } + + /** + * @see de.intevation.gnv.action.sessionmodel.SessionModel#setArtifacteFactories(java.util.Collection) + */ + public void setArtifacteFactories( + Collection<ArtifactObject> artifactFactories) { + this.artifactFactories = artifactFactories; + } + + /** + * @see de.intevation.gnv.action.sessionmodel.SessionModel#getAttributeFactories() + */ + public Collection<ArtifactObject> getArtifactFactories() { + return this.artifactFactories; + } + + /** + * @see de.intevation.gnv.action.sessionmodel.SessionModel#getSelectedArtifactFactory() + */ + public ArtifactObject getSelectedArtifactFactory() { + return this.selectedArtifactFactory; + } + + /** + * @see de.intevation.gnv.action.sessionmodel.SessionModel#getCurrentArtifact() + */ + public ArtifactObject getCurrentArtifact() { + return this.currentArtifact; + } + + /** + * @see de.intevation.gnv.action.sessionmodel.SessionModel#setCurrentArtifact(de.intevation.gnv.artifactdatabase.objects.ArtifactObject) + */ + public void setCurrentArtifact(ArtifactObject artifact) { + this.currentArtifact = artifact; + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/sessionmodel/SessionModel.java Mon Sep 14 13:56:03 2009 +0000 @@ -0,0 +1,28 @@ +/** + * + */ +package de.intevation.gnv.action.sessionmodel; + +import java.util.Collection; + +import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public interface SessionModel { + + Collection<ArtifactObject> getArtifactFactories(); + + void setArtifacteFactories(Collection<ArtifactObject> artifactFactories); + + void selectArtifactFactory(String artiFactFactoryId); + + ArtifactObject getSelectedArtifactFactory(); + + ArtifactObject getCurrentArtifact(); + + void setCurrentArtifact(ArtifactObject artifact); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/sessionmodel/SessionModelFactory.java Mon Sep 14 13:56:03 2009 +0000 @@ -0,0 +1,68 @@ +/** + * + */ +package de.intevation.gnv.action.sessionmodel; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.log4j.Logger; + +import de.intevation.gnv.artifactdatabase.client.DefaultArtifactDatabaseClient; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class SessionModelFactory { + + public final static String SESSION_MODEL_ID = "de.intevation.gnv.action.sessionmodel.SessionModel.ID"; + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(SessionModelFactory.class); + + + /** + * The singleton Instance of this Factory. + */ + private static SessionModelFactory instance = null; + + /** + * Constructor + */ + private SessionModelFactory() { + super(); + } + + /** + * This Method provides an singleton Instance of this Class. + * @return an singleton Instance of this Class + */ + public static SessionModelFactory getInstance(){ + if (instance == null){ + instance = new SessionModelFactory(); + } + return instance; + } + + + /** + * Getting the ArtifactDatabaseClient + * @return the ArtifactDatabaseClient + */ + public SessionModel getSessionModel(HttpServletRequest request){ + synchronized (this.getClass()) { + SessionModel sm = null; + if (request.getSession().getAttribute(SESSION_MODEL_ID)!= null){ + sm = (SessionModel)request.getSession().getAttribute(SESSION_MODEL_ID); + ; + }else{ + sm = new DefaultSessionModel(); + request.getSession().setAttribute(SESSION_MODEL_ID, sm); + } + + return sm; + } + } + +}
--- a/gnv/src/main/webapp/WEB-INF/config/struts-config.xml Mon Sep 14 13:46:25 2009 +0000 +++ b/gnv/src/main/webapp/WEB-INF/config/struts-config.xml Mon Sep 14 13:56:03 2009 +0000 @@ -4,13 +4,22 @@ "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"> <struts-config> <global-exceptions/> - <global-forwards> - <forward name="noSession" path="/start.do"/> - </global-forwards> <action-mappings> - <action path="/test.do" type="de.intevation.gnv.action.ArtifactDatabaseActionBase"> - <description>General Forward</description> - <forward name="noSession" path="/WEB-INF/jsp/index.jsp"/> + <action path="/start" + type="de.intevation.gnv.action.FetchArtifactFactoriesAction" + scope="request" + validate="false"> + <forward + name="success" + path="/WEB-INF/jsp/index.jsp"/> + </action> + <action path="/selectArtifactFactory" + type="de.intevation.gnv.action.SelectArtifactFactoryAction" + scope="request" + validate="false"> + <forward + name="success" + path="/WEB-INF/jsp/index.jsp"/> </action> </action-mappings> </struts-config>
--- a/gnv/src/main/webapp/WEB-INF/jsp/index.jsp Mon Sep 14 13:46:25 2009 +0000 +++ b/gnv/src/main/webapp/WEB-INF/jsp/index.jsp Mon Sep 14 13:56:03 2009 +0000 @@ -1,5 +1,29 @@ -<html> + +<%@page import="java.util.Collection"%> +<%@page import="de.intevation.gnv.artifactdatabase.objects.ArtifactObject"%> +<%@page import="de.intevation.gnv.action.sessionmodel.SessionModel"%> +<%@page import="de.intevation.gnv.action.sessionmodel.SessionModelFactory"%> +<%@page import="java.util.Iterator"%><html> <body> -<h2>Hello World!</h2> +<form action="selectArtifactFactory.do" method="post"> +<select name="artifactFactory"> +<% + SessionModel sm = SessionModelFactory.getInstance().getSessionModel(request); + Collection<ArtifactObject> artifactFactories = sm.getArtifactFactories(); + if (artifactFactories != null){ + Iterator<ArtifactObject> it = artifactFactories.iterator(); + while (it.hasNext()){ + ArtifactObject ao = it.next(); + +%> + + <option value="<%=ao.getId()%>" <%=(ao.isSelected() ? "selected=\"selected\"" : "")%> ><%=ao.getName()%></option> +<% + } + } +%> + </select> + <input type="submit" value="Auswählen" /> +</form> </body> </html>
--- a/gnv/src/main/webapp/WEB-INF/web.xml Mon Sep 14 13:46:25 2009 +0000 +++ b/gnv/src/main/webapp/WEB-INF/web.xml Mon Sep 14 13:56:03 2009 +0000 @@ -4,4 +4,19 @@ <web-app> <display-name>Archetype Created Web Application</display-name> + <servlet> + <servlet-name>action</servlet-name> + <servlet-class>de.intevation.gnv.servlet.GNVActionServlet</servlet-class> + <init-param> + <param-name>config</param-name> + <!-- --> + <param-value>/WEB-INF/config/struts-config.xml</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <!-- Standard Action Servlet Mapping --> + <servlet-mapping> + <servlet-name>action</servlet-name> + <url-pattern>*.do</url-pattern> + </servlet-mapping> </web-app>