Mercurial > dive4elements > gnv-client
comparison gnv/src/main/java/de/intevation/gnv/action/DescribeUIAction.java @ 409:df78178e1180
Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this.
gnv/trunk@599 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 22 Jan 2010 11:28:25 +0000 |
parents | |
children | 15ac78a91d1b |
comparison
equal
deleted
inserted
replaced
408:b5733f9f386b | 409:df78178e1180 |
---|---|
1 package de.intevation.gnv.action; | |
2 | |
3 import de.intevation.gnv.action.sessionmodel.SessionModel; | |
4 import de.intevation.gnv.action.sessionmodel.SessionModelFactory; | |
5 | |
6 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient; | |
7 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory; | |
8 | |
9 import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription; | |
10 | |
11 import de.intevation.gnv.util.ArtifactNamespaceContext; | |
12 import de.intevation.gnv.util.XMLUtils; | |
13 import de.intevation.gnv.util.XSLTransformer; | |
14 | |
15 import javax.servlet.http.HttpServletRequest; | |
16 import javax.servlet.http.HttpServletResponse; | |
17 | |
18 import javax.xml.xpath.XPathConstants; | |
19 | |
20 import org.apache.log4j.Logger; | |
21 | |
22 import org.apache.struts.action.ActionForm; | |
23 import org.apache.struts.action.ActionForward; | |
24 import org.apache.struts.action.ActionMapping; | |
25 | |
26 import org.w3c.dom.Node; | |
27 | |
28 /** | |
29 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) | |
30 */ | |
31 public class DescribeUIAction extends ArtifactDatabaseActionBase { | |
32 | |
33 public static final String XPATH_DYNAMIC_UI = "art:dynamic"; | |
34 public static final String XPATH_STATIC_UI = "art:static"; | |
35 | |
36 public static final String XSL_SHEET_DYNAMIC = | |
37 "WEB-INF/config/templates/describe-ui.xsl"; | |
38 | |
39 public static final String XSL_SHEET_STATIC = | |
40 "WEB-INF/config/templates/describe-ui-static.xsl"; | |
41 | |
42 private static Logger logger = Logger.getLogger(DescribeUIAction.class); | |
43 | |
44 | |
45 public DescribeUIAction() { | |
46 super(); | |
47 } | |
48 | |
49 | |
50 @Override | |
51 public ActionForward execute( | |
52 ActionMapping mapping, | |
53 ActionForm form, | |
54 HttpServletRequest request, | |
55 HttpServletResponse response | |
56 ) throws Exception | |
57 { | |
58 logger.info("describe user interface"); | |
59 try { | |
60 // render describe document and create user interface | |
61 SessionModel sm = SessionModelFactory.getInstance().getSessionModel( | |
62 request); | |
63 | |
64 ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory | |
65 .getInstance().getArtifactDatabaseClient(getLocale(request)); | |
66 | |
67 ArtifactDescription artifactDescription = | |
68 adc.getCurrentStepDescription( | |
69 sm.getSelectedArtifactFactory(), | |
70 sm.getCurrentArtifact(), | |
71 true); | |
72 | |
73 Node currentUI = artifactDescription.getCurrentUI(); | |
74 if (currentUI != null) { | |
75 XSLTransformer transformer = new XSLTransformer(); | |
76 | |
77 String url = response.encodeURL( | |
78 mapping.findForward("back").getPath()); | |
79 transformer.addParameter("back-url", url); | |
80 | |
81 String fisUrl = response.encodeURL( | |
82 mapping.findForward("selectfis").getPath()); | |
83 transformer.addParameter("selectfis", fisUrl); | |
84 | |
85 // fetch dynamic part from describe document and transform it | |
86 Node dynamicNode = (Node) XMLUtils.xpath( | |
87 currentUI, | |
88 XPATH_DYNAMIC_UI, | |
89 XPathConstants.NODE, | |
90 ArtifactNamespaceContext.INSTANCE | |
91 ); | |
92 | |
93 String ui = transformer.transform( | |
94 dynamicNode, | |
95 "UTF-8", | |
96 request.getRealPath(XSL_SHEET_DYNAMIC | |
97 )); | |
98 | |
99 if (ui != null && ui.length() > 1) | |
100 request.setAttribute("ui", ui); | |
101 | |
102 // fetch static part from describe document and transform it | |
103 Node staticNode = (Node) XMLUtils.xpath( | |
104 currentUI, | |
105 XPATH_STATIC_UI, | |
106 XPathConstants.NODE, | |
107 ArtifactNamespaceContext.INSTANCE | |
108 ); | |
109 | |
110 String staticUI = transformer.transform( | |
111 staticNode, | |
112 "UTF-8", | |
113 request.getRealPath(XSL_SHEET_STATIC)); | |
114 | |
115 if (staticUI != null && staticUI.length() > 1) | |
116 request.setAttribute("staticui", staticUI); | |
117 } | |
118 | |
119 return super.execute(mapping, form, request, response); | |
120 } | |
121 catch (Exception e) { | |
122 logger.error(e, e); | |
123 request.setAttribute( | |
124 CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, | |
125 e.getMessage()); | |
126 | |
127 return super.getExceptionForward(mapping); | |
128 } | |
129 } | |
130 } | |
131 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |