本文整理汇总了Java中com.sun.org.apache.xml.internal.utils.PrefixResolver类的典型用法代码示例。如果您正苦于以下问题:Java PrefixResolver类的具体用法?Java PrefixResolver怎么用?Java PrefixResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PrefixResolver类属于com.sun.org.apache.xml.internal.utils包,在下文中一共展示了PrefixResolver类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createExpression
import com.sun.org.apache.xml.internal.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)
*/
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());
}
}
示例2: getScriptEngine
import com.sun.org.apache.xml.internal.utils.PrefixResolver; //导入依赖的package包/类
/**
* Used core method for getting {@code ScriptEngine} from {@code
* org.netbeans.modules.templates.ScriptingCreateFromTemplateHandler}.
*/
private static ScriptEngine getScriptEngine() {
if (manager == null) {
synchronized (FileUtil.class) {
if (manager == null) {
ClassLoader loader = Lookup.getDefault().lookup(ClassLoader.class);
try {
loader.loadClass(PrefixResolver.class.getName());
} catch (ClassNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
manager = new ScriptEngineManager(loader != null ? loader : Thread.currentThread().getContextClassLoader());
}
}
}
return manager.getEngineByName((String) "freemarker");
}
示例3: LocPathIterator
import com.sun.org.apache.xml.internal.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;
}
示例4: XPath
import com.sun.org.apache.xml.internal.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 com.sun.org.apache.xml.internal.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);
}
}
示例5: Lexer
import com.sun.org.apache.xml.internal.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;
}
示例6: eval
import com.sun.org.apache.xml.internal.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 com.sun.org.apache.xpath.internal.objects.XObject
* @see com.sun.org.apache.xpath.internal.objects.XNull
* @see com.sun.org.apache.xpath.internal.objects.XBoolean
* @see com.sun.org.apache.xpath.internal.objects.XNumber
* @see com.sun.org.apache.xpath.internal.objects.XString
* @see com.sun.org.apache.xpath.internal.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);
// Execute the XPath, and have it return the result
XPathContext xpathSupport = new XPathContext();
int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
示例7: executeFilterExpr
import com.sun.org.apache.xml.internal.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 com.sun.org.apache.xml.internal.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 = (com.sun.org.apache.xpath.internal.objects.XNodeSet) expr.execute(xctxt);
result.setShouldCacheNodes(true);
// These two statements need to be combined into one operation.
vars.setStackFrame(savedStart);
}
else
result = (com.sun.org.apache.xpath.internal.objects.XNodeSet) expr.execute(xctxt);
}
catch (javax.xml.transform.TransformerException se)
{
// TODO: Fix...
throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(se);
}
finally
{
xctxt.popCurrentNode();
xctxt.setNamespaceContext(savedResolver);
}
return result;
}
示例8: eval
import com.sun.org.apache.xml.internal.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 com.sun.org.apache.xpath.internal.objects.XObject
* @see com.sun.org.apache.xpath.internal.objects.XNull
* @see com.sun.org.apache.xpath.internal.objects.XBoolean
* @see com.sun.org.apache.xpath.internal.objects.XNumber
* @see com.sun.org.apache.xpath.internal.objects.XString
* @see com.sun.org.apache.xpath.internal.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);
// Execute the XPath, and have it return the result
XPathContext xpathSupport = new XPathContext();
int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
示例9: initXPath
import com.sun.org.apache.xml.internal.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 (com.sun.org.apache.xpath.internal.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();
}
示例10: initMatchPattern
import com.sun.org.apache.xml.internal.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();
}