use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.
the class ComponentBase method setFeedbackMimeType.
protected void setFeedbackMimeType(final String mimeType) {
IContentItem feedbackContentItem = runtimeContext.getFeedbackContentItem();
feedbackContentItem.setMimeType(mimeType);
}
use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.
the class RuntimeContext method getOutputItem.
public IContentItem getOutputItem(final String outputName, final String mimeType, final String extension) {
// TODO support content output versions in the action definition
IActionParameter outputParameter = getOutputParameter(outputName);
if (outputParameter == null) {
warn(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0021_INVALID_OUTPUT_REQUEST", outputName, // $NON-NLS-1$
actionSequence.getSequenceName()));
return null;
}
// $NON-NLS-1$
String filePath = "~/workspace/" + FilenameUtils.getBaseName(getSolutionPath()) + extension;
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String contentName = "contentrepo:" + filePath;
if (!IActionParameter.TYPE_CONTENT.equals(outputParameter.getType())) {
// $NON-NLS-1$
warn(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0023_INVALID_OUTPUT_STREAM", outputName));
return null;
}
try {
IContentOutputHandler output = PentahoSystem.getOutputDestinationFromContentRef(contentName, session);
if (output != null) {
// TODO get this info
output.setInstanceId(instanceId);
output.setSolutionPath(filePath);
output.setMimeType(mimeType);
output.setSession(session);
IContentItem contentItem = output.getFileOutputContentItem();
setOutputValue(outputName, contentItem);
return contentItem;
}
} catch (Exception e) {
// ignored
}
return null;
}
use of org.pentaho.platform.api.repository.IContentItem 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.repository.IContentItem in project pentaho-platform by pentaho.
the class RuntimeContext method setOutputValue.
public void setOutputValue(final String name, final Object output) {
IActionParameter actionParameter = paramManager.getCurrentOutput(name);
if (actionParameter == null) {
throw new InvalidParameterException(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0021_INVALID_OUTPUT_REQUEST", name, // $NON-NLS-1$
actionSequence.getSequenceName()));
}
actionParameter.setValue(output);
if (output instanceof String) {
runtimeData.setStringProperty(name, (String) output);
} else if (output instanceof Date) {
runtimeData.setDateProperty(name, (Date) output);
} else if (output instanceof Long) {
runtimeData.setLongProperty(name, (Long) output);
} else if (output instanceof List) {
runtimeData.setListProperty(name, (List) output);
} else if (output instanceof Map) {
runtimeData.setMapProperty(name, (Map) output);
} else if (output instanceof IContentItem) {
runtimeData.setStringProperty(name, ((IContentItem) output).getPath());
}
}
use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.
the class SimpleContentGenerator method createContent.
@Override
public void createContent() throws Exception {
OutputStream out = null;
if (outputHandler == null) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("SimpleContentGenerator.ERROR_0001_NO_OUTPUT_HANDLER"));
throw new InvalidParameterException(Messages.getInstance().getString(// $NON-NLS-1$
"SimpleContentGenerator.ERROR_0001_NO_OUTPUT_HANDLER"));
}
if (instanceId == null) {
setInstanceId(UUIDUtil.getUUIDAsString());
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IContentItem contentItem = outputHandler.getOutputContentItem("response", "content", instanceId, getMimeType());
if (contentItem == null) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("SimpleContentGenerator.ERROR_0002_NO_CONTENT_ITEM"));
throw new InvalidParameterException(Messages.getInstance().getString(// $NON-NLS-1$
"SimpleContentGenerator.ERROR_0002_NO_CONTENT_ITEM"));
}
contentItem.setMimeType(getMimeType());
out = contentItem.getOutputStream(itemName);
if (out == null) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("SimpleContentGenerator.ERROR_0003_NO_OUTPUT_STREAM"));
throw new InvalidParameterException(Messages.getInstance().getString(// $NON-NLS-1$
"SimpleContentGenerator.ERROR_0003_NO_OUTPUT_STREAM"));
}
createContent(out);
try {
// we created the output stream, let's be sure it's closed
// do not leave it up to the implementations of SimpleContentGenerator
// do do this or not
out.flush();
out.close();
} catch (Exception ignored) {
// this is cleanup code anyway, the output stream was probably
// closed by the impl
}
}
Aggregations