Mercurial > dive4elements > gnv-client
view gnv/src/main/java/de/intevation/gnv/action/DescribeUIAction.java @ 998:27029f0ec7e1
Reverted the changes of rev1194.
gnv/trunk@1199 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 11 Jun 2010 10:28:50 +0000 |
parents | 9b126bceb0b2 |
children | b1eea43ba133 |
line wrap: on
line source
package de.intevation.gnv.action; import java.util.Locale; import java.util.ResourceBundle; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.xml.xpath.XPathConstants; import org.apache.log4j.Logger; import org.apache.struts.Globals; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.w3c.dom.Node; 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.ArtifactDescription; import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; import de.intevation.gnv.util.ArtifactNamespaceContext; import de.intevation.gnv.util.XMLUtils; import de.intevation.gnv.util.XSLTransformer; /** * This controller is called to fetch the current artifact description using the * describe operation. The describe document is used to feed an XSL transformer * that parses the xml and creats html output representing the parameter panel. * The html code is stored as attribute on the request object which is queried * in a jsp page later. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class DescribeUIAction extends ArtifactDatabaseActionBase { public static final String XPATH_DYNAMIC_UI = "art:dynamic"; public static final String XPATH_STATIC_UI = "art:static"; public static final String XSL_SHEET_DYNAMIC = "WEB-INF/config/templates/describe-ui.xsl"; public static final String XSL_SHEET_STATIC = "WEB-INF/config/templates/describe-ui-static.xsl"; /** * the logger, used to log exceptions and additonaly information */ private static Logger logger = Logger.getLogger(DescribeUIAction.class); /** * Constructor */ public DescribeUIAction() { super(); } @Override public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response ) throws Exception { if (isSessionExhausted(request)) { // session timed out before return sessionExhaustedForward(mapping, form, request, response); } logger.info("describe user interface"); try { // render describe document and create user interface SessionModel sm = SessionModelFactory.getInstance().getSessionModel( request); Locale tmp = sm.getCurrentLocale(); Locale locale = tmp != null ? tmp : request.getLocale(); ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory .getInstance().getArtifactDatabaseClient(locale); request.getSession().setAttribute(Globals.LOCALE_KEY, locale); ArtifactObject artifactFactory = sm.getSelectedArtifactFactory(); if (artifactFactory == null) { logger.error("No connection to artifact server."); request.setAttribute( CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, "java.io.ioexception..connection.refused"); return super.getExceptionForward(mapping); } ArtifactDescription artifactDescription = adc.getCurrentStepDescription( artifactFactory, sm.getCurrentArtifact(), true); Node currentUI = artifactDescription.getCurrentUI(); if (currentUI != null) { ResourceBundle res = ResourceBundle.getBundle( "applicationMessages", locale); String editText = res.getString( "gnviewer.history.back.button"); String exampleLinestring = res.getString( "gnviewer.example.linestring"); String examplePolygon = res.getString( "gnviewer.example.polygon"); XSLTransformer transformer = new XSLTransformer(); String url = response.encodeURL( mapping.findForward("back").getPath()); transformer.addParameter("back-url", url); transformer.addParameter("edit", editText); transformer.addParameter("example-polygon", examplePolygon); transformer.addParameter( "example-linestring", exampleLinestring); String fisUrl = response.encodeURL( mapping.findForward("selectfis").getPath()); transformer.addParameter("selectfis", fisUrl); // fetch dynamic part from describe document and transform it Node dynamicNode = (Node) XMLUtils.xpath( currentUI, XPATH_DYNAMIC_UI, XPathConstants.NODE, ArtifactNamespaceContext.INSTANCE ); String ui = transformer.transform( dynamicNode, "UTF-8", request.getRealPath(XSL_SHEET_DYNAMIC )); if (ui != null && ui.length() > 1) request.setAttribute("ui", ui); // fetch static part from describe document and transform it Node staticNode = (Node) XMLUtils.xpath( currentUI, XPATH_STATIC_UI, XPathConstants.NODE, ArtifactNamespaceContext.INSTANCE ); String staticUI = transformer.transform( staticNode, "UTF-8", request.getRealPath(XSL_SHEET_STATIC)); if (staticUI != null && staticUI.length() > 1) request.setAttribute("staticui", staticUI); } return super.execute(mapping, form, request, response); } catch (Exception e) { logger.error(e, e); request.setAttribute( CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e.getMessage()); return super.getExceptionForward(mapping); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :