KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > IdentityTransformer


1 package net.sf.saxon;
2 import net.sf.saxon.event.*;
3 import net.sf.saxon.trans.XPathException;
4 import org.xml.sax.SAXParseException JavaDoc;
5
6 import javax.xml.transform.Result JavaDoc;
7 import javax.xml.transform.Source JavaDoc;
8 import javax.xml.transform.TransformerException JavaDoc;
9
10 class IdentityTransformer extends Controller {
11
12     protected IdentityTransformer(Configuration config) {
13         super(config);
14     }
15
16     /**
17     * Perform identify transformation from Source to Result
18     */

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