Java Code Examples for javax.xml.transform.TransformerException#setLocator()

The following examples show how to use javax.xml.transform.TransformerException#setLocator() . 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: DefaultErrorHandler.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public static void ensureLocationSet(TransformerException exception)
{
  // SourceLocator locator = exception.getLocator();
  SourceLocator locator = null;
  Throwable cause = exception;

  // Try to find the locator closest to the cause.
  do
  {
    if(cause instanceof SAXParseException)
    {
      locator = new SAXSourceLocator((SAXParseException)cause);
    }
    else if (cause instanceof TransformerException)
    {
      SourceLocator causeLocator = ((TransformerException)cause).getLocator();
      if(null != causeLocator)
        locator = causeLocator;
    }

    if(cause instanceof TransformerException)
      cause = ((TransformerException)cause).getCause();
    else if(cause instanceof SAXException)
      cause = ((SAXException)cause).getException();
    else
      cause = null;
  }
  while(null != cause);

  exception.setLocator(locator);
}
 
Example 2
Source File: DefaultErrorHandler.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void ensureLocationSet(TransformerException exception)
{
  // SourceLocator locator = exception.getLocator();
  SourceLocator locator = null;
  Throwable cause = exception;

  // Try to find the locator closest to the cause.
  do
  {
    if(cause instanceof SAXParseException)
    {
      locator = new SAXSourceLocator((SAXParseException)cause);
    }
    else if (cause instanceof TransformerException)
    {
      SourceLocator causeLocator = ((TransformerException)cause).getLocator();
      if(null != causeLocator)
        locator = causeLocator;
    }

    if(cause instanceof TransformerException)
      cause = ((TransformerException)cause).getCause();
    else if(cause instanceof SAXException)
      cause = ((SAXException)cause).getException();
    else
      cause = null;
  }
  while(null != cause);

  exception.setLocator(locator);
}
 
Example 3
Source File: DefaultErrorHandler.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void ensureLocationSet(TransformerException exception)
{
  // SourceLocator locator = exception.getLocator();
  SourceLocator locator = null;
  Throwable cause = exception;

  // Try to find the locator closest to the cause.
  do
  {
    if(cause instanceof SAXParseException)
    {
      locator = new SAXSourceLocator((SAXParseException)cause);
    }
    else if (cause instanceof TransformerException)
    {
      SourceLocator causeLocator = ((TransformerException)cause).getLocator();
      if(null != causeLocator)
        locator = causeLocator;
    }

    if(cause instanceof TransformerException)
      cause = ((TransformerException)cause).getCause();
    else if(cause instanceof SAXException)
      cause = ((SAXException)cause).getException();
    else
      cause = null;
  }
  while(null != cause);

  exception.setLocator(locator);
}
 
Example 4
Source File: DefaultErrorHandler.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public static void ensureLocationSet(TransformerException exception)
{
  // SourceLocator locator = exception.getLocator();
  SourceLocator locator = null;
  Throwable cause = exception;

  // Try to find the locator closest to the cause.
  do
  {
    if(cause instanceof SAXParseException)
    {
      locator = new SAXSourceLocator((SAXParseException)cause);
    }
    else if (cause instanceof TransformerException)
    {
      SourceLocator causeLocator = ((TransformerException)cause).getLocator();
      if(null != causeLocator)
        locator = causeLocator;
    }

    if(cause instanceof TransformerException)
      cause = ((TransformerException)cause).getCause();
    else if(cause instanceof SAXException)
      cause = ((SAXException)cause).getException();
    else
      cause = null;
  }
  while(null != cause);

  exception.setLocator(locator);
}
 
Example 5
Source File: DefaultErrorHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void ensureLocationSet(TransformerException exception)
{
  // SourceLocator locator = exception.getLocator();
  SourceLocator locator = null;
  Throwable cause = exception;

  // Try to find the locator closest to the cause.
  do
  {
    if(cause instanceof SAXParseException)
    {
      locator = new SAXSourceLocator((SAXParseException)cause);
    }
    else if (cause instanceof TransformerException)
    {
      SourceLocator causeLocator = ((TransformerException)cause).getLocator();
      if(null != causeLocator)
        locator = causeLocator;
    }

    if(cause instanceof TransformerException)
      cause = ((TransformerException)cause).getCause();
    else if(cause instanceof SAXException)
      cause = ((SAXException)cause).getException();
    else
      cause = null;
  }
  while(null != cause);

  exception.setLocator(locator);
}
 
Example 6
Source File: DefaultErrorHandler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void ensureLocationSet(TransformerException exception)
{
  // SourceLocator locator = exception.getLocator();
  SourceLocator locator = null;
  Throwable cause = exception;

  // Try to find the locator closest to the cause.
  do
  {
    if(cause instanceof SAXParseException)
    {
      locator = new SAXSourceLocator((SAXParseException)cause);
    }
    else if (cause instanceof TransformerException)
    {
      SourceLocator causeLocator = ((TransformerException)cause).getLocator();
      if(null != causeLocator)
        locator = causeLocator;
    }

    if(cause instanceof TransformerException)
      cause = ((TransformerException)cause).getCause();
    else if(cause instanceof SAXException)
      cause = ((SAXException)cause).getException();
    else
      cause = null;
  }
  while(null != cause);

  exception.setLocator(locator);
}
 
Example 7
Source File: DefaultErrorHandler.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public static void ensureLocationSet(TransformerException exception)
{
  // SourceLocator locator = exception.getLocator();
  SourceLocator locator = null;
  Throwable cause = exception;

  // Try to find the locator closest to the cause.
  do
  {
    if(cause instanceof SAXParseException)
    {
      locator = new SAXSourceLocator((SAXParseException)cause);
    }
    else if (cause instanceof TransformerException)
    {
      SourceLocator causeLocator = ((TransformerException)cause).getLocator();
      if(null != causeLocator)
        locator = causeLocator;
    }

    if(cause instanceof TransformerException)
      cause = ((TransformerException)cause).getCause();
    else if(cause instanceof SAXException)
      cause = ((SAXException)cause).getException();
    else
      cause = null;
  }
  while(null != cause);

  exception.setLocator(locator);
}
 
Example 8
Source File: DefaultErrorHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void ensureLocationSet(TransformerException exception)
{
  // SourceLocator locator = exception.getLocator();
  SourceLocator locator = null;
  Throwable cause = exception;

  // Try to find the locator closest to the cause.
  do
  {
    if(cause instanceof SAXParseException)
    {
      locator = new SAXSourceLocator((SAXParseException)cause);
    }
    else if (cause instanceof TransformerException)
    {
      SourceLocator causeLocator = ((TransformerException)cause).getLocator();
      if(null != causeLocator)
        locator = causeLocator;
    }

    if(cause instanceof TransformerException)
      cause = ((TransformerException)cause).getCause();
    else if(cause instanceof SAXException)
      cause = ((SAXException)cause).getException();
    else
      cause = null;
  }
  while(null != cause);

  exception.setLocator(locator);
}
 
Example 9
Source File: DefaultErrorHandler.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void ensureLocationSet(TransformerException exception)
{
  // SourceLocator locator = exception.getLocator();
  SourceLocator locator = null;
  Throwable cause = exception;

  // Try to find the locator closest to the cause.
  do
  {
    if(cause instanceof SAXParseException)
    {
      locator = new SAXSourceLocator((SAXParseException)cause);
    }
    else if (cause instanceof TransformerException)
    {
      SourceLocator causeLocator = ((TransformerException)cause).getLocator();
      if(null != causeLocator)
        locator = causeLocator;
    }

    if(cause instanceof TransformerException)
      cause = ((TransformerException)cause).getCause();
    else if(cause instanceof SAXException)
      cause = ((SAXException)cause).getException();
    else
      cause = null;
  }
  while(null != cause);

  exception.setLocator(locator);
}
 
Example 10
Source File: DefaultErrorHandler.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void ensureLocationSet(TransformerException exception)
{
  // SourceLocator locator = exception.getLocator();
  SourceLocator locator = null;
  Throwable cause = exception;

  // Try to find the locator closest to the cause.
  do
  {
    if(cause instanceof SAXParseException)
    {
      locator = new SAXSourceLocator((SAXParseException)cause);
    }
    else if (cause instanceof TransformerException)
    {
      SourceLocator causeLocator = ((TransformerException)cause).getLocator();
      if(null != causeLocator)
        locator = causeLocator;
    }

    if(cause instanceof TransformerException)
      cause = ((TransformerException)cause).getCause();
    else if(cause instanceof SAXException)
      cause = ((SAXException)cause).getException();
    else
      cause = null;
  }
  while(null != cause);

  exception.setLocator(locator);
}
 
Example 11
Source File: DefaultErrorHandler.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void ensureLocationSet(TransformerException exception)
{
  // SourceLocator locator = exception.getLocator();
  SourceLocator locator = null;
  Throwable cause = exception;

  // Try to find the locator closest to the cause.
  do
  {
    if(cause instanceof SAXParseException)
    {
      locator = new SAXSourceLocator((SAXParseException)cause);
    }
    else if (cause instanceof TransformerException)
    {
      SourceLocator causeLocator = ((TransformerException)cause).getLocator();
      if(null != causeLocator)
        locator = causeLocator;
    }

    if(cause instanceof TransformerException)
      cause = ((TransformerException)cause).getCause();
    else if(cause instanceof SAXException)
      cause = ((SAXException)cause).getException();
    else
      cause = null;
  }
  while(null != cause);

  exception.setLocator(locator);
}
 
Example 12
Source File: DefaultErrorHandler.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public static void ensureLocationSet(TransformerException exception)
{
  // SourceLocator locator = exception.getLocator();
  SourceLocator locator = null;
  Throwable cause = exception;
  
  // Try to find the locator closest to the cause.
  do
  {
    if(cause instanceof SAXParseException)
    {
      locator = new SAXSourceLocator((SAXParseException)cause);
    }
    else if (cause instanceof TransformerException)
    {
      SourceLocator causeLocator = ((TransformerException)cause).getLocator();
      if(null != causeLocator)
        locator = causeLocator;
    }
    
    if(cause instanceof TransformerException)
      cause = ((TransformerException)cause).getCause();
    else if(cause instanceof SAXException)
      cause = ((SAXException)cause).getException();
    else
      cause = null;
  }
  while(null != cause);
  
  exception.setLocator(locator);
}
 
Example 13
Source File: ElemValueOf.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Execute the string expression and copy the text to the
 * result tree.
 * The required select attribute is an expression; this expression
 * is evaluated and the resulting object is converted to a string
 * as if by a call to the string function. The string specifies
 * the string-value of the created text node. If the string is
 * empty, no text node will be created. The created text node will
 * be merged with any adjacent text nodes.
 * @see <a href="http://www.w3.org/TR/xslt#value-of">value-of in XSLT Specification</a>
 *
 * @param transformer non-null reference to the the current transform-time state.
 *
 * @throws TransformerException
 */
public void execute(TransformerImpl transformer) throws TransformerException
{

  XPathContext xctxt = transformer.getXPathContext();
  SerializationHandler rth = transformer.getResultTreeHandler();

  try
  {
    // Optimize for "."
      xctxt.pushNamespaceContext(this);

      int current = xctxt.getCurrentNode();

      xctxt.pushCurrentNodeAndExpression(current, current);

      if (m_disableOutputEscaping)
        rth.processingInstruction(
          javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");

      try
      {
        Expression expr = m_selectExpression.getExpression();

          expr.executeCharsToContentHandler(xctxt, rth);
      }
      finally
      {
        if (m_disableOutputEscaping)
          rth.processingInstruction(
            javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");

        xctxt.popNamespaceContext();
        xctxt.popCurrentNodeAndExpression();
      }
  }
  catch (SAXException se)
  {
    throw new TransformerException(se);
  }
  catch (RuntimeException re) {
  	TransformerException te = new TransformerException(re);
  	te.setLocator(this);
  	throw te;
  }
}
 
Example 14
Source File: TransformerImpl.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
   * Execute each of the children of a template element.
   *
   * @param elem The ElemTemplateElement that contains the children
   * that should execute.
   * @param shouldAddAttrs true if xsl:attributes should be executed.
   *
   * @throws TransformerException
   * @xsl.usage advanced
   */
  public void executeChildTemplates(
          ElemTemplateElement elem, boolean shouldAddAttrs)
            throws TransformerException
  {

    // Does this element have any children?
    ElemTemplateElement t = elem.getFirstChildElem();

    if (null == t)
      return;      
    
    if(elem.hasTextLitOnly() && m_optimizer)
    {      
      char[] chars = ((ElemTextLiteral)t).getChars();
      try
      {
        // Have to push stuff on for tooling...
        this.pushElemTemplateElement(t);
        m_serializationHandler.characters(chars, 0, chars.length);
      }
      catch(SAXException se)
      {
        throw new TransformerException(se);
      }
      finally
      {
        this.popElemTemplateElement();
      }
      return;
    }

//    // Check for infinite loops if we have to.
//    boolean check = (m_stackGuard.m_recursionLimit > -1);
//
//    if (check)
//      getStackGuard().push(elem, xctxt.getCurrentNode());

    XPathContext xctxt = m_xcontext;
    xctxt.pushSAXLocatorNull();
    int currentTemplateElementsTop = m_currentTemplateElements.size();
    m_currentTemplateElements.push(null);

    try
    {
      // Loop through the children of the template, calling execute on 
      // each of them.
      for (; t != null; t = t.getNextSiblingElem())
      {
        if (!shouldAddAttrs
                && t.getXSLToken() == Constants.ELEMNAME_ATTRIBUTE)
          continue;

        xctxt.setSAXLocator(t);
        m_currentTemplateElements.setElementAt(t,currentTemplateElementsTop);
        t.execute(this);
      }
    }
    catch(RuntimeException re)
    {
    	TransformerException te = new TransformerException(re);
    	te.setLocator(t);
    	throw te;
    }
    finally
    {
      m_currentTemplateElements.pop();
      xctxt.popSAXLocator();
    }

    // Check for infinite loops if we have to
//    if (check)
//      getStackGuard().pop();
  }