1 16 17 package org.pentaho.ui.component; 18 19 import java.io.File ; 20 import java.util.List ; 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 40 private static final long serialVersionUID = -6106477602576378538L; 41 42 String templateName; 43 44 String stylesheetName; 45 46 String solution; 47 48 String path; 49 50 String actionName; 51 52 String instanceId; 53 54 public InputFormComponent(IPentahoUrlFactory urlFactory, String instanceId, String templateName, String stylesheetName, String solution, String path, String actionName, List 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 } 77 78 if (solution == null) { 79 error(Messages.getString("InputForm.ERROR_0001_SOLUTION_NOT_SPECIFIED")); ok = false; 81 } 82 83 if (path == null) { 84 error(Messages.getString("InputForm.ERROR_0002_ACTION_NAME_NOT_SPECIFIED")); ok = false; 86 } 87 88 if (actionName == null) { 89 error(Messages.getString("InputForm.ERROR_0003_ACTION_PATH_NOT_SPECIFIED")); ok = false; 92 } 93 94 return ok; 95 } 96 97 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 error(Messages.getString("InputForm.ERROR_0004_ACTION_NOT_FOUND") + solution + path + actionName); return null; 112 } 113 114 List 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); return null; 121 } 122 123 if (templateName == null) { 124 125 Node templateNode = node.selectSingleNode("//template"); if (templateNode != null) { 128 templateName = templateNode.getText(); 129 } 130 if (templateName == null) { 131 error(Messages.getString("InputForm.ERROR_0006_TEMPLATE_NOT_SPECIFIED")); return null; 133 } 134 } 135 Node xFormNode = node.selectSingleNode("//xForm"); 137 try { 138 139 String actionTitle = actionSequence.getTitle(); 140 if (actionTitle != null) { 141 setXslProperty("title", actionTitle); } 143 144 String description = actionSequence.getDescription(); 145 if (description != null) { 146 setXslProperty("description", description); } 148 149 String xFormHtml = XForm.transformSnippet(xFormNode, getSession()); 150 if (xFormHtml == null) { 151 error(Messages.getString("InputForm.ERROR_0007_INBOX_DEFINITION_INVALID") + solution + path + actionName); return null; 153 } 154 Document document = DocumentHelper.parseText(xFormHtml); 155 Node xFormHtmlNode = document.selectSingleNode("//xForm"); 157 setXslProperty("xForm", xFormHtmlNode.asXML()); 159 if (stylesheetName != null && !"".equals(stylesheetName)) { setXslProperty("css", stylesheetName); } 162 setXsl("text/html", templateName); 164 return document; 165 166 } catch (Exception e) { 167 return null; 168 } 169 170 } 171 172 } 173 | Popular Tags |