2
0
Fork 0

made server gui work and auto generate xml imports

This commit is contained in:
Willem Cazander 2012-11-29 20:39:24 +01:00
parent 01b3b5cc54
commit c259e28e44
69 changed files with 1669 additions and 1230 deletions

View 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>

View 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>

View file

@ -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);
}
}

View file

@ -0,0 +1,6 @@
/**
* @author willemc
*
*/
package net.forwardfire.vasc.export.json;