| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.serialize; |
| 9 |
|
| 10 |
import net.sf.saxon.event.ReceiverOptions; |
| 11 |
import net.sf.saxon.expr.parser.Location; |
| 12 |
import net.sf.saxon.om.StructuredQName; |
| 13 |
import net.sf.saxon.trans.XPathException; |
| 14 |
|
| 15 |
import javax.xml.transform.ErrorListener; |
| 16 |
import javax.xml.transform.TransformerException; |
| 17 |
import java.io.StringWriter; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public class MessageWarner extends XMLEmitter { |
| 30 |
|
| 31 |
boolean abort = false; |
| 32 |
String errorCode = null; |
| 33 |
|
| 34 |
public void startDocument(int properties) throws XPathException { |
| 35 |
setWriter(new StringWriter()); |
| 36 |
abort = (properties & ReceiverOptions.TERMINATE) != 0; |
| 37 |
super.startDocument(properties); |
| 38 |
} |
| 39 |
|
| 40 |
@Override |
| 41 |
public void processingInstruction(String target, CharSequence data, Location locationId, int properties) throws XPathException { |
| 42 |
if (target.equals("error-code")) { |
| 43 |
errorCode = data.toString(); |
| 44 |
} else { |
| 45 |
super.processingInstruction(target, data, locationId, properties); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
public void endDocument() throws XPathException { |
| 50 |
ErrorListener listener = getPipelineConfiguration().getErrorListener(); |
| 51 |
XPathException de = new XPathException(getWriter().toString()); |
| 52 |
if (errorCode != null) { |
| 53 |
de.setErrorCodeQName(StructuredQName.fromEQName(errorCode)); |
| 54 |
} else { |
| 55 |
de.setErrorCode("XTMM9000"); |
| 56 |
} |
| 57 |
try { |
| 58 |
if (abort) { |
| 59 |
listener.error(de); |
| 60 |
} else { |
| 61 |
listener.warning(de); |
| 62 |
} |
| 63 |
} catch (TransformerException te) { |
| 64 |
throw XPathException.makeXPathException(te); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
public void close() { |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
} |
| 73 |
|