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


Java PrefixResolver类代码示例

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


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

示例1: eval

import org.apache.xml.utils.PrefixResolver; //导入依赖的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 prefixResolver Will be called if the parser encounters namespace
 *                         prefixes, to resolve the prefixes to URLs.
 *   @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, PrefixResolver prefixResolver)
          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 the XPath object.
  XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);

  // 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);

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

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

示例2: eval

import org.apache.xml.utils.PrefixResolver; //导入依赖的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 prefixResolver Will be called if the parser encounters namespace
 *                         prefixes, to resolve the prefixes to URLs.
 *   @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, PrefixResolver prefixResolver)
          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 the XPath object.
  XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);

  // 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);

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

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

示例3: KeyTable

import org.apache.xml.utils.PrefixResolver; //导入依赖的package包/类
/**
 * Build a keys table.
 * @param doc The owner document key.
 * @param nscontext The stylesheet's namespace context.
 * @param name The key name
 * @param keyDeclarations The stylesheet's xsl:key declarations.
 *
 * @throws javax.xml.transform.TransformerException
 */
public KeyTable(
        int doc, PrefixResolver nscontext, QName name, Vector keyDeclarations, XPathContext xctxt)
          throws javax.xml.transform.TransformerException
{
  m_docKey = doc;
  m_keyDeclarations = keyDeclarations;
  KeyIterator ki = new KeyIterator(name, keyDeclarations);

  m_keyNodes = new XNodeSet(ki);
  m_keyNodes.allowDetachToRelease(false);
  m_keyNodes.setRoot(doc, xctxt);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:22,代码来源:KeyTable.java

示例4: LocPathIterator

import org.apache.xml.utils.PrefixResolver; //导入依赖的package包/类
/**
 * Create a LocPathIterator object.
 *
 * @param nscontext The namespace context for this iterator,
 * should be OK if null.
 */
protected LocPathIterator(PrefixResolver nscontext)
{

  setLocPathIterator(this);
  m_prefixResolver = nscontext;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:13,代码来源:LocPathIterator.java

示例5: XPath

import org.apache.xml.utils.PrefixResolver; //导入依赖的package包/类
/**
 * Construct an XPath object.  
 *
 * (Needs review -sc) This method initializes an XPathParser/
 * Compiler and compiles the expression.
 * @param exprString The XPath expression.
 * @param locator The location of the expression, may be null.
 * @param prefixResolver A prefix resolver to use to resolve prefixes to 
 *                       namespace URIs.
 * @param type one of {@link #SELECT} or {@link #MATCH}.
 * @param errorListener The error listener, or null if default should be used.
 *
 * @throws javax.xml.transform.TransformerException if syntax or other error.
 */
public XPath(
        String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type,
        ErrorListener errorListener)
          throws javax.xml.transform.TransformerException
{ 
  initFunctionTable();     
  if(null == errorListener)
    errorListener = new org.apache.xml.utils.DefaultErrorHandler();
  
  m_patternString = exprString;

  XPathParser parser = new XPathParser(errorListener, locator);
  Compiler compiler = new Compiler(errorListener, locator, m_funcTable);

  if (SELECT == type)
    parser.initXPath(compiler, exprString, prefixResolver);
  else if (MATCH == type)
    parser.initMatchPattern(compiler, exprString, prefixResolver);
  else
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE, new Object[]{Integer.toString(type)})); //"Can not deal with XPath type: " + type);

  // System.out.println("----------------");
  Expression expr = compiler.compile(0);

  // System.out.println("expr: "+expr);
  this.setExpression(expr);
  
  if((null != locator) && locator instanceof ExpressionNode)
  {
  	expr.exprSetParent((ExpressionNode)locator);
  }

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

示例6: Lexer

import org.apache.xml.utils.PrefixResolver; //导入依赖的package包/类
/**
 * Create a Lexer object.
 *
 * @param compiler The owning compiler for this lexer.
 * @param resolver The prefix resolver for mapping qualified name prefixes 
 *                 to namespace URIs.
 * @param xpathProcessor The parser that is processing strings to opcodes.
 */
Lexer(Compiler compiler, PrefixResolver resolver,
      XPathParser xpathProcessor)
{

  m_compiler = compiler;
  m_namespaceContext = resolver;
  m_processor = xpathProcessor;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:17,代码来源:Lexer.java

示例7: getXPathExpressionForDocument

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

示例8: eval

import org.apache.xml.utils.PrefixResolver; //导入依赖的package包/类
public XObject eval(Node contextNode, String xpath, PrefixResolver namespaceNode) throws TransformerException {
	checkContextNode(contextNode);
	return xpathApi.eval(contextNode, xpath, namespaceNode);
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:5,代码来源:TwsCachedXPathAPI.java

示例9: getPrefixResolver

import org.apache.xml.utils.PrefixResolver; //导入依赖的package包/类
/**
 * 
 * @param document XML Document
 * @return {@link PrefixResolver}
 */
private static PrefixResolver getPrefixResolver(Document document) {
    PropertiesBasedPrefixResolver propertiesBasedPrefixResolver =
            new PropertiesBasedPrefixResolver(document.getDocumentElement());
    return propertiesBasedPrefixResolver;
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:11,代码来源:XPathUtil.java

示例10: executeFilterExpr

import org.apache.xml.utils.PrefixResolver; //导入依赖的package包/类
/**
 * Execute the expression.  Meant for reuse by other FilterExpr iterators 
 * that are not derived from this object.
 */
public static XNodeSet executeFilterExpr(int context, XPathContext xctxt, 
												PrefixResolver prefixResolver,
												boolean isTopLevel,
												int stackFrame,
												Expression expr )
  throws org.apache.xml.utils.WrappedRuntimeException
{
  PrefixResolver savedResolver = xctxt.getNamespaceContext();
  XNodeSet result = null;

  try
  {
    xctxt.pushCurrentNode(context);
    xctxt.setNamespaceContext(prefixResolver);

    // The setRoot operation can take place with a reset operation, 
    // and so we may not be in the context of LocPathIterator#nextNode, 
    // so we have to set up the variable context, execute the expression, 
    // and then restore the variable context.

    if (isTopLevel)
    {
      // System.out.println("calling m_expr.execute(getXPathContext())");
      VariableStack vars = xctxt.getVarStack();

      // These three statements need to be combined into one operation.
      int savedStart = vars.getStackFrame();
      vars.setStackFrame(stackFrame);

      result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt);
      result.setShouldCacheNodes(true);

      // These two statements need to be combined into one operation.
      vars.setStackFrame(savedStart);
    }
    else
        result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt);

  }
  catch (javax.xml.transform.TransformerException se)
  {

    // TODO: Fix...
    throw new org.apache.xml.utils.WrappedRuntimeException(se);
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.setNamespaceContext(savedResolver);
  }
  return result;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:57,代码来源:FilterExprIteratorSimple.java

示例11: initXPath

import org.apache.xml.utils.PrefixResolver; //导入依赖的package包/类
/**
  * Given an string, init an XPath object for selections,
  * in order that a parse doesn't
  * have to be done each time the expression is evaluated.
  * 
  * @param compiler The compiler object.
  * @param expression A string conforming to the XPath grammar.
  * @param namespaceContext An object that is able to resolve prefixes in
  * the XPath to namespaces.
  *
  * @throws javax.xml.transform.TransformerException
  */
 public void initXPath(
         Compiler compiler, String expression, PrefixResolver namespaceContext)
           throws javax.xml.transform.TransformerException
 {

   m_ops = compiler;
   m_namespaceContext = namespaceContext;
   m_functionTable = compiler.getFunctionTable();

   Lexer lexer = new Lexer(compiler, namespaceContext, this);

   lexer.tokenize(expression);

   m_ops.setOp(0,OpCodes.OP_XPATH);
   m_ops.setOp(OpMap.MAPINDEX_LENGTH,2);
   
   
// Patch for Christine's gripe. She wants her errorHandler to return from
// a fatal error and continue trying to parse, rather than throwing an exception.
// Without the patch, that put us into an endless loop.
//
// %REVIEW% Is there a better way of doing this?
// %REVIEW% Are there any other cases which need the safety net?
// 	(and if so do we care right now, or should we rewrite the XPath
//	grammar engine and can fix it at that time?)
try {

     nextToken();
     Expr();

     if (null != m_token)
     {
       String extraTokens = "";

       while (null != m_token)
       {
         extraTokens += "'" + m_token + "'";

         nextToken();

         if (null != m_token)
           extraTokens += ", ";
       }

       error(XPATHErrorResources.ER_EXTRA_ILLEGAL_TOKENS,
             new Object[]{ extraTokens });  //"Extra illegal tokens: "+extraTokens);
     }

   } 
   catch (org.apache.xpath.XPathProcessorException e)
   {
  if(CONTINUE_AFTER_FATAL_ERROR.equals(e.getMessage()))
  {
	// What I _want_ to do is null out this XPath.
	// I doubt this has the desired effect, but I'm not sure what else to do.
	// %REVIEW%!!!
	initXPath(compiler, "/..",  namespaceContext);
  }
  else
	throw e;
   }

   compiler.shrink();
 }
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:77,代码来源:XPathParser.java

示例12: initMatchPattern

import org.apache.xml.utils.PrefixResolver; //导入依赖的package包/类
/**
 * Given an string, init an XPath object for pattern matches,
 * in order that a parse doesn't
 * have to be done each time the expression is evaluated.
 * @param compiler The XPath object to be initialized.
 * @param expression A String representing the XPath.
 * @param namespaceContext An object that is able to resolve prefixes in
 * the XPath to namespaces.
 *
 * @throws javax.xml.transform.TransformerException
 */
public void initMatchPattern(
        Compiler compiler, String expression, PrefixResolver namespaceContext)
          throws javax.xml.transform.TransformerException
{

  m_ops = compiler;
  m_namespaceContext = namespaceContext;
  m_functionTable = compiler.getFunctionTable();

  Lexer lexer = new Lexer(compiler, namespaceContext, this);

  lexer.tokenize(expression);

  m_ops.setOp(0, OpCodes.OP_MATCHPATTERN);
  m_ops.setOp(OpMap.MAPINDEX_LENGTH, 2);

  nextToken();
  Pattern();

  if (null != m_token)
  {
    String extraTokens = "";

    while (null != m_token)
    {
      extraTokens += "'" + m_token + "'";

      nextToken();

      if (null != m_token)
        extraTokens += ", ";
    }

    error(XPATHErrorResources.ER_EXTRA_ILLEGAL_TOKENS,
          new Object[]{ extraTokens });  //"Extra illegal tokens: "+extraTokens);
  }

  // Terminate for safety.
  m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
  m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH)+1);

  m_ops.shrink();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:55,代码来源:XPathParser.java

示例13: createExpression

import org.apache.xml.utils.PrefixResolver; //导入依赖的package包/类
/**
 * Creates a parsed XPath expression with resolved namespaces. This is
 * useful when an expression will be reused in an application since it makes
 * it possible to compile the expression string into a more efficient
 * internal form and preresolve all namespace prefixes which occur within
 * the expression.
 * 
 * @param expression
 *            The XPath expression string to be parsed.
 * @param resolver
 *            The <code>resolver</code> permits translation of prefixes
 *            within the XPath expression into appropriate namespace URIs .
 *            If this is specified as <code>null</code>, any namespace
 *            prefix within the expression will result in
 *            <code>DOMException</code> being thrown with the code
 *            <code>NAMESPACE_ERR</code>.
 * @return The compiled form of the XPath expression.
 * @exception XPathException
 *                INVALID_EXPRESSION_ERR: Raised if the expression is not
 *                legal according to the rules of the
 *                <code>XPathEvaluator</code>i
 * @exception DOMException
 *                NAMESPACE_ERR: Raised if the expression contains namespace
 *                prefixes which cannot be resolved by the specified
 *                <code>XPathNSResolver</code>.
 * 
 * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String,
 *      XPathNSResolver)
 */
@Override
public XPathExpression createExpression(String expression, XPathNSResolver resolver)
		throws XPathException, DOMException {

	try {

		// If the resolver is null, create a dummy prefix resolver
		XPath xpath = new XPath(expression, null,
				null == resolver ? new DummyPrefixResolver() : (PrefixResolver) resolver, XPath.SELECT);

		return new XPathExpressionImpl(xpath, m_doc);

	} catch (TransformerException e) {
		// Need to pass back exception code DOMException.NAMESPACE_ERR also.
		// Error found in DOM Level 3 XPath Test Suite.
		if (e instanceof XPathStylesheetDOM3Exception) {
			throw new DOMException(DOMException.NAMESPACE_ERR, e.getMessageAndLocation());
		} else {
			throw new XPathException(XPathException.INVALID_EXPRESSION_ERR, e.getMessageAndLocation());
		}

	}
}
 
开发者ID:oswetto,项目名称:LoboEvolution,代码行数:53,代码来源:XPathEvaluatorImpl.java

示例14: DocumentNamespaceContext

import org.apache.xml.utils.PrefixResolver; //导入依赖的package包/类
private DocumentNamespaceContext(PrefixResolver resolver) {
  this.resolver = resolver;
}
 
开发者ID:SonarSource,项目名称:sonar-xml,代码行数:4,代码来源:XPathCheck.java

示例15: createDTMIterator

import org.apache.xml.utils.PrefixResolver; //导入依赖的package包/类
/**
 * NEEDSDOC Method createDTMIterator
 *
 *
 * NEEDSDOC @param xpathString
 * NEEDSDOC @param presolver
 *
 * NEEDSDOC (createDTMIterator) @return
 */
synchronized public DTMIterator createDTMIterator(String xpathString,
                                     PrefixResolver presolver)
{

  /** @todo: implement this org.apache.xml.dtm.DTMManager abstract method */
  return null;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:17,代码来源:DTMManagerDefault.java


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