01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: *
13: * @created Aug 18, 2005
14: * @author James Dixon
15: */
16:
17: package org.pentaho.ui;
18:
19: import java.util.List;
20:
21: import javax.xml.transform.TransformerException;
22:
23: import org.apache.commons.logging.Log;
24: import org.apache.commons.logging.LogFactory;
25: import org.dom4j.Document;
26: import org.pentaho.core.ui.IPentahoUrlFactory;
27: import org.pentaho.core.ui.IXMLComponent;
28: import org.pentaho.core.util.XmlHelper;
29: import org.pentaho.messages.Messages;
30:
31: public abstract class XmlComponent extends BaseUIComponent implements
32: IXMLComponent {
33: private static final Log log = LogFactory
34: .getLog(XmlComponent.class);
35:
36: public XmlComponent(IPentahoUrlFactory urlFactory, List messages,
37: String sourcePath) {
38: super (urlFactory, messages, sourcePath);
39: }
40:
41: public abstract Document getXmlContent();
42:
43: public String getContent(String mimeType) {
44:
45: if ("text/xml".equalsIgnoreCase(mimeType)) { //$NON-NLS-1$
46: Document content = getXmlContent();
47: return content.asXML();
48: } else {
49: Document document = getXmlContent();
50: if (document != null) {
51: String xslName = (String) contentTypes.get(mimeType);
52: if (xslName == null) {
53: error(Messages
54: .getString("BaseUI.ERROR_0002_XSL_NOT_FOUND") + mimeType); //$NON-NLS-1$
55: return null;
56: }
57: StringBuffer sb = null;
58: try {
59: sb = XmlHelper.transformXml(xslName,
60: getSourcePath(), document,
61: getXslProperties(), getSession());
62: } catch (TransformerException e) {
63: log
64: .error(
65: Messages
66: .getString("XmlComponent.ERROR_0000_XML_XFORM_FAILED"), e); //$NON-NLS-1$
67: return null;
68: }
69: if (debug)
70: debug(sb.toString());
71: return sb.toString();
72: } else {
73: return null;
74: }
75: }
76: }
77: }
|