01: /*******************************************************************************
02: * Copyright 2007 Ketan Padegaonkar http://ketan.padegaonkar.name
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: ******************************************************************************/package net.sourceforge.cruisecontrol.dashboard.widgets;
16:
17: import java.io.File;
18: import java.io.StringWriter;
19: import java.util.Map;
20:
21: import javax.xml.transform.Source;
22: import javax.xml.transform.Transformer;
23: import javax.xml.transform.TransformerFactory;
24: import javax.xml.transform.stream.StreamResult;
25: import javax.xml.transform.stream.StreamSource;
26:
27: /**
28: * @author Ketan Padegaonkar
29: */
30: public abstract class AbstractXslOutputWidget implements Widget {
31:
32: public AbstractXslOutputWidget() {
33: super ();
34: }
35:
36: public Object getOutput(Map parameters) {
37: File logFile = (File) parameters
38: .get(Widget.PARAM_BUILD_LOG_FILE);
39: try {
40: File ccHome = (File) parameters.get(Widget.PARAM_CC_ROOT);
41: File xsl = new File(ccHome.getCanonicalPath() + "/"
42: + getXslPath());
43: Source xmlSource = new StreamSource(logFile);
44: Source xsltSource = new StreamSource(xsl);
45:
46: TransformerFactory transFact = TransformerFactory
47: .newInstance();
48: Transformer trans = transFact.newTransformer(xsltSource);
49:
50: StringWriter writer = new StringWriter();
51: trans.transform(xmlSource, new StreamResult(writer));
52: return writer.toString();
53: } catch (Exception e) {
54: return null;
55: }
56: }
57:
58: protected abstract String getXslPath();
59: }
|