com.sun.org.apache.xpath.internal.res.XPATHErrorResources Java Examples

The following examples show how to use com.sun.org.apache.xpath.internal.res.XPATHErrorResources. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AxesWalker.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #2
Source File: XPathParser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 *
 *
 * StringExpr  ::=  Expr
 *
 *
 * @throws javax.xml.transform.TransformerException
 */
protected void BooleanExpr() throws javax.xml.transform.TransformerException
{

  int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);

  appendOp(2, OpCodes.OP_BOOL);
  Expr();

  int opLen = m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos;

  if (opLen == 2)
  {
    error(XPATHErrorResources.ER_BOOLEAN_ARG_NO_LONGER_OPTIONAL, null);  //"boolean(...) argument is no longer optional with 19990709 XPath draft.");
  }

  m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH, opLen);
}
 
Example #3
Source File: VariableStack.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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)
        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 val;
}
 
Example #4
Source File: XPathResultImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Returns the <code>index</code>th item in the snapshot collection. If
     * <code>index</code> is greater than or equal to the number of nodes in
     * the list, this method returns <code>null</code>. Unlike the iterator
     * result, the snapshot does not become invalid, but may not correspond
     * to the current document if it is mutated.
     * @param index Index into the snapshot collection.
     * @return The node at the <code>index</code>th position in the
     *   <code>NodeList</code>, or <code>null</code> if that is not a valid
     *   index.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
     *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#snapshotItem(int)
         */
        public Node snapshotItem(int index) throws XPathException {

                if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
                    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
           String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
           throw new XPathException(XPathException.TYPE_ERR, fmsg);
//              "The method snapshotItem cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
//              This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
            }

        Node node = m_list.item(index);

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example #5
Source File: XPathParser.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 *
 * Basis    ::=    AxisName '::' NodeTest
 * | AbbreviatedBasis
 *
 * @return FROM_XXX axes type, found in {@link com.sun.org.apache.xpath.internal.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;
}
 
Example #6
Source File: NodeSetDTM.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  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;
}
 
Example #7
Source File: VariableStack.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * 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)
        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 val;
}
 
Example #8
Source File: NodeSet.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  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;
}
 
Example #9
Source File: NodeSet.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 *  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;
}
 
Example #10
Source File: XPathParser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 *
 * RelativeLocationPath ::= Step
 * | RelativeLocationPath '/' Step
 * | AbbreviatedRelativeLocationPath
 *
 * @returns true if, and only if, a RelativeLocationPath was matched
 *
 * @throws javax.xml.transform.TransformerException
 */
protected boolean RelativeLocationPath()
             throws javax.xml.transform.TransformerException
{
  if (!Step())
  {
    return false;
  }

  while (tokenIs('/'))
  {
    nextToken();

    if (!Step())
    {
      // RelativeLocationPath can't end with a trailing '/'
      // "Location step expected following '/' or '//'"
      error(XPATHErrorResources.ER_EXPECTED_LOC_STEP, null);
    }
  }

  return true;
}
 
Example #11
Source File: XPathImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * <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 {
        com.sun.org.apache.xpath.internal.XPath xpath = new XPath (expression, null,
                prefixResolver, com.sun.org.apache.xpath.internal.XPath.SELECT );
        // Can have errorListener
        XPathExpressionImpl ximpl = new XPathExpressionImpl (xpath,
                prefixResolver, functionResolver, variableResolver,
                featureSecureProcessing, useServiceMechanism, featureManager );
        return ximpl;
    } catch ( javax.xml.transform.TransformerException te ) {
        throw new XPathExpressionException ( te ) ;
    }
}
 
Example #12
Source File: XPathResultImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
     * Returns the <code>index</code>th item in the snapshot collection. If
     * <code>index</code> is greater than or equal to the number of nodes in
     * the list, this method returns <code>null</code>. Unlike the iterator
     * result, the snapshot does not become invalid, but may not correspond
     * to the current document if it is mutated.
     * @param index Index into the snapshot collection.
     * @return The node at the <code>index</code>th position in the
     *   <code>NodeList</code>, or <code>null</code> if that is not a valid
     *   index.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
     *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#snapshotItem(int)
         */
        public Node snapshotItem(int index) throws XPathException {

                if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
                    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
           String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
           throw new XPathException(XPathException.TYPE_ERR, fmsg);
//              "The method snapshotItem cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
//              This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
            }

        Node node = m_list.item(index);

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example #13
Source File: JAXPExtensionsProvider.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
  }


}
 
Example #14
Source File: NodeSet.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Add a node to the NodeSet. Not all types of NodeSets support this
 * operation
 *
 * @param n Node to be added
 * @throws RuntimeException thrown if this NodeSet is not of
 * a mutable type.
 */
public void addNode(Node n)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  this.addElement(n);
}
 
Example #15
Source File: NodeSet.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Remove a node.
 *
 * @param n Node to be added
 * @throws RuntimeException thrown if this NodeSet is not of
 * a mutable type.
 */
public void removeNode(Node n)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  this.removeElement(n);
}
 
Example #16
Source File: OpMap.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Given a location step position, return the end position, i.e. the
 * beginning of the next step.
 *
 * @param opPos the position of a location step.
 * @return the position of the next location step.
 */
public int getNextStepPos(int opPos)
{

  int stepType = getOp(opPos);

  if ((stepType >= OpCodes.AXES_START_TYPES)
          && (stepType <= OpCodes.AXES_END_TYPES))
  {
    return getNextOpPos(opPos);
  }
  else if ((stepType >= OpCodes.FIRST_NODESET_OP)
           && (stepType <= OpCodes.LAST_NODESET_OP))
  {
    int newOpPos = getNextOpPos(opPos);

    while (OpCodes.OP_PREDICATE == getOp(newOpPos))
    {
      newOpPos = getNextOpPos(newOpPos);
    }

    stepType = getOp(newOpPos);

    if (!((stepType >= OpCodes.AXES_START_TYPES)
          && (stepType <= OpCodes.AXES_END_TYPES)))
    {
      return OpCodes.ENDOP;
    }

    return newOpPos;
  }
  else
  {
    throw new RuntimeException(
      XSLMessages.createXPATHMessage(XPATHErrorResources.ER_UNKNOWN_STEP, new Object[]{String.valueOf(stepType)}));
    //"Programmer's assertion in getNextStepPos: unknown stepType: " + stepType);
  }
}
 
Example #17
Source File: NodeSetDTM.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #18
Source File: XPathParser.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Notify 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.
 */
private void assertion(boolean b, String msg)
{

  if (!b)
  {
    String fMsg = XSLMessages.createXPATHMessage(
      XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
      new Object[]{ msg });

    throw new RuntimeException(fMsg);
  }
}
 
Example #19
Source File: XPathImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Establishes a function resolver.</p>
 *
 * @param resolver XPath function resolver
 */
public void setXPathFunctionResolver(XPathFunctionResolver resolver) {
    if ( resolver == null ) {
        String fmsg = XSLMessages.createXPATHMessage(
                XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
                new Object[] {"XPathFunctionResolver"} );
        throw new NullPointerException( fmsg );
    }
    this.functionResolver = resolver;
}
 
Example #20
Source File: NodeSet.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Inserts the specified node in this vector at the specified index.
 * Each component in this vector with an index greater or equal to
 * the specified index is shifted upward to have an index one greater
 * than the value it had previously.
 *
 * @param value Node to insert
 * @param at Position where to insert
 */
public void insertElementAt(Node value, int at)
{
  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  if (null == m_map)
  {
    m_map = new Node[m_blocksize];
    m_mapSize = m_blocksize;
  }
  else if ((m_firstFree + 1) >= m_mapSize)
  {
    m_mapSize += m_blocksize;

    Node newMap[] = new Node[m_mapSize];

    System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);

    m_map = newMap;
  }

  if (at <= (m_firstFree - 1))
  {
    System.arraycopy(m_map, at, m_map, at + 1, m_firstFree - at);
  }

  m_map[at] = value;

  m_firstFree++;
}
 
Example #21
Source File: XStringForFSB.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #22
Source File: NodeSet.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Copy NodeList members into this nodelist, adding in
 * document order.  If a node is null, don't add it.
 *
 * @param iterator NodeIterator which yields the 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(NodeIterator iterator, XPathContext support)
{

  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  Node node;

  while (null != (node = iterator.nextNode()))
  {
    addNodeInDocOrder(node, support);
  }
}
 
Example #23
Source File: XPath.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * 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.
 */
public void assertion(boolean b, String msg)
{

  if (!b)
  {
    String fMsg = XSLMessages.createXPATHMessage(
      XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
      new Object[]{ msg });

    throw new RuntimeException(fMsg);
  }
}
 
Example #24
Source File: Compiler.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * 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.
 */
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);
  }
}
 
Example #25
Source File: FunctionMultiArgs.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs and throws a WrongNumberArgException with the appropriate
 * message for this function object.  This class supports an arbitrary
 * number of arguments, so this method must never be called.
 *
 * @throws WrongNumberArgsException
 */
protected void reportWrongNumberArgs() throws WrongNumberArgsException {
  String fMsg = XSLMessages.createXPATHMessage(
      XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
      new Object[]{ "Programmer's assertion:  the method FunctionMultiArgs.reportWrongNumberArgs() should never be called." });

  throw new RuntimeException(fMsg);
}
 
Example #26
Source File: NodeSet.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Set the current position in the node set.
 * @param i Must be a valid index.
 * @throws RuntimeException thrown if this NodeSet is not of
 * a cached type, and thus doesn't permit indexed access.
 */
public void setCurrentPos(int i)
{

  if (!m_cacheNodes)
    throw new RuntimeException(
      XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!");

  m_next = i;
}
 
Example #27
Source File: NodeSet.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes the first occurrence of the argument from this vector.
 * If the object is found in this vector, each component in the vector
 * with an index greater or equal to the object's index is shifted
 * downward to have an index one smaller than the value it had
 * previously.
 *
 * @param s Node to remove from the list
 *
 * @return True if the node was successfully removed
 */
public boolean removeElement(Node s)
{
  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  if (null == m_map)
    return false;

  for (int i = 0; i < m_firstFree; i++)
  {
    Node node = m_map[i];

    if ((null != node) && node.equals(s))
    {
      if (i < m_firstFree - 1)
        System.arraycopy(m_map, i + 1, m_map, i, m_firstFree - i - 1);

      m_firstFree--;
      m_map[m_firstFree] = null;

      return true;
    }
  }

  return false;
}
 
Example #28
Source File: XPathResultImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
         * The value of this single node result, which may be <code>null</code>.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>ANY_UNORDERED_NODE_TYPE</code> or
     *   <code>FIRST_ORDERED_NODE_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSingleNodeValue()
         */
        public Node getSingleNodeValue() throws XPathException {

                if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
                    (m_resultType != FIRST_ORDERED_NODE_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
//                               This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
            }

                NodeIterator result = null;
                try {
                        result = m_resultObj.nodeset();
                } catch (TransformerException te) {
                        throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
                }

        if (null == result) return null;

        Node node = result.nextNode();

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example #29
Source File: XPathContext.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the ErrorListener where errors and warnings are to be reported.
 *
 * @param listener A non-null ErrorListener reference.
 */
public void setErrorListener(ErrorListener listener) throws IllegalArgumentException
{
  if (listener == null)
    throw new IllegalArgumentException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, null)); //"Null error handler");
  m_errorListener = listener;
}
 
Example #30
Source File: NodeSetDTM.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}