KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > ui > XmlComponent


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * 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 JavaDoc;
20
21 import org.dom4j.Document;
22 import org.pentaho.core.ui.IPentahoUrlFactory;
23 import org.pentaho.core.ui.IXMLComponent;
24 import org.pentaho.core.util.XmlHelper;
25 import org.pentaho.messages.Messages;
26
27 public abstract class XmlComponent extends BaseUIComponent implements IXMLComponent {
28
29     public XmlComponent(IPentahoUrlFactory urlFactory, List JavaDoc messages, String JavaDoc sourcePath) {
30         super(urlFactory, messages, sourcePath);
31     }
32
33     public abstract Document getXmlContent();
34
35     public String JavaDoc getContent(String JavaDoc mimeType) {
36
37         if ("text/xml".equalsIgnoreCase(mimeType)) { //$NON-NLS-1$
38
Document content = getXmlContent();
39             return content.asXML();
40         } else {
41             Document document = getXmlContent();
42             if (document != null) {
43                 String JavaDoc xslName = (String JavaDoc) contentTypes.get(mimeType);
44                 if (xslName == null) {
45                     error(Messages.getString("BaseUI.ERROR_0002_XSL_NOT_FOUND") + mimeType); //$NON-NLS-1$
46
return null;
47                 }
48                 StringBuffer JavaDoc sb = XmlHelper.transformXml(xslName, getSourcePath(), document, getXslProperties(), getSession());
49                 if (sb != null) {
50                     if (debug)
51                         debug(sb.toString());
52                     return sb.toString();
53                 } else {
54                     return null;
55                 }
56             } else {
57                 return null;
58
59             }
60         }
61     }
62
63 }
64
Popular Tags