Added pdf export support, export servlet support, renamed frontends
without s and made vasc config object.
This commit is contained in:
parent
efcbdbd519
commit
b3923bd2fb
160 changed files with 5001 additions and 2552 deletions
23
vasc-frontend/vasc-frontend-web-export/.project
Normal file
23
vasc-frontend/vasc-frontend-web-export/.project
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>vasc-frontend-web-export</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
32
vasc-frontend/vasc-frontend-web-export/pom.xml
Normal file
32
vasc-frontend/vasc-frontend-web-export/pom.xml
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>vasc-frontend</artifactId>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<version>0.3.5-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>vasc-frontend-web-export</artifactId>
|
||||
<name>vasc-frontend-web-export</name>
|
||||
<description>vasc-frontend-web-export</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc-ejb3</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.5</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* Copyright 2007-2012 forwardfire.net All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.vasc.frontend.web.export;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import net.forwardfire.vasc.core.VascController;
|
||||
import net.forwardfire.vasc.core.VascControllerProvider;
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryExporter;
|
||||
|
||||
/**
|
||||
* VascExportServlet exports the data from the vasc exporters on fixed url.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 12, 2012
|
||||
*/
|
||||
public class VascExportServlet extends HttpServlet {
|
||||
|
||||
private Logger logger = Logger.getLogger(VascExportServlet.class.getName());
|
||||
private static final long serialVersionUID = 6165530418422144322L;
|
||||
private VascControllerProvider vascControllerProvider = null;
|
||||
private boolean exportTree = false;
|
||||
|
||||
/**
|
||||
* @see javax.servlet.GenericServlet#init()
|
||||
*/
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
super.init();
|
||||
String className = getInitParameter("vascControllerProvider");
|
||||
if (className==null) {
|
||||
throw new ServletException("Can't start with null vascControllerProvider init parameter.");
|
||||
}
|
||||
String exportTreeStr = getInitParameter("exportTree");
|
||||
if (exportTreeStr!=null && "true".equalsIgnoreCase(exportTreeStr)) {
|
||||
exportTree = true;
|
||||
}
|
||||
try {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
if (cl == null) {
|
||||
cl = className.getClass().getClassLoader();
|
||||
}
|
||||
Class<?> clazz = cl.loadClass(className);
|
||||
vascControllerProvider = (VascControllerProvider)clazz.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new ServletException("Could not create VascControllerProvider: "+e.getMessage(),e);
|
||||
}
|
||||
logger.info("Export servlet started. (exportTree: "+exportTree+")");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
@Override
|
||||
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
String method = request.getMethod();
|
||||
if (method.equals("GET")==false) {
|
||||
response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Only GET allowed.");
|
||||
return;
|
||||
}
|
||||
// Remove prefixes
|
||||
String path = request.getRequestURI();
|
||||
String servlet = request.getServletPath();
|
||||
if (path.contains(servlet)) {
|
||||
path = path.substring(path.indexOf(servlet)+servlet.length());
|
||||
}
|
||||
if (path.startsWith("/")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
|
||||
// stuff to fill
|
||||
String entryId = null;
|
||||
String exportId = null;
|
||||
|
||||
if (exportTree) {
|
||||
int index = path.indexOf("/");
|
||||
String actionString = null;
|
||||
if (index>0) {
|
||||
actionString = path.substring(index+1);
|
||||
entryId = path.substring(0,index);
|
||||
} else {
|
||||
entryId = path;
|
||||
}
|
||||
|
||||
if (actionString!=null) {
|
||||
index = actionString.indexOf("/");
|
||||
String recordString = null;
|
||||
if (index>0) {
|
||||
recordString = actionString.substring(index+1);
|
||||
exportId = actionString.substring(0,index);
|
||||
} else {
|
||||
exportId = actionString;
|
||||
}
|
||||
if (recordString!=null) {
|
||||
// actionRecordId = recordString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tree overrules parameters.
|
||||
if (entryId==null) {
|
||||
entryId = request.getParameter("ve");
|
||||
}
|
||||
if (exportId==null) {
|
||||
exportId = request.getParameter("et");
|
||||
}
|
||||
|
||||
//out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), response.getCharacterEncoding()), true);
|
||||
OutputStream out = response.getOutputStream();
|
||||
try {
|
||||
VascController vc = vascControllerProvider.getVascController();
|
||||
VascEntry ve = vc.getVascEntryConfigController().configVascEntry(vc, entryId);
|
||||
vc.getVascEntryConfigController().configVascFrontendData(vc, ve, new Locale("en"));
|
||||
|
||||
// Update total every time first
|
||||
Long total = ve.getVascFrontendData().getVascEntryState().getVascBackend().fetchTotalExecuteSize(ve.getVascFrontendData().getVascEntryState().getVascBackendState());
|
||||
ve.getVascFrontendData().getVascEntryState().setTotalBackendRecords(total);
|
||||
VascEntryExporter ex = vc.getVascEntryConfigController().getVascEntryExporterById(exportId);
|
||||
|
||||
String filename = entryId+"-export."+ex.getFileType();
|
||||
response.setHeader("Content-disposition", "attachment; filename=" + filename);
|
||||
String contentType = ex.getMineType();
|
||||
response.setContentType(contentType);
|
||||
|
||||
ex.doExport(out, ve);
|
||||
} catch (VascException e) {
|
||||
response.setStatus(500);
|
||||
response.setContentType("text/html");
|
||||
}
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue