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
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue