com.sun.org.apache.xpath.internal.objects.XNumber Java Examples

The following examples show how to use com.sun.org.apache.xpath.internal.objects.XNumber. 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: FuncCount.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
   * 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
  {

//    DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());

//    // We should probably make a function on the iterator for this,
//    // as a given implementation could optimize.
//    int i = 0;
//
//    while (DTM.NULL != nl.nextNode())
//    {
//      i++;
//    }
//    nl.detach();
        DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
        int i = nl.getLength();
        nl.detach();

    return new XNumber((double) i);
  }
 
Example #2
Source File: FuncSum.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * 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
{

  DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
  double sum = 0.0;
  int pos;

  while (DTM.NULL != (pos = nodes.nextNode()))
  {
    DTM dtm = nodes.getDTM(pos);
    XMLString s = dtm.getStringValue(pos);

    if (null != s)
      sum += s.toDouble();
  }
  nodes.detach();

  return new XNumber(sum);
}
 
Example #3
Source File: ExsltDatetime.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The date:leap-year function returns true if the year given in a date
 * is a leap year. If no argument is given, then the current local
 * date/time, as returned by date:date-time is used as a default argument.
 * The date/time string specified as the first argument must be a
 * right-truncated string in the format defined as the lexical representation
 * of xs:dateTime in one of the formats defined in
 * <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
 * The permitted formats are as follows:
 *    xs:dateTime (CCYY-MM-DDThh:mm:ss)
 *    xs:date (CCYY-MM-DD)
 *    xs:gYearMonth (CCYY-MM)
 *    xs:gYear (CCYY)
 * If the date/time string is not in one of these formats, then NaN is returned.
 */
public static XObject leapYear(String datetimeIn)
  throws ParseException
{
  String[] edz = getEraDatetimeZone(datetimeIn);
  String datetime = edz[1];
  if (datetime == null)
    return new XNumber(Double.NaN);

  String[] formats = {dt, d, gym, gy};
  double dbl = getNumber(datetime, formats, Calendar.YEAR);
  if (dbl == Double.NaN)
    return new XNumber(Double.NaN);
  int yr = (int)dbl;
  return new XBoolean(yr % 400 == 0 || (yr % 100 != 0 && yr % 4 == 0));
}
 
Example #4
Source File: ExsltDatetime.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The date:leap-year function returns true if the year given in a date
 * is a leap year. If no argument is given, then the current local
 * date/time, as returned by date:date-time is used as a default argument.
 * The date/time string specified as the first argument must be a
 * right-truncated string in the format defined as the lexical representation
 * of xs:dateTime in one of the formats defined in
 * <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
 * The permitted formats are as follows:
 *    xs:dateTime (CCYY-MM-DDThh:mm:ss)
 *    xs:date (CCYY-MM-DD)
 *    xs:gYearMonth (CCYY-MM)
 *    xs:gYear (CCYY)
 * If the date/time string is not in one of these formats, then NaN is returned.
 */
public static XObject leapYear(String datetimeIn)
  throws ParseException
{
  String[] edz = getEraDatetimeZone(datetimeIn);
  String datetime = edz[1];
  if (datetime == null)
    return new XNumber(Double.NaN);

  String[] formats = {dt, d, gym, gy};
  double dbl = getNumber(datetime, formats, Calendar.YEAR);
  if (dbl == Double.NaN)
    return new XNumber(Double.NaN);
  int yr = (int)dbl;
  return new XBoolean(yr % 400 == 0 || (yr % 100 != 0 && yr % 4 == 0));
}
 
Example #5
Source File: FuncCount.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
   * 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
  {

//    DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());

//    // We should probably make a function on the iterator for this,
//    // as a given implementation could optimize.
//    int i = 0;
//
//    while (DTM.NULL != nl.nextNode())
//    {
//      i++;
//    }
//    nl.detach();
        DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
        int i = nl.getLength();
        nl.detach();

    return new XNumber((double) i);
  }
 
Example #6
Source File: FuncCount.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
   * 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
  {

//    DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());

//    // We should probably make a function on the iterator for this,
//    // as a given implementation could optimize.
//    int i = 0;
//
//    while (DTM.NULL != nl.nextNode())
//    {
//      i++;
//    }
//    nl.detach();
        DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
        int i = nl.getLength();
        nl.detach();

    return new XNumber((double) i);
  }
 
Example #7
Source File: FuncCount.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
   * 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
  {

//    DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());

//    // We should probably make a function on the iterator for this,
//    // as a given implementation could optimize.
//    int i = 0;
//
//    while (DTM.NULL != nl.nextNode())
//    {
//      i++;
//    }
//    nl.detach();
        DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
        int i = nl.getLength();
        nl.detach();

    return new XNumber((double) i);
  }
 
Example #8
Source File: FuncSum.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
{

  DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
  double sum = 0.0;
  int pos;

  while (DTM.NULL != (pos = nodes.nextNode()))
  {
    DTM dtm = nodes.getDTM(pos);
    XMLString s = dtm.getStringValue(pos);

    if (null != s)
      sum += s.toDouble();
  }
  nodes.detach();

  return new XNumber(sum);
}
 
Example #9
Source File: XPathParser.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 *
 * Number ::= [0-9]+('.'[0-9]+)? | '.'[0-9]+
 *
 *
 * @throws javax.xml.transform.TransformerException
 */
protected void Number() throws javax.xml.transform.TransformerException
{

  if (null != m_token)
  {

    // Mutate the token to remove the quotes and have the XNumber object
    // already made.
    double num;

    try
    {
      // XPath 1.0 does not support number in exp notation
      if ((m_token.indexOf('e') > -1)||(m_token.indexOf('E') > -1))
              throw new NumberFormatException();
      num = Double.valueOf(m_token).doubleValue();
    }
    catch (NumberFormatException nfe)
    {
      num = 0.0;  // to shut up compiler.

      error(XPATHErrorResources.ER_COULDNOT_BE_FORMATTED_TO_NUMBER,
            new Object[]{ m_token });  //m_token+" could not be formatted to a number!");
    }

    m_ops.m_tokenQueue.setElementAt(new XNumber(num),m_queueMark - 1);
    m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), m_queueMark - 1);
    m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);

    nextToken();
  }
}
 
Example #10
Source File: XPathParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * Number ::= [0-9]+('.'[0-9]+)? | '.'[0-9]+
 *
 *
 * @throws javax.xml.transform.TransformerException
 */
protected void Number() throws javax.xml.transform.TransformerException
{

  if (null != m_token)
  {

    // Mutate the token to remove the quotes and have the XNumber object
    // already made.
    double num;

    try
    {
      // XPath 1.0 does not support number in exp notation
      if ((m_token.indexOf('e') > -1)||(m_token.indexOf('E') > -1))
              throw new NumberFormatException();
      num = Double.valueOf(m_token).doubleValue();
    }
    catch (NumberFormatException nfe)
    {
      num = 0.0;  // to shut up compiler.

      error(XPATHErrorResources.ER_COULDNOT_BE_FORMATTED_TO_NUMBER,
            new Object[]{ m_token });  //m_token+" could not be formatted to a number!");
    }

    m_ops.m_tokenQueue.setElementAt(new XNumber(num),m_queueMark - 1);
    m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), m_queueMark - 1);
    m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);

    nextToken();
  }
}
 
Example #11
Source File: XPathParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * Number ::= [0-9]+('.'[0-9]+)? | '.'[0-9]+
 *
 *
 * @throws javax.xml.transform.TransformerException
 */
protected void Number() throws javax.xml.transform.TransformerException
{

  if (null != m_token)
  {

    // Mutate the token to remove the quotes and have the XNumber object
    // already made.
    double num;

    try
    {
      // XPath 1.0 does not support number in exp notation
      if ((m_token.indexOf('e') > -1)||(m_token.indexOf('E') > -1))
              throw new NumberFormatException();
      num = Double.valueOf(m_token).doubleValue();
    }
    catch (NumberFormatException nfe)
    {
      num = 0.0;  // to shut up compiler.

      error(XPATHErrorResources.ER_COULDNOT_BE_FORMATTED_TO_NUMBER,
            new Object[]{ m_token });  //m_token+" could not be formatted to a number!");
    }

    m_ops.m_tokenQueue.setElementAt(new XNumber(num),m_queueMark - 1);
    m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), m_queueMark - 1);
    m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);

    nextToken();
  }
}
 
Example #12
Source File: XPathParser.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 *
 * Number ::= [0-9]+('.'[0-9]+)? | '.'[0-9]+
 *
 *
 * @throws javax.xml.transform.TransformerException
 */
protected void Number() throws javax.xml.transform.TransformerException
{

  if (null != m_token)
  {

    // Mutate the token to remove the quotes and have the XNumber object
    // already made.
    double num;

    try
    {
      // XPath 1.0 does not support number in exp notation
      if ((m_token.indexOf('e') > -1)||(m_token.indexOf('E') > -1))
              throw new NumberFormatException();
      num = Double.valueOf(m_token).doubleValue();
    }
    catch (NumberFormatException nfe)
    {
      num = 0.0;  // to shut up compiler.

      error(XPATHErrorResources.ER_COULDNOT_BE_FORMATTED_TO_NUMBER,
            new Object[]{ m_token });  //m_token+" could not be formatted to a number!");
    }

    m_ops.m_tokenQueue.setElementAt(new XNumber(num),m_queueMark - 1);
    m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), m_queueMark - 1);
    m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);

    nextToken();
  }
}
 
Example #13
Source File: FunctionPattern.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test a node to see if it matches the given node test.
 *
 * @param xctxt XPath runtime context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt, int context,
                       DTM dtm, int expType)
        throws javax.xml.transform.TransformerException
{

  DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
  XNumber score = SCORE_NONE;

  if (null != nl)
  {
    int n;

    while (DTM.NULL != (n = nl.nextNode()))
    {
      score = (n == context) ? SCORE_OTHER : SCORE_NONE;

      if (score == SCORE_OTHER)
      {
        context = n;

        break;
      }
    }

    nl.detach();
  }

  return score;
}
 
Example #14
Source File: FuncRound.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * 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
{
        final XObject obj = m_arg0.execute(xctxt);
        final double val= obj.num();
        if (val >= -0.5 && val < 0) return new XNumber(-0.0);
        if (val == 0.0) return new XNumber(val);
        return new XNumber(java.lang.Math.floor(val
                                          + 0.5));
}
 
Example #15
Source File: FunctionPattern.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test a node to see if it matches the given node test.
 *
 * @param xctxt XPath runtime context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  int context = xctxt.getCurrentNode();
  DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
  XNumber score = SCORE_NONE;

  if (null != nl)
  {
    int n;

    while (DTM.NULL != (n = nl.nextNode()))
    {
      score = (n == context) ? SCORE_OTHER : SCORE_NONE;

      if (score == SCORE_OTHER)
      {
        context = n;

        break;
      }
    }

    nl.detach();
  }

  return score;
}
 
Example #16
Source File: FuncRound.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * 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
{
        final XObject obj = m_arg0.execute(xctxt);
        final double val= obj.num();
        if (val >= -0.5 && val < 0) return new XNumber(-0.0);
        if (val == 0.0) return new XNumber(val);
        return new XNumber(java.lang.Math.floor(val
                                          + 0.5));
}
 
Example #17
Source File: HasPositionalPredChecker.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Visit a predicate within a location path.  Note that there isn't a
 * proper unique component for predicates, and that the expression will
 * be called also for whatever type Expression is.
 *
 * @param owner The owner of the expression, to which the expression can
 *              be reset if rewriting takes place.
 * @param pred The predicate object.
 * @return true if the sub expressions should be traversed.
 */
public boolean visitPredicate(ExpressionOwner owner, Expression pred)
{
  m_predDepth++;

  if(m_predDepth == 1)
  {
    if((pred instanceof Variable) ||
       (pred instanceof XNumber) ||
       (pred instanceof Div) ||
       (pred instanceof Plus) ||
       (pred instanceof Minus) ||
       (pred instanceof Mod) ||
       (pred instanceof Quo) ||
       (pred instanceof Mult) ||
       (pred instanceof com.sun.org.apache.xpath.internal.operations.Number) ||
       (pred instanceof Function))
        m_hasPositionalPred = true;
    else
      pred.callVisitors(owner, this);
  }

  m_predDepth--;

  // Don't go have the caller go any further down the subtree.
  return false;
}
 
Example #18
Source File: FunctionPattern.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test a node to see if it matches the given node test.
 *
 * @param xctxt XPath runtime context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  int context = xctxt.getCurrentNode();
  DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
  XNumber score = SCORE_NONE;

  if (null != nl)
  {
    int n;

    while (DTM.NULL != (n = nl.nextNode()))
    {
      score = (n == context) ? SCORE_OTHER : SCORE_NONE;

      if (score == SCORE_OTHER)
      {
        context = n;

        break;
      }
    }

    nl.detach();
  }

  return score;
}
 
Example #19
Source File: HasPositionalPredChecker.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Visit a predicate within a location path.  Note that there isn't a
 * proper unique component for predicates, and that the expression will
 * be called also for whatever type Expression is.
 *
 * @param owner The owner of the expression, to which the expression can
 *              be reset if rewriting takes place.
 * @param pred The predicate object.
 * @return true if the sub expressions should be traversed.
 */
public boolean visitPredicate(ExpressionOwner owner, Expression pred)
{
  m_predDepth++;

  if(m_predDepth == 1)
  {
    if((pred instanceof Variable) ||
       (pred instanceof XNumber) ||
       (pred instanceof Div) ||
       (pred instanceof Plus) ||
       (pred instanceof Minus) ||
       (pred instanceof Mod) ||
       (pred instanceof Quo) ||
       (pred instanceof Mult) ||
       (pred instanceof com.sun.org.apache.xpath.internal.operations.Number) ||
       (pred instanceof Function))
        m_hasPositionalPred = true;
    else
      pred.callVisitors(owner, this);
  }

  m_predDepth--;

  // Don't go have the caller go any further down the subtree.
  return false;
}
 
Example #20
Source File: HasPositionalPredChecker.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Visit a predicate within a location path.  Note that there isn't a
 * proper unique component for predicates, and that the expression will
 * be called also for whatever type Expression is.
 *
 * @param owner The owner of the expression, to which the expression can
 *              be reset if rewriting takes place.
 * @param pred The predicate object.
 * @return true if the sub expressions should be traversed.
 */
public boolean visitPredicate(ExpressionOwner owner, Expression pred)
{
  m_predDepth++;

  if(m_predDepth == 1)
  {
    if((pred instanceof Variable) ||
       (pred instanceof XNumber) ||
       (pred instanceof Div) ||
       (pred instanceof Plus) ||
       (pred instanceof Minus) ||
       (pred instanceof Mod) ||
       (pred instanceof Quo) ||
       (pred instanceof Mult) ||
       (pred instanceof com.sun.org.apache.xpath.internal.operations.Number) ||
       (pred instanceof Function))
        m_hasPositionalPred = true;
    else
      pred.callVisitors(owner, this);
  }

  m_predDepth--;

  // Don't go have the caller go any further down the subtree.
  return false;
}
 
Example #21
Source File: FuncRound.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
{
        final XObject obj = m_arg0.execute(xctxt);
        final double val= obj.num();
        if (val >= -0.5 && val < 0) return new XNumber(-0.0);
        if (val == 0.0) return new XNumber(val);
        return new XNumber(java.lang.Math.floor(val
                                          + 0.5));
}
 
Example #22
Source File: FuncRound.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
{
        final XObject obj = m_arg0.execute(xctxt);
        final double val= obj.num();
        if (val >= -0.5 && val < 0) return new XNumber(-0.0);
        if (val == 0.0) return new XNumber(val);
        return new XNumber(java.lang.Math.floor(val
                                          + 0.5));
}
 
Example #23
Source File: FuncRound.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
{
        final XObject obj = m_arg0.execute(xctxt);
        final double val= obj.num();
        if (val >= -0.5 && val < 0) return new XNumber(-0.0);
        if (val == 0.0) return new XNumber(val);
        return new XNumber(java.lang.Math.floor(val
                                          + 0.5));
}
 
Example #24
Source File: FunctionPattern.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Test a node to see if it matches the given node test.
 *
 * @param xctxt XPath runtime context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{

  int context = xctxt.getCurrentNode();
  DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
  XNumber score = SCORE_NONE;

  if (null != nl)
  {
    int n;

    while (DTM.NULL != (n = nl.nextNode()))
    {
      score = (n == context) ? SCORE_OTHER : SCORE_NONE;

      if (score == SCORE_OTHER)
      {
        context = n;

        break;
      }
    }

    nl.detach();
  }

  return score;
}
 
Example #25
Source File: FunctionPattern.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Test a node to see if it matches the given node test.
 *
 * @param xctxt XPath runtime context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt, int context,
                       DTM dtm, int expType)
        throws javax.xml.transform.TransformerException
{

  DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
  XNumber score = SCORE_NONE;

  if (null != nl)
  {
    int n;

    while (DTM.NULL != (n = nl.nextNode()))
    {
      score = (n == context) ? SCORE_OTHER : SCORE_NONE;

      if (score == SCORE_OTHER)
      {
        context = n;

        break;
      }
    }

    nl.detach();
  }

  return score;
}
 
Example #26
Source File: NodeTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set the static score for this node test.
 * @param score Should be one of the SCORE_XXX constants.
 */
public void setStaticScore(XNumber score)
{
  m_score = score;
}
 
Example #27
Source File: NodeTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the static score for this node test.
 * @return Should be one of the SCORE_XXX constants.
 */
public XNumber getStaticScore()
{
  return m_score;
}
 
Example #28
Source File: NodeTest.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Get the static score for this node test.
 * @return Should be one of the SCORE_XXX constants.
 */
public XNumber getStaticScore()
{
  return m_score;
}
 
Example #29
Source File: Extensions.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * This method is an extension that implements as a Xalan extension
 * the node-set function also found in xt and saxon.
 * If the argument is a Result Tree Fragment, then <code>nodeset</code>
 * returns a node-set consisting of a single root node as described in
 * section 11.1 of the XSLT 1.0 Recommendation.  If the argument is a
 * node-set, <code>nodeset</code> returns a node-set.  If the argument
 * is a string, number, or boolean, then <code>nodeset</code> returns
 * a node-set consisting of a single root node with a single text node
 * child that is the result of calling the XPath string() function on the
 * passed parameter.  If the argument is anything else, then a node-set
 * is returned consisting of a single root node with a single text node
 * child that is the result of calling the java <code>toString()</code>
 * method on the passed argument.
 * Most of the
 * actual work here is done in <code>MethodResolver</code> and
 * <code>XRTreeFrag</code>.
 * @param myProcessor Context passed by the extension processor
 * @param rtf Argument in the stylesheet to the nodeset extension function
 *
 * NEEDSDOC ($objectName$) @return
 */
public static NodeSet nodeset(ExpressionContext myProcessor, Object rtf)
{

  String textNodeValue;

  if (rtf instanceof NodeIterator)
  {
    return new NodeSet((NodeIterator) rtf);
  }
  else
  {
    if (rtf instanceof String)
    {
      textNodeValue = (String) rtf;
    }
    else if (rtf instanceof Boolean)
    {
      textNodeValue = new XBoolean(((Boolean) rtf).booleanValue()).str();
    }
    else if (rtf instanceof Double)
    {
      textNodeValue = new XNumber(((Double) rtf).doubleValue()).str();
    }
    else
    {
      textNodeValue = rtf.toString();
    }

    // This no longer will work right since the DTM.
    // Document myDoc = myProcessor.getContextNode().getOwnerDocument();
    Document myDoc = getDocument();

      Text textNode = myDoc.createTextNode(textNodeValue);
      DocumentFragment docFrag = myDoc.createDocumentFragment();

      docFrag.appendChild(textNode);

    return new NodeSet(docFrag);
  }
}
 
Example #30
Source File: NodeTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the static score for this node test.
 * @return Should be one of the SCORE_XXX constants.
 */
public XNumber getStaticScore()
{
  return m_score;
}