1 17 package org.apache.excalibur.xml.xslt; 18 19 import javax.xml.transform.ErrorListener ; 20 import javax.xml.transform.SourceLocator ; 21 import javax.xml.transform.TransformerException ; 22 23 import org.apache.avalon.framework.logger.Logger; 24 25 33 class TraxErrorHandler 34 implements ErrorListener 35 { 36 private Logger m_logger; 37 38 TraxErrorHandler( final Logger logger ) 39 { 40 if( null == logger ) 41 { 42 throw new NullPointerException ( "logger" ); 43 } 44 m_logger = logger; 45 } 46 47 public void warning( final TransformerException te ) 48 throws TransformerException 49 { 50 final String message = getMessage( te ); 51 if( null != m_logger ) 52 { 53 m_logger.warn( message, te ); 54 } 55 else 56 { 57 System.out.println( "WARNING: " + message ); 58 } 59 } 60 61 public void error( final TransformerException te ) 62 throws TransformerException 63 { 64 final String message = getMessage( te ); 65 if( null != m_logger ) 66 { 67 m_logger.error( message, te ); 68 } 69 else 70 { 71 System.out.println( "ERROR: " + message ); 72 } 73 } 74 75 public void fatalError( final TransformerException te ) 76 throws TransformerException 77 { 78 final String message = getMessage( te ); 79 if( null != m_logger ) 80 { 81 m_logger.fatalError( message, te ); 82 } 83 else 84 { 85 System.out.println( "FATAL-ERROR: " + message ); 86 } 87 throw te; 88 } 89 90 private String getMessage( final TransformerException te ) 91 { 92 final SourceLocator locator = te.getLocator(); 93 if( null != locator ) 94 { 95 final String id = 97 ( locator.getPublicId() != locator.getPublicId() ) 98 ? locator.getPublicId() 99 : ( null != locator.getSystemId() ) 100 ? locator.getSystemId() : "SystemId Unknown"; 101 return new StringBuffer ( "Error in TraxTransformer: " ) 102 .append( id ).append( "; Line " ).append( locator.getLineNumber() ) 103 .append( "; Column " ).append( locator.getColumnNumber() ) 104 .append( "; " ).toString(); 105 } 106 return "Error in TraxTransformer: " + te; 107 } 108 } 109 | Popular Tags |