001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Jul 22, 2005
014: * @author James Dixon
015: *
016: */
017:
018: package org.pentaho.ui.component;
019:
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022: import org.dom4j.Document;
023: import org.pentaho.core.repository.ISolutionRepository;
024: import org.pentaho.core.solution.SimpleParameterProvider;
025: import org.pentaho.core.system.PentahoSystem;
026: import org.pentaho.messages.Messages;
027: import org.pentaho.ui.XmlComponent;
028:
029: public class NavigationComponent extends XmlComponent implements
030: INavigationComponent {
031:
032: private static final long serialVersionUID = 851537694797388747L;
033:
034: private static final Log logger = LogFactory
035: .getLog(NavigationComponent.class);
036:
037: public Log getLogger() {
038: return logger;
039: }
040:
041: public NavigationComponent() {
042: super (null, null, null);
043: SimpleParameterProvider parameters = new SimpleParameterProvider();
044: setParameterProvider("options", parameters); //$NON-NLS-1$
045: }
046:
047: /*
048: * (non-Javadoc)
049: *
050: * @see org.pentaho.core.ui.component.BaseUIComponent#validate()
051: */
052: public boolean validate() {
053: return true;
054: }
055:
056: /*
057: * (non-Javadoc)
058: *
059: * @see org.pentaho.core.ui.IInterfaceComponent#getXmlContent()
060: */
061: public Document getXmlContent() {
062:
063: String hrefUrl = getParameter("hrefurl", ""); //$NON-NLS-1$ //$NON-NLS-2$
064: String onClick = getParameter("onclick", ""); //$NON-NLS-1$ //$NON-NLS-2$
065: String solutionParamName = getParameter("solutionparam", ""); //$NON-NLS-1$ //$NON-NLS-2$;
066: String pathParamName = getParameter("pathparam", ""); //$NON-NLS-1$ //$NON-NLS-2$
067: String options = getParameter("options", ""); //$NON-NLS-1$ //$NON-NLS-2$
068: String path = getParameter(pathParamName, null);
069: String allowNavigation = getParameter("navigate", "true"); //$NON-NLS-1$ //$NON-NLS-2$
070:
071: setXslProperty("href", hrefUrl); //$NON-NLS-1$
072: setXslProperty("onClick", onClick); //$NON-NLS-1$
073: setXslProperty("solutionParam", solutionParamName); //$NON-NLS-1$
074: setXslProperty("pathParam", pathParamName); //$NON-NLS-1$
075: setXslProperty("options", options); //$NON-NLS-1$
076: setXslProperty("navigate", allowNavigation); //$NON-NLS-1$
077: setXslProperty(
078: "baseUrl", urlFactory.getDisplayUrlBuilder().getUrl()); //$NON-NLS-1$
079: if ("".equals(path)) { //$NON-NLS-1$
080: path = null;
081: }
082: if (path != null) {
083: setXslProperty("path", path); //$NON-NLS-1$
084: }
085:
086: ISolutionRepository repository = PentahoSystem
087: .getSolutionRepository(getSession());
088:
089: if (repository == null) {
090: error(Messages
091: .getErrorString("NavigationComponent.ERROR_0001_BAD_SOLUTION_REPOSITORY")); //$NON-NLS-1$
092: return null;
093: }
094:
095: String solution = getParameter(solutionParamName, null);
096: if ("".equals(solution)) { //$NON-NLS-1$
097: solution = null;
098: }
099: Document document = repository.getNavigationUIDocument(
100: solution, path, ISolutionRepository.ACTION_EXECUTE);
101:
102: // see if the xsl name has already been set
103: String startingXSLName = getXsl("text/html"); //$NON-NLS-1$
104: String xslName = repository.getXSLName(document, solution,
105: startingXSLName);
106:
107: setXslProperty("solution", solution); //$NON-NLS-1$
108: if (xslName == null) {
109: // the template has not been set, so provide a default
110: xslName = "files-list.xsl"; //$NON-NLS-1$
111: }
112: setXsl("text/html", xslName); //$NON-NLS-1$
113: return document;
114: }
115:
116: public void setHrefUrl(String hrefUrl) {
117: SimpleParameterProvider parameters = (SimpleParameterProvider) getParameterProviders()
118: .get("options"); //$NON-NLS-1$
119: parameters.setParameter("hrefurl", hrefUrl); //$NON-NLS-1$
120: }
121:
122: public void setOnClick(String onClick) {
123: SimpleParameterProvider parameters = (SimpleParameterProvider) getParameterProviders()
124: .get("options"); //$NON-NLS-1$
125: parameters.setParameter("onClick", onClick); //$NON-NLS-1$
126: }
127:
128: public void setAllowNavigation(Boolean allowNavigation) {
129: SimpleParameterProvider parameters = (SimpleParameterProvider) getParameterProviders()
130: .get("options"); //$NON-NLS-1$
131: parameters.setParameter("navigate", allowNavigation.toString()); //$NON-NLS-1$
132: }
133:
134: public void setSolutionParamName(String solutionParamName) {
135: SimpleParameterProvider parameters = (SimpleParameterProvider) getParameterProviders()
136: .get("options"); //$NON-NLS-1$
137: parameters.setParameter("solutionparam", solutionParamName); //$NON-NLS-1$
138: }
139:
140: public void setPathParamName(String solutionPathName) {
141: SimpleParameterProvider parameters = (SimpleParameterProvider) getParameterProviders()
142: .get("options"); //$NON-NLS-1$
143: parameters.setParameter("pathparam", solutionPathName); //$NON-NLS-1$
144: }
145:
146: public void setOptions(String options) {
147: SimpleParameterProvider parameters = (SimpleParameterProvider) getParameterProviders()
148: .get("options"); //$NON-NLS-1$
149: parameters.setParameter("options", options); //$NON-NLS-1$
150: }
151: }
|