private String getFile(final String solutionPath) { IActionSequenceResource resource = new ActionSequenceResource( "", IActionSequenceResource.SOLUTION_FILE_RESOURCE, "text/html", solutionPath); //$NON-NLS-1$ //$NON-NLS-2$ try { byte[] bytes = IOUtils.toByteArray( resource.getInputStream( ISolutionRepository.ACTION_EXECUTE, LocaleHelper.getLocale())); return new String(bytes, LocaleHelper.getSystemEncoding()); } catch (Exception e) { if (errorMessage != null) { return errorMessage; } else { error( Messages.getInstance() .getErrorString( "Html.ERROR_0001_COULD_NOT_GET_CONTENT", solutionPath)); // $NON-NLS-1$ return Messages.getInstance() .getErrorString("Html.ERROR_0001_COULD_NOT_GET_CONTENT", solutionPath); // $NON-NLS-1$ } } }
public ReportSpec getReportSpec() throws FileNotFoundException { ReportSpec reportSpec = null; if (isDefinedResource(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTSPECINPUT)) { IActionSequenceResource resource = getResource(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTSPECINPUT); reportSpec = loadFromZip(resource); if (reportSpec == null) { InputStream reportSpecInputStream = resource.getInputStream(ISolutionRepository.ACTION_EXECUTE, LocaleHelper.getLocale()); reportSpec = (ReportSpec) CastorUtility.getInstance() .readCastorObject(reportSpecInputStream, ReportSpec.class); } } return reportSpec; }
private ReportSpec loadFromZip(final IActionSequenceResource resource) { try { InputStream reportSpecInputStream = resource.getInputStream(ISolutionRepository.ACTION_EXECUTE, LocaleHelper.getLocale()); ZipInputStream zis = new ZipInputStream(reportSpecInputStream); ZipEntry reportSpecEntry = findReportSpec(zis); if (reportSpecEntry == null) { return null; } // is this really sane? Blindly using the first zip entry is ... argh! // maybe you should use GZipped streams instead... return (ReportSpec) CastorUtility.getInstance().readCastorObject(zis, ReportSpec.class); } catch (Exception e) { return null; } }
/** * Create a dial image. * * <ul> * <li>Load the specified XML document describing the dial definition * <li>Create a dial definition object from the XML definition * <li>Use the JFreeChartEngine to create a dial image * <li>Create an XML document describing the dial * <li>Return the XML document * </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 ActionSequenceResource( title, IActionSequenceResource.SOLUTION_FILE_RESOURCE, "text/xml", //$NON-NLS-1$ definitionPath); Document dialDefinition = null; try { org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader(); reader.setEntityResolver(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) { error( Messages.getInstance() .getErrorString( "Widget.ERROR_0002_INVALID_RESOURCE", definitionPath)); // $NON-NLS-1$ 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) { error(Messages.getInstance().getString("Widget.ERROR_0001_COULD_NOT_CREATE")); // $NON-NLS-1$ 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 String solutionDir = "system/tmp/"; // $NON-NLS-1$ String fileNamePrefix = "tmp_pie_"; // $NON-NLS-1$ String extension = ".png"; // $NON-NLS-1$ 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(); } String dialTitle = ""; // $NON-NLS-1$ 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(); setXslProperty( "baseUrl", requestContext.getContextPath()); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ setXslProperty( "fullyQualifiedServerUrl", PentahoSystem.getApplicationContext() .getFullyQualifiedServerURL()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 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"); // $NON-NLS-1$ valueNode.setText(Double.toString(value)); valueNode.addAttribute( "in-image", Boolean.toString(widget.getValueFont() != null)); // $NON-NLS-1$ root.addElement("image").setText(fileName); // $NON-NLS-1$ return result; }