com.sun.org.apache.xalan.internal.extensions.ExpressionContext Java Examples

The following examples show how to use com.sun.org.apache.xalan.internal.extensions.ExpressionContext. 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: ExsltDynamic.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #2
Source File: ExsltDynamic.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #3
Source File: ExsltDynamic.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #4
Source File: ExsltDynamic.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #5
Source File: ExsltDynamic.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #6
Source File: ExsltDynamic.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #7
Source File: ExsltDynamic.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #8
Source File: ExsltDynamic.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #9
Source File: NodeInfo.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * <code>publicId</code> returns the public identifier of the current
 * context node.
 *
 * Xalan does not currently record this value, and will return null.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String publicId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getPublicId();
  else
    return null;
}
 
Example #10
Source File: NodeInfo.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * <code>publicId</code> returns the public identifier of the current
 * context node.
 *
 * Xalan does not currently record this value, and will return null.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String publicId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getPublicId();
  else
    return null;
}
 
Example #11
Source File: NodeInfo.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <code>systemId</code> returns the system id of the current
 * context node.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String systemId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getSystemId();
  else
    return null;
}
 
Example #12
Source File: NodeInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <code>systemId</code> returns the system id of the current
 * context node.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String systemId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getSystemId();
  else
    return null;
}
 
Example #13
Source File: Extensions.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Return a Node of basic debugging information from the
 * EnvironmentCheck utility about the Java environment.
 *
 * <p>Simply calls the {@link com.sun.org.apache.xalan.internal.xslt.EnvironmentCheck}
 * utility to grab info about the Java environment and CLASSPATH,
 * etc., and then returns the resulting Node.  Stylesheets can
 * then maniuplate this data or simply xsl:copy-of the Node.  Note
 * that we first attempt to load the more advanced
 * org.apache.env.Which utility by reflection; only if that fails
 * to we still use the internal version.  Which is available from
 * <a href="http://xml.apache.org/commons/">http://xml.apache.org/commons/</a>.</p>
 *
 * <p>We throw a WrappedRuntimeException in the unlikely case
 * that reading information from the environment throws us an
 * exception. (Is this really the best thing to do?)</p>
 *
 * @param myContext an <code>ExpressionContext</code> passed in by the
 *                  extension mechanism.  This must be an XPathContext.
 * @return a Node as described above.
 */
public static Node checkEnvironment(ExpressionContext myContext)
{

  Document factoryDocument = getDocument();

  Node resultNode = null;
  try
  {
    // First use reflection to try to load Which, which is a
    //  better version of EnvironmentCheck
    resultNode = checkEnvironmentUsingWhich(myContext, factoryDocument);

    if (null != resultNode)
      return resultNode;

    // If reflection failed, fallback to our internal EnvironmentCheck
    EnvironmentCheck envChecker = new EnvironmentCheck();
    Map<String, Object> h = envChecker.getEnvironmentHash();
    resultNode = factoryDocument.createElement("checkEnvironmentExtension");
    envChecker.appendEnvironmentReport(resultNode, factoryDocument, h);
    envChecker = null;
  }
  catch(Exception e)
  {
    throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(e);
  }

  return resultNode;
}
 
Example #14
Source File: Extensions.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Private worker method to attempt to use org.apache.env.Which.
 *
 * @param myContext an <code>ExpressionContext</code> passed in by the
 *                  extension mechanism.  This must be an XPathContext.
 * @param factoryDocument providing createElement services, etc.
 * @return a Node with environment info; null if any error
 */
private static Node checkEnvironmentUsingWhich(ExpressionContext myContext,
      Document factoryDocument)
{
  final String WHICH_CLASSNAME = "org.apache.env.Which";
  final String WHICH_METHODNAME = "which";
  final Class WHICH_METHOD_ARGS[] = { java.util.Hashtable.class,
                                      java.lang.String.class,
                                      java.lang.String.class };
  try
  {
    // Use reflection to try to find xml-commons utility 'Which'
    Class clazz = ObjectFactory.findProviderClass(WHICH_CLASSNAME, true);
    if (null == clazz)
      return null;

    // Fully qualify names since this is the only method they're used in
    java.lang.reflect.Method method = clazz.getMethod(WHICH_METHODNAME, WHICH_METHOD_ARGS);
    Hashtable report = new Hashtable();

    // Call the method with our Hashtable, common options, and ignore return value
    Object[] methodArgs = { report, "XmlCommons;Xalan;Xerces;Crimson;Ant", "" };
    Object returnValue = method.invoke(null, methodArgs);

    // Create a parent to hold the report and append hash to it
    Node resultNode = factoryDocument.createElement("checkEnvironmentExtension");
    com.sun.org.apache.xml.internal.utils.Hashtree2Node.appendHashToNode(report, "whichReport",
          resultNode, factoryDocument);

    return resultNode;
  }
  catch (Throwable t)
  {
    // Simply return null; no need to report error
    return null;
  }
}
 
Example #15
Source File: NodeInfo.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * <code>systemId</code> returns the system id of the current
 * context node.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String systemId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getSystemId();
  else
    return null;
}
 
Example #16
Source File: NodeInfo.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * <code>publicId</code> returns the public identifier of the current
 * context node.
 *
 * Xalan does not currently record this value, and will return null.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String publicId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getPublicId();
  else
    return null;
}
 
Example #17
Source File: NodeInfo.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * <code>systemId</code> returns the system id of the current
 * context node.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String systemId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getSystemId();
  else
    return null;
}
 
Example #18
Source File: NodeInfo.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <code>publicId</code> returns the public identifier of the current
 * context node.
 *
 * Xalan does not currently record this value, and will return null.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String publicId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getPublicId();
  else
    return null;
}
 
Example #19
Source File: Extensions.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a Node of basic debugging information from the
 * EnvironmentCheck utility about the Java environment.
 *
 * <p>Simply calls the {@link com.sun.org.apache.xalan.internal.xslt.EnvironmentCheck}
 * utility to grab info about the Java environment and CLASSPATH,
 * etc., and then returns the resulting Node.  Stylesheets can
 * then maniuplate this data or simply xsl:copy-of the Node.  Note
 * that we first attempt to load the more advanced
 * org.apache.env.Which utility by reflection; only if that fails
 * to we still use the internal version.  Which is available from
 * <a href="http://xml.apache.org/commons/">http://xml.apache.org/commons/</a>.</p>
 *
 * <p>We throw a WrappedRuntimeException in the unlikely case
 * that reading information from the environment throws us an
 * exception. (Is this really the best thing to do?)</p>
 *
 * @param myContext an <code>ExpressionContext</code> passed in by the
 *                  extension mechanism.  This must be an XPathContext.
 * @return a Node as described above.
 */
public static Node checkEnvironment(ExpressionContext myContext)
{

  Document factoryDocument = getDocument();

  Node resultNode = null;
  try
  {
    // First use reflection to try to load Which, which is a
    //  better version of EnvironmentCheck
    resultNode = checkEnvironmentUsingWhich(myContext, factoryDocument);

    if (null != resultNode)
      return resultNode;

    // If reflection failed, fallback to our internal EnvironmentCheck
    EnvironmentCheck envChecker = new EnvironmentCheck();
    Hashtable h = envChecker.getEnvironmentHash();
    resultNode = factoryDocument.createElement("checkEnvironmentExtension");
    envChecker.appendEnvironmentReport(resultNode, factoryDocument, h);
    envChecker = null;
  }
  catch(Exception e)
  {
    throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(e);
  }

  return resultNode;
}
 
Example #20
Source File: Extensions.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Private worker method to attempt to use org.apache.env.Which.
 *
 * @param myContext an <code>ExpressionContext</code> passed in by the
 *                  extension mechanism.  This must be an XPathContext.
 * @param factoryDocument providing createElement services, etc.
 * @return a Node with environment info; null if any error
 */
private static Node checkEnvironmentUsingWhich(ExpressionContext myContext,
      Document factoryDocument)
{
  final String WHICH_CLASSNAME = "org.apache.env.Which";
  final String WHICH_METHODNAME = "which";
  final Class WHICH_METHOD_ARGS[] = { java.util.Hashtable.class,
                                      java.lang.String.class,
                                      java.lang.String.class };
  try
  {
    // Use reflection to try to find xml-commons utility 'Which'
    Class clazz = ObjectFactory.findProviderClass(WHICH_CLASSNAME, true);
    if (null == clazz)
      return null;

    // Fully qualify names since this is the only method they're used in
    java.lang.reflect.Method method = clazz.getMethod(WHICH_METHODNAME, WHICH_METHOD_ARGS);
    Hashtable report = new Hashtable();

    // Call the method with our Hashtable, common options, and ignore return value
    Object[] methodArgs = { report, "XmlCommons;Xalan;Xerces;Crimson;Ant", "" };
    Object returnValue = method.invoke(null, methodArgs);

    // Create a parent to hold the report and append hash to it
    Node resultNode = factoryDocument.createElement("checkEnvironmentExtension");
    com.sun.org.apache.xml.internal.utils.Hashtree2Node.appendHashToNode(report, "whichReport",
          resultNode, factoryDocument);

    return resultNode;
  }
  catch (Throwable t)
  {
    // Simply return null; no need to report error
    return null;
  }
}
 
Example #21
Source File: NodeInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <code>systemId</code> returns the system id of the current
 * context node.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String systemId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getSystemId();
  else
    return null;
}
 
Example #22
Source File: NodeInfo.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <code>publicId</code> returns the public identifier of the current
 * context node.
 *
 * Xalan does not currently record this value, and will return null.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String publicId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getPublicId();
  else
    return null;
}
 
Example #23
Source File: NodeInfo.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <code>systemId</code> returns the system id of the current
 * context node.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String systemId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getSystemId();
  else
    return null;
}
 
Example #24
Source File: NodeInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <code>publicId</code> returns the public identifier of the current
 * context node.
 *
 * Xalan does not currently record this value, and will return null.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String publicId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getPublicId();
  else
    return null;
}
 
Example #25
Source File: NodeInfo.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <code>publicId</code> returns the public identifier of the current
 * context node.
 *
 * Xalan does not currently record this value, and will return null.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String publicId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getPublicId();
  else
    return null;
}
 
Example #26
Source File: NodeInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <code>publicId</code> returns the public identifier of the current
 * context node.
 *
 * Xalan does not currently record this value, and will return null.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String publicId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getPublicId();
  else
    return null;
}
 
Example #27
Source File: NodeInfo.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * <code>systemId</code> returns the system id of the current
 * context node.
 *
 * @param context an <code>ExpressionContext</code> value
 * @return a <code>String</code> value
 */
public static String systemId(ExpressionContext context)
{
  Node contextNode = context.getContextNode();
  int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
  SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
    .getSourceLocatorFor(nodeHandler);

  if (locator != null)
    return locator.getSystemId();
  else
    return null;
}
 
Example #28
Source File: ExsltDynamic.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * The dyn:max function calculates the maximum value for the nodes passed as
 * the first argument, where the value of each node is calculated dynamically
 * using an XPath expression passed as a string as the second argument.
 * <p>
 * The expressions are evaluated relative to the nodes passed as the first argument.
 * In other words, the value for each node is calculated by evaluating the XPath
 * expression with all context information being the same as that for the call to
 * the dyn:max function itself, except for the following:
 * <p>
 * <ul>
 *  <li>the context node is the node whose value is being calculated.</li>
 *  <li>the context position is the position of the node within the node set passed as
 *   the first argument to the dyn:max function, arranged in document order.</li>
 *  <li>the context size is the number of nodes passed as the first argument to the
 *   dyn:max function.</li>
 * </ul>
 * <p>
 * The dyn:max function returns the maximum of these values, calculated in exactly
 * the same way as for math:max.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns NaN.
 * <p>
 * This function must take a second argument. To calculate the maximum of a set of
 * nodes based on their string values, you should use the math:max function.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param nl The node set
 * @param expr The expression string
 *
 * @return The maximum evaluation value
 */
public static double max(ExpressionContext myContext, NodeList nl, String expr)
  throws SAXNotSupportedException
{

  XPathContext xctxt = null;
  if (myContext instanceof XPathContext.XPathExpressionContext)
    xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext }));

  if (expr == null || expr.length() == 0)
    return Double.NaN;

  NodeSetDTM contextNodes = new NodeSetDTM(nl, xctxt);
  xctxt.pushContextNodeList(contextNodes);

  double maxValue = - Double.MAX_VALUE;
  for (int i = 0; i < contextNodes.getLength(); i++)
  {
    int contextNode = contextNodes.item(i);
    xctxt.pushCurrentNode(contextNode);

    double result = 0;
    try
    {
      XPath dynamicXPath = new XPath(expr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);
      result = dynamicXPath.execute(xctxt, contextNode, xctxt.getNamespaceContext()).num();
    }
    catch (TransformerException e)
    {
      xctxt.popCurrentNode();
      xctxt.popContextNodeList();
      return Double.NaN;
    }

    xctxt.popCurrentNode();

    if (result > maxValue)
        maxValue = result;
  }

  xctxt.popContextNodeList();
  return maxValue;

}
 
Example #29
Source File: ExsltDynamic.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * The dyn:min function calculates the minimum value for the nodes passed as the
 * first argument, where the value of each node is calculated dynamically using
 * an XPath expression passed as a string as the second argument.
 * <p>
 * The expressions are evaluated relative to the nodes passed as the first argument.
 * In other words, the value for each node is calculated by evaluating the XPath
 * expression with all context information being the same as that for the call to
 * the dyn:min function itself, except for the following:
 * <p>
 * <ul>
 *  <li>the context node is the node whose value is being calculated.</li>
 *  <li>the context position is the position of the node within the node set passed
 *    as the first argument to the dyn:min function, arranged in document order.</li>
 *  <li>the context size is the number of nodes passed as the first argument to the
 *    dyn:min function.</li>
 * </ul>
 * <p>
 * The dyn:min function returns the minimum of these values, calculated in exactly
 * the same way as for math:min.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath expression
 * (including an empty string), this function returns NaN.
 * <p>
 * This function must take a second argument. To calculate the minimum of a set of
 * nodes based on their string values, you should use the math:min function.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param nl The node set
 * @param expr The expression string
 *
 * @return The minimum evaluation value
 */
public static double min(ExpressionContext myContext, NodeList nl, String expr)
  throws SAXNotSupportedException
{

  XPathContext xctxt = null;
  if (myContext instanceof XPathContext.XPathExpressionContext)
    xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext }));

  if (expr == null || expr.length() == 0)
    return Double.NaN;

  NodeSetDTM contextNodes = new NodeSetDTM(nl, xctxt);
  xctxt.pushContextNodeList(contextNodes);

  double minValue = Double.MAX_VALUE;
  for (int i = 0; i < nl.getLength(); i++)
  {
    int contextNode = contextNodes.item(i);
    xctxt.pushCurrentNode(contextNode);

    double result = 0;
    try
    {
      XPath dynamicXPath = new XPath(expr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);
      result = dynamicXPath.execute(xctxt, contextNode, xctxt.getNamespaceContext()).num();
    }
    catch (TransformerException e)
    {
      xctxt.popCurrentNode();
      xctxt.popContextNodeList();
      return Double.NaN;
    }

    xctxt.popCurrentNode();

    if (result < minValue)
        minValue = result;
  }

  xctxt.popContextNodeList();
  return minValue;

}
 
Example #30
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);
  }
}