BaseUIComponent.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.pentaho.ui |
![]() |
![]() |
Pentaho |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* Copyright 2006 Pentaho Corporation. All rights reserved.
* This software was developed by Pentaho Corporation and is provided under the terms
* of the Mozilla Public License, Version 1.1, or any later version. You may not use
* this file except in compliance with the license. If you need a copy of the license,
* please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
* BI Platform. The Initial Developer is Pentaho Corporation.
*
* Software distributed under the Mozilla Public License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
* the license for the specific language governing your rights and limitations.
*
* @created Jul 22, 2005
* @author James Dixon
*
*/
package org.pentaho.ui;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.logging.Log;
import org.pentaho.core.services.IActionRequestHandler;
import org.pentaho.core.session.IPentahoSession;
import org.pentaho.core.solution.HttpRequestParameterProvider;
import org.pentaho.core.solution.HttpSessionParameterProvider;
import org.pentaho.core.solution.IParameterProvider;
import org.pentaho.core.system.PentahoMessenger;
import org.pentaho.core.system.PentahoSystem;
import org.pentaho.core.ui.IPentahoUrlFactory;
import org.pentaho.messages.Messages;
import org.pentaho.messages.util.LocaleHelper;
/**
* @author James Dixon
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public abstract class BaseUIComponent extends PentahoMessenger {
public static final boolean debug = PentahoSystem.debug;
protected HashMap xslProperties;
protected HashMap contentTypes;
private IActionRequestHandler requestHandler;
private IPentahoSession userSession;
public abstract Log getLogger();
private HashMap parameterProviders;
protected IPentahoUrlFactory urlFactory;
private String sourcePath;
public void handleRequest(OutputStream outputStream, IActionRequestHandler actionRequestHandler, String contentType,
HashMap requestParameterProviders) throws IOException {
this.parameterProviders = requestParameterProviders;
this.requestHandler = actionRequestHandler;
String content = getContent(contentType);
if (content != null) {
outputStream.write(content.getBytes(LocaleHelper.getSystemEncoding()));
} else {
error(Messages.getString("BaseUI.ERROR_0001_NO_CONTENT")); //$NON-NLS-1$
}
}
protected void setSourcePath(String sourcePath) {
this.sourcePath = sourcePath;
}
protected String getSourcePath() {
return sourcePath;
}
public void setUrlFactory(IPentahoUrlFactory urlFactory) {
this.urlFactory = urlFactory;
}
public void setRequestHandler(IActionRequestHandler actionRequestHandler) {
this.requestHandler = actionRequestHandler;
}
public BaseUIComponent(IPentahoUrlFactory urlFactory, List messages, String sourcePath) {
super();
this.urlFactory = urlFactory;
xslProperties = new HashMap();
contentTypes = new HashMap();
setMessages(messages);
parameterProviders = new HashMap();
this.sourcePath = sourcePath;
}
public void setParameterProvider(String name, IParameterProvider parameterProvider) {
if (parameterProviders == null) {
parameterProviders = new HashMap();
}
parameterProviders.put(name, parameterProvider);
}
public void setParameterProviders(HashMap parameterProviders) {
this.parameterProviders = parameterProviders;
}
protected IPentahoUrlFactory getUrlFactory() {
return urlFactory;
}
protected IActionRequestHandler getRequestHandler() {
return requestHandler;
}
public HashMap getParameterProviders() {
return parameterProviders;
}
public String getParameter(String name, String defaultValue) {
IParameterProvider parameterProvider = (IParameterProvider) parameterProviders.get("options"); //$NON-NLS-1$
String value = null;
if (parameterProvider != null) {
value = parameterProvider.getStringParameter(name, null);
if (value != null) {
return value;
}
}
parameterProvider = (IParameterProvider) parameterProviders.get(HttpRequestParameterProvider.SCOPE_REQUEST);
if (parameterProvider != null) {
value = parameterProvider.getStringParameter(name, null);
if (value != null) {
return value;
}
}
parameterProvider = (IParameterProvider) parameterProviders.get(HttpSessionParameterProvider.SCOPE_SESSION);
if (parameterProvider != null) {
value = parameterProvider.getStringParameter(name, null);
if (value != null) {
return value;
}
}
return defaultValue;
}
public String[] getParameterAsArray(String name) {
IParameterProvider parameterProvider = (IParameterProvider) parameterProviders.get("options"); //$NON-NLS-1$
Object value;
if (parameterProvider != null) {
value = parameterProvider.getParameter(name);
if (value != null) {
return toStringArray(value);
}
}
parameterProvider = (IParameterProvider) parameterProviders.get(HttpRequestParameterProvider.SCOPE_REQUEST);
if (parameterProvider != null) {
value = parameterProvider.getParameter(name);
if (value != null) {
return toStringArray(value);
}
}
parameterProvider = (IParameterProvider) parameterProviders.get(HttpSessionParameterProvider.SCOPE_SESSION);
if (parameterProvider != null) {
value = parameterProvider.getParameter(name);
if (value != null) {
return toStringArray(value);
}
}
return (new String[] {});
}
private String[] toStringArray(Object value) {
if (value == null) {
return (new String[] {});
}
if (value instanceof String[]) {
return ((String[]) value);
}
return (new String[] { value.toString() });
}
protected IPentahoSession getSession() {
return userSession;
}
public void setXsl(String mimeType, String xslName) {
contentTypes.put(mimeType, xslName);
}
public String getXsl(String mimeType) {
return (String) contentTypes.get(mimeType);
}
public abstract boolean validate();
/**
* Set the userSession member, generate a Log Id, set the requestHandler, and validate
* the component's configuration.
* NOTE: this method has several side effects not related to validation. could
* probably use some refactoring
*
* @param session
* @param actionRequestHandler
* @return boolean true if component configuration is valid, else false
*/
public boolean validate(IPentahoSession session, IActionRequestHandler actionRequestHandler) {
this.userSession = session;
this.genLogIdFromSession(session);
this.requestHandler = actionRequestHandler;
return validate();
}
public void setXslProperty(String name, String value) {
xslProperties.put(name, value);
}
public HashMap getXslProperties() {
return xslProperties;
}
public abstract String getContent(String mimeType);
public void done() {
}
}
The table below shows all metrics for BaseUIComponent.java.




