当前位置: 首页>>代码示例>>Java>>正文


Java XPath类代码示例

本文整理汇总了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;
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:22,代码来源:XMLReader.java

示例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() });
        }
    }
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:27,代码来源:XPathPatternContentSelector.java

示例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;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:33,代码来源:TemplateList.java

示例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);
  }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:StylesheetRoot.java

示例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!
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:26,代码来源:ElemWithParam.java

示例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;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:32,代码来源:ElemNumber.java

示例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;
 }
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:28,代码来源:RedundentExprEliminator.java

示例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;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:29,代码来源:RedundentExprEliminator.java

示例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();
 }
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:37,代码来源:ProcessorPreserveSpace.java

示例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);
  }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:34,代码来源:XSLTAttributeDef.java

示例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);
  }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:34,代码来源:XSLTAttributeDef.java

示例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();

 }
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:37,代码来源:ProcessorStripSpace.java

示例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;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:22,代码来源:Variable.java

示例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();
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:12,代码来源:XMLReader.java

示例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();
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:9,代码来源:XMLReader.java


注:本文中的org.apache.xpath.XPath类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。