[jbpm-commits] JBoss JBPM SVN: r4817 - in projects/report-server/trunk: core/src/main/java/org/jboss and 6 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri May 15 05:05:11 EDT 2009
Author: heiko.braun at jboss.com
Date: 2009-05-15 05:05:11 -0400 (Fri, 15 May 2009)
New Revision: 4817
Added:
projects/report-server/trunk/core/src/main/java/org/jboss/bpm/
projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/
projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/BirtEngineFactory.java
projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/BirtService.java
projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/IntegrationConfig.java
projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/RenderMetaData.java
projects/report-server/trunk/server/src/main/java/org/jboss/bpm/
projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/
projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/FileWriter.java
projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/JMXServerConfig.java
projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/ReportFacade.java
projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/ServerApplication.java
Removed:
projects/report-server/trunk/core/src/main/java/org/jboss/balalaika/
projects/report-server/trunk/server/src/main/java/org/jboss/balalaika/
Modified:
projects/report-server/trunk/pom.xml
projects/report-server/trunk/server/src/main/webapp/WEB-INF/web.xml
Log:
Rename packages
Added: projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/BirtEngineFactory.java
===================================================================
--- projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/BirtEngineFactory.java (rev 0)
+++ projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/BirtEngineFactory.java 2009-05-15 09:05:11 UTC (rev 4817)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.report;
+
+import org.eclipse.birt.report.engine.api.IReportEngine;
+import org.eclipse.birt.report.engine.api.EngineConfig;
+import org.eclipse.birt.report.engine.api.IReportEngineFactory;
+import org.eclipse.birt.core.framework.Platform;
+import org.eclipse.birt.core.exception.BirtException;
+
+/**
+ * Constructs an {@link IReportEngine} from {@link org.jboss.bpm.report.IntegrationConfig}
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class BirtEngineFactory
+{
+ public static IReportEngine newInstance(IntegrationConfig iConfig)
+ {
+ try
+ {
+ EngineConfig config = new EngineConfig( );
+ config.setBIRTHome(iConfig.getBirtHome());
+
+ Platform.startup( config );
+ IReportEngineFactory factory = (IReportEngineFactory) Platform
+ .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
+
+ IReportEngine engine = factory.createReportEngine( config );
+ return engine;
+ }
+ catch (BirtException e)
+ {
+ throw new RuntimeException("Failed to create birt engine", e);
+ }
+ }
+}
Added: projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/BirtService.java
===================================================================
--- projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/BirtService.java (rev 0)
+++ projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/BirtService.java 2009-05-15 09:05:11 UTC (rev 4817)
@@ -0,0 +1,188 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.report;
+
+import org.eclipse.birt.report.engine.api.*;
+import org.eclipse.birt.core.framework.Platform;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Core BIRT service component. Requires to step through the lifecycle
+ * before it can be used:
+ * <ul>
+ * <li>create: constructs a BIRT engine and platform
+ * <li>start:
+ * <li>stop:
+ * <li>destroy: destroy engine and shutdown platform
+ *
+ * @see org.eclipse.birt.report.engine.api.IReportEngine#destroy()
+ * @see org.eclipse.birt.core.framework.Platform#shutdown()
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class BirtService
+{
+ private static final Log log = LogFactory.getLog(BirtService.class);
+
+ private IReportEngine engine;
+ private IntegrationConfig iConfig;
+
+ private enum State {NONE, CREATED, STARTED, STOPPED, DESTROYED};
+ private State currentState = State.NONE;
+
+ public BirtService(IntegrationConfig iConfig)
+ {
+ this.iConfig = iConfig;
+ }
+
+ public void create()
+ {
+ this.engine = BirtEngineFactory.newInstance(iConfig);
+ log.info("Service created: " +this.engine);
+ currentState = State.CREATED;
+ }
+
+ public void start()
+ {
+ if(currentState!=State.CREATED)
+ throw new IllegalStateException("Please call create lifecylce before starting the service");
+
+ currentState = State.STARTED;
+ }
+
+ public void stop()
+ {
+ if(currentState!=State.STARTED)
+ throw new IllegalStateException("Please call start lifecylce before stopping the service");
+
+ currentState = State.STOPPED;
+ }
+
+ public void destroy()
+ {
+ if(engine!=null)
+ engine.destroy();
+ Platform.shutdown();
+ log.info("Service destroyed");
+ currentState = State.DESTROYED;
+ }
+
+ /**
+ * Render a report based on render meta data.
+ * this routin simply return the output filename.
+ * in order to get to an absolute path you need to prepend the service output directory:<p>
+ * <code>
+ * BirtService.getIntegrationConfig().getOutputDir() + outputFileName;
+ * </code>
+ *
+ * @param metaData render instruction like the template name
+ * @return output filename
+ */
+ public String render(RenderMetaData metaData)
+ {
+ if( (currentState==State.CREATED || currentState==State.STARTED) == false)
+ throw new IllegalStateException("Cannot render in state " + currentState);
+
+ String outputFileName = null;
+
+ log.debug("Render " + metaData);
+
+ try
+ {
+ //Open a report design
+ IReportRunnable design = engine.openReportDesign(iConfig.getReportDir()+metaData.getReportName());
+
+ //Create runRenderTask to run and render the report,
+ IRunAndRenderTask runRenderTask = engine.createRunAndRenderTask(design);
+ //Set parent classloader for engine
+ runRenderTask.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, metaData.getClassloader());
+ runRenderTask.setParameterValues(metaData.getParameters());
+
+ // ------------------
+
+ IRenderOption options = new RenderOption();
+ switch(metaData.getFormat())
+ {
+ case HTML:
+ options.setOutputFormat("html");
+ outputFileName = extactReportName(metaData.getReportName())+".html";
+ break;
+ case PDF:
+ options.setOutputFormat("pdf");
+ outputFileName = extactReportName(metaData.getReportName())+".pdf";
+ break;
+ }
+ options.setOutputFileName(iConfig.getOutputDir() + outputFileName);
+
+ // ------------------
+
+ if( options.getOutputFormat().equalsIgnoreCase("html"))
+ {
+ HTMLRenderOption htmlOptions = new HTMLRenderOption( options);
+ htmlOptions.setImageHandler(new HTMLServerImageHandler());
+ htmlOptions.setImageDirectory(iConfig.getImageDirectory());
+ htmlOptions.setBaseImageURL(iConfig.getImageBaseUrl());
+ htmlOptions.setHtmlPagination(false);
+ htmlOptions.setHtmlRtLFlag(false);
+ //Setting this to true removes html and body tags
+ htmlOptions.setEmbeddable(false);
+ runRenderTask.setRenderOption(htmlOptions);
+ }
+ else if( options.getOutputFormat().equalsIgnoreCase("pdf") ){
+
+ PDFRenderOption pdfOptions = new PDFRenderOption( options );
+ pdfOptions.setOption( IPDFRenderOption.FIT_TO_PAGE, new Boolean(true) );
+ pdfOptions.setOption( IPDFRenderOption.PAGEBREAK_PAGINATION_ONLY, new Boolean(true) );
+ runRenderTask.setRenderOption(pdfOptions);
+ }
+
+ // ------------------
+ if(runRenderTask.getRenderOption()==null)
+ runRenderTask.setRenderOption(options);
+
+ runRenderTask.run();
+ runRenderTask.close();
+ }
+ catch (EngineException e)
+ {
+ throw new RuntimeException("Failed to render report", e);
+ }
+
+ return outputFileName;
+ }
+
+ public IntegrationConfig getIntegrationConfig()
+ {
+ return iConfig;
+ }
+
+ private static String extactReportName(String reportFile)
+ {
+ return reportFile.substring( 0, reportFile.indexOf("."));
+ }
+
+ public State getCurrentState()
+ {
+ return currentState;
+ }
+}
Added: projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/IntegrationConfig.java
===================================================================
--- projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/IntegrationConfig.java (rev 0)
+++ projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/IntegrationConfig.java 2009-05-15 09:05:11 UTC (rev 4817)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.report;
+
+/**
+ * Adopts an integration layout (i.e. working directories) to BIRT configuration.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class IntegrationConfig
+{
+ private String birtHome = null;
+ private String reportDir = null;
+ private String outputDir = null;
+ private String imageBaseUrl = null;
+
+ public String getBirtHome()
+ {
+ return birtHome;
+ }
+
+ public void setBirtHome(String birtHome)
+ {
+ this.birtHome = birtHome;
+ }
+
+ public String getReportDir()
+ {
+ return reportDir;
+ }
+
+ public void setReportDir(String reportDir)
+ {
+ this.reportDir = ensureDirectoryName(reportDir);
+ }
+
+ public String getOutputDir()
+ {
+ return outputDir;
+ }
+
+ public void setOutputDir(String outputDir)
+ {
+ this.outputDir = ensureDirectoryName(outputDir);
+ }
+
+
+ public String getImageBaseUrl()
+ {
+ return imageBaseUrl;
+ }
+
+ public void setImageBaseUrl(String imageBaseUrl)
+ {
+ this.imageBaseUrl = ensureDirectoryName(imageBaseUrl);
+ }
+
+
+ public String getImageDirectory()
+ {
+ return getOutputDir()+"image/";
+ }
+
+ private String ensureDirectoryName(String name)
+ {
+ if(name.endsWith("/"))
+ return name;
+ else
+ return name+"/";
+ }
+
+}
Added: projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/RenderMetaData.java
===================================================================
--- projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/RenderMetaData.java (rev 0)
+++ projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/RenderMetaData.java 2009-05-15 09:05:11 UTC (rev 4817)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.report;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Drives a {@link org.jboss.bpm.report.BirtService#render(RenderMetaData)} call.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class RenderMetaData
+{
+ public enum Format {HTML, PDF};
+
+ private ClassLoader classloader;
+ private String reportName;
+ private Format format;
+ private Map parameters = new HashMap();
+
+ public RenderMetaData()
+ {
+ }
+
+ public RenderMetaData(ClassLoader classloader, String reportName, Format format, String imageBaseUrl)
+ {
+ this.classloader = classloader;
+ this.reportName = reportName;
+ this.format = format;
+ }
+
+ public ClassLoader getClassloader()
+ {
+ return classloader;
+ }
+
+ public void setClassloader(ClassLoader classloader)
+ {
+ this.classloader = classloader;
+ }
+
+ public String getReportName()
+ {
+ return reportName;
+ }
+
+ public void setReportName(String reportName)
+ {
+ this.reportName = reportName;
+ }
+
+ public Format getFormat()
+ {
+ return format;
+ }
+
+ public void setFormat(Format format)
+ {
+ this.format = format;
+ }
+
+
+ public String toString()
+ {
+ return "RenderMetaData {reportName="+reportName+", format="+format+"}";
+ }
+
+ public Map getParameters()
+ {
+ return parameters;
+ }
+}
Modified: projects/report-server/trunk/pom.xml
===================================================================
--- projects/report-server/trunk/pom.xml 2009-05-14 17:19:28 UTC (rev 4816)
+++ projects/report-server/trunk/pom.xml 2009-05-15 09:05:11 UTC (rev 4817)
@@ -17,7 +17,7 @@
<properties>
<commons.logging.version>1.1.1</commons.logging.version>
<junit.version>3.8.1</junit.version>
- <resteasy.version>1.0-beta-8</resteasy.version>
+ <resteasy.version>1.0.2.GA</resteasy.version>
<servlet.version>2.4</servlet.version>
</properties>
Added: projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/FileWriter.java
===================================================================
--- projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/FileWriter.java (rev 0)
+++ projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/FileWriter.java 2009-05-15 09:05:11 UTC (rev 4817)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.report;
+
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import java.lang.reflect.Type;
+import java.lang.annotation.Annotation;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.FileInputStream;
+import java.io.File;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+ at Provider
+ at Produces({"text/html", "image/*"})
+public class FileWriter implements MessageBodyWriter
+{
+
+ public boolean isWriteable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType)
+ {
+ return aClass.equals(java.io.File.class);
+ }
+
+ public long getSize(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType)
+ {
+ return ((File)o).length();
+ }
+
+ public void writeTo(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap multivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException
+ {
+ FileInputStream fin = new FileInputStream((File)o);
+ int c;
+ while ((c = fin.read()) != -1)
+ {
+ outputStream.write(c);
+ }
+
+ fin.close();
+
+ }
+}
Added: projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/JMXServerConfig.java
===================================================================
--- projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/JMXServerConfig.java (rev 0)
+++ projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/JMXServerConfig.java 2009-05-15 09:05:11 UTC (rev 4817)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.report;
+
+import javax.management.*;
+import java.io.File;
+import java.util.Hashtable;
+import java.util.List;
+
+/**
+ * Hooks into JMX to get the JBoss AS configuration.
+ * (temp directories, etc)
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class JMXServerConfig
+{
+ // The MBeanServer
+ private MBeanServer mbeanServer;
+
+ public JMXServerConfig()
+ {
+ this.mbeanServer = getDefaultMBeanServer();
+ }
+
+ public MBeanServer getMbeanServer()
+ {
+ return mbeanServer;
+ }
+
+ public void setMbeanServer(MBeanServer mbeanServer)
+ {
+ this.mbeanServer = mbeanServer;
+ }
+
+ public File getServerTempDir()
+ {
+ try
+ {
+ ObjectName oname = ObjectNameFactory.create("jboss.system:type=ServerConfig");
+ File dir = (File)getMbeanServer().getAttribute(oname, "ServerTempDir");
+ return dir;
+ }
+ catch (JMException e)
+ {
+ return null;
+ }
+ }
+
+ public File getHomeDir()
+ {
+ try
+ {
+ ObjectName oname = ObjectNameFactory.create("jboss.system:type=ServerConfig");
+ File dir = (File)getMbeanServer().getAttribute(oname, "HomeDir");
+ return dir;
+ }
+ catch (JMException e)
+ {
+ return null;
+ }
+ }
+
+ public File getServerDataDir()
+ {
+ try
+ {
+ ObjectName oname = ObjectNameFactory.create("jboss.system:type=ServerConfig");
+ File dir = (File)getMbeanServer().getAttribute(oname, "ServerDataDir");
+ return dir;
+ }
+ catch (JMException e)
+ {
+ return null;
+ }
+ }
+
+ public static MBeanServer getDefaultMBeanServer() {
+ return findMBeanServer("jboss");
+ }
+
+ private static MBeanServer findMBeanServer(String agentId) {
+ List servers = MBeanServerFactory.findMBeanServer(null);
+ if (servers != null && servers.size() > 0) {
+ for (Object object : servers) {
+ MBeanServer server = (MBeanServer) object;
+ if (server.getDefaultDomain().equals(agentId)) {
+ return server;
+ }
+ }
+ }
+ return null;
+ }
+
+ public static class ObjectNameFactory
+ {
+ public static ObjectName create(String name)
+ {
+ try
+ {
+ return new ObjectName(name);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new Error("Invalid ObjectName: " + name + "; " + e);
+ }
+ }
+
+ public static ObjectName create(String domain, String key, String value)
+ {
+ try
+ {
+ return new ObjectName(domain, key, value);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new Error("Invalid ObjectName: " + domain + "," + key + "," + value + "; " + e);
+ }
+ }
+
+ public static ObjectName create(String domain, Hashtable table)
+ {
+ try
+ {
+ return new ObjectName(domain, table);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new Error("Invalid ObjectName: " + domain + "," + table + "; " + e);
+ }
+ }
+ }
+}
Added: projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/ReportFacade.java
===================================================================
--- projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/ReportFacade.java (rev 0)
+++ projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/ReportFacade.java 2009-05-15 09:05:11 UTC (rev 4817)
@@ -0,0 +1,167 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.report;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import java.io.*;
+import java.util.HashMap;
+import java.util.Enumeration;
+import java.util.Map;
+
+/**
+ * BIRT integration facade.<p>
+ *
+ * Uses the server data directory (i.e. <code>$JBOSS_HOME/server/default/data/birt</code>)
+ * as it's work directory (referred to as $WORK_DIR in the subsequent sections):
+ *
+ * <ul>
+ * <li>report template location: $WORK_DIR/
+ * <li>output directory: $WORK_DIR/output
+ * </ul>
+ *
+ * NOTE: It requires a BIRT report engine to be installed in the work directory:
+ * (<code>$WORK_DIR/ReportEngine</code>.
+ *
+ * @see org.jboss.bpm.report.JMXServerConfig
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+ at Path("report")
+public class ReportFacade
+{
+ private static final Log log = LogFactory.getLog(ReportFacade.class);
+ private BirtService birtService;
+ private boolean isInitialized;
+
+ public void lazyInitialize(HttpServletRequest request)
+ {
+ if(!isInitialized)
+ {
+ JMXServerConfig jmxConfig = new JMXServerConfig();
+ IntegrationConfig iConfig = new IntegrationConfig();
+
+ File severDataDir = jmxConfig.getServerDataDir();
+ String absServerDataDir = severDataDir.getAbsolutePath();
+
+ String birtDataDir = absServerDataDir + "/birt";
+ String defaultBirtHome = birtDataDir + "/ReportEngine";
+ String birtOutputDir = birtDataDir + "/output";
+
+ File birtOutput = new File(birtOutputDir);
+ birtOutput.mkdirs(); // will create parent directoy as well
+
+ // check dependency on ReportEngine
+ if(! new File(defaultBirtHome).exists())
+ throw new IllegalStateException("The BIRT report engine doesn't seem to be installed:" +defaultBirtHome);
+
+ // --
+
+ iConfig.setBirtHome(defaultBirtHome);
+ iConfig.setOutputDir( birtOutputDir );
+ iConfig.setReportDir( birtDataDir );
+
+ StringBuffer sb = new StringBuffer();
+ sb.append("http://");
+ sb.append(request.getServerName()).append(":");
+ sb.append(request.getServerPort());
+ sb.append(request.getContextPath());
+ sb.append(request.getServletPath());
+ sb.append("/report/view/image");
+
+ iConfig.setImageBaseUrl(sb.toString());
+
+ log.info("BIRT home: " +iConfig.getBirtHome());
+ log.info("Output dir: " +iConfig.getOutputDir());
+ log.info("Report dir: " +iConfig.getReportDir());
+
+ this.birtService = new BirtService(iConfig);
+ this.birtService.create();
+
+ isInitialized = true;
+ }
+ }
+
+ @GET
+ @Path("view/{fileName}")
+ @Produces("text/html")
+ public Response viewReportHtml(
+ @PathParam("fileName")
+ String fileName,
+ @Context HttpServletRequest
+ request
+ )
+ {
+ lazyInitialize(request);
+
+ Map queryParams = convertRequestParametersToMap(request);
+
+ RenderMetaData renderMeta = new RenderMetaData();
+ renderMeta.setReportName(fileName);
+ renderMeta.setFormat(RenderMetaData.Format.HTML);
+ renderMeta.setClassloader(Thread.currentThread().getContextClassLoader());
+ renderMeta.getParameters().putAll(queryParams);
+
+ String outputFileName = birtService.render(renderMeta);
+ String absoluteFile = birtService.getIntegrationConfig().getOutputDir() + outputFileName;
+ log.info("Render " + absoluteFile);
+
+ File reportFile = new File(absoluteFile);
+ return Response.ok(reportFile).type("text/html").build();
+ }
+
+ @GET
+ @Path("view/image/{fileName}")
+ public Response getImage(
+ @PathParam("fileName")
+ String fileName,
+ @Context HttpServletRequest
+ request
+ )
+ {
+ lazyInitialize(request);
+
+ String imageDir = birtService.getIntegrationConfig().getImageDirectory();
+ String absName = imageDir + fileName;
+ File imageFile = new File(absName);
+ if(!imageFile.exists())
+ throw new IllegalArgumentException("Image " +absName+" doesn't exist");
+ return Response.ok(imageFile).build();
+ }
+
+ static public Map<String, String> convertRequestParametersToMap(HttpServletRequest request){
+ Enumeration<?> initParameters=request.getParameterNames();
+ HashMap<String, String> parameterMap = new HashMap<String, String>();
+ while (initParameters.hasMoreElements()) {
+ String param = (String) initParameters.nextElement();
+ String value = request.getParameter(param);
+ if (param != null & value != null)
+ parameterMap.put(param, value);
+ }
+ return parameterMap;
+ }
+}
Added: projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/ServerApplication.java
===================================================================
--- projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/ServerApplication.java (rev 0)
+++ projects/report-server/trunk/server/src/main/java/org/jboss/bpm/report/ServerApplication.java 2009-05-15 09:05:11 UTC (rev 4817)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.report;
+
+import javax.ws.rs.core.Application;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * JAX-RS core component.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class ServerApplication extends Application
+{
+ HashSet<Object> singletons = new HashSet<Object>();
+
+ public ServerApplication()
+ {
+ singletons.add(new ReportFacade());
+ }
+
+ @Override
+ public Set<Class<?>> getClasses()
+ {
+ HashSet<Class<?>> set = new HashSet<Class<?>>();
+ return set;
+ }
+
+ @Override
+ public Set<Object> getSingletons()
+ {
+ return singletons;
+ }
+}
Modified: projects/report-server/trunk/server/src/main/webapp/WEB-INF/web.xml
===================================================================
--- projects/report-server/trunk/server/src/main/webapp/WEB-INF/web.xml 2009-05-14 17:19:28 UTC (rev 4816)
+++ projects/report-server/trunk/server/src/main/webapp/WEB-INF/web.xml 2009-05-15 09:05:11 UTC (rev 4817)
@@ -7,7 +7,7 @@
<context-param>
<param-name>javax.ws.rs.core.Application</param-name>
- <param-value>org.jboss.balalaika.ServerApplication</param-value>
+ <param-value>org.jboss.bpm.report.ServerApplication</param-value>
</context-param>
<context-param>
@@ -17,7 +17,7 @@
<context-param>
<param-name>resteasy.providers</param-name>
- <param-value>org.jboss.balalaika.FileWriter</param-value>
+ <param-value>org.jboss.bpm.report.FileWriter</param-value>
</context-param>
<!--context-param>
More information about the jbpm-commits
mailing list