/* */ package org.jaxen;
/* */
/* */ import java.io.
Serializable;
/* */ import java.util.
List;
/* */ import org.jaxen.expr.
Expr;
/* */ import org.jaxen.expr.
XPathExpr;
/* */ import org.jaxen.function.
BooleanFunction;
/* */ import org.jaxen.function.
NumberFunction;
/* */ import org.jaxen.function.
StringFunction;
/* */ import org.jaxen.saxpath.
SAXPathException;
/* */ import org.jaxen.saxpath.
XPathReader;
/* */ import org.jaxen.saxpath.
XPathSyntaxException;
/* */ import org.jaxen.saxpath.helpers.
XPathReaderFactory;
/* */ import org.jaxen.util.
SingletonList;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class
BaseXPath
/* */ implements
XPath,
Serializable
/* */ {
/* */ private final
String exprText;
/* */ private final
XPathExpr xpath;
/* */ private
ContextSupport support;
/* */ private
Navigator navigator;
/* */
/* */ protected
BaseXPath(
String xpathExpr) throws
JaxenException {
/* */ try {
/* 110 */
XPathReader reader =
XPathReaderFactory.
createReader();
/* 111 */
JaxenHandler handler = new
JaxenHandler();
/* 112 */
reader.
setXPathHandler(
handler);
/* 113 */
reader.
parse(
xpathExpr);
/* 114 */ this.
xpath =
handler.
getXPathExpr();
/* */ }
/* 116 */ catch (
XPathSyntaxException e) {
/* */
/* 118 */ throw new
XPathSyntaxException(
e);
/* */ }
/* 120 */ catch (
SAXPathException e) {
/* */
/* 122 */ throw new
JaxenException(
e);
/* */ }
/* */
/* 125 */ this.
exprText =
xpathExpr;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public
BaseXPath(
String xpathExpr,
Navigator navigator) throws
JaxenException {
/* 139 */ this(
xpathExpr);
/* 140 */ this.
navigator =
navigator;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public
Object evaluate(
Object context) throws
JaxenException {
/* 172 */
List answer =
selectNodes(
context);
/* */
/* 174 */ if (
answer != null &&
answer.
size() == 1) {
/* */
/* */
/* */
/* 178 */
Object first =
answer.
get(0);
/* */
/* 180 */ if (
first instanceof
String ||
first instanceof
Number ||
first instanceof
Boolean)
/* */ {
/* */
/* */
/* */
/* */
/* 186 */ return
first;
/* */ }
/* */ }
/* 189 */ return
answer;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public
List selectNodes(
Object node) throws
JaxenException {
/* 212 */
Context context =
getContext(
node);
/* 213 */ return
selectNodesForContext(
context);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public
Object selectSingleNode(
Object node) throws
JaxenException {
/* 234 */
List results =
selectNodes(
node);
/* */
/* 236 */ if (
results.
isEmpty())
/* */ {
/* 238 */ return null;
/* */ }
/* */
/* 241 */ return
results.
get(0);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public
String valueOf(
Object node) throws
JaxenException {
/* 254 */ return
stringValueOf(
node);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public
String stringValueOf(
Object node) throws
JaxenException {
/* 277 */
Context context =
getContext(
node);
/* */
/* 279 */
Object result =
selectSingleNodeForContext(
context);
/* */
/* 281 */ if (
result == null)
/* */ {
/* 283 */ return "";
/* */ }
/* */
/* 286 */ return
StringFunction.
evaluate(
result,
context.
getNavigator());
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public boolean
booleanValueOf(
Object node) throws
JaxenException {
/* 309 */
Context context =
getContext(
node);
/* 310 */
List result =
selectNodesForContext(
context);
/* 311 */ if (
result == null) return false;
/* 312 */ return
BooleanFunction.
evaluate(
result,
context.
getNavigator()).
booleanValue();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public
Number numberValueOf(
Object node) throws
JaxenException {
/* 334 */
Context context =
getContext(
node);
/* 335 */
Object result =
selectSingleNodeForContext(
context);
/* 336 */ return
NumberFunction.
evaluate(
result,
context.
getNavigator());
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void
addNamespace(
String prefix,
String uri) throws
JaxenException {
/* 369 */
NamespaceContext nsContext =
getNamespaceContext();
/* 370 */ if (
nsContext instanceof
SimpleNamespaceContext) {
/* */
/* 372 */ ((
SimpleNamespaceContext)
nsContext).
addNamespace(
prefix,
uri);
/* */
/* */ return;
/* */ }
/* */
/* 377 */ throw new
JaxenException("Operation not permitted while using a non-simple namespace context.");
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void
setNamespaceContext(
NamespaceContext namespaceContext) {
/* 404 */
getContextSupport().
setNamespaceContext(
namespaceContext);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void
setFunctionContext(
FunctionContext functionContext) {
/* 423 */
getContextSupport().
setFunctionContext(
functionContext);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void
setVariableContext(
VariableContext variableContext) {
/* 442 */
getContextSupport().
setVariableContext(
variableContext);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public
NamespaceContext getNamespaceContext() {
/* 465 */ return
getContextSupport().
getNamespaceContext();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public
FunctionContext getFunctionContext() {
/* 488 */ return
getContextSupport().
getFunctionContext();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public
VariableContext getVariableContext() {
/* 511 */ return
getContextSupport().
getVariableContext();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public
Expr getRootExpr() {
/* 531 */ return this.
xpath.
getRootExpr();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public
String toString() {
/* 540 */ return this.
exprText;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public
String debug() {
/* 549 */ return this.
xpath.
toString();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ protected
Context getContext(
Object node) {
/* 569 */ if (
node instanceof
Context)
/* */ {
/* 571 */ return (
Context)
node;
/* */ }
/* */
/* 574 */
Context fullContext = new
Context(
getContextSupport());
/* */
/* 576 */ if (
node instanceof
List) {
/* */
/* 578 */
fullContext.
setNodeSet((
List)
node);
/* */ }
/* */ else {
/* */
/* 582 */
SingletonList singletonList = new
SingletonList(
node);
/* 583 */
fullContext.
setNodeSet((
List)
singletonList);
/* */ }
/* */
/* 586 */ return
fullContext;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ protected
ContextSupport getContextSupport() {
/* 598 */ if (this.
support == null)
/* */ {
/* 600 */ this.
support = new
ContextSupport(
createNamespaceContext(),
createFunctionContext(),
createVariableContext(),
getNavigator());
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* 608 */ return this.
support;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public
Navigator getNavigator() {
/* 618 */ return this.
navigator;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ protected
FunctionContext createFunctionContext() {
/* 635 */ return
XPathFunctionContext.
getInstance();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ protected
NamespaceContext createNamespaceContext() {
/* 644 */ return new
SimpleNamespaceContext();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ protected
VariableContext createVariableContext() {
/* 653 */ return new
SimpleVariableContext();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ protected
List selectNodesForContext(
Context context) throws
JaxenException {
/* 674 */
List list = this.
xpath.
asList(
context);
/* 675 */ return
list;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ protected
Object selectSingleNodeForContext(
Context context) throws
JaxenException {
/* 698 */
List results =
selectNodesForContext(
context);
/* */
/* 700 */ if (
results.
isEmpty())
/* */ {
/* 702 */ return null;
/* */ }
/* */
/* 705 */ return
results.
get(0);
/* */ }
/* */ }
/* Location: /Users/tommy/.m2/repository/jaxen/jaxen/1.1.1/jaxen-1.1.1.jar!/org/jaxen/BaseXPath.class
* Java compiler version: 2 (46.0)
* JD-Core Version: 1.1.3
*/