Ignore:
Timestamp:
2012-04-19T14:58:44+12:00 (12 years ago)
Author:
ak19
Message:

Better error reporting during transformations. Extended the TransformErrorListener to store the XSLT upon construction and print it out (besides the exception message) upon exception.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r25313 r25423  
    3131import javax.xml.transform.stream.StreamResult;
    3232import javax.xml.transform.dom.DOMSource;
     33import javax.xml.transform.OutputKeys;
    3334
    3435import java.util.Map;
     
    12341235    }
    12351236
    1236     public static void elementToLogAsString(Element e)
    1237     {
    1238         try
    1239         {
    1240             TransformerFactory tf = TransformerFactory.newInstance();
    1241             Transformer trans = tf.newTransformer();
    1242             StringWriter sw = new StringWriter();
    1243             trans.transform(new DOMSource(e), new StreamResult(sw));
    1244             System.err.println(sw.toString());
    1245         }
    1246         catch (Exception ex)
    1247         {
    1248             System.err.println("couldn't write " + e + " to log");
    1249         }
     1237    public static void elementToLogAsString(Element e, boolean indent)
     1238    {
     1239    String str = elementToString(e, indent);
     1240    System.err.println(str);
     1241    logger.error(str);
     1242    }
     1243
     1244    public static String elementToString(Element e, boolean indent)
     1245    {
     1246        String str = "**********START*************\n";
     1247        try {
     1248        TransformerFactory tf = TransformerFactory.newInstance();
     1249        Transformer trans = tf.newTransformer();
     1250        StringWriter sw = new StringWriter();
     1251        if(indent) {
     1252            trans.setOutputProperty(OutputKeys.INDENT, "yes");
     1253        } else {
     1254            trans.setOutputProperty(OutputKeys.INDENT, "no");
     1255        }
     1256        trans.transform(new DOMSource(e), new StreamResult(sw));
     1257        str += sw.toString();
     1258        }
     1259        catch (Exception ex) {
     1260        str += "Exception: couldn't write " + e + " to log";
     1261        }
     1262        finally {
     1263        str += "\n***********************\n";
     1264        return str;
     1265        }
    12501266    }
    12511267
Note: See TracChangeset for help on using the changeset viewer.