use of org.pentaho.platform.engine.services.actionsequence.ActionSequenceResource in project pentaho-platform by pentaho.
the class DashboardWidgetComponent method getXmlContent.
/**
* Create a dial image.
* <ul>
* <li>Load the specified XML document describing the dial definition</li>
* <li>Create a dial definition object from the XML definition</li>
* <li>Use the JFreeChartEngine to create a dial image</li>
* <li>Create an XML document describing the dial</li>
* <li>Return the XML document</li>
* </ul>
*
* @return The XML document describing this dial
*/
@Override
public Document getXmlContent() {
WidgetDefinition widget = null;
if (type == DashboardWidgetComponent.TYPE_DIAL) {
// load the XML document that defines the dial
IActionSequenceResource resource = new // $NON-NLS-1$
ActionSequenceResource(// $NON-NLS-1$
title, // $NON-NLS-1$
IActionSequenceResource.SOLUTION_FILE_RESOURCE, // $NON-NLS-1$
"text/xml", definitionPath);
Document dialDefinition = null;
try {
org.dom4j.io.SAXReader reader = XMLParserFactoryProducer.getSAXReader(new SolutionURIResolver());
dialDefinition = reader.read(resource.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale()));
} catch (Throwable t) {
// XML document can't be read. We'll just return a null document.
}
if (dialDefinition == null) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("Widget.ERROR_0002_INVALID_RESOURCE", definitionPath));
return null;
}
// create a dial definition from the XML definition
widget = new DialWidgetDefinition(dialDefinition, 0, width, height, getSession());
if (widget != null) {
// set the value to be displayed on the dial
widget.setValue(new Double(value));
}
}
/*
* else if( type == TYPE_THERMOMETER ) { // load the XML document that defines the thermometer
*
* ActionResource resource = new ActionResource( title, IActionResource.SOLUTION_FILE_RESOURCE, "text/xml",
* //$NON-NLS-1$ PentahoSystem.getApplicationContext().getSolutionPath( definitionPath ) ); //$NON-NLS-1$
* Document thermometerDefinition = null; try { thermometerDefinition = PentahoSystem.getResourceAsDocument(
* resource ); } catch (IOException e) {} // create a dial definition from the XML definition widget =
* createThermometer( thermometerDefinition );
*
* if( widget != null ) { // set the value to be displayed on the dial widget.setValue( new Double(value) ); //
* Set the XSL file to be used to generate the HTML setXsl( "text/html", "DialWidget.xsl" ); //$NON-NLS-1$
* //$NON-NLS-2$ } else { error( Messages.getInstance().getString("Widget.ERROR_0001_COULD_NOT_CREATE") );
* //$NON-NLS-1$ return null; } }
*/
if (widget == null) {
// $NON-NLS-1$
error(Messages.getInstance().getString("Widget.ERROR_0001_COULD_NOT_CREATE"));
return null;
}
// create an image for the dial using the JFreeChart engine
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
// create temporary file names
// $NON-NLS-1$
String solutionDir = "system/tmp/";
// $NON-NLS-1$
String fileNamePrefix = "tmp_pie_";
// $NON-NLS-1$
String extension = ".png";
String fileName = null;
String filePathWithoutExtension = null;
try {
File file = PentahoSystem.getApplicationContext().createTempFile(getSession(), fileNamePrefix, extension, true);
fileName = file.getName();
filePathWithoutExtension = solutionDir + fileName.substring(0, fileName.indexOf('.'));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// $NON-NLS-1$
String dialTitle = "";
JFreeChartEngine.saveChart(widget, dialTitle, units, filePathWithoutExtension, width, height, JFreeChartEngine.OUTPUT_PNG, printWriter, this);
// Create a document that describes the result
Document result = DocumentHelper.createDocument();
IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
setXslProperty("baseUrl", requestContext.getContextPath());
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
setXslProperty("fullyQualifiedServerUrl", PentahoSystem.getApplicationContext().getFullyQualifiedServerURL());
// $NON-NLS-1$
Element root = result.addElement("widget");
// $NON-NLS-1$
root.addElement("title").setText(title);
// $NON-NLS-1$
root.addElement("units").setText(units);
// $NON-NLS-1$
root.addElement("width").setText(Integer.toString(width));
// $NON-NLS-1$
root.addElement("height").setText(Integer.toString(height));
// $NON-NLS-1$
Element valueNode = root.addElement("value");
valueNode.setText(Double.toString(value));
// $NON-NLS-1$
valueNode.addAttribute("in-image", Boolean.toString(widget.getValueFont() != null));
// $NON-NLS-1$
root.addElement("image").setText(fileName);
return result;
}
use of org.pentaho.platform.engine.services.actionsequence.ActionSequenceResource in project pentaho-platform by pentaho.
the class GetResource method doPost.
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
// TODO perform any authorization here...
// TODO support caching
PentahoSystem.systemEntryPoint();
try {
IPentahoSession session = getPentahoSession(request);
// $NON-NLS-1$
String resource = request.getParameter("resource");
if ((resource == null) || StringUtil.doesPathContainParentPathSegment(resource)) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("GetResource.ERROR_0001_RESOURCE_PARAMETER_MISSING"));
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
return;
}
String resLower = resource.toLowerCase();
String resourcePath;
if (resLower.endsWith(".xsl")) {
// $NON-NLS-1$
// $NON-NLS-1$
resourcePath = "system/custom/xsl/" + resource;
} else if (resLower.endsWith(".mondrian.xml")) {
// $NON-NLS-1$
// Ensure user is authenticated by checking the default role
// gets defaultRole from pentahoObjects-s-s.x
String defaultRole = PentahoSystem.get(String.class, "defaultRole", null);
if (defaultRole != null) {
if (!SecurityHelper.getInstance().isGranted(session, new SimpleGrantedAuthority(defaultRole))) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
}
// If no defaultRole is defined, then just continue action as per normal.
resourcePath = resource;
} else if (resLower.endsWith(".jpg") || resLower.endsWith(".jpeg") || resLower.endsWith(".gif") || resLower.endsWith(".png") || resLower.endsWith(".bmp")) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
resourcePath = resource;
} else {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("GetResource.ERROR_0002_INVALID_FILE", resource));
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
return;
}
IActionSequenceResource asqr = new // $NON-NLS-1$ //$NON-NLS-2$
ActionSequenceResource(// $NON-NLS-1$ //$NON-NLS-2$
"", // $NON-NLS-1$ //$NON-NLS-2$
IActionSequenceResource.SOLUTION_FILE_RESOURCE, // $NON-NLS-1$ //$NON-NLS-2$
"", resourcePath);
InputStream in = asqr.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale());
if (in == null) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("GetResource.ERROR_0003_RESOURCE_MISSING", resourcePath));
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
return;
}
String mimeType = getServletContext().getMimeType(resourcePath);
String resourceName = resourcePath;
if (resourcePath.indexOf("/") != -1) {
// $NON-NLS-1$
// $NON-NLS-1$
resourceName = resourcePath.substring(resourcePath.lastIndexOf("/") + 1);
}
// $NON-NLS-1$ //$NON-NLS-2$
response.setHeader("content-disposition", "attachment;filename=" + resourceName);
if ((null == mimeType) || (mimeType.length() <= 0)) {
// Hard coded to PNG because BIRT does not give us a mime type at
// all...
// $NON-NLS-1$
response.setContentType("image/png");
} else {
response.setContentType(mimeType);
}
response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
// $NON-NLS-1$ //$NON-NLS-2$
response.setHeader("expires", "0");
// Open the input and output streams
OutputStream out = response.getOutputStream();
try {
// Copy the contents of the file to the output stream
byte[] buf = new byte[1024];
int count = 0;
int totalBytes = 0;
while ((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);
totalBytes += count;
}
response.setContentLength(totalBytes);
} finally {
in.close();
out.close();
}
} finally {
PentahoSystem.systemExitPoint();
}
}
use of org.pentaho.platform.engine.services.actionsequence.ActionSequenceResource in project pentaho-platform by pentaho.
the class SolutionURIResolver method loadXsl.
public InputStream loadXsl(final String name) {
InputStream xslIS = null;
IActionSequenceResource resource = new // $NON-NLS-1$ //$NON-NLS-2$
ActionSequenceResource(// $NON-NLS-1$ //$NON-NLS-2$
"", // $NON-NLS-1$ //$NON-NLS-2$
IActionSequenceResource.SOLUTION_FILE_RESOURCE, // $NON-NLS-1$ //$NON-NLS-2$
"text/xml", name);
xslIS = resource.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale());
return xslIS;
}
use of org.pentaho.platform.engine.services.actionsequence.ActionSequenceResource in project pentaho-platform by pentaho.
the class PentahoResourceData method getResourceAsStream.
/**
* gets a resource stream from the runtime context.
*
* @param caller
* resource manager
* @return input stream
*/
public InputStream getResourceAsStream(final ResourceManager caller) throws ResourceLoadingException {
int resourceType = IActionResource.SOLUTION_FILE_RESOURCE;
if (filename.contains("://")) {
resourceType = IActionResource.URL_RESOURCE;
}
final IActionSequenceResource resource = // $NON-NLS-1$ //$NON-NLS-2$
new ActionSequenceResource("", resourceType, "application/binary", (String) key.getIdentifier());
return resource.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale());
}
use of org.pentaho.platform.engine.services.actionsequence.ActionSequenceResource in project pentaho-platform by pentaho.
the class SolutionURIResolver method resolve.
/*
* (non-Javadoc)
*
* @see javax.xml.transform.URIResolver#resolve(java.lang.String, java.lang.String)
*/
public Source resolve(final String href, final String base) {
StreamSource xslSrc = null;
InputStream xslIS = null;
IActionSequenceResource resource = new // $NON-NLS-1$ //$NON-NLS-2$
ActionSequenceResource(// $NON-NLS-1$ //$NON-NLS-2$
"", // $NON-NLS-1$ //$NON-NLS-2$
IActionSequenceResource.SOLUTION_FILE_RESOURCE, // $NON-NLS-1$ //$NON-NLS-2$
"text/xml", href);
xslIS = resource.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale());
xslSrc = new StreamSource(xslIS);
return xslSrc;
}
Aggregations