本文整理汇总了Java中org.apache.xpath.XPath类的典型用法代码示例。如果您正苦于以下问题:Java XPath类的具体用法?Java XPath怎么用?Java XPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XPath类属于org.apache.xpath包,在下文中一共展示了XPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAttributeBooleanValue
import org.apache.xpath.XPath; //导入依赖的package包/类
private static final boolean getAttributeBooleanValue(XSLProcessorContext ctx, ElemExtensionCall call, String attr, boolean defaultValue) throws TransformerException {
Node node = ctx.getContextNode();
String expr = call.getAttribute(attr);
if (expr == null || expr.isEmpty())
return defaultValue;
XPathContext xpctx = ctx.getTransformer().getXPathContext();
XPath xp = new XPath(expr, call, xpctx.getNamespaceContext(), XPath.SELECT);
XObject xobj = xp.execute(xpctx, node, call);
String value = xobj.str();
if (value == null)
return defaultValue;
if (value.equals("yes"))
return true;
if (value.equals("true"))
return true;
if (value.equals("no"))
return false;
if (value.equals("false"))
return false;
return defaultValue;
}
示例2: update
import org.apache.xpath.XPath; //导入依赖的package包/类
protected void update(Node n) {
if (!isSelected(n)) {
try {
double matchScore
= xpath.execute(context, n, prefixResolver).num();
if (matchScore != XPath.MATCH_SCORE_NONE) {
if (!descendantSelected(n)) {
nodes.add(n);
}
} else {
n = n.getFirstChild();
while (n != null) {
update(n);
n = n.getNextSibling();
}
}
} catch (javax.xml.transform.TransformerException te) {
AbstractDocument doc
= (AbstractDocument) contentElement.getOwnerDocument();
throw doc.createXPathException
(XPathException.INVALID_EXPRESSION_ERR,
"xpath.error",
new Object[] { expression, te.getMessage() });
}
}
}
示例3: getPriorityOrScore
import org.apache.xpath.XPath; //导入依赖的package包/类
/**
* Given a match pattern and template association, return the
* score of that match. This score or priority can always be
* statically calculated.
*
* @param matchPat The match pattern to template association.
*
* @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
* {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}, or
* the value defined by the priority attribute of the template.
*
*/
private double getPriorityOrScore(TemplateSubPatternAssociation matchPat)
{
double priority = matchPat.getTemplate().getPriority();
if (priority == XPath.MATCH_SCORE_NONE)
{
Expression ex = matchPat.getStepPattern();
if (ex instanceof NodeTest)
{
return ((NodeTest) ex).getDefaultScore();
}
}
return priority;
}
示例4: StylesheetRoot
import org.apache.xpath.XPath; //导入依赖的package包/类
/**
* Uses an XSL stylesheet document.
* @throws TransformerConfigurationException if the baseIdentifier can not be resolved to a URL.
*/
public StylesheetRoot(ErrorListener errorListener) throws TransformerConfigurationException
{
super(null);
setStylesheetRoot(this);
try
{
m_selectDefault = new XPath("node()", this, this, XPath.SELECT, errorListener);
initDefaultRule(errorListener);
}
catch (TransformerException se)
{
throw new TransformerConfigurationException(XSLMessages.createMessage(XSLTErrorResources.ER_CANNOT_INIT_DEFAULT_TEMPLATES, null), se); //"Can't init default templates!", se);
}
}
示例5: compose
import org.apache.xpath.XPath; //导入依赖的package包/类
/**
* This function is called after everything else has been
* recomposed, and allows the template to set remaining
* values that may be based on some other property that
* depends on recomposition.
*/
public void compose(StylesheetRoot sroot) throws TransformerException
{
// See if we can reduce an RTF to a select with a string expression.
if(null == m_selectPattern
&& sroot.getOptimizer())
{
XPath newSelect = ElemVariable.rewriteChildToExpression(this);
if(null != newSelect)
m_selectPattern = newSelect;
}
m_qnameID = sroot.getComposeState().getQNameID(m_qname);
super.compose(sroot);
java.util.Vector vnames = sroot.getComposeState().getVariableNames();
if(null != m_selectPattern)
m_selectPattern.fixupVariables(vnames, sroot.getComposeState().getGlobalsSize());
// m_index must be resolved by ElemApplyTemplates and ElemCallTemplate!
}
示例6: getTargetNode
import org.apache.xpath.XPath; //导入依赖的package包/类
/**
* Get the target node that will be counted..
*
* @param xctxt The XPath runtime state for this.
* @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
*
* @return the target node that will be counted
*
* @throws TransformerException
*/
public int getTargetNode(XPathContext xctxt, int sourceNode)
throws TransformerException
{
int target = DTM.NULL;
XPath countMatchPattern = getCountMatchPattern(xctxt, sourceNode);
if (Constants.NUMBERLEVEL_ANY == m_level)
{
target = findPrecedingOrAncestorOrSelf(xctxt, m_fromMatchPattern,
countMatchPattern, sourceNode,
this);
}
else
{
target = findAncestor(xctxt, m_fromMatchPattern, countMatchPattern,
sourceNode, this);
}
return target;
}
示例7: createGlobalPseudoVarDecl
import org.apache.xpath.XPath; //导入依赖的package包/类
/**
* Create a psuedo variable reference that will represent the
* shared redundent XPath, for a local reduction.
*
* @param uniquePseudoVarName The name of the new variable.
* @param stylesheetRoot The broadest scope of where the variable
* should be inserted, which must be a StylesheetRoot element in this case.
* @param lpi The LocationPathIterator that the variable should represent.
* @return null if the decl was not created, otherwise the new Pseudo var
* element.
*/
protected ElemVariable createGlobalPseudoVarDecl(QName uniquePseudoVarName,
StylesheetRoot stylesheetRoot,
LocPathIterator lpi)
throws org.w3c.dom.DOMException
{
ElemVariable psuedoVar = new ElemVariable();
psuedoVar.setIsTopLevel(true);
XPath xpath = new XPath(lpi);
psuedoVar.setSelect(xpath);
psuedoVar.setName(uniquePseudoVarName);
Vector globalVars = stylesheetRoot.getVariablesAndParamsComposed();
psuedoVar.setIndex(globalVars.size());
globalVars.addElement(psuedoVar);
return psuedoVar;
}
示例8: createLocalPseudoVarDecl
import org.apache.xpath.XPath; //导入依赖的package包/类
/**
* Create a psuedo variable reference that will represent the
* shared redundent XPath, for a local reduction.
*
* @param uniquePseudoVarName The name of the new variable.
* @param psuedoVarRecipient The broadest scope of where the variable
* should be inserted, usually an xsl:template or xsl:for-each.
* @param lpi The LocationPathIterator that the variable should represent.
* @return null if the decl was not created, otherwise the new Pseudo var
* element.
*/
protected ElemVariable createLocalPseudoVarDecl(QName uniquePseudoVarName,
ElemTemplateElement psuedoVarRecipient,
LocPathIterator lpi)
throws org.w3c.dom.DOMException
{
ElemVariable psuedoVar = new ElemVariablePsuedo();
XPath xpath = new XPath(lpi);
psuedoVar.setSelect(xpath);
psuedoVar.setName(uniquePseudoVarName);
ElemVariable var = addVarDeclToElem(psuedoVarRecipient, lpi, psuedoVar);
lpi.exprSetParent(var);
return var;
}
示例9: startElement
import org.apache.xpath.XPath; //导入依赖的package包/类
/**
* Receive notification of the start of an preserve-space element.
*
* @param handler The calling StylesheetHandler/TemplatesBuilder.
* @param uri The Namespace URI, or the empty string if the
* element has no Namespace URI or if Namespace
* processing is not being performed.
* @param localName The local name (without prefix), or the
* empty string if Namespace processing is not being
* performed.
* @param rawName The raw XML 1.0 name (with prefix), or the
* empty string if raw names are not available.
* @param attributes The attributes attached to the element. If
* there are no attributes, it shall be an empty
* Attributes object.
*/
public void startElement(
StylesheetHandler handler, String uri, String localName, String rawName,
Attributes attributes)
throws org.xml.sax.SAXException
{
Stylesheet thisSheet = handler.getStylesheet();
WhitespaceInfoPaths paths = new WhitespaceInfoPaths(thisSheet);
setPropertiesFromAttributes(handler, rawName, attributes, paths);
Vector xpaths = paths.getElements();
for (int i = 0; i < xpaths.size(); i++)
{
WhiteSpaceInfo wsi = new WhiteSpaceInfo((XPath) xpaths.elementAt(i), false, thisSheet);
wsi.setUid(handler.nextUid());
thisSheet.setPreserveSpaces(wsi);
}
paths.clearElements();
}
示例10: processEXPR
import org.apache.xpath.XPath; //导入依赖的package包/类
/**
* Process an attribute string of type T_EXPR into
* an XPath value.
*
* @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
* @param uri The Namespace URI, or an empty string.
* @param name The local name (without prefix), or empty string if not namespace processing.
* @param rawName The qualified name (with prefix).
* @param value An XSLT expression string.
*
* @return an XPath object that may be used for evaluation.
*
* @throws org.xml.sax.SAXException that wraps a
* {@link javax.xml.transform.TransformerException} if the expression
* string contains a syntax error.
*/
Object processEXPR(
StylesheetHandler handler, String uri, String name, String rawName, String value,
ElemTemplateElement owner)
throws org.xml.sax.SAXException
{
try
{
XPath expr = handler.createXPath(value, owner);
return expr;
}
catch (TransformerException te)
{
throw new org.xml.sax.SAXException(te);
}
}
示例11: processPATTERN
import org.apache.xpath.XPath; //导入依赖的package包/类
/**
* Process an attribute string of type T_PATTERN into
* an XPath match pattern value.
*
* @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
* @param uri The Namespace URI, or an empty string.
* @param name The local name (without prefix), or empty string if not namespace processing.
* @param rawName The qualified name (with prefix).
* @param value A match pattern string.
*
* @return An XPath pattern that may be used to evaluate the XPath.
*
* @throws org.xml.sax.SAXException that wraps a
* {@link javax.xml.transform.TransformerException} if the match pattern
* string contains a syntax error.
*/
Object processPATTERN(
StylesheetHandler handler, String uri, String name, String rawName, String value,
ElemTemplateElement owner)
throws org.xml.sax.SAXException
{
try
{
XPath pattern = handler.createMatchPatternXPath(value, owner);
return pattern;
}
catch (TransformerException te)
{
throw new org.xml.sax.SAXException(te);
}
}
示例12: startElement
import org.apache.xpath.XPath; //导入依赖的package包/类
/**
* Receive notification of the start of an strip-space element.
*
* @param handler The calling StylesheetHandler/TemplatesBuilder.
* @param uri The Namespace URI, or the empty string if the
* element has no Namespace URI or if Namespace
* processing is not being performed.
* @param localName The local name (without prefix), or the
* empty string if Namespace processing is not being
* performed.
* @param rawName The raw XML 1.0 name (with prefix), or the
* empty string if raw names are not available.
* @param attributes The attributes attached to the element. If
* there are no attributes, it shall be an empty
* Attributes object.
*/
public void startElement(
StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes)
throws org.xml.sax.SAXException
{
Stylesheet thisSheet = handler.getStylesheet();
WhitespaceInfoPaths paths = new WhitespaceInfoPaths(thisSheet);
setPropertiesFromAttributes(handler, rawName, attributes, paths);
Vector xpaths = paths.getElements();
for (int i = 0; i < xpaths.size(); i++)
{
WhiteSpaceInfo wsi = new WhiteSpaceInfo((XPath) xpaths.elementAt(i), true, thisSheet);
wsi.setUid(handler.nextUid());
thisSheet.setStripSpaces(wsi);
}
paths.clearElements();
}
示例13: getAnalysisBits
import org.apache.xpath.XPath; //导入依赖的package包/类
/**
* Get the analysis bits for this walker, as defined in the WalkerFactory.
* @return One of WalkerFactory#BIT_DESCENDANT, etc.
*/
public int getAnalysisBits()
{
org.apache.xalan.templates.ElemVariable vvar = getElemVariable();
if(null != vvar)
{
XPath xpath = vvar.getSelect();
if(null != xpath)
{
Expression expr = xpath.getExpression();
if(null != expr && expr instanceof PathComponent)
{
return ((PathComponent)expr).getAnalysisBits();
}
}
}
return WalkerFactory.BIT_FILTER;
}
示例14: getAttributeStringValue
import org.apache.xpath.XPath; //导入依赖的package包/类
private static final String getAttributeStringValue(XSLProcessorContext ctx, ElemExtensionCall call, String exprAttr, String valueAttr) throws TransformerException {
Node node = ctx.getContextNode();
String expr = call.getAttribute(exprAttr);
if (expr == null || expr.isEmpty()) {
return call.getAttribute(valueAttr);
}
XPathContext xpctx = ctx.getTransformer().getXPathContext();
XPath xp = new XPath(expr, call, xpctx.getNamespaceContext(), XPath.SELECT);
XObject xobj = xp.execute(xpctx, node, call);
return xobj.str();
}
示例15: getAttributeIntValue
import org.apache.xpath.XPath; //导入依赖的package包/类
private static final int getAttributeIntValue(XSLProcessorContext ctx, ElemExtensionCall call, String attr) throws TransformerException {
Node node = ctx.getContextNode();
String expr = call.getAttribute(attr);
XPathContext xpctx = ctx.getTransformer().getXPathContext();
XPath xp = new XPath(expr, call, xpctx.getNamespaceContext(), XPath.SELECT);
XObject xobj = xp.execute(xpctx, node, call);
return (int) xobj.num();
}