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