KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > ui > component > InputFormComponent


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 7, 2005
14  * @author James Dixon
15  */

16
17 package org.pentaho.ui.component;
18
19 import java.io.File JavaDoc;
20 import java.util.List JavaDoc;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.dom4j.Document;
24 import org.dom4j.DocumentHelper;
25 import org.dom4j.Node;
26 import org.pentaho.ui.XmlComponent;
27 import org.pentaho.core.repository.ISolutionRepository;
28 import org.pentaho.core.solution.IActionDefinition;
29 import org.pentaho.core.solution.IActionSequence;
30 import org.pentaho.core.system.PentahoSystem;
31 import org.pentaho.core.ui.IPentahoUrlFactory;
32 import org.pentaho.core.util.XForm;
33 import org.pentaho.messages.Messages;
34
35 public class InputFormComponent extends XmlComponent {
36
37     /**
38      *
39      */

40     private static final long serialVersionUID = -6106477602576378538L;
41
42     String JavaDoc templateName;
43
44     String JavaDoc stylesheetName;
45
46     String JavaDoc solution;
47
48     String JavaDoc path;
49
50     String JavaDoc actionName;
51
52     String JavaDoc instanceId;
53
54     public InputFormComponent(IPentahoUrlFactory urlFactory, String JavaDoc instanceId, String JavaDoc templateName, String JavaDoc stylesheetName, String JavaDoc solution, String JavaDoc path, String JavaDoc actionName, List JavaDoc messages) {
55         super(urlFactory, messages, solution + File.separator + path);
56         this.instanceId = instanceId;
57         this.templateName = templateName;
58         this.stylesheetName = stylesheetName;
59         this.solution = solution;
60         this.path = path;
61         this.actionName = actionName;
62     }
63
64     private static final Log logger = LogFactory.getLog(InputFormComponent.class);
65
66     public Log getLogger() {
67         return logger;
68     }
69
70     public boolean validate() {
71         boolean ok = true;
72         if (instanceId == null) {
73             // error( "Instance id not specified" );
74
// out.write( "instance id not provided" );
75
// ok = false;
76
}
77
78         if (solution == null) {
79             error(Messages.getString("InputForm.ERROR_0001_SOLUTION_NOT_SPECIFIED")); //$NON-NLS-1$
80
ok = false;
81         }
82
83         if (path == null) {
84             error(Messages.getString("InputForm.ERROR_0002_ACTION_NAME_NOT_SPECIFIED")); //$NON-NLS-1$
85
ok = false;
86         }
87
88         if (actionName == null) {
89             // TODO log this
90
error(Messages.getString("InputForm.ERROR_0003_ACTION_PATH_NOT_SPECIFIED")); //$NON-NLS-1$
91
ok = false;
92         }
93
94         return ok;
95     }
96
97     /*
98      * (non-Javadoc)
99      *
100      * @see org.pentaho.core.ui.component.BaseUIComponent#getXmlContent()
101      */

102     public Document getXmlContent() {
103
104         ISolutionRepository repository = PentahoSystem.getSolutionRepository(getSession());
105
106         IActionSequence actionSequence = repository.getActionSequence(solution, path, actionName, getLoggingLevel(), ISolutionRepository.ACTION_EXECUTE);
107
108         if (actionSequence == null) {
109             // TODO log this
110
error(Messages.getString("InputForm.ERROR_0004_ACTION_NOT_FOUND") + solution + path + actionName); //$NON-NLS-1$
111
return null;
112         }
113
114         List JavaDoc actions = actionSequence.getActionDefinitionsAndSequences();
115         IActionDefinition action = (IActionDefinition) actions.get(0);
116
117         Node node = action.getComponentSection();
118         if (node == null) {
119             error(Messages.getString("InputForm.ERROR_0005_INBOX_DEFINITION_MISSING") + solution + path + actionName); //$NON-NLS-1$
120
return null;
121         }
122
123         if (templateName == null) {
124
125             // see if the template is specified in the action document
126
Node templateNode = node.selectSingleNode("//template"); //$NON-NLS-1$
127
if (templateNode != null) {
128                 templateName = templateNode.getText();
129             }
130             if (templateName == null) {
131                 error(Messages.getString("InputForm.ERROR_0006_TEMPLATE_NOT_SPECIFIED")); //$NON-NLS-1$
132
return null;
133             }
134         }
135         Node xFormNode = node.selectSingleNode("//xForm"); //$NON-NLS-1$
136

137         try {
138
139             String JavaDoc actionTitle = actionSequence.getTitle();
140             if (actionTitle != null) {
141                 setXslProperty("title", actionTitle); //$NON-NLS-1$
142
}
143
144             String JavaDoc description = actionSequence.getDescription();
145             if (description != null) {
146                 setXslProperty("description", description); //$NON-NLS-1$
147
}
148
149             String JavaDoc xFormHtml = XForm.transformSnippet(xFormNode, getSession());
150             if (xFormHtml == null) {
151                 error(Messages.getString("InputForm.ERROR_0007_INBOX_DEFINITION_INVALID") + solution + path + actionName); //$NON-NLS-1$
152
return null;
153             }
154             Document document = DocumentHelper.parseText(xFormHtml);
155             Node xFormHtmlNode = document.selectSingleNode("//xForm"); //$NON-NLS-1$
156

157             setXslProperty("xForm", xFormHtmlNode.asXML()); //$NON-NLS-1$
158

159             if (stylesheetName != null && !"".equals(stylesheetName)) { //$NON-NLS-1$
160
setXslProperty("css", stylesheetName); //$NON-NLS-1$
161
}
162             setXsl("text/html", templateName); //$NON-NLS-1$
163

164             return document;
165
166         } catch (Exception JavaDoc e) {
167             return null;
168         }
169
170     }
171
172 }
173
Popular Tags