• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java XPath类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.xpath.XPath的典型用法代码示例。如果您正苦于以下问题:Java XPath类的具体用法?Java XPath怎么用?Java XPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



XPath类属于org.apache.xpath包,在下文中一共展示了XPath类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: compileXQExpr

import org.apache.xpath.XPath; //导入依赖的package包/类
/**
 * Take the received string, which is an XML query expression, compile it, and
 * store the compiled query locally. Note that for now, we only support XPath
 * because that's what Xalan supports.
 * 
 * @param queryExpr
 *          The XPath expression to compile
 */
public void compileXQExpr(final String queryExpr, final String opName,
    final DocumentBuilder dBuilder) throws StandardException {
  try {

    /* The following XPath constructor compiles the expression
     * as part of the construction process.  We have to pass
     * in a PrefixResolver object in order to avoid NPEs when
     * invalid/unknown functions are used, so we just create
     * a dummy one, which means prefixes will not be resolved
     * in the query (Xalan will just throw an error if a prefix
     * is used).  In the future we may want to revisit this
     * to make it easier for users to query based on namespaces.
     */
    query = new XPath(queryExpr, null, new PrefixResolverDefault(
        dBuilder.newDocument()), XPath.SELECT);

  } catch (Throwable te) {

    /* Something went wrong during compilation of the
     * expression; wrap the error and re-throw it.
     * Note: we catch "Throwable" here to catch as many
     * Xalan-produced errors as possible in order to
     * minimize the chance of an uncaught Xalan error
     * (such as a NullPointerException) causing Derby
     * to fail in a more serious way.  In particular, an
     * uncaught Java exception like NPE can result in
     * Derby throwing "ERROR 40XT0: An internal error was
     * identified by RawStore module" for all statements on
     * the connection after the failure--which we clearly
     * don't want.  If we catch the error and wrap it,
     * though, the statement will fail but Derby will
     * continue to run as normal. 
     */
    throw StandardException.newException(SQLState.LANG_XML_QUERY_ERROR, te,
        opName, te.getMessage());

  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:47,代码来源:SqlXmlHelperXalan.java


示例17: parse

import org.apache.xpath.XPath; //导入依赖的package包/类
/**
 * Parses the XPath selector.
 */
protected void parse() {
    context = new XPathContext();
    try {
        xpath = new XPath(expression, null, prefixResolver, XPath.MATCH);
    } catch (javax.xml.transform.TransformerException te) {
        AbstractDocument doc
            = (AbstractDocument) contentElement.getOwnerDocument();
        throw doc.createXPathException
            (XPathException.INVALID_EXPRESSION_ERR,
             "xpath.invalid.expression",
             new Object[] { expression, te.getMessage() });
    }
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:17,代码来源:XPathPatternContentSelector.java


示例18: XPathExpr

import org.apache.xpath.XPath; //导入依赖的package包/类
/**
 * Creates a new XPathExpr object.
 */
public XPathExpr(String expr, XPathNSResolver res)
        throws DOMException, XPathException {
    resolver = res;
    prefixResolver = new NSPrefixResolver();
    try {
        xpath = new XPath(expr, null, prefixResolver, XPath.SELECT);
        context = new XPathContext();
    } catch (javax.xml.transform.TransformerException te) {
        throw createXPathException
            (XPathException.INVALID_EXPRESSION_ERR,
             "xpath.invalid.expression",
             new Object[] { expr, te.getMessage() });
    }
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:18,代码来源:AbstractDocument.java


示例19: setSelect

import org.apache.xpath.XPath; //导入依赖的package包/类
/**
 * Set the "select" attribute.
 *
 * @param xpath The XPath expression for the "select" attribute.
 */
public void setSelect(XPath xpath)
{
  m_selectExpression = xpath.getExpression();
  
  // The following line is part of the codes added to fix bug#16889
  // Store xpath which will be needed when firing Selected Event
  m_xpath = xpath;    
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:14,代码来源:ElemForEach.java


示例20: findAncestor

import org.apache.xpath.XPath; //导入依赖的package包/类
/**
 * Given a 'from' pattern (ala xsl:number), a match pattern
 * and a context, find the first ancestor that matches the
 * pattern (including the context handed in).
 *
 * @param xctxt The XPath runtime state for this.
 * @param fromMatchPattern The ancestor must match this pattern.
 * @param countMatchPattern The ancestor must also match this pattern.
 * @param context The node that "." expresses.
 * @param namespaceContext The context in which namespaces in the
 * queries are supposed to be expanded.
 *
 * @return the first ancestor that matches the given pattern
 *
 * @throws javax.xml.transform.TransformerException
 */
int findAncestor(
        XPathContext xctxt, XPath fromMatchPattern, XPath countMatchPattern, 
        int context, ElemNumber namespaceContext)
          throws javax.xml.transform.TransformerException
{
  DTM dtm = xctxt.getDTM(context);
  while (DTM.NULL != context)
  {
    if (null != fromMatchPattern)
    {
      if (fromMatchPattern.getMatchScore(xctxt, context)
              != XPath.MATCH_SCORE_NONE)
      {

        //context = null;
        break;
      }
    }

    if (null != countMatchPattern)
    {
      if (countMatchPattern.getMatchScore(xctxt, context)
              != XPath.MATCH_SCORE_NONE)
      {
        break;
      }
    }

    context = dtm.getParent(context);
  }

  return context;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:50,代码来源:ElemNumber.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CreatureType类代码示例发布时间:2022-05-21
下一篇:
Java AutoEscapeBeanHandler类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap