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

Java PrefixResolverDefault类代码示例

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

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



PrefixResolverDefault类属于org.apache.xml.utils包,在下文中一共展示了PrefixResolverDefault类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: compileXQExpr

import org.apache.xml.utils.PrefixResolverDefault; //导入依赖的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


示例2: eval

import org.apache.xml.utils.PrefixResolverDefault; //导入依赖的package包/类
/**
 *  Evaluate XPath string to an XObject.
 *  XPath namespace prefixes are resolved from the namespaceNode.
 *  The implementation of this is a little slow, since it creates
 *  a number of objects each time it is called.  This could be optimized
 *  to keep the same objects around, but then thread-safety issues would arise.
 *
 *  @param contextNode The node to start searching from.
 *  @param str A valid XPath string.
 *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 *  @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null.
 *  @see org.apache.xpath.objects.XObject
 *  @see org.apache.xpath.objects.XNull
 *  @see org.apache.xpath.objects.XBoolean
 *  @see org.apache.xpath.objects.XNumber
 *  @see org.apache.xpath.objects.XString
 *  @see org.apache.xpath.objects.XRTreeFrag
 *
 * @throws TransformerException
 */
public static XObject eval(Node contextNode, String str, Node namespaceNode)
        throws TransformerException
{

  // Since we don't have a XML Parser involved here, install some default support
  // for things like namespaces, etc.
  // (Changed from: XPathContext xpathSupport = new XPathContext();
  //    because XPathContext is weak in a number of areas... perhaps
  //    XPathContext should be done away with.)
  // Create an XPathContext that doesn't support pushing and popping of
  // variable resolution scopes.  Sufficient for simple XPath 1.0 expressions.
  XPathContext xpathSupport = new XPathContext(false);

  // Create an object to resolve namespace prefixes.
  // XPath namespaces are resolved from the input context node's document element
  // if it is a root node, or else the current context node (for lack of a better
  // resolution space, given the simplicity of this sample code).
  PrefixResolverDefault prefixResolver = new PrefixResolverDefault(
    (namespaceNode.getNodeType() == Node.DOCUMENT_NODE)
    ? ((Document) namespaceNode).getDocumentElement() : namespaceNode);

  // Create the XPath object.
  XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);

  // Execute the XPath, and have it return the result
  // return xpath.execute(xpathSupport, contextNode, prefixResolver);
  int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);

  return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:51,代码来源:XPathAPI.java


示例3: eval

import org.apache.xml.utils.PrefixResolverDefault; //导入依赖的package包/类
/**
 *  Evaluate XPath string to an XObject. 
 *  XPath namespace prefixes are resolved from the namespaceNode.
 *  The implementation of this is a little slow, since it creates
 *  a number of objects each time it is called.  This could be optimized
 *  to keep the same objects around, but then thread-safety issues would arise.
 *
 *  @param contextNode The node to start searching from.
 *  @param str A valid XPath string.
 *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 *  @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null.
 *  @see org.apache.xpath.objects.XObject
 *  @see org.apache.xpath.objects.XNull
 *  @see org.apache.xpath.objects.XBoolean
 *  @see org.apache.xpath.objects.XNumber
 *  @see org.apache.xpath.objects.XString
 *  @see org.apache.xpath.objects.XRTreeFrag
 *
 * @throws TransformerException
 */
public  XObject eval(Node contextNode, String str, Node namespaceNode)
        throws TransformerException
{

  // Since we don't have a XML Parser involved here, install some default support
  // for things like namespaces, etc.
  // (Changed from: XPathContext xpathSupport = new XPathContext();
  //    because XPathContext is weak in a number of areas... perhaps
  //    XPathContext should be done away with.)

  // Create an object to resolve namespace prefixes.
  // XPath namespaces are resolved from the input context node's document element
  // if it is a root node, or else the current context node (for lack of a better
  // resolution space, given the simplicity of this sample code).
  PrefixResolverDefault prefixResolver = new PrefixResolverDefault(
    (namespaceNode.getNodeType() == Node.DOCUMENT_NODE)
    ? ((Document) namespaceNode).getDocumentElement() : namespaceNode);

  // Create the XPath object.
  XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);

  // Execute the XPath, and have it return the result
  // return xpath.execute(xpathSupport, contextNode, prefixResolver);
  int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);

  return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:48,代码来源:CachedXPathAPI.java


示例4: EvalCheck

import org.apache.xml.utils.PrefixResolverDefault; //导入依赖的package包/类
/**
 * Creates a new instance from a DOM node.
 * @param node DOM node that defines this check
 */
public EvalCheck(Node node) {
    this.expected = node.getAttributes().getNamedItem("expected").getNodeValue();
    this.xpath = node.getAttributes().getNamedItem("xpath").getNodeValue();
    Node nd = node.getAttributes().getNamedItem("tolerance");
    if (nd != null) {
        this.tolerance = Double.parseDouble(nd.getNodeValue());
    }
    this.prefixResolver = new PrefixResolverDefault(node);
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:14,代码来源:EvalCheck.java


示例5: TrueCheck

import org.apache.xml.utils.PrefixResolverDefault; //导入依赖的package包/类
/**
 * Creates a new instance from a DOM node.
 * @param node DOM node that defines this check
 */
public TrueCheck(Node node) {
    this.xpath = node.getAttributes().getNamedItem("xpath").getNodeValue();
    Node nd = node.getAttributes().getNamedItem("fail-msg");
    if (nd != null) {
        this.failureMessage = nd.getNodeValue();
    }
    this.prefixResolver = new PrefixResolverDefault(node);
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:13,代码来源:TrueCheck.java


示例6: getXPathExpressionForDocument

import org.apache.xml.utils.PrefixResolverDefault; //导入依赖的package包/类
private XPathExpression getXPathExpressionForDocument(Document document) {
  try {
    XPath xpath = XPathFactory.newInstance().newXPath();
    PrefixResolver resolver = new PrefixResolverDefault(document.getDocumentElement());
    xpath.setNamespaceContext(new DocumentNamespaceContext(resolver));
    return xpath.compile(expression);
  } catch (XPathExpressionException e) {
    throw createExpressionException(e);
  }
}
 
开发者ID:SonarSource,项目名称:sonar-xml,代码行数:11,代码来源:XPathCheck.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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