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

The following examples show how to use com.sun.org.apache.xpath.internal.objects.XBoolean. 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: ExsltDatetime.java    From jdk1.8-source-analysis with Apache License 2.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 #2
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 #3
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 #4
Source File: ExsltDatetime.java    From JDKSourceCode1.8 with MIT License 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: FuncLang.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
{

  String lang = m_arg0.execute(xctxt).str();
  int parent = xctxt.getCurrentNode();
  boolean isLang = false;
  DTM dtm = xctxt.getDTM(parent);

  while (DTM.NULL != parent)
  {
    if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
    {
      int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");

      if (DTM.NULL != langAttr)
      {
        String langVal = dtm.getNodeValue(langAttr);
        // %OPT%
        if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
        {
          int valLen = lang.length();

          if ((langVal.length() == valLen)
                  || (langVal.charAt(valLen) == '-'))
          {
            isLang = true;
          }
        }

        break;
      }
    }

    parent = dtm.getParent(parent);
  }

  return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example #6
Source File: Or.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * OR two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (!expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_TRUE;
}
 
Example #7
Source File: FuncExtElementAvailable.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
{

  String prefix;
  String namespace;
  String methName;

  String fullName = m_arg0.execute(xctxt).str();
  int indexOfNSSep = fullName.indexOf(':');

  if (indexOfNSSep < 0)
  {
    prefix = "";
    namespace = Constants.S_XSLNAMESPACEURL;
    methName = fullName;
  }
  else
  {
    prefix = fullName.substring(0, indexOfNSSep);
    namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix);
    if (null == namespace)
      return XBoolean.S_FALSE;
    methName= fullName.substring(indexOfNSSep + 1);
  }

  if (namespace.equals(Constants.S_XSLNAMESPACEURL)
  ||  namespace.equals(Constants.S_BUILTIN_EXTENSIONS_URL)) {

      // J2SE does not support Xalan interpretive
      /*
    try {
      TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
      return transformer.getStylesheet().getAvailableElements().containsKey(
                                                          new QName(namespace, methName))
             ? XBoolean.S_TRUE : XBoolean.S_FALSE;
    } catch (Exception e) {
      return XBoolean.S_FALSE;
    }
    */
      return XBoolean.S_FALSE;
  } else {
    //dml
    ExtensionsProvider extProvider = (ExtensionsProvider)xctxt.getOwnerObject();
    return extProvider.elementAvailable(namespace, methName)
           ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
}
 
Example #8
Source File: And.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * AND two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_FALSE;
}
 
Example #9
Source File: FuncLang.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
{

  String lang = m_arg0.execute(xctxt).str();
  int parent = xctxt.getCurrentNode();
  boolean isLang = false;
  DTM dtm = xctxt.getDTM(parent);

  while (DTM.NULL != parent)
  {
    if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
    {
      int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");

      if (DTM.NULL != langAttr)
      {
        String langVal = dtm.getNodeValue(langAttr);
        // %OPT%
        if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
        {
          int valLen = lang.length();

          if ((langVal.length() == valLen)
                  || (langVal.charAt(valLen) == '-'))
          {
            isLang = true;
          }
        }

        break;
      }
    }

    parent = dtm.getParent(parent);
  }

  return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example #10
Source File: FuncContains.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
{

  String s1 = m_arg0.execute(xctxt).str();
  String s2 = m_arg1.execute(xctxt).str();

  // Add this check for JDK consistency for empty strings.
  if (s1.length() == 0 && s2.length() == 0)
    return XBoolean.S_TRUE;

  int index = s1.indexOf(s2);

  return (index > -1) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example #11
Source File: And.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * AND two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_FALSE;
}
 
Example #12
Source File: Or.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * OR two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (!expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_TRUE;
}
 
Example #13
Source File: Or.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * OR two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (!expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_TRUE;
}
 
Example #14
Source File: And.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * AND two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_FALSE;
}
 
Example #15
Source File: FuncLang.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
{

  String lang = m_arg0.execute(xctxt).str();
  int parent = xctxt.getCurrentNode();
  boolean isLang = false;
  DTM dtm = xctxt.getDTM(parent);

  while (DTM.NULL != parent)
  {
    if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
    {
      int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");

      if (DTM.NULL != langAttr)
      {
        String langVal = dtm.getNodeValue(langAttr);
        // %OPT%
        if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
        {
          int valLen = lang.length();

          if ((langVal.length() == valLen)
                  || (langVal.charAt(valLen) == '-'))
          {
            isLang = true;
          }
        }

        break;
      }
    }

    parent = dtm.getParent(parent);
  }

  return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example #16
Source File: FuncContains.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
{

  String s1 = m_arg0.execute(xctxt).str();
  String s2 = m_arg1.execute(xctxt).str();

  // Add this check for JDK consistency for empty strings.
  if (s1.length() == 0 && s2.length() == 0)
    return XBoolean.S_TRUE;

  int index = s1.indexOf(s2);

  return (index > -1) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example #17
Source File: FuncLang.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
{

  String lang = m_arg0.execute(xctxt).str();
  int parent = xctxt.getCurrentNode();
  boolean isLang = false;
  DTM dtm = xctxt.getDTM(parent);

  while (DTM.NULL != parent)
  {
    if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
    {
      int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");

      if (DTM.NULL != langAttr)
      {
        String langVal = dtm.getNodeValue(langAttr);
        // %OPT%
        if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
        {
          int valLen = lang.length();

          if ((langVal.length() == valLen)
                  || (langVal.charAt(valLen) == '-'))
          {
            isLang = true;
          }
        }

        break;
      }
    }

    parent = dtm.getParent(parent);
  }

  return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example #18
Source File: Or.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * OR two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (!expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_TRUE;
}
 
Example #19
Source File: And.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * AND two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_FALSE;
}
 
Example #20
Source File: And.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * AND two expressions and return the boolean result. Override
 * superclass method for optimization purposes.
 *
 * @param xctxt The runtime execution context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_TRUE} or
 * {@link com.sun.org.apache.xpath.internal.objects.XBoolean#S_FALSE}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject expr1 = m_left.execute(xctxt);

  if (expr1.bool())
  {
    XObject expr2 = m_right.execute(xctxt);

    return expr2.bool() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
  else
    return XBoolean.S_FALSE;
}
 
Example #21
Source File: FuncContains.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
{

  String s1 = m_arg0.execute(xctxt).str();
  String s2 = m_arg1.execute(xctxt).str();

  // Add this check for JDK consistency for empty strings.
  if (s1.length() == 0 && s2.length() == 0)
    return XBoolean.S_TRUE;

  int index = s1.indexOf(s2);

  return (index > -1) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example #22
Source File: FuncContains.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
{

  String s1 = m_arg0.execute(xctxt).str();
  String s2 = m_arg1.execute(xctxt).str();

  // Add this check for JDK consistency for empty strings.
  if (s1.length() == 0 && s2.length() == 0)
    return XBoolean.S_TRUE;

  int index = s1.indexOf(s2);

  return (index > -1) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example #23
Source File: FuncContains.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
{

  String s1 = m_arg0.execute(xctxt).str();
  String s2 = m_arg1.execute(xctxt).str();

  // Add this check for JDK consistency for empty strings.
  if (s1.length() == 0 && s2.length() == 0)
    return XBoolean.S_TRUE;

  int index = s1.indexOf(s2);

  return (index > -1) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example #24
Source File: Extensions.java    From openjdk-jdk8u with GNU General Public License v2.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 = JdkXmlUtils.getDOMDocument();

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

      docFrag.appendChild(textNode);

      return new NodeSet(docFrag);
  }
}
 
Example #25
Source File: Extensions.java    From jdk8u60 with GNU General Public License v2.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 #26
Source File: Extensions.java    From TencentKona-8 with GNU General Public License v2.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 = JdkXmlUtils.getDOMDocument();

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

      docFrag.appendChild(textNode);

      return new NodeSet(docFrag);
  }
}
 
Example #27
Source File: FuncExtElementAvailable.java    From jdk8u60 with GNU General Public License v2.0 4 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
{

  String prefix;
  String namespace;
  String methName;

  String fullName = m_arg0.execute(xctxt).str();
  int indexOfNSSep = fullName.indexOf(':');

  if (indexOfNSSep < 0)
  {
    prefix = "";
    namespace = Constants.S_XSLNAMESPACEURL;
    methName = fullName;
  }
  else
  {
    prefix = fullName.substring(0, indexOfNSSep);
    namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix);
    if (null == namespace)
      return XBoolean.S_FALSE;
    methName= fullName.substring(indexOfNSSep + 1);
  }

  if (namespace.equals(Constants.S_XSLNAMESPACEURL)
  ||  namespace.equals(Constants.S_BUILTIN_EXTENSIONS_URL)) {

      // J2SE does not support Xalan interpretive
      /*
    try {
      TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
      return transformer.getStylesheet().getAvailableElements().containsKey(
                                                          new QName(namespace, methName))
             ? XBoolean.S_TRUE : XBoolean.S_FALSE;
    } catch (Exception e) {
      return XBoolean.S_FALSE;
    }
    */
      return XBoolean.S_FALSE;
  } else {
    //dml
    ExtensionsProvider extProvider = (ExtensionsProvider)xctxt.getOwnerObject();
    return extProvider.elementAvailable(namespace, methName)
           ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
}
 
Example #28
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 #29
Source File: FuncExtElementAvailable.java    From openjdk-jdk8u with GNU General Public License v2.0 4 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
{

  String prefix;
  String namespace;
  String methName;

  String fullName = m_arg0.execute(xctxt).str();
  int indexOfNSSep = fullName.indexOf(':');

  if (indexOfNSSep < 0)
  {
    prefix = "";
    namespace = Constants.S_XSLNAMESPACEURL;
    methName = fullName;
  }
  else
  {
    prefix = fullName.substring(0, indexOfNSSep);
    namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix);
    if (null == namespace)
      return XBoolean.S_FALSE;
    methName= fullName.substring(indexOfNSSep + 1);
  }

  if (namespace.equals(Constants.S_XSLNAMESPACEURL)
  ||  namespace.equals(Constants.S_BUILTIN_EXTENSIONS_URL)) {

      // J2SE does not support Xalan interpretive
      /*
    try {
      TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
      return transformer.getStylesheet().getAvailableElements().containsKey(
                                                          new QName(namespace, methName))
             ? XBoolean.S_TRUE : XBoolean.S_FALSE;
    } catch (Exception e) {
      return XBoolean.S_FALSE;
    }
    */
      return XBoolean.S_FALSE;
  } else {
    //dml
    ExtensionsProvider extProvider = (ExtensionsProvider)xctxt.getOwnerObject();
    return extProvider.elementAvailable(namespace, methName)
           ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
}
 
Example #30
Source File: Gte.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Apply the operation to two operands, and return the result.
 *
 *
 * @param left non-null reference to the evaluated left operand.
 * @param right non-null reference to the evaluated right operand.
 *
 * @return non-null reference to the XObject that represents the result of the operation.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject operate(XObject left, XObject right)
        throws javax.xml.transform.TransformerException
{
  return left.greaterThanOrEqual(right)
         ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}