here is a patch which removes the xalan dependency. but it breaks the
ForEachTagTest.
i notice that every constructor generates a JSTLXPathCompiler. could it
not be a singleton?
On 07/12/2017 15:08, Matthew Broadhead wrote:
is there any other way to rewrite it so that it doesn't use
DTMManager? that would also keep the speed? is it a matter of
keeping the object in memory so that it doesn't have to keep building
fragments?
also could i build the old version that doesn't need DTMManager and
drop it in my system to see what effect it has?
On 06/12/2017 14:30, Romain Manni-Bucau wrote:
requires a classloader hack, no other trivial way, and that's why we
removed it from tomee
2017-12-06 14:27 GMT+01:00 Matthew Broadhead
<matthew.broadh...@nbmlaw.co.uk>:
is there any way that i can get the correct xalan at runtime?
to recap this is the code that is blowing up for me:
Reader xsl = new InputStreamReader(filepath.openStream());
TransformerFactory transformerfactory =
TransformerFactory.newInstance();
StreamSource ssXsl = new StreamSource(xsl);
ssXsl.setSystemId(filepath.toExternalForm());
Templates templates = transformerfactory.newTemplates(ssXsl);
Transformer transformer = templates.newTransformer();
last line causes:
java.lang.ClassCastException: org.apache.xml.dtm.ref.DTMManagerDefault
cannot be cast to org.apache.xml.dtm.DTMManager
at org.apache.xml.dtm.DTMManager.newInstance(DTMManager.java:137)
at org.apache.xpath.XPathContext.<init>(XPathContext.java:102)
at org.apache.xpath.XPathContext.<init>(XPathContext.java:349)
at org.apache.xpath.XPathContext.<init>(XPathContext.java:337)
at
org.apache.xalan.transformer.TransformerImpl.<init>(TransformerImpl.java:397)
at
org.apache.xalan.templates.StylesheetRoot.newTransformer(StylesheetRoot.java:200)
maybe you know some way to find the Impl with the correct DTMManager?
On 30/11/2017 17:30, Romain Manni-Bucau wrote:
2017-11-30 16:51 GMT+01:00 Jeremy Boynes <jer...@boynes.com>:
On Nov 30, 2017, at 3:14 AM, Matthew Broadhead
<matthew.broadh...@nbmlaw.co.uk> wrote:
has anything been decided? if i try to redeploy a context in
production
all my xslt processors blow up. there should be a solution that
fits all?
Taglibs (both Apache and Glassfish) has always had a dependency on
Xalan.
My understanding is that TomEE did not include it and so broke
users that
use the XML tags. If so, TomEE should fix that.
Sadly this is not a bug on tomee but the best solution we went through
after having delivered xalan for some releases. Xalan dependency
breaks 80% of apps so no way to include it - and this is the issue of
Matthew. Note it also affects simple apps in tomcat including taglib
and other libs.
You can probably add Xalan to your TomEE installation somehow to work
around it but how to do that is really a question for the TomEE
users list.
A patch for Taglibs that removes the Xalan dependency and doesn't
regress
the #27717 performance fix would be great. A patch that removed the
dependency but regressed performance would have to be evaluated at
the time.
The previous decision was not to do that.
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscr...@tomcat.apache.org
For additional commands, e-mail: taglibs-user-h...@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscr...@tomcat.apache.org
For additional commands, e-mail: taglibs-user-h...@tomcat.apache.org
Index: apache-taglibs-trunk/impl/pom.xml
===================================================================
--- apache-taglibs-trunk/impl/pom.xml (revision 1815893)
+++ apache-taglibs-trunk/impl/pom.xml (working copy)
@@ -91,13 +91,13 @@
<version>1.0</version>
<scope>provided</scope>
</dependency>
- <dependency>
+ <!-- <dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.1</version>
<scope>provided</scope>
<optional>true</optional>
- </dependency>
+ </dependency> -->
<dependency>
<groupId>junit</groupId>
Index:
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/ExprSupport.java
===================================================================
---
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/ExprSupport.java
(revision 1815893)
+++
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/ExprSupport.java
(working copy)
@@ -22,52 +22,55 @@
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
-import javax.xml.transform.TransformerException;
+//import javax.xml.transform.TransformerException;
import org.apache.taglibs.standard.util.EscapeXML;
-import org.apache.xpath.XPath;
-import org.apache.xpath.XPathContext;
+import org.apache.taglibs.standard.xpath.JSTLXPathCompiler;
+import org.apache.taglibs.standard.xpath.JSTLXPathExpression;
+import org.apache.taglibs.standard.xpath.JSTLXPathFactory;
+//import org.apache.xpath.XPath;
+//import org.apache.xpath.XPathContext;
/**
- * Tag handler for <out> in JSTL's XML library.
- * TODO: should we rename this to OutSupport to match the tag name?
+ * Tag handler for <out> in JSTL's XML library. TODO: should we rename
+ * this to OutSupport to match the tag name?
*
* @author Shawn Bayern
*/
public abstract class ExprSupport extends TagSupport {
- private XPath select;
- protected boolean escapeXml = true; // tag attribute
+ private JSTLXPathCompiler compiler;
+ private JSTLXPathExpression select;
+ protected boolean escapeXml = true; // tag attribute
- @Override
- public void release() {
- super.release();
- select = null;
- }
+ public ExprSupport() {
+ JSTLXPathFactory xpf = JSTLXPathFactory.getFactory();
+ compiler = xpf.newCompiler();
+ }
- //*********************************************************************
- // Tag logic
+ @Override
+ public void release() {
+ super.release();
+ compiler = null;
+ select = null;
+ }
- // applies XPath expression from 'select' and prints the result
- @Override
- public int doStartTag() throws JspException {
- try {
- XPathContext context = XalanUtil.getContext(this, pageContext);
- String result = select.execute(context, context.getCurrentNode(),
null).str();
- EscapeXML.emit(result, escapeXml, pageContext.getOut());
- return SKIP_BODY;
- } catch (IOException ex) {
- throw new JspTagException(ex.toString(), ex);
- } catch (TransformerException e) {
- throw new JspTagException(e);
- }
- }
+ // *********************************************************************
+ // Tag logic
- public void setSelect(String select) {
- try {
- this.select = new XPath(select, null, null, XPath.SELECT);
- } catch (TransformerException e) {
- throw new AssertionError();
- }
- }
+ // applies XPath expression from 'select' and prints the result
+ @Override
+ public int doStartTag() throws JspException {
+ try {
+ String result =
select.evaluateString(ForEachTag.getContext(this), pageContext);
+ EscapeXML.emit(result, escapeXml, pageContext.getOut());
+ return SKIP_BODY;
+ } catch (IOException ex) {
+ throw new JspTagException(ex.toString(), ex);
+ }
+ }
+
+ public void setSelect(String select) {
+ this.select = compiler.compile(select);
+ }
}
Index:
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/ForEachTag.java
===================================================================
---
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/ForEachTag.java
(revision 1815893)
+++
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/ForEachTag.java
(working copy)
@@ -17,16 +17,23 @@
package org.apache.taglibs.standard.tag.common.xml;
-import javax.servlet.jsp.JspException;
+//import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.jstl.core.LoopTagSupport;
-import javax.xml.transform.TransformerException;
+import javax.servlet.jsp.tagext.Tag;
+import javax.servlet.jsp.tagext.TagSupport;
+//import javax.xml.transform.TransformerException;
-import org.apache.xml.dtm.DTMIterator;
-import org.apache.xpath.XPath;
-import org.apache.xpath.XPathContext;
-import org.apache.xpath.objects.XObject;
+import org.apache.taglibs.standard.xpath.JSTLXPathCompiler;
+import org.apache.taglibs.standard.xpath.JSTLXPathContext;
+import org.apache.taglibs.standard.xpath.JSTLXPathExpression;
+import org.apache.taglibs.standard.xpath.JSTLXPathFactory;
+//import org.apache.xml.dtm.DTMIterator;
+//import org.apache.xpath.XPath;
+//import org.apache.xpath.XPathContext;
+//import org.apache.xpath.objects.XObject;
+
/**
* Implementation of <x:forEach> tag using low-level Xalan API.
*
@@ -35,95 +42,85 @@
*/
public class ForEachTag extends LoopTagSupport {
- private XPath select;
- private XPathContext context;
+ private JSTLXPathCompiler compiler;
+ private JSTLXPathExpression select;
+ private JSTLXPathContext context;
- @Override
- public void release() {
- super.release();
- select = null;
- context = null;
- }
+ public ForEachTag() {
+ JSTLXPathFactory xpf = JSTLXPathFactory.getFactory();
+ compiler = xpf.newCompiler();
+ }
- @Override
- protected void prepare() throws JspTagException {
- context = XalanUtil.getContext(this, pageContext);
- try {
- XObject nodes = select.execute(context, context.getCurrentNode(),
null);
+ @Override
+ public void release() {
+ super.release();
+ compiler = null;
+ select = null;
+ context = null;
+ }
- // create an iterator over the returned nodes and push into the
context
- DTMIterator iterator = nodes.iter();
- context.pushContextNodeList(iterator);
- } catch (TransformerException e) {
- throw new JspTagException(e);
- }
- }
+ @Override
+ protected void prepare() throws JspTagException {
+ context = select.iterate(getContext(this), pageContext);
+ }
- @Override
- protected boolean hasNext() throws JspTagException {
- DTMIterator iterator = context.getContextNodeList();
- return iterator.getCurrentPos() < iterator.getLength();
- }
+ @Override
+ protected boolean hasNext() throws JspTagException {
+ return context.hasNext();
+ }
- @Override
- protected Object next() throws JspTagException {
- DTMIterator iterator = context.getContextNodeList();
- int next = iterator.nextNode();
- context.pushCurrentNode(next);
- return iterator.getDTM(next).getNode(next);
- }
+ @Override
+ protected Object next() throws JspTagException {
+ return context.next();
+ }
- @Override
- public int doAfterBody() throws JspException {
- // pop the context node after executing the body
- context.popCurrentNode();
- return super.doAfterBody();
- }
+ // @Override
+ // public int doAfterBody() throws JspException {
+ // // pop the context node after executing the body
+ // context.popCurrentNode();
+ // return super.doAfterBody();
+ // }
+ //
+ // @Override
+ // public void doFinally() {
+ // // context might be null as prepare is not called if end < begin
+ // if (context != null) {
+ // // pop the list of nodes being iterated
+ // context.popContextNodeList();
+ // context = null;
+ // }
+ // super.doFinally();
+ // }
- @Override
- public void doFinally() {
- // context might be null as prepare is not called if end < begin
- if (context != null) {
- // pop the list of nodes being iterated
- context.popContextNodeList();
- context = null;
- }
- super.doFinally();
- }
+ public void setSelect(String select) {
+ this.select = compiler.compile(select);
+ }
- public void setSelect(String select) {
- try {
- this.select = new XPath(select, null, null, XPath.SELECT);
- } catch (TransformerException e) {
- throw new AssertionError();
- }
- }
+ public void setBegin(int begin) throws JspTagException {
+ this.beginSpecified = true;
+ this.begin = begin;
+ validateBegin();
+ }
- public void setBegin(int begin) throws JspTagException {
- this.beginSpecified = true;
- this.begin = begin;
- validateBegin();
- }
+ public void setEnd(int end) throws JspTagException {
+ this.endSpecified = true;
+ this.end = end;
+ validateEnd();
+ }
- public void setEnd(int end) throws JspTagException {
- this.endSpecified = true;
- this.end = end;
- validateEnd();
- }
+ public void setStep(int step) throws JspTagException {
+ this.stepSpecified = true;
+ this.step = step;
+ validateStep();
+ }
- public void setStep(int step) throws JspTagException {
- this.stepSpecified = true;
- this.step = step;
- validateStep();
- }
-
- /**
- * Return the current XPath context to support expression evaluation in
nested tags.
- *
- * @return the current XPath context
- */
- XPathContext getContext() {
- return context;
- }
+ /* Retrieves the current context. */
+ public static JSTLXPathContext getContext(Tag child) {
+ ForEachTag forEachTag = (ForEachTag)
TagSupport.findAncestorWithClass(child, ForEachTag.class);
+ if (forEachTag == null) {
+ return null;
+ } else {
+ return forEachTag.context;
+ }
+ }
}
-
Index:
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/IfTag.java
===================================================================
---
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/IfTag.java
(revision 1815893)
+++
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/IfTag.java
(working copy)
@@ -19,13 +19,18 @@
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.jstl.core.ConditionalTagSupport;
-import javax.xml.transform.TransformerException;
+//import javax.xml.transform.TransformerException;
-import org.apache.xpath.XPath;
-import org.apache.xpath.XPathContext;
+import org.apache.taglibs.standard.xpath.JSTLXPathCompiler;
+import org.apache.taglibs.standard.xpath.JSTLXPathExpression;
+import org.apache.taglibs.standard.xpath.JSTLXPathFactory;
+//import org.apache.xpath.XPath;
+//import org.apache.xpath.XPathContext;
/**
- * <p>Tag handler for <if> in JSTL's XML library.</p>
+ * <p>
+ * Tag handler for <if> in JSTL's XML library.
+ * </p>
*
* @author Shawn Bayern
*/
@@ -32,30 +37,27 @@
public class IfTag extends ConditionalTagSupport {
- private XPath select;
+ private JSTLXPathCompiler compiler;
+ private JSTLXPathExpression select;
+ public IfTag() {
+ JSTLXPathFactory xpf = JSTLXPathFactory.getFactory();
+ compiler = xpf.newCompiler();
+ }
- @Override
- public void release() {
- super.release();
- select = null;
- }
+ @Override
+ public void release() {
+ super.release();
+ compiler = null;
+ select = null;
+ }
- @Override
- protected boolean condition() throws JspTagException {
- XPathContext context = XalanUtil.getContext(this, pageContext);
- try {
- return select.bool(context, context.getCurrentNode(), null);
- } catch (TransformerException e) {
- throw new JspTagException(e);
- }
- }
+ @Override
+ protected boolean condition() throws JspTagException {
+ return select.evaluateBoolean(ForEachTag.getContext(this),
pageContext);
+ }
- public void setSelect(String select) {
- try {
- this.select = new XPath(select, null, null, XPath.SELECT);
- } catch (TransformerException e) {
- throw new AssertionError();
- }
- }
+ public void setSelect(String select) {
+ this.select = compiler.compile(select);
+ }
}
Index:
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/SetTag.java
===================================================================
---
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/SetTag.java
(revision 1815893)
+++
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/SetTag.java
(working copy)
@@ -18,70 +18,73 @@
package org.apache.taglibs.standard.tag.common.xml;
import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.JspTagException;
+//import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
-import javax.xml.transform.TransformerException;
+//import javax.xml.transform.TransformerException;
import org.apache.taglibs.standard.tag.common.core.Util;
-import org.apache.xpath.XPath;
-import org.apache.xpath.XPathContext;
-import org.apache.xpath.objects.XObject;
+import org.apache.taglibs.standard.xpath.JSTLXPathCompiler;
+import org.apache.taglibs.standard.xpath.JSTLXPathExpression;
+import org.apache.taglibs.standard.xpath.JSTLXPathFactory;
+//import org.apache.xpath.XPath;
+//import org.apache.xpath.XPathContext;
+//import org.apache.xpath.objects.XObject;
/**
- * <p>Tag handler for <set> in JSTL's XML library.</p>
+ * <p>
+ * Tag handler for <set> in JSTL's XML library.
+ * </p>
*
* @author Shawn Bayern
*/
public class SetTag extends TagSupport {
- private XPath select;
- private String var;
- private int scope = PageContext.PAGE_SCOPE;
+ private JSTLXPathCompiler compiler;
+ private JSTLXPathExpression select;
+ private String var;
+ private int scope = PageContext.PAGE_SCOPE;
- //*********************************************************************
- // Construction and initialization
+ // *********************************************************************
+ // Construction and initialization
- @Override
- public void release() {
- super.release();
- select = null;
- var = null;
- }
+ public SetTag() {
+ JSTLXPathFactory xpf = JSTLXPathFactory.getFactory();
+ compiler = xpf.newCompiler();
+ }
- //*********************************************************************
- // Tag logic
+ @Override
+ public void release() {
+ super.release();
+ compiler = null;
+ select = null;
+ var = null;
+ }
- // applies XPath expression from 'select' and stores the result in 'var'
+ // *********************************************************************
+ // Tag logic
- @Override
- public int doStartTag() throws JspException {
- try {
- XPathContext context = XalanUtil.getContext(this, pageContext);
- XObject result = select.execute(context, context.getCurrentNode(),
null);
- pageContext.setAttribute(var, XalanUtil.coerceToJava(result),
scope);
- return SKIP_BODY;
- } catch (TransformerException e) {
- throw new JspTagException(e);
- }
- }
+ // applies XPath expression from 'select' and stores the result in 'var'
- //*********************************************************************
- // Attribute accessors
+ @Override
+ public int doStartTag() throws JspException {
+ Object result =
select.evaluateObject(ForEachTag.getContext(this), pageContext);
+ pageContext.setAttribute(var, result, scope);
+ return SKIP_BODY;
+ }
- public void setSelect(String select) {
- try {
- this.select = new XPath(select, null, null, XPath.SELECT);
- } catch (TransformerException e) {
- throw new AssertionError();
- }
- }
+ // *********************************************************************
+ // Attribute accessors
- public void setVar(String var) {
- this.var = var;
- }
+ public void setSelect(String select) {
+ this.select = compiler.compile(select);
+ }
- public void setScope(String scope) {
- this.scope = Util.getScope(scope);
- }
+ public void setVar(String var) {
+ this.var = var;
+ }
+
+ public void setScope(String scope) {
+ this.scope = Util.getScope(scope);
+ }
}
Index:
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/WhenTag.java
===================================================================
---
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/WhenTag.java
(revision 1815893)
+++
apache-taglibs-trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/WhenTag.java
(working copy)
@@ -18,14 +18,19 @@
package org.apache.taglibs.standard.tag.common.xml;
import javax.servlet.jsp.JspTagException;
-import javax.xml.transform.TransformerException;
+//import javax.xml.transform.TransformerException;
import org.apache.taglibs.standard.tag.common.core.WhenTagSupport;
-import org.apache.xpath.XPath;
-import org.apache.xpath.XPathContext;
+import org.apache.taglibs.standard.xpath.JSTLXPathCompiler;
+import org.apache.taglibs.standard.xpath.JSTLXPathExpression;
+import org.apache.taglibs.standard.xpath.JSTLXPathFactory;
+//import org.apache.xpath.XPath;
+//import org.apache.xpath.XPathContext;
/**
- * <p>Tag handler for <if> in JSTL's XML library.</p>
+ * <p>
+ * Tag handler for <if> in JSTL's XML library.
+ * </p>
*
* @author Shawn Bayern
*/
@@ -32,29 +37,27 @@
public class WhenTag extends WhenTagSupport {
- private XPath select;
+ private JSTLXPathCompiler compiler;
+ private JSTLXPathExpression select;
- @Override
- public void release() {
- super.release();
- select = null;
- }
+ public WhenTag() {
+ JSTLXPathFactory xpf = JSTLXPathFactory.getFactory();
+ compiler = xpf.newCompiler();
+ }
- @Override
- protected boolean condition() throws JspTagException {
- XPathContext context = XalanUtil.getContext(this, pageContext);
- try {
- return select.bool(context, context.getCurrentNode(), null);
- } catch (TransformerException e) {
- throw new JspTagException(e);
- }
- }
+ @Override
+ public void release() {
+ super.release();
+ compiler = null;
+ select = null;
+ }
- public void setSelect(String select) {
- try {
- this.select = new XPath(select, null, null, XPath.SELECT);
- } catch (TransformerException e) {
- throw new AssertionError();
- }
- }
+ @Override
+ protected boolean condition() throws JspTagException {
+ return select.evaluateBoolean(ForEachTag.getContext(this),
pageContext);
+ }
+
+ public void setSelect(String select) {
+ this.select = compiler.compile(select);
+ }
}
Index:
apache-taglibs-trunk/impl/src/test/java/org/apache/taglibs/standard/tag/common/xml/ForEachTagTest.java
===================================================================
---
apache-taglibs-trunk/impl/src/test/java/org/apache/taglibs/standard/tag/common/xml/ForEachTagTest.java
(revision 1815893)
+++
apache-taglibs-trunk/impl/src/test/java/org/apache/taglibs/standard/tag/common/xml/ForEachTagTest.java
(working copy)
@@ -34,6 +34,7 @@
import org.junit.Test;
import org.apache.taglibs.standard.util.XmlUtil;
+import org.apache.taglibs.standard.xpath.JSTLXPathContext;
import org.apache.xml.dtm.DTMIterator;
import org.apache.xpath.CachedXPathAPI;
import org.apache.xpath.XPath;
@@ -82,7 +83,7 @@
tag.setSelect("$doc/root/a/num");
replay(pageContext);
tag.prepare();
- XPathContext context = tag.getContext();
+ JSTLXPathContext context = tag.getContext();
Assert.assertTrue(tag.hasNext());
Node one = (Node) tag.next();
assertEquals("one", one.getTextContent());
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscr...@tomcat.apache.org
For additional commands, e-mail: taglibs-user-h...@tomcat.apache.org