Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Developer-supplied XSLT params in AbstractXsltView (patch) [SPR-40] #4775

Closed
spring-projects-issues opened this issue Feb 18, 2004 · 2 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Aaron Hamid opened SPR-40 and commented

I originally posted this issue on the SourceForge forums (http://sourceforge.net/forum/forum.php?thread_id=1024298&forum_id=250339).

It would be nice to be able to set XSLT parameters in XSLT view. Also, AbstractXsltView for some reason will bomb if no model is supplied in the ModelAndView, even though createDomNode can supply a valid node. This patch includes some of my commentary - remove at will.

--- AbstractXsltViewOriginal.java 2004-02-17 12:39:18.142750000 -0500
+++ AbstractXsltView.java 2004-02-17 12:47:01.674000000 -0500
@@ -8,6 +8,7 @@
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.util.Map;
+import java.util.Iterator;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -168,7 +169,7 @@
}

if (model == null)
  throw new ServletException("Cannot do XSLT transform on null model");
  throw new ServletException("Cannot do XSLT transform on null model"); // XXX: why not? just use createDomNode

Node dom = null;
String docRoot = null;
@@ -181,6 +182,10 @@
singleModel = model.get(docRoot);
}

  • // XXX: not sure what this business is about, but if I have an empty/null model in my ModelAndView

  • // I consistently get the error: "Cannot domify multiple non-Node objects without a root element name in XSLT view"

  • // even though I can supply a perfectly fine Dom node from createDomNode

  • // handle special case when we have a single node
    if (singleModel != null && (singleModel instanceof Node)) {
    // Don't domify if the model is already an XML node
    @@ -199,7 +204,9 @@
    dom = createDomNode(model, (docRoot == null) ? this.root : docRoot, request, response);
    }

  • doTransform(response, dom);
  • Map params = getParameters(model, (docRoot == null) ? this.root : docRoot, request, response);
  • doTransform(response, dom, params);
    }

/**
@@ -219,14 +226,42 @@
HttpServletResponse response) throws Exception;

/**

    • Return parameters to set in the XSLT transform.
    • Subclasses must implement this method.
    • NOTE: might be better to merge createDomNode and getParameters, returning a combined object,
    • instead of two seperate calls
    • @param model the model Map
    • @param root name for root element
    • @param request HTTP request. Subclasses won't normally use this, as
    • request processing should have been complete. However, we might to
    • create a RequestContext to expose as part of the model.
    • @param response HTTP response. Subclasses won't normally use this,
    • however there may sometimes be a need to set cookies.
    • @throws Exception we let this method throw any exception; the
    • AbstractXlstView superclass will catch exceptions
  • */
  • protected Map getParameters(Map model, String root, HttpServletRequest request, HttpServletResponse response) {
  • return null;
  • }
  • /**
    • Use TrAX to perform the transform.
      */
  • protected void doTransform(HttpServletResponse response, Node dom) throws ServletException, IOException {
  • protected void doTransform(HttpServletResponse response, Node dom, Map parameters) throws ServletException, IOException {
    try {
    Transformer trans = (this.templates != null) ?
    this.templates.newTransformer() : // we have a stylesheet
    this.transformerFactory.newTransformer(); // just a copy

  // set our developer-supplied parameters if any
  if (parameters != null) {
  Iterator it = parameters.entrySet().iterator();
  while (it.hasNext()) {
  Map.Entry entry = (Map.Entry) it.next();
  trans.setParameter(entry.getKey().toString(), entry.getValue());
  }
  }
  trans.setOutputProperty(OutputKeys.INDENT, "yes");
  // Xalan-specific, but won't do any harm in other XSLT engines
  trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

No further details from SPR-40

@spring-projects-issues
Copy link
Collaborator Author

Darren Davison commented

the check for null model (throwing ServletException) is removed. Unlikely to be reached anyway since if the controller returns a null model, AbstractView.render() will throw NPE.

a root tag name no longer needs to be supplied, but a default one will be passed to createDomNode if it isn't. Of course your subclasses are free to ignore this default at their leisure.

single model key name will still override a root tag name supplied in views.properties (or whatever)

new method [protected Map getParameters()] added for subclasses to override and return XSLT parameter name/value pairs. Default impl. returns null

@spring-projects-issues
Copy link
Collaborator Author

Darren Davison commented

in cvs from 27/02/2004

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 10, 2019
@spring-projects-issues spring-projects-issues added this to the 1.0 RC2 milestone Jan 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant