1 16 package org.apache.cocoon.components.xslt; 17 18 import javax.xml.transform.ErrorListener ; 19 import javax.xml.transform.TransformerException ; 20 21 import org.apache.avalon.framework.logger.Logger; 22 import org.apache.cocoon.util.location.Location; 23 import org.apache.cocoon.util.location.LocationUtils; 24 25 32 public class TraxErrorListener implements ErrorListener { 33 34 private Logger logger; 35 private String uri; 36 37 38 private TransformerException warningEx; 39 40 41 private TransformerException exception; 42 43 public TraxErrorListener(Logger logger, String uri) { 44 this.logger = logger; 45 this.uri = uri; 46 } 47 48 53 public Throwable getThrowable() { 54 if (exception == null) { 55 return null; 56 } 57 58 Location loc = LocationUtils.getLocation(exception); 59 if (LocationUtils.isKnown(loc)) { 60 return exception; 62 } 63 64 if (exception.getCause() != null) { 66 return exception.getCause(); 67 } 68 69 return exception; 71 } 72 73 public void warning(TransformerException ex) throws TransformerException { 74 79 if (logger.isWarnEnabled()) { 80 Location loc = LocationUtils.getLocation(ex); 81 logger.warn(ex.getMessage() + " at "+ loc == null ? uri : loc.toString()); 82 } 83 warningEx = ex; 85 } 86 87 public void error(TransformerException ex) throws TransformerException { 88 89 if (warningEx != null && ex.getCause() == null) { 93 ex = warningEx; 94 } 95 warningEx = null; 96 97 exception = ex; 99 throw ex; 101 } 102 103 public void fatalError(TransformerException ex) throws TransformerException { 104 if (warningEx != null && ex.getCause() == null) { 105 ex = warningEx; 106 } 107 warningEx = null; 108 109 exception = ex; 110 throw ex; 111 } 112 } 113 | Popular Tags |