Mercurial > dive4elements > gnv-client
view gnv/src/main/java/de/intevation/gnv/action/DescribeUIAction.java @ 690:254f062e334b
Added JavaDoc.
gnv/trunk@908 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 12 Apr 2010 16:45:16 +0000 |
parents | 57fa8019fbdc |
children | af22fa5567a6 |
line wrap: on
line source
package de.intevation.gnv.action; 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.util.ArtifactNamespaceContext; import de.intevation.gnv.util.XMLUtils; import de.intevation.gnv.util.XSLTransformer; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; 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; /** * 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"; private static Logger logger = Logger.getLogger(DescribeUIAction.class); public DescribeUIAction() { super(); } @Override public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response ) throws Exception { logger.info("describe user interface"); try { // render describe document and create user interface SessionModel sm = SessionModelFactory.getInstance().getSessionModel( request); ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory .getInstance().getArtifactDatabaseClient(request.getLocale()); request.getSession().setAttribute(Globals.LOCALE_KEY, request.getLocale()); ArtifactDescription artifactDescription = adc.getCurrentStepDescription( sm.getSelectedArtifactFactory(), sm.getCurrentArtifact(), true); Node currentUI = artifactDescription.getCurrentUI(); if (currentUI != null) { XSLTransformer transformer = new XSLTransformer(); String url = response.encodeURL( mapping.findForward("back").getPath()); transformer.addParameter("back-url", url); 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 :