1 19 20 package org.netbeans.spi.xml.cookies; 21 22 import javax.xml.transform.*; 23 24 import org.xml.sax.SAXException ; 25 import org.xml.sax.SAXParseException ; 26 27 import org.netbeans.api.xml.cookies.XMLProcessorDetail; 28 29 37 public class DefaultXMLProcessorDetail extends XMLProcessorDetail { 38 39 private int columnNumber; 40 41 private int lineNumber; 42 43 private String publicId; 44 45 private String systemId; 46 47 private Exception exception; 48 49 50 54 public DefaultXMLProcessorDetail(SAXParseException spex) { 55 if (spex == null) throw new NullPointerException (); 56 57 this.exception = spex; 58 this.columnNumber = spex.getColumnNumber(); 59 this.lineNumber = spex.getLineNumber(); 60 this.publicId = spex.getPublicId(); 61 this.systemId = spex.getSystemId(); 62 63 if ( Util.THIS.isLoggable() ) { 64 Util.THIS.debug ("DefaultXMLProcessorDetail: SAXParseException"); 65 Util.THIS.debug (" exception= " + exception); 66 Util.THIS.debug (" columnNumber= " + columnNumber); 67 Util.THIS.debug (" lineNumber= " + lineNumber); 68 Util.THIS.debug (" publicId= " + publicId); 69 Util.THIS.debug (" systemId= " + systemId); 70 } 71 } 72 73 77 public DefaultXMLProcessorDetail(TransformerException trex) { 78 if (trex == null) throw new NullPointerException (); 79 80 this.exception = trex; 81 82 84 SourceLocator locator = trex.getLocator(); 85 if (locator != null) { 86 this.columnNumber = locator.getColumnNumber(); 87 this.lineNumber = locator.getLineNumber(); 88 this.publicId = locator.getPublicId(); 89 this.systemId = locator.getSystemId(); 90 91 if (lineNumber == -1) { 93 tryWrappedLocator(trex); 94 } 95 } else { 96 97 this.columnNumber = -1; 99 this.lineNumber = -1; 100 this.publicId = null; 101 this.systemId = null; 102 103 tryWrappedLocator(trex); 105 } 106 107 if ( Util.THIS.isLoggable() ) { 108 Util.THIS.debug ("DefaultXMLProcessorDetail: TransformerException"); 109 Util.THIS.debug (" exception= " + exception); 110 Util.THIS.debug (" columnNumber= " + columnNumber); 111 Util.THIS.debug (" lineNumber= " + lineNumber); 112 Util.THIS.debug (" publicId= " + publicId); 113 Util.THIS.debug (" systemId= " + systemId); 114 } 115 } 116 117 private void tryWrappedLocator(Exception ex) { 119 if ( Util.THIS.isLoggable() ) { 120 Util.THIS.debug ("DefaultXMLProcessorDetail.tryWrappedLocator: " + ex); 121 } 122 123 125 Throwable wrapped = null; 126 if (ex instanceof TransformerException) { 127 wrapped = ((TransformerException) ex).getException(); 128 } else if (ex instanceof SAXException ) { 129 wrapped = ((SAXException ) ex).getException(); 130 } else { 131 return; 132 } 133 134 136 if (wrapped instanceof SAXParseException ) { 137 SAXParseException pex = (SAXParseException ) wrapped; 138 if (pex.getLineNumber() == -1) { 139 tryWrappedLocator(pex); 140 } else { 141 this.columnNumber = pex.getColumnNumber(); 142 this.lineNumber = pex.getLineNumber(); 143 this.publicId = pex.getPublicId(); 144 this.systemId = pex.getSystemId(); 145 } 146 } else if (wrapped instanceof TransformerException) { 147 TransformerException wrappedTransformerEx = 148 (TransformerException) wrapped; 149 SourceLocator locator = wrappedTransformerEx.getLocator(); 150 if (locator == null) { 151 tryWrappedLocator(wrappedTransformerEx); 152 } else { 153 if (locator.getLineNumber() == -1) { 154 tryWrappedLocator(wrappedTransformerEx); 155 } else { 156 this.columnNumber = locator.getColumnNumber(); 157 this.lineNumber = locator.getLineNumber(); 158 this.publicId = locator.getPublicId(); 159 this.systemId = locator.getSystemId(); 160 } 161 } 162 } else if (wrapped instanceof SAXException ) { 163 tryWrappedLocator((SAXException )wrapped); 164 } 165 } 166 167 public int getColumnNumber() { 168 return columnNumber; 169 } 170 171 public int getLineNumber() { 172 return lineNumber; 173 } 174 175 public String getPublicId() { 176 return publicId; 177 } 178 179 public String getSystemId() { 180 return systemId; 181 } 182 183 public Exception getException() { 184 return exception; 185 } 186 187 } 188 | Popular Tags |