Java XML Transform exceptionToString(TransformerException exception, boolean showSystemId)

Here you can find the source of exceptionToString(TransformerException exception, boolean showSystemId)

Description

exception To String

License

Apache License

Declaration

public static String exceptionToString(TransformerException exception, boolean showSystemId) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.xml.sax.SAXParseException;
import javax.xml.transform.SourceLocator;
import javax.xml.transform.TransformerException;

public class Main {
    public static String exceptionToString(TransformerException exception, boolean showSystemId) {
        StringBuffer message = new StringBuffer(20);
        if (exception.getLocator() != null) {
            SourceLocator locator = exception.getLocator();
            appendLocation(message, showSystemId ? locator.getSystemId() : null, locator.getLineNumber(),
                    locator.getColumnNumber());
        }/*  ww w .jav  a 2 s. c o m*/

        message.append(exception.getMessage());
        return message.toString();
    }

    public static String exceptionToString(SAXParseException exception, boolean showSystemId) {
        StringBuffer message = new StringBuffer(20);
        appendLocation(message, showSystemId ? exception.getSystemId() : null, exception.getLineNumber(),
                exception.getColumnNumber());

        message.append(exception.getMessage());
        return message.toString();
    }

    private static void appendLocation(StringBuffer message, String systemId, int lineNum, int colNum) {
        if (systemId != null)
            message.append(systemId);
        String line = "";
        String column = "";
        if (lineNum > 0)
            line = "line#: " + lineNum;
        if (colNum > 0)
            column = "col#: " + colNum;

        if (line.length() > 0 && systemId != null)
            message.append(", ");
        message.append(line);
        if (column.length() > 0)
            message.append(", ");
        message.append(column);

        if (systemId != null || lineNum > 0 || colNum > 0)
            message.append("; ");
    }
}

Related

  1. createTransformer()
  2. createTransformer()
  3. createTransformer(final File xsltFile)
  4. createTransformerHandler(int indent)
  5. createTXT(Transformer xf, Node doc)
  6. getDefaultTransformerFactoryThreadLocal()
  7. getNewTransformer()
  8. getThreadedIdentityTransformer( boolean omitXmlDeclaration)
  9. getThreadedIdentityTransformer(final boolean omitXmlDeclaration)