1 16 17 package org.pentaho.ui.component; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.util.HashMap ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.dom4j.Document; 28 import org.pentaho.core.solution.ActionResource; 29 import org.pentaho.core.solution.IActionResource; 30 import org.pentaho.core.system.PentahoSystem; 31 import org.pentaho.core.ui.IPentahoUrlFactory; 32 import org.pentaho.ui.XmlComponent; 33 34 41 public class FilterPanelComponent extends XmlComponent { 42 43 46 private static final long serialVersionUID = 700681534058825526L; 47 48 private static final Log logger = LogFactory.getLog(FilterPanelComponent.class); 49 50 private String definitionPath; 51 52 private FilterPanel filterPanel; 53 54 private String xslName; 55 56 private Map defaultValues; 57 58 public FilterPanelComponent(String definitionPath, String xslName, IPentahoUrlFactory urlFactory, List messages) { 59 super(urlFactory, messages, null); 60 this.definitionPath = definitionPath; 61 if (xslName == null) { 62 xslName = "FilterPanelDefault.xsl"; } 65 String info[] = PentahoSystem.parseActionString(definitionPath); 66 if (info != null && info.length == 3) { 67 setSourcePath(info[0] + File.separator + info[1]); 68 } 69 this.xslName = xslName; 70 defaultValues = new HashMap (); 71 } 72 73 public void setDefaultValue(String filterName, String [] defaultValue) { 74 defaultValues.put(filterName, defaultValue); 75 } 76 77 public Log getLogger() { 78 return logger; 79 } 80 81 public boolean validate() { 82 return true; 83 } 84 85 public List getFilters() { 86 return filterPanel.getFilters(); 87 } 88 89 public boolean init() { 90 if (filterPanel == null) { 91 ActionResource resource = new ActionResource("", IActionResource.SOLUTION_FILE_RESOURCE, "text/xml", definitionPath); 94 Document filterDocument = null; 95 try { 96 filterDocument = PentahoSystem.getSolutionRepository(getSession()).getResourceAsDocument(resource); 97 filterPanel = getFilterPanel(filterDocument); 98 return true; 99 } catch (IOException e) { 100 } 101 return false; 102 } else { 103 return true; 104 } 105 } 106 107 public Document getXmlContent() { 108 109 boolean ok = filterPanel.populate(getParameterProviders(), defaultValues); 110 111 if (!ok) { 112 } 114 115 Document xForm = filterPanel.getXForm(); 116 117 setXsl("text/html", xslName); 119 return xForm; 120 } 121 122 private FilterPanel getFilterPanel(Document filterDocument) { 123 FilterPanel newFilterPanel = new FilterPanel(getSession(), filterDocument, getUrlFactory(), this); 124 return newFilterPanel; 125 } 126 127 } 128 | Popular Tags |