author | joehw |
Tue, 27 Jan 2015 22:01:46 -0800 | |
changeset 28695 | 427254b89b9e |
parent 25868 | 686eef1e7a79 |
child 39907 | db51759e3695 |
permissions | -rw-r--r-- |
6 | 1 |
/* |
28695 | 2 |
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
6 | 3 |
*/ |
4 |
/* |
|
28695 | 5 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
6 |
* contributor license agreements. See the NOTICE file distributed with |
|
7 |
* this work for additional information regarding copyright ownership. |
|
8 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
9 |
* (the "License"); you may not use this file except in compliance with |
|
10 |
* the License. You may obtain a copy of the License at |
|
6 | 11 |
* |
28695 | 12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
6 | 13 |
* |
14 |
* Unless required by applicable law or agreed to in writing, software |
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17 |
* See the License for the specific language governing permissions and |
|
18 |
* limitations under the License. |
|
19 |
*/ |
|
20 |
||
21 |
package com.sun.org.apache.xpath.internal.jaxp; |
|
22 |
||
28695 | 23 |
import com.sun.org.apache.xalan.internal.utils.FeatureManager; |
6 | 24 |
import com.sun.org.apache.xpath.internal.objects.XObject; |
25 |
import javax.xml.namespace.QName; |
|
28695 | 26 |
import javax.xml.transform.TransformerException; |
27 |
import javax.xml.xpath.XPathConstants; |
|
28 |
import javax.xml.xpath.XPathEvaluationResult; |
|
29 |
import javax.xml.xpath.XPathExpression; |
|
6 | 30 |
import javax.xml.xpath.XPathExpressionException; |
31 |
import javax.xml.xpath.XPathFunctionResolver; |
|
32 |
import javax.xml.xpath.XPathVariableResolver; |
|
28695 | 33 |
import org.w3c.dom.Document; |
6 | 34 |
import org.w3c.dom.Node; |
35 |
import org.xml.sax.InputSource; |
|
36 |
||
37 |
/** |
|
38 |
* The XPathExpression interface encapsulates a (compiled) XPath expression. |
|
39 |
* |
|
40 |
* @author Ramesh Mandava |
|
41 |
*/ |
|
28695 | 42 |
public class XPathExpressionImpl extends XPathImplUtil implements XPathExpression { |
6 | 43 |
|
28695 | 44 |
private com.sun.org.apache.xpath.internal.XPath xpath; |
21467
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
12458
diff
changeset
|
45 |
|
6 | 46 |
/** Protected constructor to prevent direct instantiation; use compile() |
47 |
* from the context. |
|
48 |
*/ |
|
21467
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
12458
diff
changeset
|
49 |
protected XPathExpressionImpl() { |
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
12458
diff
changeset
|
50 |
this(null, null, null, null, |
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
12458
diff
changeset
|
51 |
false, true, new FeatureManager()); |
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
12458
diff
changeset
|
52 |
}; |
6 | 53 |
|
54 |
protected XPathExpressionImpl(com.sun.org.apache.xpath.internal.XPath xpath, |
|
55 |
JAXPPrefixResolver prefixResolver, |
|
56 |
XPathFunctionResolver functionResolver, |
|
28695 | 57 |
XPathVariableResolver variableResolver) { |
21467
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
12458
diff
changeset
|
58 |
this(xpath, prefixResolver, functionResolver, variableResolver, |
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
12458
diff
changeset
|
59 |
false, true, new FeatureManager()); |
6 | 60 |
}; |
61 |
||
62 |
protected XPathExpressionImpl(com.sun.org.apache.xpath.internal.XPath xpath, |
|
21467
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
12458
diff
changeset
|
63 |
JAXPPrefixResolver prefixResolver,XPathFunctionResolver functionResolver, |
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
12458
diff
changeset
|
64 |
XPathVariableResolver variableResolver, boolean featureSecureProcessing, |
28695 | 65 |
boolean useServiceMechanism, FeatureManager featureManager) { |
6 | 66 |
this.xpath = xpath; |
67 |
this.prefixResolver = prefixResolver; |
|
68 |
this.functionResolver = functionResolver; |
|
69 |
this.variableResolver = variableResolver; |
|
70 |
this.featureSecureProcessing = featureSecureProcessing; |
|
28695 | 71 |
this.useServiceMechanism = useServiceMechanism; |
21467
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
12458
diff
changeset
|
72 |
this.featureManager = featureManager; |
6 | 73 |
}; |
74 |
||
28695 | 75 |
public void setXPath (com.sun.org.apache.xpath.internal.XPath xpath) { |
6 | 76 |
this.xpath = xpath; |
77 |
} |
|
78 |
||
79 |
public Object eval(Object item, QName returnType) |
|
80 |
throws javax.xml.transform.TransformerException { |
|
28695 | 81 |
XObject resultObject = eval(item, xpath); |
82 |
return getResultAsType(resultObject, returnType); |
|
6 | 83 |
} |
84 |
||
28695 | 85 |
@Override |
6 | 86 |
public Object evaluate(Object item, QName returnType) |
87 |
throws XPathExpressionException { |
|
28695 | 88 |
isSupported(returnType); |
6 | 89 |
try { |
28695 | 90 |
return eval(item, returnType); |
91 |
} catch (java.lang.NullPointerException npe) { |
|
6 | 92 |
// If VariableResolver returns null Or if we get |
93 |
// NullPointerException at this stage for some other reason |
|
94 |
// then we have to reurn XPathException |
|
28695 | 95 |
throw new XPathExpressionException (npe); |
96 |
} catch (javax.xml.transform.TransformerException te) { |
|
6 | 97 |
Throwable nestedException = te.getException(); |
28695 | 98 |
if (nestedException instanceof javax.xml.xpath.XPathFunctionException) { |
6 | 99 |
throw (javax.xml.xpath.XPathFunctionException)nestedException; |
100 |
} else { |
|
101 |
// For any other exceptions we need to throw |
|
28695 | 102 |
// XPathExpressionException (as per spec) |
103 |
throw new XPathExpressionException(te); |
|
6 | 104 |
} |
105 |
} |
|
106 |
} |
|
107 |
||
108 |
||
28695 | 109 |
@Override |
110 |
public String evaluate(Object item) |
|
111 |
throws XPathExpressionException { |
|
112 |
return (String)this.evaluate(item, XPathConstants.STRING); |
|
113 |
} |
|
6 | 114 |
|
28695 | 115 |
@Override |
6 | 116 |
public Object evaluate(InputSource source, QName returnType) |
117 |
throws XPathExpressionException { |
|
28695 | 118 |
isSupported (returnType); |
6 | 119 |
try { |
28695 | 120 |
Document document = getDocument(source); |
121 |
return eval(document, returnType); |
|
122 |
} catch (TransformerException e) { |
|
123 |
throw new XPathExpressionException(e); |
|
6 | 124 |
} |
125 |
} |
|
126 |
||
28695 | 127 |
@Override |
6 | 128 |
public String evaluate(InputSource source) |
129 |
throws XPathExpressionException { |
|
28695 | 130 |
return (String)this.evaluate(source, XPathConstants.STRING); |
6 | 131 |
} |
132 |
||
28695 | 133 |
@Override |
134 |
public <T>T evaluateExpression(Object item, Class<T> type) |
|
135 |
throws XPathExpressionException { |
|
136 |
isSupportedClassType(type); |
|
6 | 137 |
|
28695 | 138 |
try { |
139 |
XObject resultObject = eval(item, xpath); |
|
140 |
if (type.isAssignableFrom(XPathEvaluationResult.class)) { |
|
141 |
return getXPathResult(resultObject, type); |
|
142 |
} else { |
|
143 |
return XPathResultImpl.getValue(resultObject, type); |
|
144 |
} |
|
6 | 145 |
|
28695 | 146 |
} catch (javax.xml.transform.TransformerException te) { |
147 |
throw new XPathExpressionException(te); |
|
6 | 148 |
} |
149 |
} |
|
150 |
||
28695 | 151 |
@Override |
152 |
public XPathEvaluationResult<?> evaluateExpression(Object item) |
|
153 |
throws XPathExpressionException { |
|
154 |
return evaluateExpression(item, XPathEvaluationResult.class); |
|
155 |
} |
|
156 |
||
157 |
@Override |
|
158 |
public <T>T evaluateExpression(InputSource source, Class<T> type) |
|
159 |
throws XPathExpressionException { |
|
160 |
Document document = getDocument(source); |
|
161 |
return evaluateExpression(document, type); |
|
162 |
} |
|
163 |
||
164 |
@Override |
|
165 |
public XPathEvaluationResult<?> evaluateExpression(InputSource source) |
|
166 |
throws XPathExpressionException { |
|
167 |
return evaluateExpression(source, XPathEvaluationResult.class); |
|
168 |
} |
|
6 | 169 |
} |