Propchange: ofbiz/branches/addBirt/framework/webtools/config/BirtUiLabels.xml
------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/config/BirtUiLabels.xml ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/config/BirtUiLabels.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: ofbiz/branches/addBirt/framework/webtools/config/birt.properties URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/config/birt.properties?rev=825391&view=auto ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/config/birt.properties (added) +++ ofbiz/branches/addBirt/framework/webtools/config/birt.properties Thu Oct 15 04:48:28 2009 @@ -0,0 +1,24 @@ +############################################################################### +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +############################################################################### + +# -- array of OSGi's arguments separate with comma "," +birt.osgi.arguments= + +# -- html image directory +birt.html.image.directory=/images \ No newline at end of file Propchange: ofbiz/branches/addBirt/framework/webtools/config/birt.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/config/birt.properties ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/config/birt.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/addBirt/framework/webtools/data/helpdata/BirtHelpData.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/data/helpdata/BirtHelpData.xml?rev=825391&view=auto ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/data/helpdata/BirtHelpData.xml (added) +++ ofbiz/branches/addBirt/framework/webtools/data/helpdata/BirtHelpData.xml Thu Oct 15 04:48:28 2009 @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<entity-engine-xml> + <DataResource dataResourceId="HELP_BIRT" localeString="en" dataResourceTypeId="OFBIZ_FILE" + objectInfo="framework/webtools/data/helpdata/HELP_BIRT.xml" dataTemplateTypeId="NONE" statusId="CTNT_IN_PROGRESS" + dataResourceName="BIRT Overview" mimeTypeId="text/xml" isPublic="Y" /> + <Content contentId="HELP_BIRT" contentTypeId="DOCUMENT" contentName="BIRT Overview" templateDataResourceId="HELP_TEMPL" + dataResourceId="HELP_BIRT" statusId="CTNT_IN_PROGRESS" mimeTypeId="text/html"/>/> + <ContentAssoc contentId="HELP_ROOT" contentIdTo="HELP_BIRT" contentAssocTypeId="TREE_CHILD" fromDate="2006-01-12 01:01:01" sequenceNum="000"/> + + <DataResource dataResourceId="BIRT_reports" localeString="en" dataResourceTypeId="OFBIZ_FILE" + objectInfo="framework/webtools/data/helpdata/HELP_BIRT_reports.xml" dataTemplateTypeId="NONE" statusId="CTNT_IN_PROGRESS" dataResourceName="BIRT Reports" mimeTypeId="text/xml" isPublic="Y" /> + <Content contentId="BIRT_reports" contentTypeId="DOCUMENT" contentName="Reports" templateDataResourceId="HELP_TEMPL" dataResourceId="BIRT_reports" statusId="CTNT_IN_PROGRESS" mimeTypeId="text/html"/> + <ContentAssoc contentId="HELP_BIRT" contentIdTo="BIRT_reports" contentAssocTypeId="TREE_CHILD" fromDate="2006-01-12 01:01:01" sequenceNum="000"/> +</entity-engine-xml> \ No newline at end of file Propchange: ofbiz/branches/addBirt/framework/webtools/data/helpdata/BirtHelpData.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/data/helpdata/BirtHelpData.xml ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/data/helpdata/BirtHelpData.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: ofbiz/branches/addBirt/framework/webtools/data/helpdata/HELP_BIRT.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/data/helpdata/HELP_BIRT.xml?rev=825391&view=auto ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/data/helpdata/HELP_BIRT.xml (added) +++ ofbiz/branches/addBirt/framework/webtools/data/helpdata/HELP_BIRT.xml Thu Oct 15 04:48:28 2009 @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<section xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="5.0" + xmlns:xl="http://www.w3.org/1999/xlink" + xmlns:xi="http://www.w3.org/2001/XInclude" + xsi:schemaLocation="http://docbook.org/ns/docbook ../../../content/dtd/docbook.xsd" + xmlns="http://docbook.org/ns/docbook"> + + <title>BIRT Overview</title> + <para> + BIRT is an Eclipse-based open source reporting system for web applications, + especially those based on Java and J2EE. BIRT has two main components: a report designer based on Eclipse, + and a runtime component that you can add to your app server. + BIRT also offers a charting engine that lets you add charts to your own application. + </para> + <section> + <title>With BIRT, you can add a rich variety of reports to your application.</title> + <para>Lists - The simplest reports are lists of data. As the lists get longer, + you can add grouping to organize related data together (orders grouped by customer, + products grouped by supplier). If your data is numeric, you can easily add totals, averages and other summaries.</para> + <para>Charts - Numeric data is much easier to understand when presented as a chart. + BIRT provides pie charts, line & bar charts and many more. + BIRT charts can be rendered in SVG and support events to allow user interaction.</para> + <para>Crosstabs - Crosstabs (also called a cross-tabulation or matrix) shows data in two dimensions: sales per quarter or hits per web page.</para> + <para>Letters & Documents - Notices, form letters, and other textual documents are easy to create with BIRT. + Documents can include text, formatting, lists, charts and more.</para> + <para>Compound Reports - Many reports need to combine the above into a single document. + For example, a customer statement may list the information for the customer, + provide text about current promotions, and provide side-by-side lists of payments and charges. A financial report may include disclaimers, + charts, tables all with extensive formatting that matches corporate color schemes.</para> + </section> +</section> \ No newline at end of file Propchange: ofbiz/branches/addBirt/framework/webtools/data/helpdata/HELP_BIRT.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/data/helpdata/HELP_BIRT.xml ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/data/helpdata/HELP_BIRT.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: ofbiz/branches/addBirt/framework/webtools/data/helpdata/HELP_BIRT_reports.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/data/helpdata/HELP_BIRT_reports.xml?rev=825391&view=auto ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/data/helpdata/HELP_BIRT_reports.xml (added) +++ ofbiz/branches/addBirt/framework/webtools/data/helpdata/HELP_BIRT_reports.xml Thu Oct 15 04:48:28 2009 @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<section xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="5.0" + xmlns:xl="http://www.w3.org/1999/xlink" + xmlns:xi="http://www.w3.org/2001/XInclude" + xsi:schemaLocation="http://docbook.org/ns/docbook ../../../content/dtd/docbook.xsd" + xmlns="http://docbook.org/ns/docbook"> + + <section> + <title>How do I create BIRT report in OFBiz.</title> + <para>Create new report</para> + <para>Create Scripted Data Source</para> + <para>Create Data Set that use Scripted Data Source</para> + <para>Add output columns</para> + <para>Add script to Data Set</para> + <para>Bind report's element to Data Set</para> + </section> + <section> + <title>How do I add script code to report.</title> + <para>Report can use delegator, dispatcher and security object in script.</para> + <para>Report can use same classpath with ofbiz.</para> + </section> + <section> + <title>How do I send parameter to report.</title> + <para>If report be rendered through view map, you can send parameter through attribute of request object, attribute's name "birtParameters" that is map.</para> + <para>If report be rendered through e-mail, you can send parameter through service's parameter name is birtParameters.</para> + </section> + <section> + <title>How do I send report through e-mail.</title> + <para>Report can sent through email by using sendBirtMail service.</para> + </section> + <section> + <title>How do I embed report to screen.</title> + <para>Report can embeded in screen by using jsp tag, viewer and report tag, that can use in ftl file.</para> + </section> + <section> + <title>What content's type that report supported.</title> + <para>text/html</para> + <para>application/pdf</para> + <para>application/vnd.ms-excel</para> + <para>application/vnd.ms-word</para> + <para>application/vnd.ms-powerpoint</para> + </section> + <section> + <title>How do I change report content's type</title> + <para>If report be rendered through view map, can set content's type at content-type attribute of view map.</para> + <para>If report be rendered through e-mail, can set content's type at service's parameter name is birtContentType.</para> + </section> +</section> \ No newline at end of file Propchange: ofbiz/branches/addBirt/framework/webtools/data/helpdata/HELP_BIRT_reports.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/data/helpdata/HELP_BIRT_reports.xml ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/data/helpdata/HELP_BIRT_reports.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Modified: ofbiz/branches/addBirt/framework/webtools/ofbiz-component.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/ofbiz-component.xml?rev=825391&r1=825390&r2=825391&view=diff ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/ofbiz-component.xml (original) +++ ofbiz/branches/addBirt/framework/webtools/ofbiz-component.xml Thu Oct 15 04:48:28 2009 @@ -33,4 +33,11 @@ location="webapp/webtools" base-permission="OFBTOOLS,WEBTOOLS" mount-point="/webtools"/> + <webapp name="birt" + title="Birt" + menu-name="secondary" + server="default-server" + location="webapp/birt" + base-permission="OFBTOOLS,WEBTOOLS" + mount-point="/birt"/> </ofbiz-component> Modified: ofbiz/branches/addBirt/framework/webtools/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/servicedef/services.xml?rev=825391&r1=825390&r2=825391&view=diff ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/servicedef/services.xml (original) +++ ofbiz/branches/addBirt/framework/webtools/servicedef/services.xml Thu Oct 15 04:48:28 2009 @@ -137,4 +137,20 @@ <attribute name="localeValues" type="List" mode="IN" optional="true"/> <attribute name="localeComments" type="List" mode="IN" optional="true"/> </service> + + <!-- Birt Email Services --> + <service name="sendBirtMail" engine="java" location="org.ofbiz.birt.email.BirtEmailServices" invoke="sendBirtMail"> + <description>Birt Email Service</description> + <implements service="sendMailInterface"/> + <attribute name="bodyText" type="String" mode="IN" optional="true"/> + <attribute name="bodyScreenUri" type="String" mode="IN" optional="true"/> + <attribute name="birtReportLocation" type="String" mode="IN" optional="false"/> + <attribute name="attachmentName" type="String" mode="IN" optional="false"/> + <attribute name="bodyParameters" type="Map" mode="IN" optional="true"/> + <attribute name="birtParameters" type="Map" mode="IN" optional="true"/> + <attribute name="birtLocale" type="Locale" mode="IN" optional="true"/> + <attribute name="birtContentType" type="String" mode="IN" optional="true"></attribute> + <attribute name="webSiteId" type="String" mode="IN" optional="true"/> + <attribute name="body" type="String" mode="OUT" optional="false"/> + </service> </services> Added: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/BirtWorker.java URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/BirtWorker.java?rev=825391&view=auto ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/BirtWorker.java (added) +++ ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/BirtWorker.java Thu Oct 15 04:48:28 2009 @@ -0,0 +1,122 @@ +package org.ofbiz.birt; + +import java.io.OutputStream; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Locale; +import java.util.Map; + +import org.eclipse.birt.report.engine.api.EXCELRenderOption; +import org.eclipse.birt.report.engine.api.EngineException; +import org.eclipse.birt.report.engine.api.HTMLRenderOption; +import org.eclipse.birt.report.engine.api.HTMLServerImageHandler; +import org.eclipse.birt.report.engine.api.IPDFRenderOption; +import org.eclipse.birt.report.engine.api.IReportEngine; +import org.eclipse.birt.report.engine.api.IReportRunnable; +import org.eclipse.birt.report.engine.api.IRunAndRenderTask; +import org.eclipse.birt.report.engine.api.PDFRenderOption; +import org.eclipse.birt.report.engine.api.RenderOption; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.birt.container.BirtContainer; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.jdbc.ConnectionFactory; + +public class BirtWorker { + + public final static String module = BirtWorker.class.getName(); + + public final static String BIRT_PARAMETERS = "birtParameters"; + public final static String REPORT_ENGINE = "reportEngine"; + public final static String BIRT_LOCALE = "birtLocale"; + public final static String BIRT_IMAGE_DIRECTORY = "birtImageDirectory"; + public final static String BIRT_CONTENT_TYPE = "birtContentType"; + + private static HTMLServerImageHandler imageHandler = new HTMLServerImageHandler(); + + /** + * export report + * @param design + * @param context + * @param contentType + * @param output + * @throws EngineException + * @throws GeneralException + * @throws SQLException + */ + public static void exportReport(IReportRunnable design, Map context, String contentType, OutputStream output) + throws EngineException, GeneralException, SQLException { + + Locale birtLocale = (Locale)context.get(BIRT_LOCALE); + String birtImageDirectory = (String)context.get(BIRT_IMAGE_DIRECTORY); + + if (contentType == null) { + contentType = "text/html"; + } + if (birtImageDirectory == null) { + birtImageDirectory = "/"; + } + Debug.logInfo("Get report engine", module); + IReportEngine engine = BirtContainer.getReportEngine(); + + // set the jdbc connection + String delegatorGroupHelperName = BirtContainer.getDelegatorGroupHelperName(); + Delegator delegator = BirtContainer.getDelegator(); + Debug.logInfo("Get the JDBC connection from group helper's name:" + delegatorGroupHelperName, module); + String helperName = delegator.getGroupHelperName(delegatorGroupHelperName); // gets the helper (localderby, localmysql, localpostgres, etc.) for your entity group org.ofbiz + Connection connection = ConnectionFactory.getConnection(helperName); + engine.getConfig().getAppContext().put("OdaJDBCDriverPassInConnection", connection); + + IRunAndRenderTask task = engine.createRunAndRenderTask(design); + if (birtLocale != null) { + Debug.logInfo("Set birt locale:" + birtLocale, module); + task.setLocale(birtLocale); + } + + // set parameters if exists + Map parameters = (Map)context.get(BirtWorker.BIRT_PARAMETERS); + if (parameters != null) { + Debug.logInfo("Set birt parameters:" + parameters, module); + task.setParameterValues(parameters); + } + + // set output options + RenderOption options = new RenderOption(); + if ("text/html".equalsIgnoreCase(contentType)) { + options.setOutputFormat(RenderOption.OUTPUT_FORMAT_HTML); + } else if ("application/pdf".equalsIgnoreCase(contentType)) { + options.setOutputFormat(RenderOption.OUTPUT_FORMAT_PDF); + } else if ("application/vnd.ms-word".equalsIgnoreCase(contentType)) { + options.setOutputFormat("doc"); + } else if ("application/vnd.ms-excel".equalsIgnoreCase(contentType)) { + options.setOutputFormat("xls"); + } else if ("application/vnd.ms-powerpoint".equalsIgnoreCase(contentType)) { + options.setOutputFormat("ppt"); + } else { + throw new GeneralException("Unknown content type : " + contentType); + } + + if (options.getOutputFormat().equalsIgnoreCase(RenderOption.OUTPUT_FORMAT_HTML)) { + // set html render options + HTMLRenderOption htmlOptions = new HTMLRenderOption(options); + htmlOptions.setImageDirectory(birtImageDirectory); + htmlOptions.setBaseImageURL(birtImageDirectory); + options.setImageHandler(imageHandler); + } else if (options.getOutputFormat().equalsIgnoreCase(RenderOption.OUTPUT_FORMAT_PDF)) { + // set pdf render options + PDFRenderOption pdfOptions = new PDFRenderOption(options); + pdfOptions.setOption(IPDFRenderOption.PAGE_OVERFLOW, new Boolean(true) ); + } else if (options.getOutputFormat().equalsIgnoreCase("xls")) { + // set excel render options + EXCELRenderOption excelOptions = new EXCELRenderOption(options); + } + options.setOutputStream(output); + task.setRenderOption(options); + + // run report + Debug.logInfo("Birt's locale is: " + task.getLocale(), module); + Debug.logInfo("Run report's task", module); + task.run(); + task.close(); + } +} Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/BirtWorker.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/BirtWorker.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/BirtWorker.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/container/BirtContainer.java URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/container/BirtContainer.java?rev=825391&view=auto ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/container/BirtContainer.java (added) +++ ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/container/BirtContainer.java Thu Oct 15 04:48:28 2009 @@ -0,0 +1,195 @@ +package org.ofbiz.birt.container; + +import java.net.MalformedURLException; +import java.net.URL; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.logging.Level; + +import org.eclipse.birt.core.exception.BirtException; +import org.eclipse.birt.core.framework.Platform; +import org.eclipse.birt.core.framework.PlatformFileContext; +import org.eclipse.birt.report.engine.api.EngineConfig; +import org.eclipse.birt.report.engine.api.EngineConstants; +import org.eclipse.birt.report.engine.api.IReportEngine; +import org.eclipse.birt.report.engine.api.IReportEngineFactory; +import org.ofbiz.base.container.Container; +import org.ofbiz.base.container.ContainerConfig; +import org.ofbiz.base.container.ContainerException; +import org.ofbiz.base.location.FlexibleLocation; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilObject; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.DelegatorFactory; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.service.GenericDispatcher; +import org.ofbiz.service.LocalDispatcher; +import org.ofbiz.widget.screen.ScreenFactory; + +public class BirtContainer implements Container { + + public static final String module = BirtContainer.class.getName(); + + public final static String CONFIG_FILE = "birt.properties"; + + protected EngineConfig config; + protected String configFile; + + private static IReportEngine engine; + private static String delegatorGroupHelperName; + private static String delegatorName; + private static String dispatcherName; + private static Delegator delegator; + private static LocalDispatcher dispatcher; + + public void init(String[] args, String configFile) + throws ContainerException { + // TODO Auto-generated method stub + this.configFile = configFile; + } + + /** + * start container + */ + public boolean start() throws ContainerException { + // TODO Auto-generated method stub + + Debug.logInfo("Start birt container", module); + + // make sure the subclass sets the config name + if (this.getContainerConfigName() == null) { + throw new ContainerException("Unknown container config name"); + } + // get the container config + ContainerConfig.Container cc = ContainerConfig.getContainer(this.getContainerConfigName(), configFile); + if (cc == null) { + throw new ContainerException("No " + this.getContainerConfigName() + " configuration found in container config!"); + } + + config = new EngineConfig(); + HashMap context = config.getAppContext(); + + // set delegator, dispatcher and security objects to report + + // get the delegator + delegatorName = ContainerConfig.getPropertyValue(cc, "delegator-name", "default"); + try { + delegator = UtilObject.getObjectFromFactory(DelegatorFactory.class, delegatorName); + } catch (ClassNotFoundException e) { + Debug.logError(e, module); + } + + // get the dispatcher + dispatcherName = ContainerConfig.getPropertyValue(cc, "dispatcher-name", "birt-dispatcher"); + dispatcher = GenericDispatcher.getLocalDispatcher(dispatcherName, delegator); + + context.put("delegator", delegator); + context.put("dispatcher", dispatcher); + + delegatorGroupHelperName = ContainerConfig.getPropertyValue(cc, "delegator-group-helper-name", "org.ofbiz"); + + // set classloader for engine + context.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, BirtContainer.class.getClassLoader()); + context.put(EngineConstants.WEBAPP_CLASSPATH_KEY, BirtContainer.class.getClassLoader()); + + // set log config to show all level in console + config.setLogConfig(null, Level.ALL); + + // get report engine home + URL reportEngineDirUrl = null; + String reportEngineResourceName = "component://webtools/webapp/birt/WEB-INF/ReportEngine"; + synchronized (BirtContainer.class) { + long startTime = System.currentTimeMillis(); + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + if (loader == null) { + loader = ScreenFactory.class.getClassLoader(); + } + reportEngineDirUrl = null; + try { + reportEngineDirUrl = FlexibleLocation.resolveLocation(reportEngineResourceName, loader); + } catch (MalformedURLException e) { + throw new ContainerException(e); + } + if (reportEngineDirUrl == null) { + throw new IllegalArgumentException("Could not resolve location to URL: " + reportEngineResourceName); + } + } + + // set engine home + if (reportEngineDirUrl != null) { + config.setEngineHome(reportEngineDirUrl.getPath()); + config.setBIRTHome(reportEngineDirUrl.getPath()); + } + + // set OSGi arguments specific in properties + String argumentsString = UtilProperties.getPropertyValue(BirtContainer.CONFIG_FILE, "birt.osgi.arguments"); + config.setOSGiArguments(argumentsString.split(",")); + + // set platform file context + config.setPlatformContext(new PlatformFileContext(config)); + config.setAppContext(context); + + // startup platform + try { + Debug.logInfo("Startup birt platform", module); + Platform.startup( config ); + } catch ( BirtException e ) { + throw new ContainerException(e); + } + + // create report engine + Debug.logInfo("Create factory object", module); + IReportEngineFactory factory = (IReportEngineFactory) Platform + .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY ); + if (factory == null) { + throw new ContainerException("can not create birt engine factory"); + } + Debug.logInfo("Create report engine", module); + engine = factory.createReportEngine( config ); + String[] supportedFormats = engine.getSupportedFormats(); + String formatList = null; + for (String supportedFormat : supportedFormats) { + if (formatList != null) { + formatList += ", " + supportedFormat; + } else { + formatList = supportedFormat; + } + } + Debug.logInfo("BIRT supported formats: " + formatList, module); + return false; + } + + public void stop() throws ContainerException { + // TODO Auto-generated method stub + + } + + public String getContainerConfigName() { + return "birt-container"; + } + + public static IReportEngine getReportEngine() throws GenericEntityException, SQLException { + return engine; + } + + public static String getDelegatorGroupHelperName() { + return delegatorGroupHelperName; + } + + public static String getDelegatorName() { + return delegatorName; + } + + public static String getDispatcherName() { + return dispatcherName; + } + + public static Delegator getDelegator() { + return delegator; + } + + public static LocalDispatcher getDispatcher() { + return dispatcher; + } +} Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/container/BirtContainer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/container/BirtContainer.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/container/BirtContainer.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/email/BirtEmailServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/email/BirtEmailServices.java?rev=825391&view=auto ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/email/BirtEmailServices.java (added) +++ ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/email/BirtEmailServices.java Thu Oct 15 04:48:28 2009 @@ -0,0 +1,226 @@ +package org.ofbiz.birt.email; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.sql.SQLException; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import javax.xml.parsers.ParserConfigurationException; + +import javolution.util.FastList; +import javolution.util.FastMap; + +import org.apache.fop.apps.FOPException; +import org.eclipse.birt.report.engine.api.EngineException; +import org.eclipse.birt.report.engine.api.IReportEngine; +import org.eclipse.birt.report.engine.api.IReportRunnable; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.collections.MapStack; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.birt.BirtWorker; +import org.ofbiz.birt.container.BirtContainer; +import org.ofbiz.common.email.NotificationServices; +import org.ofbiz.service.DispatchContext; +import org.ofbiz.service.LocalDispatcher; +import org.ofbiz.service.ServiceUtil; +import org.ofbiz.widget.birt.BirtFactory; +import org.ofbiz.widget.html.HtmlScreenRenderer; +import org.ofbiz.widget.screen.ScreenRenderer; +import org.xml.sax.SAXException; + +public class BirtEmailServices { + + public static final String module = BirtEmailServices.class.getName(); + + protected static final HtmlScreenRenderer htmlScreenRenderer = new HtmlScreenRenderer(); + + /** + * send birt mail + * + * @param ctx + * @param context + * @return + */ + public static Map<String, Object> sendBirtMail(DispatchContext ctx, Map<String, ? extends Object> context) { + Map<String, Object> serviceContext = UtilMisc.makeMapWritable(context); + LocalDispatcher dispatcher = ctx.getDispatcher(); + String webSiteId = (String) serviceContext.remove("webSiteId"); + String bodyText = (String) serviceContext.remove("bodyText"); + String bodyScreenUri = (String) serviceContext.remove("bodyScreenUri"); + String birtReportLocation = (String) serviceContext.remove("birtReportLocation"); + String attachmentName = (String) serviceContext.remove("attachmentName"); + Locale locale = (Locale) serviceContext.get("locale"); + Map bodyParameters = (Map) serviceContext.remove("bodyParameters"); + Locale birtLocale = (Locale) serviceContext.remove(BirtWorker.BIRT_LOCALE); + Map birtParameters = (Map) serviceContext.remove(BirtWorker.BIRT_PARAMETERS); + String birtImageDirectory = (String) serviceContext.remove(BirtWorker.BIRT_IMAGE_DIRECTORY); + String birtContentType = (String) serviceContext.remove(BirtWorker.BIRT_CONTENT_TYPE); + if (bodyParameters == null) { + bodyParameters = MapStack.create(); + } + if (!bodyParameters.containsKey("locale")) { + bodyParameters.put("locale", locale); + } else { + locale = (Locale) bodyParameters.get("locale"); + } + String partyId = (String) bodyParameters.get("partyId"); + if (UtilValidate.isNotEmpty(webSiteId)) { + NotificationServices.setBaseUrl(ctx.getDelegator(), webSiteId, bodyParameters); + } + String contentType = (String) serviceContext.remove("contentType"); + + if (UtilValidate.isEmpty(attachmentName)) { + attachmentName = "Details.pdf"; + } + StringWriter bodyWriter = new StringWriter(); + + MapStack screenContext = MapStack.create(); + screenContext.put("locale", locale); + ScreenRenderer screens = new ScreenRenderer(bodyWriter, screenContext, htmlScreenRenderer); + screens.populateContextForService(ctx, bodyParameters); + screenContext.putAll(bodyParameters); + + if (bodyScreenUri != null) { + try { + screens.render(bodyScreenUri); + } catch (GeneralException e) { + String errMsg = "Error rendering screen for email: " + e.toString(); + Debug.logError(e, errMsg, module); + return ServiceUtil.returnError(errMsg); + } catch (IOException e) { + String errMsg = "Error I/O rendering screen for email: " + e.toString(); + Debug.logError(e, errMsg, module); + return ServiceUtil.returnError(errMsg); + } catch (SAXException e) { + String errMsg = "Error SAX rendering screen for email: " + e.toString(); + Debug.logError(e, errMsg, module); + return ServiceUtil.returnError(errMsg); + } catch (ParserConfigurationException e) { + String errMsg = "Error parser config rendering screen for email: " + e.toString(); + Debug.logError(e, errMsg, module); + return ServiceUtil.returnError(errMsg); + } + } + + boolean isMultiPart = false; + + // check if attachment screen location passed in + if (UtilValidate.isNotEmpty(birtReportLocation)) { + isMultiPart = true; + // start processing fo pdf attachment + try { + // create the output stream for the generation + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + Map birtContext = FastMap.newInstance(); + if (birtLocale == null) { + birtLocale = locale; + } + birtContext.put(BirtWorker.BIRT_LOCALE, birtLocale); + if (birtParameters != null) { + birtContext.put(BirtWorker.BIRT_PARAMETERS, birtParameters); + } + if (birtImageDirectory != null) { + birtContext.put(BirtWorker.BIRT_IMAGE_DIRECTORY, birtImageDirectory); + } + if (birtContentType == null) { + birtContentType = "application/pdf"; + } + IReportEngine engine = BirtContainer.getReportEngine(); + InputStream reportInputStream = BirtFactory.getReportInputStreamFromLocation(birtReportLocation); + IReportRunnable design = engine.openReportDesign(reportInputStream); + Debug.logInfo("Export report as content type:" + birtContentType, module); + BirtWorker.exportReport(design, context, birtContentType, baos); + // and generate the PDF + baos.flush(); + baos.close(); + + // store in the list of maps for sendmail.... + List bodyParts = FastList.newInstance(); + if (bodyText != null) { + bodyText = FlexibleStringExpander.expandString(bodyText, screenContext, locale); + bodyParts.add(UtilMisc.toMap("content", bodyText, "type", "text/html")); + } else { + bodyParts.add(UtilMisc.toMap("content", bodyWriter.toString(), "type", "text/html")); + } + bodyParts.add(UtilMisc.toMap("content", baos.toByteArray(), "type", "application/pdf", "filename", attachmentName)); + serviceContext.put("bodyParts", bodyParts); + } catch (GeneralException ge) { + String errMsg = "Error rendering " + birtContentType + " attachment for email: " + ge.toString(); + Debug.logError(ge, errMsg, module); + return ServiceUtil.returnError(errMsg); + } catch (IOException ie) { + String errMsg = "Error I/O rendering " + birtContentType + " attachment for email: " + ie.toString(); + Debug.logError(ie, errMsg, module); + return ServiceUtil.returnError(errMsg); + } catch (FOPException fe) { + String errMsg = "Error FOP rendering " + birtContentType + " attachment for email: " + fe.toString(); + Debug.logError(fe, errMsg, module); + return ServiceUtil.returnError(errMsg); + } catch (SAXException se) { + String errMsg = "Error SAX rendering " + birtContentType + " attachment for email: " + se.toString(); + Debug.logError(se, errMsg, module); + return ServiceUtil.returnError(errMsg); + } catch (ParserConfigurationException pe) { + String errMsg = "Error parser rendering " + birtContentType + " attachment for email: " + pe.toString(); + Debug.logError(pe, errMsg, module); + return ServiceUtil.returnError(errMsg); + } catch (EngineException ee) { + String errMsg = "Error rendering " + birtContentType + " attachment for email: " + ee.toString(); + Debug.logError(ee, errMsg, module); + return ServiceUtil.returnError(errMsg); + } catch (SQLException se) { + String errMsg = "Error SQL rendering " + birtContentType + " attachment for email: " + se.toString(); + Debug.logError(se, errMsg, module); + return ServiceUtil.returnError(errMsg); + } + } else { + isMultiPart = false; + // store body and type for single part message in the context. + if (bodyText != null) { + bodyText = FlexibleStringExpander.expandString(bodyText, screenContext, locale); + serviceContext.put("body", bodyText); + } else { + serviceContext.put("body", bodyWriter.toString()); + } + + // Only override the default contentType in case of plaintext, since other contentTypes may be multipart + // and would require specific handling. + if (contentType != null && contentType.equalsIgnoreCase("text/plain")) { + serviceContext.put("contentType", "text/plain"); + } else { + serviceContext.put("contentType", "text/html"); + } + } + + // also expand the subject at this point, just in case it has the FlexibleStringExpander syntax in it... + String subject = (String) serviceContext.remove("subject"); + subject = FlexibleStringExpander.expandString(subject, screenContext, locale); + serviceContext.put("subject", subject); + serviceContext.put("partyId", partyId); + + if (Debug.verboseOn()) Debug.logVerbose("sendMailFromScreen sendMail context: " + serviceContext, module); + + Map result = ServiceUtil.returnSuccess(); + try { + if (isMultiPart) { + dispatcher.runSync("sendMailMultiPart", serviceContext); + } else { + dispatcher.runSync("sendMail", serviceContext); + } + } catch (Exception e) { + String errMsg = "Error send email :" + e.toString(); + Debug.logError(e, errMsg, module); + return ServiceUtil.returnError(errMsg); + } + result.put("body", bodyWriter.toString()); + return result; + } +} Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/email/BirtEmailServices.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/email/BirtEmailServices.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/email/BirtEmailServices.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/context/BirtViewerAttributeBean.java URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/context/BirtViewerAttributeBean.java?rev=825391&view=auto ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/context/BirtViewerAttributeBean.java (added) +++ ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/context/BirtViewerAttributeBean.java Thu Oct 15 04:48:28 2009 @@ -0,0 +1,171 @@ +package org.ofbiz.birt.report.context; + +import java.net.URL; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.eclipse.birt.report.IBirtConstants; +import org.eclipse.birt.report.context.ViewerAttributeBean; +import org.eclipse.birt.report.exception.ViewerException; +import org.eclipse.birt.report.resource.BirtResources; +import org.eclipse.birt.report.resource.ResourceConstants; +import org.eclipse.birt.report.utility.BirtUtility; +import org.eclipse.birt.report.utility.DataUtil; +import org.eclipse.birt.report.utility.ParameterAccessor; +import org.ofbiz.base.location.FlexibleLocation; + +public class BirtViewerAttributeBean extends ViewerAttributeBean { + + public final static String module = BirtViewerAttributeBean.class.getName(); + + /** + * Module Options + */ + private Map moduleOptions = null; + + /** + * Request Type + */ + private String requestType; + + private Boolean reportRtl; + + public BirtViewerAttributeBean(HttpServletRequest arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + + /** + * Init the bean. + * + * @param request + * @throws Exception + */ + @Override + protected void __init( HttpServletRequest request ) throws Exception + { + // If GetImage operate, return directly. + if ( ParameterAccessor.isGetImageOperator( request ) + && ( IBirtConstants.SERVLET_PATH_FRAMESET + .equalsIgnoreCase( request.getServletPath( ) ) + || IBirtConstants.SERVLET_PATH_OUTPUT + .equalsIgnoreCase( request.getServletPath( ) ) + || IBirtConstants.SERVLET_PATH_RUN + .equalsIgnoreCase( request.getServletPath( ) ) || IBirtConstants.SERVLET_PATH_PREVIEW + .equalsIgnoreCase( request.getServletPath( ) ) ) ) + { + return; + } + + this.category = "BIRT"; //$NON-NLS-1$ + this.masterPageContent = ParameterAccessor + .isMasterPageContent( request ); + this.isDesigner = ParameterAccessor.isDesigner( ); + + if ( !ParameterAccessor.isBookmarkReportlet( request ) ) + { + this.bookmark = ParameterAccessor.getBookmark( request ); + } + else + { + this.bookmark = null; + } + + this.isToc = ParameterAccessor.isToc( request ); + this.reportPage = ParameterAccessor.getPage( request ); + this.reportPageRange = ParameterAccessor.getPageRange( request ); + this.action = ParameterAccessor.getAction( request ); + + // If use frameset/output/download/extract servlet pattern, generate + // document + // from design file + if ( IBirtConstants.SERVLET_PATH_FRAMESET.equalsIgnoreCase( request + .getServletPath( ) ) + || IBirtConstants.SERVLET_PATH_OUTPUT.equalsIgnoreCase( request + .getServletPath( ) ) + || IBirtConstants.SERVLET_PATH_DOWNLOAD + .equalsIgnoreCase( request.getServletPath( ) ) + || IBirtConstants.SERVLET_PATH_EXTRACT + .equalsIgnoreCase( request.getServletPath( ) ) ) + { + this.reportDocumentName = ParameterAccessor.getReportDocument( + request, null, true ); + } + else + { + this.reportDocumentName = ParameterAccessor.getReportDocument( + request, null, false ); + } + + String reportParam = DataUtil.trimString( ParameterAccessor.getParameter( request, ParameterAccessor.PARAM_REPORT )); + if (reportParam.startsWith("component://")) { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + if (loader == null) { + loader = BirtViewerAttributeBean.class.getClassLoader(); + } + URL reportFileUrl = null; + reportFileUrl = FlexibleLocation.resolveLocation(reportParam, loader); + if (reportFileUrl == null) { + throw new IllegalArgumentException("Could not resolve location to URL: " + reportParam); + } + this.reportDesignName = reportFileUrl.getPath(); + } else { + this.reportDesignName = ParameterAccessor.getReport( request, null ); + } + + this.emitterId = ParameterAccessor.getEmitterId( request ); + + // If print action, force to use postscript format + this.format = ParameterAccessor.getFormat( request ); + if ( IBirtConstants.ACTION_PRINT.equalsIgnoreCase( action ) ) + { + // Check whether turn on this funtion + if ( ParameterAccessor.isSupportedPrintOnServer ) + { + this.format = IBirtConstants.POSTSCRIPT_RENDER_FORMAT; + this.emitterId = null; + } + else + { + this.action = null; + } + } + + // Set locale information + BirtResources.setLocale( ParameterAccessor.getLocale( request ) ); + + // Set the request type + this.requestType = request + .getHeader( ParameterAccessor.HEADER_REQUEST_TYPE ); + + // Determine the report design and doc 's timestamp + processReport( request ); + + // Report title. + this.reportTitle = ParameterAccessor.getTitle( request ); + + // Set whether show the report title + this.isShowTitle = ParameterAccessor.isShowTitle( request ); + + // Set whether show the toolbar + this.isShowToolbar = ParameterAccessor.isShowToolbar( request ); + + // Set whether show the navigation bar + this.isShowNavigationbar = ParameterAccessor + .isShowNavigationbar( request ); + + // get some module options + this.moduleOptions = BirtUtility.getModuleOptions( request ); + + this.reportDesignHandle = getDesignHandle( request ); + if ( this.reportDesignHandle == null ) + throw new ViewerException( + ResourceConstants.GENERAL_EXCEPTION_NO_REPORT_DESIGN ); + + this.reportRtl = null; + + // Initialize report parameters. + __initParameters( request ); + } +} Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/context/BirtViewerAttributeBean.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/context/BirtViewerAttributeBean.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/context/BirtViewerAttributeBean.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/context/OFBizBirtContext.java URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/context/OFBizBirtContext.java?rev=825391&view=auto ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/context/OFBizBirtContext.java (added) +++ ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/context/OFBizBirtContext.java Thu Oct 15 04:48:28 2009 @@ -0,0 +1,29 @@ +package org.ofbiz.birt.report.context; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.birt.report.IBirtConstants; +import org.eclipse.birt.report.context.BirtContext; +import org.eclipse.birt.report.context.ViewerAttributeBean; + +public class OFBizBirtContext extends BirtContext { + + public OFBizBirtContext(HttpServletRequest request, + HttpServletResponse response) { + super(request, response); + // TODO Auto-generated constructor stub + } + + @Override + protected void __init() { + // TODO Auto-generated method stub + this.bean = (ViewerAttributeBean) request + .getAttribute( IBirtConstants.ATTRIBUTE_BEAN ); + if ( bean == null ) + { + bean = new BirtViewerAttributeBean( request ); + } + request.setAttribute( IBirtConstants.ATTRIBUTE_BEAN, bean ); + } +} Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/context/OFBizBirtContext.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/context/OFBizBirtContext.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/context/OFBizBirtContext.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/service/OFBizBirtViewerReportService.java URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/service/OFBizBirtViewerReportService.java?rev=825391&view=auto ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/service/OFBizBirtViewerReportService.java (added) +++ ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/service/OFBizBirtViewerReportService.java Thu Oct 15 04:48:28 2009 @@ -0,0 +1,336 @@ +package org.ofbiz.birt.report.service; + +import java.io.File; +import java.io.OutputStream; +import java.rmi.RemoteException; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.TimeZone; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; + +import org.eclipse.birt.core.exception.BirtException; +import org.eclipse.birt.report.IBirtConstants; +import org.eclipse.birt.report.context.ViewerAttributeBean; +import org.eclipse.birt.report.engine.api.IReportRunnable; +import org.eclipse.birt.report.engine.api.IRunTask; +import org.eclipse.birt.report.resource.BirtResources; +import org.eclipse.birt.report.resource.ResourceConstants; +import org.eclipse.birt.report.service.BirtViewerReportService; +import org.eclipse.birt.report.service.ReportEngineService; +import org.eclipse.birt.report.service.ReportEngineService.DummyRemoteException; +import org.eclipse.birt.report.service.api.IViewerReportDesignHandle; +import org.eclipse.birt.report.service.api.InputOptions; +import org.eclipse.birt.report.service.api.ReportServiceException; +import org.eclipse.birt.report.utility.BirtUtility; +import org.eclipse.birt.report.utility.DataUtil; +import org.eclipse.birt.report.utility.ParameterAccessor; +import org.ofbiz.base.util.Debug; +import org.ofbiz.birt.container.BirtContainer; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.jdbc.ConnectionFactory; + +public class OFBizBirtViewerReportService extends BirtViewerReportService { + + public final static String module = OFBizBirtViewerReportService.class.getName(); + + public OFBizBirtViewerReportService(ServletContext servletContext) { + super(servletContext); + // TODO Auto-generated constructor stub + } + + @Override + public String runReport(IViewerReportDesignHandle design, + String outputDocName, InputOptions runOptions, Map parameters, + Map displayTexts, List<Exception> errorList) throws ReportServiceException { + // TODO Auto-generated method stub + + if ( design == null || design.getDesignObject( ) == null ) + throw new ReportServiceException( BirtResources.getMessage( ResourceConstants.GENERAL_EXCEPTION_NO_REPORT_DESIGN ) ); + + IReportRunnable runnable; + HttpServletRequest request = (HttpServletRequest) runOptions.getOption( InputOptions.OPT_REQUEST ); + Locale locale = (Locale) runOptions.getOption( InputOptions.OPT_LOCALE ); + TimeZone timeZone = (TimeZone) runOptions.getOption( InputOptions.OPT_TIMEZONE ); + + ViewerAttributeBean attrBean = (ViewerAttributeBean) request.getAttribute( IBirtConstants.ATTRIBUTE_BEAN ); + // Set parameters + Map parsedParams = attrBean.getParameters( ); + if ( parameters != null ) + { + parsedParams.putAll( parameters ); + } + // Set display Text of select parameters + Map displayTextMap = attrBean.getDisplayTexts( ); + if ( displayTexts != null ) + { + displayTextMap.putAll( displayTexts ); + } + + runnable = (IReportRunnable) design.getDesignObject( ); + try + { + // get maxRows + Integer maxRows = null; + if ( ParameterAccessor.isReportParameterExist( request, + ParameterAccessor.PARAM_MAXROWS ) ) + maxRows = Integer.valueOf( ParameterAccessor.getMaxRows( request ) ); + + try { + // put all app context from Birt Container to Report Engine Service + ReportEngineService.getInstance().getEngineConfig().getAppContext().putAll( + BirtContainer.getReportEngine().getConfig().getAppContext()); + Connection connection = getConnection(); + BirtContainer.getReportEngine().getConfig().getAppContext().put("OdaJDBCDriverPassInConnection", connection); + } catch (Exception e) { + Debug.logError(e, module); + } + List<Exception> errors = this.runReport( request, + runnable, + outputDocName, + locale, + timeZone, + parsedParams, + displayTextMap, + maxRows ); + if ( errors != null && !errors.isEmpty( ) ) + { + errorList.addAll( errors ); + } + } + catch ( RemoteException e ) + { + if ( e.getCause( ) instanceof ReportServiceException ) + { + throw (ReportServiceException) e.getCause( ); + } + else + { + throw new ReportServiceException( e.getLocalizedMessage( ), + e.getCause( ) ); + } + } + return outputDocName; + } + + /** + * Run report. + * + * @param request + * + * @param runnable + * @param archive + * @param documentName + * @param locale + * @param parameters + * @param displayTexts + * @param maxRows + * @return list of exceptions which occured during the run or null + * @throws RemoteException + */ + public List<Exception> runReport( HttpServletRequest request, + IReportRunnable runnable, String documentName, Locale locale, + TimeZone timeZone, Map parameters, Map displayTexts, Integer maxRows ) + throws RemoteException + { + assert runnable != null; + + // Preapre the run report task. + IRunTask runTask = null; + try { + runTask = BirtContainer.getReportEngine().createRunTask( runnable ); + } catch (Exception e) { + throwDummyException(e); + } + runTask.setLocale( locale ); + + com.ibm.icu.util.TimeZone tz = BirtUtility.toICUTimeZone( timeZone ); + if ( tz != null ) + { + runTask.setTimeZone( tz ); + } + + runTask.setParameterValues( parameters ); + + // set MaxRows settings + if ( maxRows != null ) + runTask.setMaxRowsPerQuery( maxRows.intValue( ) ); + + // add task into session + BirtUtility.addTask( request, runTask ); + + // Set display Text for select parameters + if ( displayTexts != null ) + { + Iterator keys = displayTexts.keySet( ).iterator( ); + while ( keys.hasNext( ) ) + { + String paramName = DataUtil.getString( keys.next( ) ); + String displayText = DataUtil.getString( displayTexts + .get( paramName ) ); + runTask.setParameterDisplayText( paramName, displayText ); + } + } + + // set app context + Map context = BirtUtility.getAppContext( request ); + runTask.setAppContext( context ); + + // Run report. + try + { + runTask.run( documentName ); + } + catch ( BirtException e ) + { + // clear document file + File doc = new File( documentName ); + if ( doc != null ) + doc.delete( ); + + throwDummyException( e ); + } + finally + { + // Remove task from http session + BirtUtility.removeTask( request ); + + // Append errors + if ( ParameterAccessor.isDesigner( ) ) + BirtUtility.error( request, runTask.getErrors( ) ); + + runTask.close( ); + + // check for non-fatal errors + List<Exception> errors = (List<Exception>) runTask.getErrors( ); + if ( !errors.isEmpty( ) ) + { + return errors; + } + } + return null; + } + + /** + * @see org.eclipse.birt.report.service.api.IViewerReportService#runAndRenderReport(org.eclipse.birt.report.service.api.IViewerReportDesignHandle, + * java.lang.String, org.eclipse.birt.report.service.api.InputOptions, + * java.util.Map, java.io.OutputStream, java.util.List, java.util.Map) + */ + public void runAndRenderReport( IViewerReportDesignHandle design, + String outputDocName, InputOptions options, Map parameters, + OutputStream out, List activeIds, Map displayTexts ) + throws ReportServiceException + { + if ( design == null || design.getDesignObject( ) == null ) + throw new ReportServiceException( BirtResources.getMessage( ResourceConstants.GENERAL_EXCEPTION_NO_REPORT_DESIGN ) ); + + HttpServletRequest request = (HttpServletRequest) options.getOption( InputOptions.OPT_REQUEST ); + + try + { + ViewerAttributeBean attrBean = (ViewerAttributeBean) request.getAttribute( IBirtConstants.ATTRIBUTE_BEAN ); + String reportTitle = ParameterAccessor.htmlDecode( attrBean.getReportTitle( ) ); + IReportRunnable runnable = (IReportRunnable) design.getDesignObject( ); + + // get maxRows + Integer maxRows = null; + if ( ParameterAccessor.isReportParameterExist( request, + ParameterAccessor.PARAM_MAXROWS ) ) + maxRows = Integer.valueOf( ParameterAccessor.getMaxRows( request ) ); + + try { + // put all app context from Birt Container to Report Engine Service + ReportEngineService.getInstance().getEngineConfig().getAppContext().putAll( + BirtContainer.getReportEngine().getConfig().getAppContext()); + Connection connection = getConnection(); + ReportEngineService.getInstance( ).getEngineConfig().getAppContext().put("OdaJDBCDriverPassInConnection", connection); + } catch (Exception e) { + Debug.logError(e, module); + } + ReportEngineService.getInstance( ).runAndRenderReport( runnable, + out, + options, + parameters, + null, + null, + null, + displayTexts, + reportTitle, + maxRows ); + } + catch ( RemoteException e ) + { + throwReportServiceException( e ); + } + } + + /** + * get connection + */ + private Connection getConnection() { + Connection connection = null; + try { + String delegatorGroupHelperName = BirtContainer.getDelegatorGroupHelperName(); + Delegator delegator = BirtContainer.getDelegator(); + Debug.logInfo("Get the JDBC connection from group helper's name:" + delegatorGroupHelperName, module); + String helperName = delegator.getGroupHelperName(delegatorGroupHelperName); // gets the helper (localderby, localmysql, localpostgres, etc.) for your entity group org.ofbiz + connection = ConnectionFactory.getConnection(helperName); + } catch (GenericEntityException e) { + Debug.logError(e, module); + } catch (SQLException e) { + Debug.logError(e, module); + } + return connection; + } + + /** + * @param e + * @throws DummyRemoteException + */ + private void throwDummyException( Exception e ) + throws DummyRemoteException + { + if ( e instanceof ReportServiceException ) + { + throw new DummyRemoteException(e); + } + else + { + throw new DummyRemoteException( new ReportServiceException( e + .getLocalizedMessage( ), e ) ); + } + } + + /** + * Temporary method for extracting the exception from the + * DummyRemoteException and throwing it. + */ + private void throwReportServiceException( RemoteException e ) + throws ReportServiceException + { + Throwable wrappedException = e; + if ( e instanceof ReportEngineService.DummyRemoteException ) + { + wrappedException = e.getCause( ); + } + if ( wrappedException instanceof ReportServiceException ) + { + throw (ReportServiceException) wrappedException; + } + else if ( wrappedException != null ) + { + throw new ReportServiceException( wrappedException.getLocalizedMessage( ), + wrappedException ); + } + else + { + throw new ReportServiceException( e.getLocalizedMessage( ), e ); + } + } +} Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/service/OFBizBirtViewerReportService.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/service/OFBizBirtViewerReportService.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/service/OFBizBirtViewerReportService.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/servlet/BirtEngineServlet.java URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/servlet/BirtEngineServlet.java?rev=825391&view=auto ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/servlet/BirtEngineServlet.java (added) +++ ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/servlet/BirtEngineServlet.java Thu Oct 15 04:48:28 2009 @@ -0,0 +1,126 @@ +package org.ofbiz.birt.report.servlet; + +import java.io.IOException; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.birt.core.exception.BirtException; +import org.eclipse.birt.report.IBirtConstants; +import org.eclipse.birt.report.context.IContext; +import org.eclipse.birt.report.context.ViewerAttributeBean; +import org.eclipse.birt.report.presentation.aggregation.layout.EngineFragment; +import org.eclipse.birt.report.presentation.aggregation.layout.RequesterFragment; +import org.eclipse.birt.report.service.BirtReportServiceFactory; +import org.eclipse.birt.report.servlet.BaseReportEngineServlet; +import org.eclipse.birt.report.utility.BirtUtility; +import org.ofbiz.birt.report.context.OFBizBirtContext; +import org.ofbiz.birt.report.service.OFBizBirtViewerReportService; + +public class BirtEngineServlet extends BaseReportEngineServlet { + /** + * TODO: what's this? + */ + private static final long serialVersionUID = 1L; + + /** + * Local initialization. + * + * @return + */ + protected void __init( ServletConfig config ) + { + BirtReportServiceFactory.init( new OFBizBirtViewerReportService( config + .getServletContext( ) ) ); + + engine = new EngineFragment( ); + + requester = new RequesterFragment( ); + requester.buildComposite( ); + requester.setJSPRootPath( "/webcontent/birt" ); //$NON-NLS-1$ + } + + /** + * Init context. + * + * @param request + * incoming http request + * @param response + * http response + * @exception BirtException + * @return IContext + */ + protected IContext __getContext( HttpServletRequest request, + HttpServletResponse response ) throws BirtException + { + BirtReportServiceFactory.getReportService( ).setContext( + getServletContext( ), null ); + return new OFBizBirtContext( request, response ); + } + + /** + * Local authentication. + * + * @param request + * incoming http request + * @param response + * http response + * @return + */ + protected boolean __authenticate( HttpServletRequest request, + HttpServletResponse response ) + { + return true; + } + + /** + * Local do get. + */ + protected void __doGet( IContext context ) throws ServletException, + IOException, BirtException + { + ViewerAttributeBean bean = (ViewerAttributeBean) context.getBean( ); + assert bean != null; + + if ( ( IBirtConstants.SERVLET_PATH_PREVIEW.equalsIgnoreCase( context + .getRequest( ).getServletPath( ) ) + || IBirtConstants.SERVLET_PATH_DOCUMENT + .equalsIgnoreCase( context.getRequest( ) + .getServletPath( ) ) || IBirtConstants.SERVLET_PATH_OUTPUT + .equalsIgnoreCase( context.getRequest( ).getServletPath( ) ) ) + && bean.isShowParameterPage( ) ) + { + requester.service( context.getRequest( ), context.getResponse( ) ); + } + else if ( IBirtConstants.SERVLET_PATH_PARAMETER + .equalsIgnoreCase( context.getRequest( ).getServletPath( ) ) ) + { + requester.service( context.getRequest( ), context.getResponse( ) ); + } + else + { + engine.service( context.getRequest( ), context.getResponse( ) ); + } + } + + /** + * Process exception for non soap request. + * + * @param request + * incoming http request + * @param response + * http response + * @param exception + * @throws ServletException + * @throws IOException + */ + protected void __handleNonSoapException( HttpServletRequest request, + HttpServletResponse response, Exception exception ) + throws ServletException, IOException + { + exception.printStackTrace( ); + BirtUtility.appendErrorMessage( response.getOutputStream( ), exception ); + } +} Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/servlet/BirtEngineServlet.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/servlet/BirtEngineServlet.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/servlet/BirtEngineServlet.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/servlet/BirtViewerServlet.java URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/servlet/BirtViewerServlet.java?rev=825391&view=auto ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/servlet/BirtViewerServlet.java (added) +++ ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/servlet/BirtViewerServlet.java Thu Oct 15 04:48:28 2009 @@ -0,0 +1,143 @@ +package org.ofbiz.birt.report.servlet; + +import java.io.IOException; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.birt.core.exception.BirtException; +import org.eclipse.birt.report.IBirtConstants; +import org.eclipse.birt.report.context.IContext; +import org.eclipse.birt.report.presentation.aggregation.IFragment; +import org.eclipse.birt.report.presentation.aggregation.layout.FramesetFragment; +import org.eclipse.birt.report.presentation.aggregation.layout.RunFragment; +import org.eclipse.birt.report.service.BirtReportServiceFactory; +import org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet; +import org.eclipse.birt.report.utility.BirtUtility; +import org.ofbiz.birt.report.context.OFBizBirtContext; +import org.ofbiz.birt.report.service.OFBizBirtViewerReportService; + +public class BirtViewerServlet extends BirtSoapMessageDispatcherServlet { + + public final static String module = BirtViewerServlet.class.getName(); + + @Override + protected void __init(ServletConfig config) { + // TODO Auto-generated method stub + BirtReportServiceFactory.init( new OFBizBirtViewerReportService( config + .getServletContext( ) ) ); + + // handle 'frameset' pattern + viewer = new FramesetFragment( ); + viewer.buildComposite( ); + viewer.setJSPRootPath( "/webcontent/birt" ); //$NON-NLS-1$ + + // handle 'run' pattern + run = new RunFragment( ); + run.buildComposite( ); + run.setJSPRootPath( "/webcontent/birt" ); //$NON-NLS-1$ + } + + /** + * Init context. + * + * @param request + * incoming http request + * @param response + * http response + * @exception BirtException + * @return IContext + */ + protected IContext __getContext( HttpServletRequest request, + HttpServletResponse response ) throws BirtException + { + BirtReportServiceFactory.getReportService( ).setContext( + getServletContext( ), null ); + return new OFBizBirtContext( request, response ); + } + + /** + * Local process http request with GET method. + * + * @param request + * incoming http request + * @param response + * http response + * @exception ServletException + * @exception IOException + * @return + */ + protected void __doGet( IContext context ) throws ServletException, + IOException, BirtException + { + IFragment activeFragment = null; + String servletPath = context.getRequest( ).getServletPath( ); + if ( IBirtConstants.SERVLET_PATH_FRAMESET + .equalsIgnoreCase( servletPath ) ) + { + activeFragment = viewer; + } + else if ( IBirtConstants.SERVLET_PATH_RUN + .equalsIgnoreCase( servletPath ) ) + { + activeFragment = run; + } + + if ( activeFragment != null ) + activeFragment.service( context.getRequest( ), context + .getResponse( ) ); + } + + /** + * Locale process http request with POST method. Four different servlet + * paths are expected: "/frameset", "/navigation", "/toolbar", and "/run". + * + * @param request + * incoming http request + * @param response + * http response + * @exception ServletException + * @exception IOException + * @return + */ + protected void __doPost( IContext context ) throws ServletException, + IOException, BirtException + { + } + + /** + * Local authentication. Alwasy returns true. + * + * @param request + * incoming http request + * @param response + * http response + * @return + */ + protected boolean __authenticate( HttpServletRequest request, + HttpServletResponse response ) + { + return true; + } + + /** + * Process exception for non soap request. + * + * @param request + * incoming http request + * @param response + * http response + * @param exception + * @throws ServletException + * @throws IOException + */ + protected void __handleNonSoapException( HttpServletRequest request, + HttpServletResponse response, Exception exception ) + throws ServletException, IOException + { + exception.printStackTrace( ); + BirtUtility.appendErrorMessage( response.getOutputStream( ), exception ); + } +} Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/servlet/BirtViewerServlet.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/servlet/BirtViewerServlet.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/report/servlet/BirtViewerServlet.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/webapp/view/BirtViewHandler.java URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/webapp/view/BirtViewHandler.java?rev=825391&view=auto ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/webapp/view/BirtViewHandler.java (added) +++ ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/webapp/view/BirtViewHandler.java Thu Oct 15 04:48:28 2009 @@ -0,0 +1,102 @@ +package org.ofbiz.webapp.view; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.SQLException; +import java.util.Locale; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.parsers.ParserConfigurationException; + +import javolution.util.FastMap; + +import org.eclipse.birt.core.exception.BirtException; +import org.eclipse.birt.report.engine.api.IReportEngine; +import org.eclipse.birt.report.engine.api.IReportRunnable; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.birt.BirtWorker; +import org.ofbiz.birt.container.BirtContainer; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.widget.birt.BirtFactory; +import org.xml.sax.SAXException; + +public class BirtViewHandler implements ViewHandler { + + public static final String module = BirtViewHandler.class.getName(); + + protected ServletContext servletContext = null; + + private String name = "birt"; + + public void init(ServletContext context) throws ViewHandlerException { + // TODO Auto-generated method stub + this.servletContext = context; + } + + public String getName() { + // TODO Auto-generated method stub + return name; + } + + public void setName(String name) { + // TODO Auto-generated method stub + this.name = name; + } + + public void render(String name, String page, String info, + String contentType, String encoding, HttpServletRequest request, + HttpServletResponse response) throws ViewHandlerException { + // TODO Auto-generated method stub + try { + IReportEngine engine = BirtContainer.getReportEngine(); + // open report design + IReportRunnable design = null; + if (page.startsWith("component://")) { + InputStream reportInputStream = BirtFactory.getReportInputStreamFromLocation(page); + design = engine.openReportDesign(reportInputStream); + } else { + design = engine.openReportDesign(servletContext.getRealPath(page)); + } + + Map context = FastMap.newInstance(); + // set parameters from request + Map parameters = (Map)request.getAttribute(BirtWorker.BIRT_PARAMETERS); + if (parameters != null) { + context.put(BirtWorker.BIRT_PARAMETERS, parameters); + } + // set locale from request + Locale locale = (Locale)request.getAttribute(BirtWorker.BIRT_LOCALE); + if (locale == null) { + locale = UtilHttp.getLocale(request); + } + context.put(BirtWorker.BIRT_LOCALE, locale); + String birtImageDirectory = UtilProperties.getPropertyValue("birt", "birt.html.image.directory"); + context.put(BirtWorker.BIRT_IMAGE_DIRECTORY, birtImageDirectory); + BirtWorker.exportReport(design, context, contentType, response.getOutputStream()); + } catch (BirtException e) { + throw new ViewHandlerException("Birt Error create engine: " + e.toString(), e); + } catch (IOException e) { + throw new ViewHandlerException("Error in the response writer/output stream: " + e.toString(), e); + } catch (SQLException e) { + throw new ViewHandlerException("get connection error: " + e.toString(), e); + } catch (GenericEntityException e) { + throw new ViewHandlerException("generic entity error: " + e.toString(), e); + } catch (GeneralException e) { + throw new ViewHandlerException("general error: " + e.toString(), e); + } catch (SAXException se) { + String errMsg = "Error SAX rendering " + page + " view handler: " + se.toString(); + Debug.logError(se, errMsg, module); + throw new ViewHandlerException(errMsg, se); + } catch (ParserConfigurationException pe) { + String errMsg = "Error parser rendering " + page + " view handler: " + pe.toString(); + Debug.logError(pe, errMsg, module); + throw new ViewHandlerException(errMsg, pe); + } + } +} Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/webapp/view/BirtViewHandler.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/webapp/view/BirtViewHandler.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/webapp/view/BirtViewHandler.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/widget/BirtFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/widget/BirtFactory.java?rev=825391&view=auto ============================================================================== --- ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/widget/BirtFactory.java (added) +++ ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/widget/BirtFactory.java Thu Oct 15 04:48:28 2009 @@ -0,0 +1,51 @@ +package org.ofbiz.widget.birt; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import javax.xml.parsers.ParserConfigurationException; + +import org.ofbiz.base.location.FlexibleLocation; +import org.ofbiz.base.util.Debug; +import org.ofbiz.widget.screen.ScreenFactory; +import org.xml.sax.SAXException; + +public class BirtFactory { + + public static final String module = BirtFactory.class.getName(); + + /** + * get report inport stream from location + * @param resourceName + * @return + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + */ + public static InputStream getReportInputStreamFromLocation(String resourceName) + throws IOException, SAXException, ParserConfigurationException{ + + InputStream reportInputStream = null; + synchronized (BirtFactory.class) { + long startTime = System.currentTimeMillis(); + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + if (loader == null) { + loader = ScreenFactory.class.getClassLoader(); + } + URL reportFileUrl = null; + reportFileUrl = FlexibleLocation.resolveLocation(resourceName, loader); + if (reportFileUrl == null) { + throw new IllegalArgumentException("Could not resolve location to URL: " + resourceName); + } + reportInputStream = reportFileUrl.openStream(); + double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; + Debug.logInfo("Got report in " + totalSeconds + "s from: " + reportFileUrl.toExternalForm(), module); + } + + if (reportInputStream == null) { + throw new IllegalArgumentException("Could not find report file with location [" + resourceName + "]"); + } + return reportInputStream; + } +} Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/widget/BirtFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/widget/BirtFactory.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/addBirt/framework/webtools/src/org/ofbiz/birt/widget/BirtFactory.java ------------------------------------------------------------------------------ svn:mime-type = text/plain |
Free forum by Nabble | Edit this page |