下面列出了javax.xml.xpath.XPathFunction#org.apache.xpath.res.XPATHErrorResources 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
*
* Basis ::= AxisName '::' NodeTest
* | AbbreviatedBasis
*
* @return FROM_XXX axes type, found in {@link org.apache.xpath.compiler.Keywords}.
*
* @throws javax.xml.transform.TransformerException
*/
protected int AxisName() throws javax.xml.transform.TransformerException
{
Object val = Keywords.getAxisName(m_token);
if (null == val)
{
error(XPATHErrorResources.ER_ILLEGAL_AXIS_NAME,
new Object[]{ m_token }); //"illegal axis name: "+m_token);
}
int axesType = ((Integer) val).intValue();
appendOp(2, axesType);
return axesType;
}
/**
* Set the root node of the TreeWalker.
* (Not part of the DOM2 TreeWalker interface).
*
* @param root The context node of this step.
*/
public void setRoot(int root)
{
// %OPT% Get this directly from the lpi.
XPathContext xctxt = wi().getXPathContext();
m_dtm = xctxt.getDTM(root);
m_traverser = m_dtm.getAxisTraverser(m_axis);
m_isFresh = true;
m_foundLast = false;
m_root = root;
m_currentNode = root;
if (DTM.NULL == root)
{
throw new RuntimeException(
XSLMessages.createXPATHMessage(XPATHErrorResources.ER_SETTING_WALKER_ROOT_TO_NULL, null)); //"\n !!!! Error! Setting the root of a walker to null!!!");
}
resetProximityPositions();
}
/**
* Returns the previous node in the set and moves the position of the
* iterator backwards in the set.
* @return The previous <code>Node</code> in the set being iterated over,
* or<code>DTM.NULL</code> if there are no more members in that set.
* @throws DOMException
* INVALID_STATE_ERR: Raised if this method is called after the
* <code>detach</code> method was invoked.
* @throws RuntimeException thrown if this NodeSetDTM is not of
* a cached type, and hence doesn't know what the previous node was.
*/
public int previousNode()
{
if (!m_cacheNodes)
throw new RuntimeException(
XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_ITERATE, null)); //"This NodeSetDTM can not iterate to a previous node!");
if ((m_next - 1) > 0)
{
m_next--;
return this.elementAt(m_next);
}
else
return DTM.NULL;
}
/**
* Returns the previous node in the set and moves the position of the
* iterator backwards in the set.
* @return The previous <code>Node</code> in the set being iterated over,
* or<code>null</code> if there are no more members in that set.
* @throws DOMException
* INVALID_STATE_ERR: Raised if this method is called after the
* <code>detach</code> method was invoked.
* @throws RuntimeException thrown if this NodeSet is not of
* a cached type, and hence doesn't know what the previous node was.
*/
public Node previousNode() throws DOMException
{
if (!m_cacheNodes)
throw new RuntimeException(
XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_ITERATE, null)); //"This NodeSet can not iterate to a previous node!");
if ((m_next - 1) > 0)
{
m_next--;
return this.elementAt(m_next);
}
else
return null;
}
/**
* Copy NodeList members into this nodelist, adding in
* document order. If a node is null, don't add it.
*
* @param nodelist List of nodes which should now be referenced by
* this NodeSet.
* @throws RuntimeException thrown if this NodeSet is not of
* a mutable type.
*/
public void addNodes(NodeList nodelist)
{
if (!m_mutable)
throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
if (null != nodelist) // defensive to fix a bug that Sanjiva reported.
{
int nChildren = nodelist.getLength();
for (int i = 0; i < nChildren; i++)
{
Node obj = nodelist.item(i);
if (null != obj)
{
addElement(obj);
}
}
}
// checkDups();
}
/**
* Copy NodeList members into this nodelist, adding in
* document order. Null references are not added.
*
* @param iterator NodeIterator which yields the nodes to be added.
* @throws RuntimeException thrown if this NodeSet is not of
* a mutable type.
*/
public void addNodes(NodeIterator iterator)
{
if (!m_mutable)
throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
if (null != iterator) // defensive to fix a bug that Sanjiva reported.
{
Node obj;
while (null != (obj = iterator.nextNode()))
{
addElement(obj);
}
}
// checkDups();
}
/**
* Copy NodeList members into this nodelist, adding in
* document order. If a node is null, don't add it.
*
* @param nodelist List of nodes to be added
* @param support The XPath runtime context.
* @throws RuntimeException thrown if this NodeSet is not of
* a mutable type.
*/
public void addNodesInDocOrder(NodeList nodelist, XPathContext support)
{
if (!m_mutable)
throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
int nChildren = nodelist.getLength();
for (int i = 0; i < nChildren; i++)
{
Node node = nodelist.item(i);
if (null != node)
{
addNodeInDocOrder(node, support);
}
}
}
/**
* Tell the user of an assertion error, and probably throw an
* exception.
*
* @param b If false, a TransformerException will be thrown.
* @param msg The assertion message, which should be informative.
*
* @throws javax.xml.transform.TransformerException if b is false.
*/
private void assertion(boolean b, String msg) throws javax.xml.transform.TransformerException
{
if (!b)
{
ErrorListener errorHandler = getErrorListener();
if (errorHandler != null)
{
errorHandler.fatalError(
new TransformerException(
XSLMessages.createMessage(
XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
new Object[]{ msg }), (SAXSourceLocator)this.getSAXLocator()));
}
}
}
/**
* Is the extension function available?
*/
public boolean functionAvailable(String ns, String funcName)
throws javax.xml.transform.TransformerException {
try {
if ( funcName == null ) {
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
new Object[] {"Function Name"} );
throw new NullPointerException ( fmsg );
}
//Find the XPathFunction corresponding to namespace and funcName
javax.xml.namespace.QName myQName = new QName( ns, funcName );
javax.xml.xpath.XPathFunction xpathFunction =
resolver.resolveFunction ( myQName, 0 );
if ( xpathFunction == null ) {
return false;
}
return true;
} catch ( Exception e ) {
return false;
}
}
/**
* <p>Compile an XPath expression for later evaluation.</p>
*
* <p>If <code>expression</code> contains any {@link XPathFunction}s,
* they must be available via the {@link XPathFunctionResolver}.
* An {@link XPathExpressionException} will be thrown if the <code>XPathFunction</code>
* cannot be resovled with the <code>XPathFunctionResolver</code>.</p>
*
* <p>If <code>expression</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.</p>
*
* @param expression The XPath expression.
*
* @return Compiled XPath expression.
* @throws XPathExpressionException If <code>expression</code> cannot be compiled.
* @throws NullPointerException If <code>expression</code> is <code>null</code>.
*/
public XPathExpression compile(String expression)
throws XPathExpressionException {
if ( expression == null ) {
String fmsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
new Object[] {"XPath expression"} );
throw new NullPointerException ( fmsg );
}
try {
org.apache.xpath.XPath xpath = new XPath (expression, null,
prefixResolver, org.apache.xpath.XPath.SELECT );
// Can have errorListener
XPathExpressionImpl ximpl = new XPathExpressionImpl (xpath,
prefixResolver, functionResolver, variableResolver,
featureSecureProcessing );
return ximpl;
} catch ( javax.xml.transform.TransformerException te ) {
throw new XPathExpressionException ( te ) ;
}
}
/**
* Get a local variable or parameter in the current stack frame.
*
*
* @param xctxt The XPath context, which must be passed in order to
* lazy evaluate variables.
*
* @param index Local variable index relative to the current stack
* frame bottom.
*
* @return The value of the variable.
*
* @throws TransformerException
*/
public XObject getLocalVariable(XPathContext xctxt, int index, boolean destructiveOK)
throws TransformerException
{
index += _currentFrameBottom;
XObject val = _stackFrames[index];
if(null == val)
throw new TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VARIABLE_ACCESSED_BEFORE_BIND, null),
xctxt.getSAXLocator());
// "Variable accessed before it is bound!", xctxt.getSAXLocator());
// Lazy execution of variables.
if (val.getType() == XObject.CLASS_UNRESOLVEDVARIABLE)
return (_stackFrames[index] = val.execute(xctxt));
return destructiveOK ? val : val.getFresh();
}
/**
* Cast result object to a number. Always issues an error.
*
* @return 0.0
*
* @throws javax.xml.transform.TransformerException
*/
public double num() throws javax.xml.transform.TransformerException
{
error(XPATHErrorResources.ER_CANT_CONVERT_TO_NUMBER,
new Object[]{ getTypeString() }); //"Can not convert "+getTypeString()+" to a number");
return 0.0;
}
/**
* Cast result object to a boolean. Always issues an error.
*
* @return false
*
* @throws javax.xml.transform.TransformerException
*/
public boolean bool() throws javax.xml.transform.TransformerException
{
error(XPATHErrorResources.ER_CANT_CONVERT_TO_NUMBER,
new Object[]{ getTypeString() }); //"Can not convert "+getTypeString()+" to a number");
return false;
}
/**
* Cast result object to a nodelist. Always issues an error.
*
* @return null
*
* @throws javax.xml.transform.TransformerException
*/
public DTMIterator iter() throws javax.xml.transform.TransformerException
{
error(XPATHErrorResources.ER_CANT_CONVERT_TO_NODELIST,
new Object[]{ getTypeString() }); //"Can not convert "+getTypeString()+" to a NodeList!");
return null;
}
/**
* Cast result object to a nodelist. Always issues an error.
*
* @return null
*
* @throws javax.xml.transform.TransformerException
*/
public NodeIterator nodeset() throws javax.xml.transform.TransformerException
{
error(XPATHErrorResources.ER_CANT_CONVERT_TO_NODELIST,
new Object[]{ getTypeString() }); //"Can not convert "+getTypeString()+" to a NodeList!");
return null;
}
/**
* Cast result object to a nodelist. Always issues an error.
*
* @return null
*
* @throws javax.xml.transform.TransformerException
*/
public NodeList nodelist() throws javax.xml.transform.TransformerException
{
error(XPATHErrorResources.ER_CANT_CONVERT_TO_NODELIST,
new Object[]{ getTypeString() }); //"Can not convert "+getTypeString()+" to a NodeList!");
return null;
}
/**
* Cast result object to a nodelist. Always issues an error.
*
* @return The object as a NodeSetDTM.
*
* @throws javax.xml.transform.TransformerException
*/
public NodeSetDTM mutableNodeset()
throws javax.xml.transform.TransformerException
{
error(XPATHErrorResources.ER_CANT_CONVERT_TO_MUTABLENODELIST,
new Object[]{ getTypeString() }); //"Can not convert "+getTypeString()+" to a NodeSetDTM!");
return (NodeSetDTM) m_obj;
}
/**
* Construct a XNodeSet object.
*
* @param val FastStringBuffer object this will wrap, must be non-null.
* @param start The start position in the array.
* @param length The number of characters to read from the array.
*/
public XStringForChars(char[] val, int start, int length)
{
super(val);
m_start = start;
m_length = length;
if(null == val)
throw new IllegalArgumentException(
XSLMessages.createXPATHMessage(XPATHErrorResources.ER_FASTSTRINGBUFFER_CANNOT_BE_NULL, null)); //"The FastStringBuffer argument can not be null!!");
}
/**
* Construct a XNodeSet object.
*
* @param val String object this will wrap.
*/
private XStringForChars(String val)
{
super(val);
throw new IllegalArgumentException(
XSLMessages.createXPATHMessage(XPATHErrorResources.ER_XSTRINGFORCHARS_CANNOT_TAKE_STRING, null)); //"XStringForChars can not take a string for an argument!");
}
/**
* Construct a XNodeSet object.
*
* @param val FastStringBuffer object this will wrap, must be non-null.
* @param start The start position in the array.
* @param length The number of characters to read from the array.
*/
public XStringForFSB(FastStringBuffer val, int start, int length)
{
super(val);
m_start = start;
m_length = length;
if (null == val)
throw new IllegalArgumentException(
XSLMessages.createXPATHMessage(XPATHErrorResources.ER_FASTSTRINGBUFFER_CANNOT_BE_NULL, null));
}
/**
* Construct a XNodeSet object.
*
* @param val String object this will wrap.
*/
private XStringForFSB(String val)
{
super(val);
throw new IllegalArgumentException(
XSLMessages.createXPATHMessage(XPATHErrorResources.ER_FSB_CANNOT_TAKE_STRING, null)); // "XStringForFSB can not take a string for an argument!");
}
/**
* Cast result object to a number.
*
* @return The result tree fragment as a number or NaN
*/
public double num()
throws javax.xml.transform.TransformerException
{
throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NUM_NOT_SUPPORTED_XRTREEFRAGSELECTWRAPPER, null)); //"num() not supported by XRTreeFragSelectWrapper!");
}
/**
* This function is used to fixup variables from QNames to stack frame
* indexes at stylesheet build time.
* @param vars List of QNames that correspond to variables. This list
* should be searched backwards for the first qualified name that
* corresponds to the variable reference qname. The position of the
* QName in the vector from the start of the vector will be its position
* in the stack frame (but variables above the globalsTop value will need
* to be offset to the current stack frame).
*/
public void fixupVariables(java.util.Vector vars, int globalsSize)
{
m_fixUpWasCalled = true;
int sz = vars.size();
for (int i = vars.size()-1; i >= 0; i--)
{
QName qn = (QName)vars.elementAt(i);
// System.out.println("qn: "+qn);
if(qn.equals(m_qname))
{
if(i < globalsSize)
{
m_isGlobal = true;
m_index = i;
}
else
{
m_index = i-globalsSize;
}
return;
}
}
java.lang.String msg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_COULD_NOT_FIND_VAR,
new Object[]{m_qname.toString()});
TransformerException te = new TransformerException(msg, this);
throw new org.apache.xml.utils.WrappedRuntimeException(te);
}
/**
* Tell the user of an assertion error, and probably throw an
* exception.
*
* @param b If false, a runtime exception will be thrown.
* @param msg The assertion message, which should be informative.
*
* @throws RuntimeException if the b argument is false.
*
* @throws javax.xml.transform.TransformerException
*/
public void assertion(boolean b, java.lang.String msg)
{
if (!b)
{
java.lang.String fMsg = XSLMessages.createXPATHMessage(
XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
new Object[]{ msg });
throw new RuntimeException(fMsg);
}
}
/**
* If an index is requested, NodeSetDTM will call this method
* to run the iterator to the index. By default this sets
* m_next to the index. If the index argument is -1, this
* signals that the iterator should be run to the end.
*
* @param index Position to advance (or retreat) to, with
* 0 requesting the reset ("fresh") position and -1 (or indeed
* any out-of-bounds value) requesting the final position.
* @throws RuntimeException thrown if this NodeSetDTM is not
* one of the types which supports indexing/counting.
*/
public void runTo(int index)
{
if (!m_cacheNodes)
throw new RuntimeException(
XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_INDEX, null)); //"This NodeSetDTM can not do indexing or counting functions!");
if ((index >= 0) && (m_next < m_firstFree))
m_next = index;
else
m_next = m_firstFree - 1;
}
/**
* Given an FROM_stepType position, return the position of the
* first predicate, if there is one, or else this will point
* to the end of the FROM_stepType.
* Example:
* int posOfPredicate = xpath.getNextOpPos(stepPos);
* boolean hasPredicates =
* OpCodes.OP_PREDICATE == xpath.getOp(posOfPredicate);
*
* @param opPos position of FROM_stepType op.
* @return position of predicate in FROM_stepType structure.
*/
public int getFirstPredicateOpPos(int opPos)
throws javax.xml.transform.TransformerException
{
int stepType = m_opMap.elementAt(opPos);
if ((stepType >= OpCodes.AXES_START_TYPES)
&& (stepType <= OpCodes.AXES_END_TYPES))
{
return opPos + m_opMap.elementAt(opPos + 2);
}
else if ((stepType >= OpCodes.FIRST_NODESET_OP)
&& (stepType <= OpCodes.LAST_NODESET_OP))
{
return opPos + m_opMap.elementAt(opPos + 1);
}
else if(-2 == stepType)
{
return -2;
}
else
{
error(org.apache.xpath.res.XPATHErrorResources.ER_UNKNOWN_OPCODE,
new Object[]{ String.valueOf(stepType) }); //"ERROR! Unknown op code: "+m_opMap[opPos]);
return -1;
}
}
/**
* Remove a node.
*
* @param n Node to be added
* @throws RuntimeException thrown if this NodeSetDTM is not of
* a mutable type.
*/
public void removeNode(int n)
{
if (!m_mutable)
throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!");
this.removeElement(n);
}
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt)
throws javax.xml.transform.TransformerException
{
if (xctxt.isSecureProcessing())
throw new javax.xml.transform.TransformerException(
XPATHMessages.createXPATHMessage(
XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED,
new Object[] {toString()}));
XObject result;
Vector argVec = new Vector();
int nArgs = m_argVec.size();
for (int i = 0; i < nArgs; i++)
{
Expression arg = (Expression) m_argVec.elementAt(i);
XObject xobj = arg.execute(xctxt);
/*
* Should cache the arguments for func:function
*/
xobj.allowDetachToRelease(false);
argVec.addElement(xobj);
}
//dml
ExtensionsProvider extProvider = (ExtensionsProvider)xctxt.getOwnerObject();
Object val = extProvider.extFunction(this, argVec);
if (null != val)
{
result = XObject.create(val, xctxt);
}
else
{
result = new XNull();
}
return result;
}
/**
* Copy NodeList members into this nodelist, adding in
* document order. If a node is null, don't add it.
*
* @param iterator DTMIterator which yields the nodes to be added.
* @param support The XPath runtime context.
* @throws RuntimeException thrown if this NodeSetDTM is not of
* a mutable type.
*/
public void addNodesInDocOrder(DTMIterator iterator, XPathContext support)
{
if (!m_mutable)
throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!");
int node;
while (DTM.NULL != (node = iterator.nextNode()))
{
addNodeInDocOrder(node, support);
}
}
/**
* Append a Node onto the vector.
*
* @param value The node to be added.
* @throws RuntimeException thrown if this NodeSetDTM is not of
* a mutable type.
*/
public void addElement(int value)
{
if (!m_mutable)
throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_NOT_MUTABLE, null)); //"This NodeSetDTM is not mutable!");
super.addElement(value);
}