use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.
the class BaseTest method run.
public IRuntimeContext run(ISolutionEngine solutionEngine, String actionPath, String instanceId, boolean persisted, IParameterProvider parameterProvider, IOutputHandler outputHandler) {
assertTrue(initOk);
// $NON-NLS-1$
info(Messages.getInstance().getString("BaseTest.INFO_START_TEST_MSG", actionPath));
info(actionPath);
// $NON-NLS-1$
String baseUrl = "";
HashMap<String, IParameterProvider> parameterProviderMap = new HashMap<String, IParameterProvider>();
parameterProviderMap.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
IPentahoUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
dispose();
context = solutionEngine.execute(actionPath, Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_TEST"), false, true, instanceId, persisted, parameterProviderMap, outputHandler, this, urlFactory, // $NON-NLS-1$
messages);
// $NON-NLS-1$
info(Messages.getInstance().getString("BaseTest.INFO_FINISH_TEST_MSG", actionPath));
return context;
}
use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.
the class RuntimeContext method sendFeedbackForm.
// Feebdack form handling
public void sendFeedbackForm() throws ActionSequencePromptException {
try {
if (!feedbackAllowed()) {
return;
}
// add the standard parameters that we need
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
createFeedbackParameter("path", "path", "", getSolutionPath(), false);
// ProSolutionEngine proSolutionEngine = (ProSolutionEngine) solutionEngine;
// $NON-NLS-1$
IParameterProvider parameterProvider = (IParameterProvider) parameterProviders.get("PRO_EDIT_SUBSCRIPTION");
if (parameterProvider == null) {
// Then we are not editing subscriptions
parameterProvider = (IParameterProvider) parameterProviders.get(IParameterProvider.SCOPE_REQUEST);
} else {
// $NON-NLS-1$
parameterProvider.getStringParameter("subscribe-id", null);
}
Iterator parameterNameIterator = parameterProvider.getParameterNames();
while (parameterNameIterator.hasNext()) {
String name = (String) parameterNameIterator.next();
if (!"path".equals(name) && (xformFields.get(name) == null)) {
// TODO we need to check to see if this has been handled as
// a control before adding a hidden field
Object value = parameterProvider.getParameter(name);
if (value != null) {
// $NON-NLS-1$
createFeedbackParameter(name, name, "", value, false);
}
}
}
SolutionURIResolver resolver = new SolutionURIResolver();
if (parameterXsl == null) {
// Generate XForm for the parameters needed, transform into
// HTML, and float it down the feedback stream
// $NON-NLS-1$
xformBody.append("<tr><td>");
XForm.createXFormSubmit(RuntimeContext.PARAMETER_FORM, xformBody, Messages.getInstance().getString(// $NON-NLS-1$
"RuntimeContext.USER_PARAMETER_FORM_SUBMIT"));
// $NON-NLS-1$
xformBody.append("</td></tr></table></body>");
String html = XForm.completeXForm(XForm.OUTPUT_HTML_PAGE, RuntimeContext.PARAMETER_FORM, xformHeader, xformBody, getSession(), resolver);
if (RuntimeContext.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("RuntimeContext.DEBUG_PARAMETER_HTML", html));
}
// $NON-NLS-1$
outputHandler.getFeedbackContentItem().setMimeType("text/html");
OutputStream os = outputHandler.getFeedbackContentItem().getOutputStream(getActionName());
os.write(html.getBytes());
} else if (parameterTemplate != null) {
String html = XForm.completeXForm(XForm.OUTPUT_HTML_PAGE, RuntimeContext.PARAMETER_FORM, xformHeader, new StringBuffer(parameterTemplate), getSession(), resolver);
if (RuntimeContext.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("RuntimeContext.DEBUG_PARAMETER_HTML", html));
}
IContentItem contentItem = outputHandler.getFeedbackContentItem();
// $NON-NLS-1$
contentItem.setMimeType("text/html");
OutputStream os = contentItem.getOutputStream(getActionName());
os.write(html.getBytes(LocaleHelper.getSystemEncoding()));
os.close();
} else if (parameterXsl.endsWith(".xsl")) {
// $NON-NLS-1$
String id = actionSequence.getSequenceName();
int pos = id.indexOf('.');
if (pos > -1) {
id = id.substring(0, pos);
}
// make sure the id can form a valid javascript variable or
// function name
id = id.replace('-', '_');
id = id.replace(' ', '_');
String actionUrl = urlFactory.getActionUrlBuilder().getUrl();
String displayUrl = urlFactory.getDisplayUrlBuilder().getUrl();
// String target = (parameterTarget == null) ? "" : parameterTarget; //$NON-NLS-1$
XForm.completeXFormHeader(RuntimeContext.PARAMETER_FORM, xformHeader);
Document document = XmlDom4JHelper.getDocFromString(// $NON-NLS-1$ //$NON-NLS-2$
"<?xml version=\"1.0\" encoding=\"" + LocaleHelper.getSystemEncoding() + "\" ?><filters xmlns:xf=\"http://www.w3.org/2002/xforms\">" + xformHeader + // $NON-NLS-1$
"<id><![CDATA[" + id + // $NON-NLS-1$
"]]></id><title><![CDATA[" + Messages.getInstance().getEncodedString(actionSequence.getTitle()) + // $NON-NLS-1$
"]]></title><description><![CDATA[" + Messages.getInstance().getEncodedString(actionSequence.getDescription()) + // $NON-NLS-1$
"]]></description><icon><![CDATA[" + actionSequence.getIcon() + // $NON-NLS-1$
"]]></icon><help><![CDATA[" + Messages.getInstance().getEncodedString(actionSequence.getHelp()) + // $NON-NLS-1$
"]]></help>" + "<action><![CDATA[" + actionUrl + // $NON-NLS-1$ //$NON-NLS-2$
"]]></action>" + "<display><![CDATA[" + displayUrl + // $NON-NLS-1$ //$NON-NLS-2$
"]]></display>" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
((parameterTarget != null) ? "<target>" + parameterTarget + "</target>" : "") + xformBody.toString() + "</filters>", // $NON-NLS-1$
null);
// add any subscription information here
Element root = document.getRootElement();
// notify the xsl whether we're in parameter view or not.
root.addAttribute("parameterView", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
(getOutputPreference() == IOutputHandler.OUTPUT_TYPE_PARAMETERS) ? "true" : "false");
Map<String, String> parameters = new HashMap<String, String>();
// $NON-NLS-1$
parameters.put("baseUrl", PentahoSystem.getApplicationContext().getBaseUrl());
// $NON-NLS-1$
parameters.put("actionUrl", this.getUrlFactory().getActionUrlBuilder().getUrl());
// $NON-NLS-1$
parameters.put("displayUrl", this.getUrlFactory().getDisplayUrlBuilder().getUrl());
// Uncomment this line for troubleshooting the XSL.
StringBuffer content = XmlHelper.transformXml(parameterXsl, getSolutionPath(), document.asXML(), parameters, resolver);
IContentItem contentItem = outputHandler.getFeedbackContentItem();
// $NON-NLS-1$
contentItem.setMimeType("text/html");
OutputStream os = contentItem.getOutputStream(getActionName());
try {
os.write(content.toString().getBytes(LocaleHelper.getSystemEncoding()));
} finally {
if (os != null) {
os.close();
}
}
}
/*
* We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
* contextual information, including the root cause. Allowing unchecked exceptions to pass through would
* prevent valuable feedback in the log or response.
*/
} catch (Throwable e) {
throw new ActionSequencePromptException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"RuntimeContext.ERROR_0030_SEND_FEEDBACKFORM"), // $NON-NLS-1$
e, session.getName(), instanceId, getActionSequence().getSequenceName(), null);
}
}
use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.
the class RuntimeContext method createFeedbackParameter.
public void createFeedbackParameter(String fieldName, final String displayName, String hint, Object defaultValue, final boolean visible, final boolean optional) {
// If there is a "PRO_EDIT_SUBSCRIPTION" param provider, then we must be editing a subscription so use its
// values
// $NON-NLS-1$
IParameterProvider parameterProvider = (IParameterProvider) parameterProviders.get("PRO_EDIT_SUBSCRIPTION");
if (parameterProvider != null) {
Object newValue = parameterProvider.getParameter(paramManager.getActualRequestParameterName(fieldName));
defaultValue = newValue == null ? defaultValue : newValue;
}
if (createFeedbackParameterCallback != null) {
createFeedbackParameterCallback.createFeedbackParameter(this, fieldName, displayName, hint, defaultValue, null, null, null, optional, visible);
}
if ((xformHeader == null) || (xformHeader.length() == 0)) {
// this is the first parameter, need to create the header...
addXFormHeader();
}
if (parameterTemplate != null) {
// see if the parameter is defined in the HTML template
if (checkForFieldInTemplate(fieldName)) {
return;
}
}
if (hint == null) {
// $NON-NLS-1$
hint = "";
}
fieldName = paramManager.getActualRequestParameterName(fieldName);
if (parameterXsl == null) {
if (visible) {
xformBody.append(Messages.getInstance().getString("RuntimeContext.CODE_XFORM_CONTROL_LABEL_START", // $NON-NLS-1$
displayName));
}
XForm.createXFormControl(fieldName, defaultValue, RuntimeContext.PARAMETER_FORM, xformHeader, xformBody, visible);
if (visible) {
// $NON-NLS-1$
xformBody.append(Messages.getInstance().getString("RuntimeContext.CODE_XFORM_CONTROL_LABEL_END"));
}
} else if (parameterTemplate != null) {
StringBuffer body = new StringBuffer();
if (visible) {
XForm.createXFormControl(fieldName, defaultValue, RuntimeContext.PARAMETER_FORM, xformHeader, body, visible);
} else {
try {
if (defaultValue instanceof Object[]) {
setObjectArrayParameters(fieldName, (Object[]) defaultValue);
}
String value = StringEscapeUtils.escapeXml(defaultValue.toString());
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
body.append("<input type=\"hidden\" name=\"" + fieldName + "\" value=\"" + value + "\"></input>");
} catch (Exception e) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
body.append("<input type=\"hidden\" name=\"" + fieldName + "\" value=\"" + defaultValue + "\"></input>");
}
}
// $NON-NLS-1$ //$NON-NLS-2$
parameterTemplate = parameterTemplate.replaceAll("\\{" + fieldName + "\\}", Matcher.quoteReplacement(body.toString()));
} else {
if (visible) {
StringBuffer body = new StringBuffer();
XForm.createXFormControl(fieldName, defaultValue, RuntimeContext.PARAMETER_FORM, xformHeader, body, visible);
// $NON-NLS-1$
xformBody.append("<filter");
if (optional) {
// $NON-NLS-1$
xformBody.append(" optional=\"true\"");
}
// $NON-NLS-1$ //$NON-NLS-2$
xformBody.append("><id><![CDATA[" + fieldName + "]]></id>").append(// $NON-NLS-1$ //$NON-NLS-2$
"<title><![CDATA[" + displayName + "]]></title>").append(// $NON-NLS-1$ //$NON-NLS-2$
"<help><![CDATA[" + hint + "]]></help><control>").append(body).append(// $NON-NLS-1$
"</control></filter>");
} else {
try {
if (defaultValue instanceof Object[]) {
setObjectArrayParameters(fieldName, (Object[]) defaultValue);
} else {
// $NON-NLS-1$//$NON-NLS-2$
String value = defaultValue.toString().replaceAll("&", "&");
// $NON-NLS-1$ //$NON-NLS-2$
value = value.replaceAll("\"", "''");
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
xformBody.append("<input type=\"hidden\" name=\"" + fieldName + "\" value=\"" + value + "\"></input>");
}
} catch (Exception e) {
xformBody.append(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"<input type=\"hidden\" name=\"" + fieldName + "\" value=\"" + defaultValue + "\"></input>");
}
}
}
xformFields.put(fieldName, fieldName);
}
use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.
the class RuntimeContext method createFeedbackParameter.
public void createFeedbackParameter(String fieldName, final String displayName, String hint, Object defaultValues, final List values, final Map dispNames, final String displayStyle, final boolean optional) {
if (createFeedbackParameterCallback != null) {
createFeedbackParameterCallback.createFeedbackParameter(this, fieldName, displayName, hint, defaultValues, values, dispNames, displayStyle, optional, true);
}
// If there is a "PRO_EDIT_SUBSCRIPTION" param provider, then we must be editing a subscription so use its
// values
// $NON-NLS-1$
IParameterProvider parameterProvider = (IParameterProvider) parameterProviders.get("PRO_EDIT_SUBSCRIPTION");
if (parameterProvider != null) {
defaultValues = parameterProvider.getParameter(paramManager.getActualRequestParameterName(fieldName));
}
if (values == null) {
return;
}
if ((xformHeader == null) || (xformHeader.length() == 0)) {
// this is the first parameter, need to create the header...
addXFormHeader();
}
// don't add it to the XForm.
if (checkForFieldInTemplate(fieldName)) {
return;
}
int type = (values.size() < 6) ? XForm.TYPE_RADIO : XForm.TYPE_SELECT;
if (displayStyle != null) {
if ("text-box".equals(displayStyle)) {
// $NON-NLS-1$
type = XForm.TYPE_TEXT;
} else if ("radio".equals(displayStyle)) {
// $NON-NLS-1$
type = XForm.TYPE_RADIO;
} else if ("select".equals(displayStyle)) {
// $NON-NLS-1$
type = XForm.TYPE_SELECT;
} else if ("list".equals(displayStyle)) {
// $NON-NLS-1$
type = XForm.TYPE_LIST;
} else if ("list-multi".equals(displayStyle)) {
// $NON-NLS-1$
type = XForm.TYPE_LIST_MULTI;
} else if ("check-multi".equals(displayStyle)) {
// $NON-NLS-1$
type = XForm.TYPE_CHECK_MULTI;
} else if ("check-multi-scroll".equals(displayStyle)) {
// $NON-NLS-1$
type = XForm.TYPE_CHECK_MULTI_SCROLL;
} else if ("check-multi-scroll-2-column".equals(displayStyle)) {
// $NON-NLS-1$
type = XForm.TYPE_CHECK_MULTI_SCROLL_2_COLUMN;
} else if ("check-multi-scroll-3-column".equals(displayStyle)) {
// $NON-NLS-1$
type = XForm.TYPE_CHECK_MULTI_SCROLL_3_COLUMN;
} else if ("check-multi-scroll-4-column".equals(displayStyle)) {
// $NON-NLS-1$
type = XForm.TYPE_CHECK_MULTI_SCROLL_4_COLUMN;
}
}
fieldName = paramManager.getActualRequestParameterName(fieldName);
if (hint == null) {
// $NON-NLS-1$
hint = "";
}
if (parameterXsl == null) {
// create some xform to represent this parameter...
xformBody.append(// $NON-NLS-1$
Messages.getInstance().getString("RuntimeContext.CODE_XFORM_CONTROL_LABEL_START", displayName));
XForm.createXFormControl(type, fieldName, defaultValues, values, dispNames, RuntimeContext.PARAMETER_FORM, xformHeader, xformBody);
// $NON-NLS-1$
xformBody.append(Messages.getInstance().getString("RuntimeContext.CODE_XFORM_CONTROL_LABEL_END"));
} else if (parameterTemplate != null) {
StringBuffer body = new StringBuffer();
XForm.createXFormControl(type, fieldName, defaultValues, values, dispNames, RuntimeContext.PARAMETER_FORM, xformHeader, body);
// $NON-NLS-1$ //$NON-NLS-2$
parameterTemplate = parameterTemplate.replaceAll("\\{" + fieldName + "\\}", body.toString());
} else if (parameterXsl.endsWith(".xsl")) {
// $NON-NLS-1$
StringBuffer body = new StringBuffer();
XForm.createXFormControl(type, fieldName, defaultValues, values, dispNames, RuntimeContext.PARAMETER_FORM, xformHeader, body);
// $NON-NLS-1$
xformBody.append("<filter");
if (optional) {
// $NON-NLS-1$
xformBody.append(" optional=\"true\"");
}
// $NON-NLS-1$ //$NON-NLS-2$
xformBody.append("><id><![CDATA[" + fieldName + "]]></id>").append(// $NON-NLS-1$ //$NON-NLS-2$
"<title><![CDATA[" + displayName + "]]></title>").append(// $NON-NLS-1$ //$NON-NLS-2$
"<help><![CDATA[" + hint + "]]></help><control>").append(body).append(// $NON-NLS-1$
"</control></filter>");
}
xformFields.put(fieldName, fieldName);
}
use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.
the class RuntimeContext method resolveParameters.
private void resolveParameters() throws UnresolvedParameterException {
Set inputNames = getInputNames();
Iterator inputNamesIterator = inputNames.iterator();
IActionParameter actionParameter;
List variables;
Iterator variablesIterator;
ActionParameterSource variable;
String sourceName;
String sourceValue;
Object variableValue = null;
IParameterProvider parameterProvider;
while (inputNamesIterator.hasNext()) {
variableValue = null;
String inputName = (String) inputNamesIterator.next();
actionParameter = paramManager.getCurrentInput(inputName);
if (actionParameter == null) {
throw new UnresolvedParameterException(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0031_INPUT_NOT_FOUND", // $NON-NLS-1$
inputName), session.getName(), instanceId, getActionSequence().getSequenceName(), null);
}
variables = actionParameter.getVariables();
variablesIterator = variables.iterator();
while (variablesIterator.hasNext()) {
variable = (ActionParameterSource) variablesIterator.next();
sourceName = variable.getSourceName();
sourceValue = variable.getValue();
variableValue = null;
// e.g. runtme.parent
if ("runtime".equals(sourceName)) {
// $NON-NLS-1$
// first check the standard variables
variableValue = getStringParameter(sourceValue, null);
if (variableValue == null) {
// now check the runtime data
variableValue = runtimeData.getStringProperty(sourceValue, null);
}
if (variableValue != null) {
break;
}
} else {
parameterProvider = (IParameterProvider) parameterProviders.get(sourceName);
if (parameterProvider == null) {
warn(Messages.getInstance().getString("RuntimeContext.WARN_REQUESTED_PARAMETER_SOURCE_NOT_AVAILABLE", sourceName, // $NON-NLS-1$
inputName));
} else {
variableValue = parameterProvider.getParameter(sourceValue);
if (variableValue != null) {
break;
}
}
}
}
if (variableValue == null) {
if (actionParameter.getValue() != null) {
if (actionParameter.hasDefaultValue()) {
if (PentahoSystem.trace) {
// $NON-NLS-1$
trace(Messages.getInstance().getString("RuntimeContext.TRACE_USING_DEFAULT_PARAMETER_VALUE", inputName));
}
} else {
if (PentahoSystem.trace) {
trace(Messages.getInstance().getString(// $NON-NLS-1$
"RuntimeContext.TRACE_INFO_USING_CURRENT_PARAMETER_VALUE" + inputName));
}
}
} else if ("content".equals(actionParameter.getType())) {
// $NON-NLS-1$
// $NON-NLS-1$
variableValue = "";
}
} else {
actionParameter.setValue(variableValue);
}
}
// while
}
Aggregations