made server gui work and auto generate xml imports
This commit is contained in:
parent
01b3b5cc54
commit
c259e28e44
69 changed files with 1669 additions and 1230 deletions
17
vasc-export/.project
Normal file
17
vasc-export/.project
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>vasc-export</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
18
vasc-export/pom.xml
Normal file
18
vasc-export/pom.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<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>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc</artifactId>
|
||||
<version>0.4.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>vasc-export</artifactId>
|
||||
<groupId>net.forwardfire.vasc.export</groupId>
|
||||
<packaging>pom</packaging>
|
||||
<name>vasc-export</name>
|
||||
<description>vasc-export</description>
|
||||
<modules>
|
||||
<module>vasc-export-jr4o</module>
|
||||
<module>vasc-export-json</module>
|
||||
<module>vasc-export-generic</module>
|
||||
</modules>
|
||||
</project>
|
||||
23
vasc-export/vasc-export-generic/.project
Normal file
23
vasc-export/vasc-export-generic/.project
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>vasc-export-generic</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>
|
||||
18
vasc-export/vasc-export-generic/pom.xml
Normal file
18
vasc-export/vasc-export-generic/pom.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<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>
|
||||
<groupId>net.forwardfire.vasc.export</groupId>
|
||||
<artifactId>vasc-export</artifactId>
|
||||
<version>0.4.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>vasc-export-generic</artifactId>
|
||||
<name>vasc-export-generic</name>
|
||||
<description>vasc-export-generic</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* 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.export.generic;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryExport;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryExportWriter;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
|
||||
/**
|
||||
* AbstractVascEntryExportWriter make read of paged data into methods.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Nov 23, 2012
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
abstract public class AbstractVascEntryExportWriter implements VascEntryExportWriter {
|
||||
|
||||
private VascEntryExport vascEntryExport = null;
|
||||
private VascEntry vascEntry = null;
|
||||
|
||||
public void doInit(VascEntryExport vascEntryExport,VascEntry vascEntry) throws VascException {
|
||||
this.vascEntryExport=vascEntryExport;
|
||||
this.vascEntry=vascEntry;
|
||||
}
|
||||
|
||||
public void doExport(OutputStream out) throws IOException,VascException {
|
||||
|
||||
doExportInit(out);
|
||||
doExportStart();
|
||||
|
||||
VascEntry entry = getVascEntry();
|
||||
int oldIndex = entry.getVascFrontendController().getVascEntryState().getVascBackendState().getPageIndex();
|
||||
Long total = entry.getVascFrontendController().getVascEntryState().getTotalBackendRecords();
|
||||
int pages = total.intValue()/entry.getVascFrontendController().getVascEntryState().getVascBackendState().getPageSize();
|
||||
for (int page=0;page<=pages;page++) {
|
||||
entry.getVascFrontendController().getVascEntryState().getVascBackendState().setPageIndex(page);
|
||||
entry.getVascFrontendController().getVascFrontendActions().refreshData();
|
||||
|
||||
int dataSize = entry.getVascFrontendController().getVascEntryState().getEntryDataList().size();
|
||||
for (int dataIndex=0;dataIndex<dataSize;dataIndex++) {
|
||||
Object o = entry.getVascFrontendController().getVascEntryState().getEntryDataList().get(dataIndex);
|
||||
doExportRowStart(o);
|
||||
doExportRowFields(o);
|
||||
doExportRowEnd(o,(dataIndex==dataSize-1));
|
||||
}
|
||||
}
|
||||
doExportEnd();
|
||||
|
||||
// restore old page size
|
||||
entry.getVascFrontendController().getVascEntryState().getVascBackendState().setPageIndex(oldIndex);
|
||||
}
|
||||
|
||||
protected VascEntry getVascEntry() {
|
||||
return vascEntry;
|
||||
}
|
||||
|
||||
|
||||
protected VascEntryExport getVascEntryExport() {
|
||||
return vascEntryExport;
|
||||
}
|
||||
|
||||
abstract protected void doExportInit(OutputStream out);
|
||||
|
||||
abstract protected void doExportStart() throws IOException;
|
||||
abstract protected void doExportEnd() throws IOException;
|
||||
|
||||
abstract protected void doExportRowStart(Object row) throws IOException;
|
||||
abstract protected void doExportRowEnd(Object row,boolean isLast) throws IOException;
|
||||
|
||||
protected void doExportRowFields(Object row) throws IOException,VascException {
|
||||
// todo: rm me and use data selector
|
||||
List<VascEntryField> fieldList = new ArrayList<VascEntryField>(getVascEntry().getVascEntryFields());
|
||||
int fields = fieldList.size();
|
||||
for (int i=0;i<fields;i++) {
|
||||
VascEntryField c = fieldList.get(i);
|
||||
doExportRowField(row,c,(i==fields-1));
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected void doExportRowField(Object row,VascEntryField field,boolean isLast) throws IOException,VascException;
|
||||
}
|
||||
|
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
* 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.export.generic;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
|
||||
/**
|
||||
* VascEntryExporterCsv writes data to csv output format.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 30, 2007
|
||||
*/
|
||||
public class VascEntryExportWriterCsv extends AbstractVascEntryExportWriter {
|
||||
|
||||
private static final long serialVersionUID = 2770924442917617161L;
|
||||
static public final String EXPORT_TYPE = "csv";
|
||||
private PrintWriter p = null;
|
||||
private CsvSeparator separatorChar = CsvSeparator.SEMICOLON;
|
||||
private CsvQuote quoteChar = CsvQuote.DOUBLE;
|
||||
private CsvLineEnd lineEnd = CsvLineEnd.LF;
|
||||
|
||||
enum CsvSeparator {
|
||||
TAB("\t"),
|
||||
COMMA(","),
|
||||
DOT("."),
|
||||
COLON(":"),
|
||||
SEMICOLON(";"),
|
||||
EQUAL("="),
|
||||
EQUALS("==");
|
||||
final String charType;
|
||||
CsvSeparator(String charType) {
|
||||
this.charType=charType;
|
||||
}
|
||||
String toCharType() {
|
||||
return charType;
|
||||
}
|
||||
}
|
||||
|
||||
enum CsvQuote {
|
||||
NONE(""),
|
||||
SINGLE("'"),
|
||||
DOUBLE("\"");
|
||||
|
||||
final String charType;
|
||||
CsvQuote(String charType) {
|
||||
this.charType=charType;
|
||||
}
|
||||
String toCharType() {
|
||||
return charType;
|
||||
}
|
||||
}
|
||||
|
||||
enum CsvLineEnd {
|
||||
CR("\r"),
|
||||
LF("\n"),
|
||||
CRLF("\r\n");
|
||||
|
||||
final String charType;
|
||||
CsvLineEnd(String charType) {
|
||||
this.charType=charType;
|
||||
}
|
||||
String toCharType() {
|
||||
return charType;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportInit(OutputStream out) {
|
||||
p = new PrintWriter(out);
|
||||
String separatorCharString = getVascEntryExport().getWriterParameter("separatorChar");
|
||||
if (separatorCharString!=null && separatorCharString.isEmpty()==false) {
|
||||
separatorChar = CsvSeparator.valueOf(separatorCharString);
|
||||
}
|
||||
String quoteCharString = getVascEntryExport().getWriterParameter("quoteChar");
|
||||
if (quoteCharString!=null && quoteCharString.isEmpty()==false) {
|
||||
quoteChar = CsvQuote.valueOf(quoteCharString);
|
||||
}
|
||||
String lineEndString = getVascEntryExport().getWriterParameter("lineEnd");
|
||||
if (lineEndString!=null && lineEndString.isEmpty()==false) {
|
||||
lineEnd = CsvLineEnd.valueOf(lineEndString);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportStart() {
|
||||
//p.write("# csv\n");
|
||||
for (VascEntryField c:getVascEntry().getVascEntryFields()) {
|
||||
p.write(c.getId()+separatorChar.toCharType());
|
||||
}
|
||||
p.write(lineEnd.toCharType());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportEnd() {
|
||||
p.write("#EOF end-of-file");
|
||||
p.write(lineEnd.toCharType());
|
||||
p.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportRowStart(Object row) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportRowEnd(Object row,boolean isLast) {
|
||||
p.write(lineEnd.toCharType());
|
||||
p.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportRowField(Object o, VascEntryField c,boolean isLast) throws VascException {
|
||||
p.write(quoteChar.toCharType());
|
||||
p.write(c.getVascEntryFieldValue().getDisplayValue(c, o));
|
||||
p.write(quoteChar.toCharType());
|
||||
if (isLast==false) {
|
||||
p.write(separatorChar.toCharType());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.entry.VascEntryExport#getMineType()
|
||||
*/
|
||||
public String getMineType() {
|
||||
return "text/csv";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.entry.VascEntryExport#getFileType()
|
||||
*/
|
||||
public String getFileType() {
|
||||
return EXPORT_TYPE;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* 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.export.generic;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
|
||||
/**
|
||||
* VascEntryExportWriterXml writes entry data to xml format.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 30, 2007
|
||||
*/
|
||||
public class VascEntryExportWriterXml extends AbstractVascEntryExportWriter {
|
||||
|
||||
private static final long serialVersionUID = 3719424578585760828L;
|
||||
static public final String EXPORT_TYPE = "xml";
|
||||
private boolean xmlTree = false;
|
||||
private PrintWriter p = null;
|
||||
|
||||
@Override
|
||||
protected void doExportInit(OutputStream out) {
|
||||
p = new PrintWriter(out);
|
||||
String xmlTreeString = getVascEntryExport().getWriterParameter("xmltree");
|
||||
if (xmlTreeString!=null && "true".equalsIgnoreCase(xmlTreeString)) {
|
||||
xmlTree = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportStart() {
|
||||
p.write("<?xml version=\"1.0\"?>\n");
|
||||
p.write("<data>\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportEnd() {
|
||||
p.write("</data>\n");
|
||||
p.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportRowStart(Object row) {
|
||||
p.write("\t<row>\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportRowEnd(Object row,boolean isLast) {
|
||||
p.write("\t</row>\n");
|
||||
p.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportRowField(Object o, VascEntryField c,boolean isLast) throws VascException {
|
||||
if (xmlTree) {
|
||||
p.write("\t\t<"+c.getId()+"><![CDATA[");
|
||||
p.write(""+c.getVascEntryFieldValue().getDisplayValue(c, o));
|
||||
p.write("]]></"+c.getId()+">\n");
|
||||
} else {
|
||||
p.write("\t\t<column name=\""+c.getId()+"\"><![CDATA[");
|
||||
p.write(""+c.getVascEntryFieldValue().getDisplayValue(c, o));
|
||||
p.write("]]></column>\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.entry.VascEntryExport#getMineType()
|
||||
*/
|
||||
public String getMineType() {
|
||||
return "text/xml";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.entry.VascEntryExport#getFileType()
|
||||
*/
|
||||
public String getFileType() {
|
||||
return EXPORT_TYPE;
|
||||
}
|
||||
}
|
||||
23
vasc-export/vasc-export-jr4o/.project
Normal file
23
vasc-export/vasc-export-jr4o/.project
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>vasc-export-jr4o</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>
|
||||
23
vasc-export/vasc-export-jr4o/pom.xml
Normal file
23
vasc-export/vasc-export-jr4o/pom.xml
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<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>
|
||||
<groupId>net.forwardfire.vasc.export</groupId>
|
||||
<artifactId>vasc-export</artifactId>
|
||||
<version>0.4.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>vasc-export-jr4o</artifactId>
|
||||
<name>vasc-export-jr4o</name>
|
||||
<description>vasc-export-jr4o</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.forwardfire.vasc.export</groupId>
|
||||
<artifactId>vasc-export-generic</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.forwardfire.vasc.lib</groupId>
|
||||
<artifactId>vasc-lib-jr4o</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* 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.export.jr4o;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.lib.jr4o.data.AbstractJRDynamicDataSource;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
import net.sf.jasperreports.engine.JRField;
|
||||
import net.sf.jasperreports.engine.design.JRDesignField;
|
||||
import net.sf.jasperreports.engine.design.JasperDesign;
|
||||
|
||||
/**
|
||||
* JRDynamicDataSourceVascEntry converts the Vasc backend data to JasperReports data.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 11, 2012
|
||||
*/
|
||||
public class JRDynamicDataSourceVascEntry extends AbstractJRDynamicDataSource {
|
||||
|
||||
|
||||
private VascEntry vascEntry = null;
|
||||
private long total = -1;
|
||||
private int index = -1;
|
||||
private static final String PREFIX_COLUMN = "COLUMN_";
|
||||
private static final String PREFIX_HEADER = "HEADER_";
|
||||
private static final String INFIX_CLASS = "CLASS_";
|
||||
|
||||
private List<List<String>> data = null;
|
||||
|
||||
public JRDynamicDataSourceVascEntry(VascEntry vascEntry) {
|
||||
if (vascEntry==null) {
|
||||
throw new NullPointerException("vascEntry can't be null.");
|
||||
}
|
||||
this.vascEntry = vascEntry;
|
||||
total = vascEntry.getVascFrontendController().getVascEntryState().getTotalBackendRecords();
|
||||
|
||||
// hackje until calc index to page and row.
|
||||
try {
|
||||
data = new ArrayList<List<String>>(1000);
|
||||
int pages = (int)total/vascEntry.getVascFrontendController().getVascEntryState().getVascBackendState().getPageSize();
|
||||
for (int page=0;page<=pages;page++) {
|
||||
vascEntry.getVascFrontendController().getVascEntryState().getVascBackendState().setPageIndex(page);
|
||||
vascEntry.getVascFrontendController().getVascFrontendActions().refreshData();
|
||||
for (Object o:vascEntry.getVascFrontendController().getVascEntryState().getEntryDataList()) {
|
||||
List<String> row = new ArrayList<String>(30);
|
||||
for (VascEntryField c:vascEntry.getVascEntryFields()) {
|
||||
row.add(c.getVascEntryFieldValue().getDisplayValue(c, o));
|
||||
}
|
||||
data.add(row);
|
||||
}
|
||||
}
|
||||
} catch (VascException ve) {
|
||||
throw new RuntimeException(ve);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sf.jasperreports.engine.JRDataSource#getFieldValue(net.sf.jasperreports.engine.JRField)
|
||||
*/
|
||||
public Object getFieldValue(JRField jrField) throws JRException {
|
||||
String fieldName = jrField.getName();
|
||||
if (fieldName.startsWith(PREFIX_COLUMN)) {
|
||||
return data.get(index).get(Integer.parseInt(fieldName.substring(7)));
|
||||
}
|
||||
if (fieldName.startsWith(PREFIX_HEADER)) {
|
||||
return "todo"; // TODO: fixme
|
||||
//List<VascEntryField> fields = vascEntry.getVascEntryFields();
|
||||
//VascEntryField field = fields.get(Integer.parseInt(fieldName.substring(7)));
|
||||
//return vascEntry.getVascFrontendController().getVascEntryResourceResolver().getTextValue(field.getName());
|
||||
}
|
||||
throw new JRException("Unknown column name : " + fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.lib.jr4o.data.JRDynamicDataSource#addDynamicColumnClassFields(net.sf.jasperreports.engine.design.JasperDesign)
|
||||
*/
|
||||
public void addDynamicColumnClassFields(JasperDesign jd) throws JRException {
|
||||
JRDesignField field;
|
||||
for (int i=0;i<getDynamicColumnCount();i++) {
|
||||
field = new JRDesignField();
|
||||
field.setName(PREFIX_COLUMN+i);
|
||||
field.setValueClass(String.class); // todo
|
||||
jd.addField(field);
|
||||
|
||||
field = new JRDesignField();
|
||||
field.setName(PREFIX_HEADER+i);
|
||||
field.setValueClass(String.class);
|
||||
jd.addField(field);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.lib.jr4o.data.JRDynamicDataSource#addDynamicELBean()
|
||||
*/
|
||||
public Map<String, Object> addDynamicELBean() {
|
||||
Map<String,Object> result = new HashMap<String,Object>(10);
|
||||
for (int i=0;i<getDynamicColumnCount();i++) {
|
||||
result.put(PREFIX_COLUMN+INFIX_CLASS+i,String.class); // todo
|
||||
result.put(PREFIX_HEADER+INFIX_CLASS+i,String.class);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.lib.jr4o.data.JRDynamicDataSource#getDynamicColumnX(int)
|
||||
*/
|
||||
public int getDynamicColumnX(int col) {
|
||||
int result = 0;
|
||||
for (int i=0;i<col;i++) {
|
||||
result += 80;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.lib.jr4o.data.JRDynamicDataSource#getDynamicColumnWidth(int)
|
||||
*/
|
||||
public int getDynamicColumnWidth(int col) {
|
||||
return 80; // todo
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.lib.jr4o.data.JRDynamicDataSource#getDynamicColumnCount()
|
||||
*/
|
||||
public int getDynamicColumnCount() {
|
||||
return vascEntry.getVascEntryFields().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sf.jasperreports.engine.JRDataSource#next()
|
||||
*/
|
||||
public boolean next() throws JRException {
|
||||
index++;
|
||||
return (index < total);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sf.jasperreports.engine.JRRewindableDataSource#moveFirst()
|
||||
*/
|
||||
public void moveFirst() throws JRException {
|
||||
index = -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* 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.export.jr4o;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryExport;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryExportWriter;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.lib.jr4o.JR4ODesignManager;
|
||||
import net.forwardfire.vasc.lib.jr4o.JR4ODesignManager.JRExportType;
|
||||
|
||||
/**
|
||||
* VascEntryExportWriterJR4O creates an pdf view of the data.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 11, 2012
|
||||
*/
|
||||
public class VascEntryExportWriterJR4O implements VascEntryExportWriter {
|
||||
|
||||
private static final long serialVersionUID = -3951608685719832654L;
|
||||
static public final String EXPORT_TYPE = "pdf";
|
||||
private VascEntry entry = null;
|
||||
private JRExportType reportType = JRExportType.PDF;
|
||||
private String reportResource = null;
|
||||
private String reportName = null;
|
||||
private File reportFile = null;
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.entry.VascEntryExportWriter#doInit(net.forwardfire.vasc.core.entry.VascEntryExport, net.forwardfire.vasc.core.VascEntry)
|
||||
*/
|
||||
@Override
|
||||
public void doInit(VascEntryExport export, VascEntry vascEntry) throws VascException {
|
||||
this.entry = vascEntry;
|
||||
|
||||
String reportTypeString = export.getWriterParameter("reportType");
|
||||
if (reportTypeString!=null && reportTypeString.isEmpty()==false) {
|
||||
reportType = JRExportType.valueOf(reportTypeString);
|
||||
}
|
||||
reportName = export.getWriterParameter("reportName");
|
||||
if (reportName==null) {
|
||||
throw new NullPointerException("Can work with null reportName parameter.");
|
||||
}
|
||||
|
||||
String reportFileString = export.getWriterParameter("reportFile");
|
||||
if (reportFileString!=null && reportFileString.isEmpty()==false) {
|
||||
reportFile = new File(reportFileString);
|
||||
}
|
||||
reportResource = export.getWriterParameter("reportResource");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.entry.VascEntryExport#doExport(java.io.OutputStream, net.forwardfire.vasc.core.VascEntry)
|
||||
*/
|
||||
public void doExport(OutputStream out) throws VascException {
|
||||
|
||||
Map<String,Object> parameters = new HashMap<String,Object>(5);
|
||||
parameters.put("title", entry.getVascFrontendController().getVascEntryResourceResolver().getTextValue(entry.getName()));
|
||||
parameters.put("description", entry.getVascFrontendController().getVascEntryResourceResolver().getTextValue(entry.getListDescription()));
|
||||
parameters.put("titleSubject", entry.getVascFrontendController().getVascEntryResourceResolver().getTextValue(entry.getId()));
|
||||
|
||||
int oldIndex = entry.getVascFrontendController().getVascEntryState().getVascBackendState().getPageIndex();
|
||||
String bundle = entry.getVascFrontendController().getVascController().getVascEntryConfigController().getResourceBundle();
|
||||
JRDynamicDataSourceVascEntry dataSource = new JRDynamicDataSourceVascEntry(entry);
|
||||
JR4ODesignManager jr4o = new JR4ODesignManager(dataSource,bundle,parameters);
|
||||
try {
|
||||
if (reportResource!=null) {
|
||||
jr4o.parseResource(reportResource);
|
||||
} else if (reportFile!=null) {
|
||||
jr4o.parseFile(reportFile);
|
||||
} else {
|
||||
throw new NullPointerException("No report input data defined,reportResource and reportFile are null.");
|
||||
}
|
||||
jr4o.saveReportStream(reportName, reportType, out);
|
||||
} catch (Exception e) {
|
||||
throw new VascException(e);
|
||||
} finally {
|
||||
entry.getVascFrontendController().getVascEntryState().getVascBackendState().setPageIndex(oldIndex); // restore page index
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.entry.VascEntryExport#getMineType()
|
||||
*/
|
||||
public String getMineType() {
|
||||
return "text/pdf";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.entry.VascEntryExport#getFileType()
|
||||
*/
|
||||
public String getFileType() {
|
||||
return EXPORT_TYPE;
|
||||
}
|
||||
}
|
||||
23
vasc-export/vasc-export-json/.project
Normal file
23
vasc-export/vasc-export-json/.project
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>vasc-export-json</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>
|
||||
23
vasc-export/vasc-export-json/pom.xml
Normal file
23
vasc-export/vasc-export-json/pom.xml
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<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>
|
||||
<groupId>net.forwardfire.vasc.export</groupId>
|
||||
<artifactId>vasc-export</artifactId>
|
||||
<version>0.4.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>vasc-export-json</artifactId>
|
||||
<name>vasc-export-json</name>
|
||||
<description>vasc-export-json</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.forwardfire.vasc.export</groupId>
|
||||
<artifactId>vasc-export-generic</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>${json-simple.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* 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.export.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.export.generic.AbstractVascEntryExportWriter;
|
||||
|
||||
/**
|
||||
* VascEntryExportWriterJson exports the entry data to json format.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Nov 23, 2012
|
||||
*/
|
||||
public class VascEntryExportWriterJson extends AbstractVascEntryExportWriter {
|
||||
|
||||
private static final long serialVersionUID = 2965474124451161061L;
|
||||
private PrintWriter p = null;
|
||||
private Map<String,Object> rowData = null;
|
||||
|
||||
public VascEntryExportWriterJson() {
|
||||
rowData = new HashMap<String,Object>(60);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMineType() {
|
||||
return "text/json";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileType() {
|
||||
return "json";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportInit(OutputStream out) {
|
||||
p = new PrintWriter(out);
|
||||
}
|
||||
|
||||
private void writeField(String key,String value) {
|
||||
p.write("\"");
|
||||
p.write(key);
|
||||
p.write("\": \"");
|
||||
p.write(JSONValue.escape(value));
|
||||
p.write("\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportStart() {
|
||||
p.write("{\"entry\": {\n");
|
||||
writeField("id",getVascEntry().getId());
|
||||
p.write(",\n");
|
||||
writeField("vascGroupId",getVascEntry().getVascGroupId());
|
||||
p.write(",\n");
|
||||
p.write("\"data\": [\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportEnd() {
|
||||
p.write("]\n");
|
||||
p.write("}}\n");
|
||||
p.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportRowStart(Object row) {
|
||||
rowData.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportRowEnd(Object row,boolean isLast) throws IOException {
|
||||
JSONObject.writeJSONString(rowData, p);
|
||||
if (isLast==false) {
|
||||
p.write(",");
|
||||
}
|
||||
p.write("\n");
|
||||
p.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExportRowField(Object row, VascEntryField field,boolean isLast) throws VascException {
|
||||
String key = field.getId();
|
||||
Object data = field.getVascEntryFieldValue().getValue(field, row);
|
||||
rowData.put(key, data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
/**
|
||||
* @author willemc
|
||||
*
|
||||
*/
|
||||
package net.forwardfire.vasc.export.json;
|
||||
Loading…
Add table
Add a link
Reference in a new issue