Search in sources :

Example 11 with SourceLocator

use of javax.xml.transform.SourceLocator in project robovm by robovm.

the class StylesheetHandler method getBaseIdentifier.

/**
   * Return the base identifier.
   *
   * @return The base identifier of the current stylesheet.
   */
public String getBaseIdentifier() {
    // Try to get the baseIdentifier from the baseIdentifier's stack,
    // which may not be the same thing as the value found in the
    // SourceLocators stack.
    String base = (String) (m_baseIdentifiers.isEmpty() ? null : m_baseIdentifiers.peek());
    // Otherwise try the stylesheet.
    if (null == base) {
        SourceLocator locator = getLocator();
        base = (null == locator) ? "" : locator.getSystemId();
    }
    return base;
}
Also used : SourceLocator(javax.xml.transform.SourceLocator) SAXSourceLocator(org.apache.xml.utils.SAXSourceLocator)

Example 12 with SourceLocator

use of javax.xml.transform.SourceLocator in project robovm by robovm.

the class DefaultErrorHandler method ensureLocationSet.

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);
}
Also used : SourceLocator(javax.xml.transform.SourceLocator) SAXParseException(org.xml.sax.SAXParseException) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 13 with SourceLocator

use of javax.xml.transform.SourceLocator in project robovm by robovm.

the class DefaultErrorHandler method printLocation.

public static void printLocation(PrintWriter pw, Throwable exception) {
    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 WrappedRuntimeException)
            cause = ((WrappedRuntimeException) cause).getException();
        else if (cause instanceof SAXException)
            cause = ((SAXException) cause).getException();
        else
            cause = null;
    } while (null != cause);
    if (null != locator) {
        // getErrorWriter().println("Parser fatal error: "+exception.getMessage());
        String id = (null != locator.getPublicId()) ? locator.getPublicId() : (null != locator.getSystemId()) ? locator.getSystemId() : //"SystemId Unknown";
        XMLMessages.createXMLMessage(XMLErrorResources.ER_SYSTEMID_UNKNOWN, null);
        pw.print(id + "; " + XMLMessages.createXMLMessage("line", null) + locator.getLineNumber() + "; " + XMLMessages.createXMLMessage("column", null) + locator.getColumnNumber() + "; ");
    } else
        pw.print("(" + XMLMessages.createXMLMessage(XMLErrorResources.ER_LOCATION_UNKNOWN, null) + ")");
}
Also used : SourceLocator(javax.xml.transform.SourceLocator) SAXParseException(org.xml.sax.SAXParseException) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 14 with SourceLocator

use of javax.xml.transform.SourceLocator in project robovm by robovm.

the class XPath method error.

/**
   * Tell the user of an error, and probably throw an
   * exception.
   *
   * @param xctxt The XPath runtime context.
   * @param sourceNode Not used.
   * @param msg An error msgkey that corresponds to one of the constants found 
   *            in {@link org.apache.xpath.res.XPATHErrorResources}, which is 
   *            a key for a format string.
   * @param args An array of arguments represented in the format string, which 
   *             may be null.
   *
   * @throws TransformerException if the current ErrorListoner determines to 
   *                              throw an exception.
   */
public void error(XPathContext xctxt, int sourceNode, String msg, Object[] args) throws javax.xml.transform.TransformerException {
    String fmsg = XSLMessages.createXPATHMessage(msg, args);
    ErrorListener ehandler = xctxt.getErrorListener();
    if (null != ehandler) {
        ehandler.fatalError(new TransformerException(fmsg, (SAXSourceLocator) xctxt.getSAXLocator()));
    } else {
        SourceLocator slocator = xctxt.getSAXLocator();
        System.out.println(fmsg + "; file " + slocator.getSystemId() + "; line " + slocator.getLineNumber() + "; column " + slocator.getColumnNumber());
    }
}
Also used : ErrorListener(javax.xml.transform.ErrorListener) SourceLocator(javax.xml.transform.SourceLocator) SAXSourceLocator(org.apache.xml.utils.SAXSourceLocator) SAXSourceLocator(org.apache.xml.utils.SAXSourceLocator) TransformerException(javax.xml.transform.TransformerException)

Aggregations

SourceLocator (javax.xml.transform.SourceLocator)14 TransformerException (javax.xml.transform.TransformerException)10 SAXSourceLocator (org.apache.xml.utils.SAXSourceLocator)6 XObject (org.apache.xpath.objects.XObject)6 IOException (java.io.IOException)4 SAXException (org.xml.sax.SAXException)4 SAXParseException (org.xml.sax.SAXParseException)4 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 ErrorListener (javax.xml.transform.ErrorListener)2 Source (javax.xml.transform.Source)2 DOMResult (javax.xml.transform.dom.DOMResult)2 SAXResult (javax.xml.transform.sax.SAXResult)2 StreamResult (javax.xml.transform.stream.StreamResult)2 SerializationHandler (org.apache.xml.serializer.SerializationHandler)2 ToXMLSAXHandler (org.apache.xml.serializer.ToXMLSAXHandler)2 DOMBuilder (org.apache.xml.utils.DOMBuilder)2 XMLString (org.apache.xml.utils.XMLString)2 SourceTreeManager (org.apache.xpath.SourceTreeManager)2 VariableStack (org.apache.xpath.VariableStack)2