KickJava   Java API By Example, From Geeks To Geeks.

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


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

17
18 package org.pentaho.ui.component;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.dom4j.Document;
23 import org.dom4j.Node;
24 import org.pentaho.core.repository.ISolutionRepository;
25 import org.pentaho.core.solution.SimpleParameterProvider;
26 import org.pentaho.core.system.PentahoSystem;
27 import org.pentaho.ui.XmlComponent;
28 import org.pentaho.messages.Messages;
29
30 public class NavigationComponent extends XmlComponent implements INavigationComponent {
31
32     private static final long serialVersionUID = 851537694797388747L;
33
34     private static final Log logger = LogFactory.getLog(NavigationComponent.class);
35
36     public Log getLogger() {
37         return logger;
38     }
39
40     public NavigationComponent() {
41         super(null, null, null);
42         SimpleParameterProvider parameters = new SimpleParameterProvider();
43         setParameterProvider("options", parameters); //$NON-NLS-1$
44
}
45
46     /*
47      * (non-Javadoc)
48      *
49      * @see org.pentaho.core.ui.component.BaseUIComponent#validate()
50      */

51     public boolean validate() {
52         return true;
53     }
54
55     /*
56      * (non-Javadoc)
57      *
58      * @see org.pentaho.core.ui.IInterfaceComponent#getXmlContent()
59      */

60     public Document getXmlContent() {
61
62         String JavaDoc hrefUrl = getParameter("hrefurl", ""); //$NON-NLS-1$ //$NON-NLS-2$
63
String JavaDoc onClick = getParameter("onclick", ""); //$NON-NLS-1$ //$NON-NLS-2$
64
String JavaDoc solutionParamName = getParameter("solutionparam", ""); //$NON-NLS-1$ //$NON-NLS-2$;
65
String JavaDoc pathParamName = getParameter("pathparam", ""); //$NON-NLS-1$ //$NON-NLS-2$
66
String JavaDoc options = getParameter("options", ""); //$NON-NLS-1$ //$NON-NLS-2$
67
String JavaDoc path = getParameter(pathParamName, null);
68         String JavaDoc allowNavigation = getParameter("navigate", "true"); //$NON-NLS-1$ //$NON-NLS-2$
69

70         setXslProperty("href", hrefUrl); //$NON-NLS-1$
71
setXslProperty("onClick", onClick); //$NON-NLS-1$
72
setXslProperty("solutionParam", solutionParamName); //$NON-NLS-1$
73
setXslProperty("pathParam", pathParamName); //$NON-NLS-1$
74
setXslProperty("options", options); //$NON-NLS-1$
75
setXslProperty("navigate", allowNavigation); //$NON-NLS-1$
76
setXslProperty("baseUrl", urlFactory.getDisplayUrlBuilder().getUrl()); //$NON-NLS-1$
77
if ("".equals(path)) { //$NON-NLS-1$
78
path = null;
79         }
80         if (path != null) {
81             setXslProperty("path", path); //$NON-NLS-1$
82
}
83
84         ISolutionRepository repository = PentahoSystem.getSolutionRepository(getSession());
85
86         if( repository == null ) {
87                 error( Messages.getErrorString("NavigationComponent.ERROR_0001_BAD_SOLUTION_REPOSITORY") ); //$NON-NLS-1$
88
return null;
89         }
90         
91         String JavaDoc solution = getParameter(solutionParamName, null);
92         if( "".equals( solution ) ) { //$NON-NLS-1$
93
solution = null;
94         }
95         Document document = null;
96         // see if the xsl name has already been set
97
String JavaDoc xslName = getXsl("text/html"); //$NON-NLS-1$
98
if (solution == null) {
99             document = repository.getSolutions(ISolutionRepository.ACTION_EXECUTE);
100             if( xslName == null ) {
101                     Node node = document.selectSingleNode( "/repository/@displaytype" ); //$NON-NLS-1$
102
if( node != null ) {
103                         String JavaDoc displayType = node.getText();
104                         if( displayType.endsWith( ".xsl" ) ) { //$NON-NLS-1$
105
// this folder has a custom XSL
106
xslName = displayType;
107                         }
108                     }
109             }
110             if (xslName == null) {
111                 // the template has not been set, so provide a default
112
xslName = "files-list.xsl"; //$NON-NLS-1$
113
}
114         } else {
115             document = repository.getActionSequences(solution, path, false, true, ISolutionRepository.ACTION_EXECUTE);
116             if (debug)
117                 debug(document.asXML());
118             if( xslName == null ) {
119                 Node node = document.selectSingleNode( "/files/@displaytype" ); //$NON-NLS-1$
120
if( node != null ) {
121                     String JavaDoc displayType = node.getText();
122                     if( displayType.endsWith( ".xsl" ) ) { //$NON-NLS-1$
123
// this folder has a custom XSL
124
xslName = displayType;
125                     }
126                 }
127         }
128
129             setXslProperty("solution", solution); //$NON-NLS-1$
130
if (xslName == null) {
131                 // the template has not been set, so provide a default
132
xslName = "files-list.xsl"; //$NON-NLS-1$
133
}
134         }
135         
136         if (xslName != null) {
137             setXsl("text/html", xslName); //$NON-NLS-1$
138
}
139         return document;
140     }
141     
142     public void setHrefUrl(String JavaDoc hrefUrl) {
143         SimpleParameterProvider parameters = (SimpleParameterProvider) getParameterProviders().get("options"); //$NON-NLS-1$
144
parameters.setParameter("hrefurl", hrefUrl); //$NON-NLS-1$
145
}
146     
147     public void setOnClick(String JavaDoc onClick) {
148         SimpleParameterProvider parameters = (SimpleParameterProvider) getParameterProviders().get("options"); //$NON-NLS-1$
149
parameters.setParameter("onClick", onClick); //$NON-NLS-1$
150
}
151     
152     public void setAllowNavigation(Boolean JavaDoc allowNavigation) {
153         SimpleParameterProvider parameters = (SimpleParameterProvider) getParameterProviders().get("options"); //$NON-NLS-1$
154
parameters.setParameter("navigate", allowNavigation.toString()); //$NON-NLS-1$
155
}
156
157     public void setSolutionParamName(String JavaDoc solutionParamName) {
158         SimpleParameterProvider parameters = (SimpleParameterProvider) getParameterProviders().get("options"); //$NON-NLS-1$
159
parameters.setParameter("solutionparam", solutionParamName); //$NON-NLS-1$
160
}
161
162     public void setPathParamName(String JavaDoc solutionPathName) {
163         SimpleParameterProvider parameters = (SimpleParameterProvider) getParameterProviders().get("options"); //$NON-NLS-1$
164
parameters.setParameter("pathparam", solutionPathName); //$NON-NLS-1$
165
}
166
167     public void setOptions(String JavaDoc options) {
168         SimpleParameterProvider parameters = (SimpleParameterProvider) getParameterProviders().get("options"); //$NON-NLS-1$
169
parameters.setParameter("options", options); //$NON-NLS-1$
170
}
171 }
172
Popular Tags