View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   */ 
19  package org.apache.rat;
20  
21  import java.io.InputStream;
22  import java.io.Reader;
23  import java.io.Writer;
24  
25  import javax.xml.transform.Transformer;
26  import javax.xml.transform.TransformerConfigurationException;
27  import javax.xml.transform.TransformerException;
28  import javax.xml.transform.TransformerFactory;
29  import javax.xml.transform.stream.StreamResult;
30  import javax.xml.transform.stream.StreamSource;
31  
32  
33  class ReportTransformer implements Runnable {
34  
35      private final Writer out;
36      private final Transformer transformer;
37      private final Reader in;
38      
39      public ReportTransformer(final Writer out, final Reader style, 
40              final Reader in) throws TransformerConfigurationException {
41          this.out = out;
42          transformer = TransformerFactory.newInstance().newTransformer(
43                  new StreamSource(style));
44          this.in = in;
45      }
46      
47      public ReportTransformer(final Writer out, final InputStream style, 
48              final Reader in) throws TransformerConfigurationException {
49          this.out = out;
50          transformer = TransformerFactory.newInstance().newTransformer(
51                  new StreamSource(style));
52          this.in = in;
53      }
54      
55      public void run() {
56          try {
57              transform();
58          } catch (TransformerException e) {
59              throw new ReportFailedRuntimeException(e.getMessage(), e);
60          }
61      }
62  
63      public void transform() throws TransformerException {
64          transformer.transform(new StreamSource(in), new StreamResult(out));
65      }
66  
67  }