01: package net.sf.saxon;
02:
03: import net.sf.saxon.event.*;
04: import net.sf.saxon.trans.XPathException;
05: import org.xml.sax.SAXParseException;
06:
07: import javax.xml.transform.Result;
08: import javax.xml.transform.Source;
09: import javax.xml.transform.TransformerException;
10:
11: class IdentityTransformer extends Controller {
12:
13: protected IdentityTransformer(Configuration config) {
14: super (config);
15: }
16:
17: /**
18: * Perform identify transformation from Source to Result
19: */
20:
21: public void transform(Source source, Result result)
22: throws TransformerException {
23: try {
24: PipelineConfiguration pipe = makePipelineConfiguration();
25: Receiver receiver = ResultWrapper.getReceiver(result, pipe,
26: getOutputProperties());
27: NamespaceReducer reducer = new NamespaceReducer();
28: reducer.setUnderlyingReceiver(receiver);
29: new Sender(pipe).send(source, reducer, true);
30: } catch (XPathException err) {
31: Throwable cause = err.getException();
32: if (cause != null && cause instanceof SAXParseException) {
33: // This generally means the error was already reported.
34: // But if a RuntimeException occurs in Saxon during a callback from
35: // the Crimson parser, Crimson wraps this in a SAXParseException without
36: // reporting it further.
37: SAXParseException spe = (SAXParseException) cause;
38: cause = spe.getException();
39: if (cause instanceof RuntimeException) {
40: reportFatalError(err);
41: }
42: } else {
43: reportFatalError(err);
44: }
45: throw err;
46: }
47: }
48:
49: }
50:
51: //
52: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
53: // you may not use this file except in compliance with the License. You may obtain a copy of the
54: // License at http://www.mozilla.org/MPL/
55: //
56: // Software distributed under the License is distributed on an "AS IS" basis,
57: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
58: // See the License for the specific language governing rights and limitations under the License.
59: //
60: // The Original Code is: all this file.
61: //
62: // The Initial Developer of the Original Code is Michael H. Kay
63: //
64: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
65: //
66: // Contributor(s): None
67: //
|