summaryrefslogtreecommitdiff
path: root/jasper_reports/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'jasper_reports/java/com')
-rwxr-xr-xjasper_reports/java/com/nantic/jasperreports/CsvMultiLanguageDataSource.java115
-rwxr-xr-xjasper_reports/java/com/nantic/jasperreports/I18nGetText.java60
-rwxr-xr-xjasper_reports/java/com/nantic/jasperreports/I18nGroovyCompiler.java224
-rwxr-xr-xjasper_reports/java/com/nantic/jasperreports/JasperServer.java343
-rwxr-xr-xjasper_reports/java/com/nantic/jasperreports/LanguageTable.java49
-rwxr-xr-xjasper_reports/java/com/nantic/jasperreports/ReportCompiler.java51
-rwxr-xr-xjasper_reports/java/com/nantic/jasperreports/Translator.java206
-rwxr-xr-xjasper_reports/java/com/nantic/jasperreports/XmlMultiLanguageDataSource.java78
8 files changed, 1126 insertions, 0 deletions
diff --git a/jasper_reports/java/com/nantic/jasperreports/CsvMultiLanguageDataSource.java b/jasper_reports/java/com/nantic/jasperreports/CsvMultiLanguageDataSource.java
new file mode 100755
index 0000000..43908b4
--- /dev/null
+++ b/jasper_reports/java/com/nantic/jasperreports/CsvMultiLanguageDataSource.java
@@ -0,0 +1,115 @@
+/*
+Copyright (c) 2008-2012 NaN Projectes de Programari Lliure, S.L.
+ http://www.NaN-tic.com
+
+WARNING: This program as such is intended to be used by professional
+programmers who take the whole responsability of assessing all potential
+consequences resulting from its eventual inadequacies and bugs
+End users who are looking for a ready-to-use solution with commercial
+garantees and support are strongly adviced to contract a Free Software
+Service Company
+
+This program is Free Software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+package com.nantic.jasperreports;
+
+import net.sf.jasperreports.engine.JRRewindableDataSource;
+import net.sf.jasperreports.engine.JRException;
+import net.sf.jasperreports.engine.data.JRCsvDataSource;
+import net.sf.jasperreports.engine.JRField;
+import net.sf.jasperreports.engine.design.JRDesignField;
+
+import java.io.*;
+import java.text.NumberFormat;
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+
+/*
+This class overrides getFieldValue() from JRCsvDataSource to parse
+java.lang.Object fields that will come from Python coded with data
+for each language.
+*/
+public class CsvMultiLanguageDataSource implements JRRewindableDataSource {
+ private JRCsvDataSource csvDataSource;
+ private String fileName;
+ private String charsetName;
+ private java.text.DateFormat dateFormat;
+ private char fieldDelimiter;
+ private java.text.NumberFormat numberFormat;
+ private String recordDelimiter;
+ private String[] columnNames;
+ private boolean useFirstRowAsHeader;
+ private Translator translator;
+
+ public CsvMultiLanguageDataSource(String fileName, String charsetName, Translator translator) throws java.io.FileNotFoundException, java.io.UnsupportedEncodingException {
+
+ this.fileName = fileName;
+ this.charsetName = charsetName;
+ this.translator = translator;
+ csvDataSource = new JRCsvDataSource( new File( fileName ), "utf-8");
+ csvDataSource.setUseFirstRowAsHeader( true );
+ csvDataSource.setDateFormat( new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ) );
+ csvDataSource.setNumberFormat( NumberFormat.getInstance( Locale.ENGLISH ) );
+ }
+ public void moveFirst() throws JRException {
+ csvDataSource.close();
+ try {
+ csvDataSource = new JRCsvDataSource( new File( fileName ), "utf-8" );
+ csvDataSource.setUseFirstRowAsHeader( true );
+ csvDataSource.setDateFormat( new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ) );
+ csvDataSource.setNumberFormat( NumberFormat.getInstance( Locale.ENGLISH ) );
+ } catch ( Exception exception ) {
+ throw new JRException( exception );
+ }
+ }
+
+ public Object getFieldValue(JRField jrField) throws JRException {
+ Object value;
+ if ( jrField.getValueClassName().equals( "java.lang.Object" ) ) {
+ JRDesignField fakeField = new JRDesignField();
+ fakeField.setName( jrField.getName() );
+ fakeField.setDescription( jrField.getDescription() );
+ fakeField.setValueClassName( "java.lang.String" );
+ fakeField.setValueClass( String.class );
+ value = csvDataSource.getFieldValue( fakeField );
+
+ LanguageTable values = new LanguageTable("en_US");
+ String v = (String) value;
+ String[] p = v.split( "\\|" );
+ for( int j=0; j < p.length ; j++ ) {
+ String[] map = p[j].split( "~" );
+ if ( map.length == 2 )
+ values.put( map[0], map[1] );
+ }
+ value = (Object)values;
+ } else {
+ value = csvDataSource.getFieldValue(jrField);
+ }
+ return value;
+ }
+ public void close() {
+ csvDataSource.close();
+ }
+ public boolean next() throws JRException {
+ return csvDataSource.next();
+ }
+ public Translator getTranslator() {
+ return translator;
+ }
+
+}
+
+
diff --git a/jasper_reports/java/com/nantic/jasperreports/I18nGetText.java b/jasper_reports/java/com/nantic/jasperreports/I18nGetText.java
new file mode 100755
index 0000000..8cf9bfd
--- /dev/null
+++ b/jasper_reports/java/com/nantic/jasperreports/I18nGetText.java
@@ -0,0 +1,60 @@
+/*
+Copyright (c) 2008-2012 NaN Projectes de Programari Lliure, S.L.
+ http://www.NaN-tic.com
+
+WARNING: This program as such is intended to be used by professional
+programmers who take the whole responsability of assessing all potential
+consequences resulting from its eventual inadequacies and bugs
+End users who are looking for a ready-to-use solution with commercial
+garantees and support are strongly adviced to contract a Free Software
+Service Company
+
+This program is Free Software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+package com.nantic.jasperreports;
+
+import java.util.Iterator;
+import java.util.ArrayList;
+
+import java.io.PrintStream;
+import net.sf.jasperreports.engine.JasperCompileManager;
+
+public class I18nGetText {
+ public static void main (String [] args) {
+ if ( args.length != 1 ) {
+ System.out.println( "Syntax: I18nGetText filename.jrxml" );
+ System.exit(1);
+ }
+ String fileName = args[0];
+
+ System.setProperty("jasper.reports.compiler.class", "com.nantic.jasperreports.I18nGroovyCompiler");
+
+ try {
+ I18nGroovyCompiler.sourceCodeList = new ArrayList();
+ JasperCompileManager.compileReport( fileName );
+ //System.out.println( I18nGroovyCompiler.lastGeneratedSourceCode );
+ PrintStream out = new PrintStream(System.out, true, "UTF-8");
+ Iterator<String> iterator = I18nGroovyCompiler.sourceCodeList.iterator();
+ while ( iterator.hasNext() ) {
+ out.println( iterator.next() );
+ }
+ System.exit(0);
+
+ } catch (Exception e) {
+ System.out.println( "Error compiling report: " + e.getMessage() );
+ System.exit(2);
+ }
+ }
+}
diff --git a/jasper_reports/java/com/nantic/jasperreports/I18nGroovyCompiler.java b/jasper_reports/java/com/nantic/jasperreports/I18nGroovyCompiler.java
new file mode 100755
index 0000000..979e4b3
--- /dev/null
+++ b/jasper_reports/java/com/nantic/jasperreports/I18nGroovyCompiler.java
@@ -0,0 +1,224 @@
+/*
+Copyright (c) 2008-2012 NaN Projectes de Programari Lliure, S.L.
+ http://www.NaN-tic.com
+
+WARNING: This program as such is intended to be used by professional
+programmers who take the whole responsability of assessing all potential
+consequences resulting from its eventual inadequacies and bugs
+End users who are looking for a ready-to-use solution with commercial
+garantees and support are strongly adviced to contract a Free Software
+Service Company
+
+This program is Free Software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+package com.nantic.jasperreports;
+
+import net.sf.jasperreports.engine.JasperReportsContext;
+import net.sf.jasperreports.engine.JRDefaultScriptlet;
+import net.sf.jasperreports.engine.design.JRCompilationUnit;
+import net.sf.jasperreports.compilers.JRGroovyCompiler;
+import net.sf.jasperreports.engine.JRException;
+import net.sf.jasperreports.engine.design.JRSourceCompileTask;
+import net.sf.jasperreports.engine.design.JRCompilationSourceCode;
+import net.sf.jasperreports.engine.JRExpression;
+import net.sf.jasperreports.engine.design.JRDefaultCompilationSourceCode;
+import net.sf.jasperreports.engine.design.JRDesignExpression;
+import net.sf.jasperreports.engine.JRExpressionChunk;
+import net.sf.jasperreports.engine.design.JRDesignExpressionChunk;
+import net.sf.jasperreports.engine.JRReport;
+
+import java.util.List;
+
+public class I18nGroovyCompiler extends JRGroovyCompiler {
+ static public List sourceCodeList = null;
+ static private String newImport = "import com.nantic.jasperreports.Translator;\nimport com.nantic.jasperreports.CsvMultiLanguageDataSource;\nimport net.sf.jasperreports.engine.JRDataSource;";
+ static private String newVariable = "public Translator translator = null;\n";
+ static private String returnTranslator =
+ "if (translator == null) {\n" +
+ " // For some reason parameter_REPORT_DATA_SOURCE may become of type\n" +
+ " // net.sf.jasperreports.engine.data.ListOfArrayDataSource\n" +
+ " // even if the value in the parameters map is actually a CsvMultiLanguageDataSource.\n" +
+ " // So we use the map instead of parameter_REPORT_DATA_SOURCE.\n" +
+ " JRDataSource dataSource = (JRDataSource)parameter_REPORT_PARAMETERS_MAP.getValue().get(\"REPORT_DATA_SOURCE\");\n" +
+ " if (dataSource.class == CsvMultiLanguageDataSource) {\n" +
+ " translator = ((CsvMultiLanguageDataSource)dataSource).getTranslator();\n" +
+ " } else if (translator == parameter_REPORT_PARAMETERS_MAP.getValue().containsKey(\"TRANSLATOR\")){\n"+
+ " translator = (CsvMultiLanguageDataSource)parameter_TRANSLATOR.getValue();\n" +
+ " } else {\n" +
+ " translator = new Translator(null, null);\n" +
+ " }\n" +
+ "}\n" +
+ "return translator";
+ static private String newFunction =
+ "public String tr(Locale locale, String text) {\n" +
+ "TRANSLATOR.tr(locale, text);\n" +
+ "}\n" +
+ "public String tr(Locale locale, String text, Object o) {\n" +
+ "TRANSLATOR.tr(locale, text, o);\n" +
+ "}\n" +
+ "public String tr(Locale locale, String text, Object o1, Object o2) {\n" +
+ "TRANSLATOR.tr(locale, text, o1, o2);\n" +
+ "}\n" +
+ "public String tr(Locale locale, String text, Object o1, Object o2, Object o3) {\n" +
+ "TRANSLATOR.tr(locale, text, o1, o2, o3);\n" +
+ "}\n" +
+ "public String tr(Locale locale, String text, Object o1, Object o2, Object o3, Object o4) {\n" +
+ "TRANSLATOR.tr(locale, text, o1, o2, o3, o4);\n" +
+ "}\n" +
+ "public String tr(Locale locale, String text, Object[] objects) {\n" +
+ "TRANSLATOR.tr(locale, text, objects);\n" +
+ "}\n" +
+ "public String tr(String text) {\n" +
+ "TRANSLATOR.tr(text);\n" +
+ "}\n" +
+ "public String tr(String text, Object o) {\n" +
+ "TRANSLATOR.tr(text, o);\n" +
+ "}\n" +
+ "public String tr(String text, Object o1, Object o2) {\n" +
+ "TRANSLATOR.tr(text, o1, o2);\n" +
+ "}\n" +
+ "public String tr(String text, Object o1, Object o2, Object o3) {\n" +
+ "TRANSLATOR.tr(text, o1, o2, o3);\n" +
+ "}\n" +
+ "public String tr(String text, Object o1, Object o2, Object o3, Object o4) {\n" +
+ "TRANSLATOR.tr(text, o1, o2, o3, o4);\n" +
+ "}\n" +
+ "public String tr(String text, Object[] objects) {\n" +
+ "TRANSLATOR.tr(text, objects);\n" +
+ "}\n" +
+ "public String trn(Locale locale, String text, String pluralText, long n) {\n" +
+ "TRANSLATOR.trn(locale, text, pluralText, n);\n" +
+ "}\n" +
+ "public String trn(Locale locale, String text, String pluralText, long n, Object o) {\n" +
+ "TRANSLATOR.trn(locale, text, pluralText, n, o);\n" +
+ "}\n" +
+ "public String trn(Locale locale, String text, String pluralText, long n, Object o1, Object o2) {\n" +
+ "TRANSLATOR.trn(locale, text, pluralText, n, o1, o2);\n" +
+ "}\n" +
+ "public String trn(Locale locale, String text, String pluralText, long n, Object o1, Object o2, Object o3) {\n" +
+ "TRANSLATOR.trn(locale, text, pluralText, n, o1, o2, o3);\n" +
+ "}\n" +
+ "public String trn(Locale locale, String text, String pluralText, long n, Object o1, Object o2, Object o3, Object o4) {\n" +
+ "TRANSLATOR.trn(locale, text, pluralText, n, o1, o2, o3, o4);\n" +
+ "}\n" +
+ "public String trn(Locale locale, String text, String pluralText, long n, Object[] objects) {\n" +
+ "TRANSLATOR.trn(locale, text, pluralText, n, objects);\n" +
+ "}\n" +
+ "public String trn(String text, String pluralText, long n) {\n" +
+ "TRANSLATOR.trn(text, pluralText, n);\n" +
+ "}\n" +
+ "public String trn(String text, String pluralText, long n, Object o) {\n" +
+ "TRANSLATOR.trn(text, pluralText, n, o);\n" +
+ "}\n" +
+ "public String trn(String text, String pluralText, long n, Object o1, Object o2) {\n" +
+ "TRANSLATOR.trn(text, pluralText, n, o1, o2);\n" +
+ "}\n" +
+ "public String trn(String text, String pluralText, long n, Object o1, Object o2, Object o3) {\n" +
+ "TRANSLATOR.trn(text, pluralText, n, o1, o2, o3);\n" +
+ "}\n" +
+ "public String trn(String text, String pluralText, long n, Object o1, Object o2, Object o3, Object o4) {\n" +
+ "TRANSLATOR.trn(text, pluralText, n, o1, o2, o3, o4);\n" +
+ "}\n" +
+ "public String trn(String text, String pluralText, long n, Object[] objects) {\n" +
+ "TRANSLATOR.trn(text, pluralText, n, objects);\n" +
+ "}\n" +
+ "public String trl(String localeCode, String text) {\n" +
+ "TRANSLATOR.trl(localeCode, text);\n" +
+ "}\n" +
+ "public String trl(String localeCode, String text, Object o) {\n" +
+ "TRANSLATOR.trl(localeCode, text, o);\n" +
+ "}\n" +
+ "public String trl(String localeCode, String text, Object o1, Object o2) {\n" +
+ "TRANSLATOR.trl(localeCode, text, o1, o2);\n" +
+ "}\n" +
+ "public String trl(String localeCode, String text, Object o1, Object o2, Object o3) {\n" +
+ "TRANSLATOR.trl(localeCode, text, o1, o2, o3);\n" +
+ "}\n" +
+ "public String trl(String localeCode, String text, Object o1, Object o2, Object o3, Object o4) {\n" +
+ "TRANSLATOR.trl(localeCode, text, o1, o2, o3, o4);\n" +
+ "}\n" +
+ "public String trl(String localeCode, String text, Object[] objects) {\n" +
+ "TRANSLATOR.trl(localeCode, text, objects);\n" +
+ "}\n";
+
+ /**
+ * Creates a I18n Groovy compiler.
+ */
+ public I18nGroovyCompiler(JasperReportsContext jasperReportsContext)
+ {
+ super(jasperReportsContext);
+ }
+
+ protected JRCompilationSourceCode generateSourceCode(JRSourceCompileTask sourceTask) throws JRException {
+ JRCompilationSourceCode superCode = super.generateSourceCode(sourceTask);
+ String code = superCode.getCode();
+ String existingCode;
+
+ existingCode = "import java.net";
+ code = code.replace( existingCode, newImport + "\n" + existingCode );
+
+ existingCode = "void customizedInit";
+ String newFunctionCode = newFunction.replaceAll("TRANSLATOR", returnTranslator);
+ code = code.replace( existingCode, newFunctionCode + "\n\n" + existingCode );
+
+ existingCode = "private JRFillParameter parameter_JASPER_REPORT = null;";
+ code = code.replace( existingCode, existingCode + "\n" + newVariable + "\n" );
+
+ JRDesignExpression ee;
+ JRExpression[] expressions = new JRExpression[sourceTask.getExpressions().size()];
+ int i = -1;
+ for (Object o : sourceTask.getExpressions() ) {
+ JRExpression e = (JRExpression)o;
+ if ( e.getValueClass() == null )
+ continue;
+ i++;
+
+ ee = new JRDesignExpression();
+ ee.setValueClass( e.getValueClass() );
+ ee.setValueClassName( e.getValueClassName() );
+ ee.setText( e.getText().replaceAll( "_\\(", "a(" ) );
+ ee.setId( e.getId() );
+ if ( e.getChunks() != null ) {
+ for (Object chunk : e.getChunks() ) {
+ JRDesignExpressionChunk newChunk = new JRDesignExpressionChunk();
+ newChunk.setType( ((JRExpressionChunk)chunk).getType() );
+ newChunk.setText( ((JRExpressionChunk)chunk).getText() );
+ ee.addChunk( newChunk );
+ }
+ }
+ expressions[i] = ee;
+ }
+ JRDefaultCompilationSourceCode newCode = new JRDefaultCompilationSourceCode( code, expressions );
+ // Store last generated source code so it can be extracted
+ if (sourceCodeList != null)
+ sourceCodeList.add( (Object) code );
+ return newCode;
+ }
+
+ protected void checkLanguage(String language) throws JRException {
+ if (
+ !JRReport.LANGUAGE_GROOVY.equals(language)
+ && !JRReport.LANGUAGE_JAVA.equals(language)
+ && !language.equals("i18ngroovy")
+ )
+ {
+ throw new JRException(
+ "Language \"" + language
+ + "\" not supported by this report compiler.\n"
+ + "Expecting \"i18ngroovy\", \"groovy\" or \"java\" instead."
+ );
+ }
+ }
+}
diff --git a/jasper_reports/java/com/nantic/jasperreports/JasperServer.java b/jasper_reports/java/com/nantic/jasperreports/JasperServer.java
new file mode 100755
index 0000000..cd3e3b2
--- /dev/null
+++ b/jasper_reports/java/com/nantic/jasperreports/JasperServer.java
@@ -0,0 +1,343 @@
+/*
+Copyright (c) 2008-2012 NaN Projectes de Programari Lliure, S.L.
+ http://www.NaN-tic.com
+
+WARNING: This program as such is intended to be used by professional
+programmers who take the whole responsability of assessing all potential
+consequences resulting from its eventual inadequacies and bugs
+End users who are looking for a ready-to-use solution with commercial
+garantees and support are strongly adviced to contract a Free Software
+Service Company
+
+This program is Free Software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+package com.nantic.jasperreports;
+
+import org.apache.xmlrpc.server.XmlRpcServer;
+import org.apache.xmlrpc.webserver.WebServer;
+//import org.apache.xmlrpc.webserver.*;
+import org.apache.xmlrpc.*;
+import org.apache.xmlrpc.server.PropertyHandlerMapping;
+//import org.apache.xml.security.utils.Base64;
+
+import net.sf.jasperreports.engine.JRRewindableDataSource;
+import net.sf.jasperreports.engine.JRException;
+import net.sf.jasperreports.engine.design.JRDesignField;
+import net.sf.jasperreports.engine.util.JRLoader;
+import net.sf.jasperreports.engine.JasperFillManager;
+import net.sf.jasperreports.engine.JasperExportManager;
+import net.sf.jasperreports.engine.JasperCompileManager;
+import net.sf.jasperreports.engine.JasperReport;
+import net.sf.jasperreports.engine.JasperPrint;
+import net.sf.jasperreports.engine.JRParameter;
+import net.sf.jasperreports.engine.xml.JRXmlLoader;
+import net.sf.jasperreports.engine.design.JasperDesign;
+import net.sf.jasperreports.engine.data.JRXmlDataSource;
+import net.sf.jasperreports.engine.data.JRCsvDataSource;
+import net.sf.jasperreports.engine.JREmptyDataSource;
+
+// Exporters
+import net.sf.jasperreports.engine.JRAbstractExporter;
+// import net.sf.jasperreports.engine.JRExporterParameter;
+import net.sf.jasperreports.engine.export.JRPdfExporter;
+import net.sf.jasperreports.engine.export.JRRtfExporter;
+import net.sf.jasperreports.engine.export.JRCsvExporter;
+import net.sf.jasperreports.export.SimpleWriterExporterOutput;
+import net.sf.jasperreports.engine.export.JRXlsExporter;
+// import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
+import net.sf.jasperreports.export.SimpleExporterInput;
+import net.sf.jasperreports.export.SimpleXlsReportConfiguration;
+import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;
+import net.sf.jasperreports.engine.export.JRTextExporter;
+import net.sf.jasperreports.export.SimpleTextReportConfiguration;
+// import net.sf.jasperreports.engine.export.JRTextExporterParameter;
+import net.sf.jasperreports.export.TextReportConfiguration;
+import net.sf.jasperreports.engine.export.HtmlExporter;
+// import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
+import net.sf.jasperreports.export.SimpleHtmlExporterConfiguration;
+import net.sf.jasperreports.export.SimpleHtmlReportConfiguration;
+import net.sf.jasperreports.export.SimpleHtmlExporterOutput;
+import net.sf.jasperreports.engine.export.oasis.JROdtExporter;
+import net.sf.jasperreports.engine.export.oasis.JROdsExporter;
+
+import java.text.NumberFormat;
+import java.lang.Object;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.ResourceBundle;
+import java.util.Hashtable;
+import java.io.ByteArrayInputStream;
+import java.io.*;
+import java.sql.*;
+import java.lang.Class;
+import java.math.BigDecimal;
+import java.io.InputStream;
+import java.util.Locale;
+
+
+
+public class JasperServer {
+ /* Compiles the given .jrxml (inputFile) */
+ public Boolean compile( String jrxmlPath ) throws java.lang.Exception {
+ File jrxmlFile;
+ File jasperFile;
+
+ System.setProperty("jasper.reports.compiler.class", "com.nantic.jasperreports.I18nGroovyCompiler");
+
+ jrxmlFile = new File( jrxmlPath );
+ jasperFile = new File( jasperPath( jrxmlPath ) );
+ if ( (! jasperFile.exists()) || (jrxmlFile.lastModified() > jasperFile.lastModified()) ) {
+ System.out.println( "JasperServer: Compiling " + jrxmlPath ) ;
+ JasperCompileManager.compileReportToFile( jrxmlPath, jasperPath( jrxmlPath ) );
+ System.out.println( "JasperServer: Compiled.");
+ }
+ return true;
+ }
+
+ /* Returns path where bundle files are expected to be */
+ public String bundlePath( String jrxmlPath ) {
+ int index;
+ index = jrxmlPath.lastIndexOf('.');
+ if ( index != -1 )
+ return jrxmlPath.substring( 0, index );
+ else
+ return jrxmlPath;
+ }
+
+ /* Returns the path to the .jasper file for the given .jrxml */
+ public String jasperPath( String jrxmlPath ) {
+ return bundlePath( jrxmlPath ) + ".jasper";
+ }
+
+ public int execute( Hashtable connectionParameters, String jrxmlPath, String outputPath, Hashtable<String, Object> parameters) throws java.lang.Exception {
+ try {
+ return privateExecute( connectionParameters, jrxmlPath, outputPath, parameters );
+ } catch (Exception exception) {
+ //exception.printStackTrace();
+ throw exception;
+ }
+ }
+
+ public int privateExecute( Hashtable connectionParameters, String jrxmlPath, String outputPath, Hashtable<String, Object> parameters) throws java.lang.Exception {
+
+ JasperReport report = null;
+ byte[] result = null;
+ JasperPrint jasperPrint = null;
+ InputStream in = null;
+ int index;
+
+ // Ensure report is compiled
+ compile( jrxmlPath );
+
+ report = (JasperReport) JRLoader.loadObjectFromFile( jasperPath( jrxmlPath ) );
+
+ // Add SUBREPORT_DIR parameter
+ index = jrxmlPath.lastIndexOf('/');
+ if ( index != -1 )
+ parameters.put( "SUBREPORT_DIR", jrxmlPath.substring( 0, index+1 ) );
+
+ // Declare it outside the parameters loop because we'll use it when we will create the data source.
+ Translator translator = null;
+
+ // Fill in report parameters
+ JRParameter[] reportParameters = report.getParameters();
+ for( int j=0; j < reportParameters.length; j++ ){
+ JRParameter jparam = reportParameters[j];
+ if ( jparam.getValueClassName().equals( "java.util.Locale" ) ) {
+ // REPORT_LOCALE
+ if ( ! parameters.containsKey( jparam.getName() ) )
+ continue;
+ String[] locales = ((String)parameters.get( jparam.getName() )).split( "_" );
+
+ Locale locale;
+ if ( locales.length == 1 )
+ locale = new Locale( locales[0] );
+ else
+ locale = new Locale( locales[0], locales[1] );
+
+ parameters.put( jparam.getName(), locale );
+
+ // Initialize translation system
+ // SQL reports will need to declare the TRANSLATOR paramter for translations to work.
+ // CSV/XML based ones will not need that because we will integrate the translator
+ // with the CsvMultiLanguageDataSource.
+ translator = new Translator( bundlePath(jrxmlPath), locale );
+ parameters.put( "TRANSLATOR", translator );
+
+ } else if( jparam.getValueClassName().equals( "java.lang.BigDecimal" )){
+ Object param = parameters.get( jparam.getName());
+ parameters.put( jparam.getName(), new BigDecimal( (Double) parameters.get(jparam.getName() ) ) );
+ }
+ }
+
+ if ( connectionParameters.containsKey("subreports") ) {
+ Object[] subreports = (Object[]) connectionParameters.get("subreports");
+ for (int i = 0; i < subreports.length; i++ ) {
+ Map m = (Map)subreports[i];
+
+ // Ensure subreport is compiled
+ String jrxmlFile = (String)m.get("jrxmlFile");
+ if ( ! jrxmlFile.equals( "DATASET" ) )
+ compile( (String)m.get("jrxmlFile") );
+
+ // Create DataSource for subreport
+ CsvMultiLanguageDataSource dataSource = new CsvMultiLanguageDataSource( (String)m.get("dataFile"), "utf-8", translator );
+ System.out.println( "JasperServer: Adding parameter '" + ( (String)m.get("parameter") ) + "' with datasource '" + ( (String)m.get("dataFile") ) + "'" );
+
+ parameters.put( (String)m.get("parameter"), dataSource );
+ }
+ }
+
+ System.out.println( "JasperServer: Filling report..." );
+
+ // Fill in report
+ String language;
+ if ( report.getQuery() == null )
+ language = "";
+ else
+ language = report.getQuery().getLanguage();
+
+ if( language.equalsIgnoreCase( "XPATH") ){
+ // If available, use a CSV file because it's faster to process.
+ // Otherwise we'll use an XML file.
+ if ( connectionParameters.containsKey("csv") ) {
+ CsvMultiLanguageDataSource dataSource = new CsvMultiLanguageDataSource( (String)connectionParameters.get("csv"), "utf-8", translator );
+ jasperPrint = JasperFillManager.fillReport( report, parameters, dataSource );
+ } else {
+ JRXmlDataSource dataSource = new JRXmlDataSource( (String)connectionParameters.get("xml"), "/data/record" );
+ dataSource.setDatePattern( "yyyy-MM-dd HH:mm:ss" );
+ dataSource.setNumberPattern( "#######0.##" );
+ dataSource.setLocale( Locale.ENGLISH );
+ jasperPrint = JasperFillManager.fillReport( report, parameters, dataSource );
+ }
+ } else if( language.equalsIgnoreCase( "SQL") ) {
+ Connection connection = getConnection( connectionParameters );
+ jasperPrint = JasperFillManager.fillReport( report, parameters, connection );
+ } else {
+ JREmptyDataSource dataSource = new JREmptyDataSource();
+ jasperPrint = JasperFillManager.fillReport( report, parameters, dataSource );
+ }
+
+ // Create output file
+ File outputFile = new File( outputPath );
+ JRAbstractExporter exporter;
+
+ String output;
+ if ( connectionParameters.containsKey( "output" ) )
+ output = (String)connectionParameters.get("output");
+ else
+ output = "pdf";
+
+ System.out.println( "JasperServer: Exporting..." );
+ if ( output.equalsIgnoreCase( "html" ) ) {
+ // exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
+ // exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "");
+ // exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, "");
+ // exporter.setParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
+ // exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "");
+ exporter = new HtmlExporter();
+ SimpleHtmlExporterConfiguration configuration = new SimpleHtmlExporterConfiguration();
+ configuration.setHtmlHeader("");
+ configuration.setBetweenPagesHtml("");
+ configuration.setHtmlFooter("");
+ SimpleHtmlReportConfiguration reportExportConfiguration = new SimpleHtmlReportConfiguration();
+ reportExportConfiguration.setRemoveEmptySpaceBetweenRows(true);
+ exporter.setConfiguration(reportExportConfiguration);
+ exporter.setConfiguration(configuration);
+ exporter.setExporterOutput(new SimpleHtmlExporterOutput(outputFile));
+ } else if ( output.equalsIgnoreCase( "csv" ) ) {
+ exporter = new JRCsvExporter();
+ exporter.setExporterOutput(new SimpleWriterExporterOutput(outputFile));
+ } else if ( output.equalsIgnoreCase( "xls" ) ) {
+ // exporter = new JRXlsExporter();
+ // exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
+ // exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS,Boolean.TRUE);
+ // exporter.setParameter(JRXlsExporterParameter.MAXIMUM_ROWS_PER_SHEET, new Integer(65000));
+ // exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
+ exporter = new JRXlsExporter();
+ SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
+ configuration.setRemoveEmptySpaceBetweenRows(true);
+ configuration.setRemoveEmptySpaceBetweenColumns(true);
+ configuration.setMaxRowsPerSheet(Integer.valueOf(65000));
+ configuration.setDetectCellType(true);
+ exporter.setConfiguration(configuration);
+ exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputFile));
+ } else if ( output.equalsIgnoreCase( "rtf" ) ) {
+ exporter = new JRRtfExporter();
+ exporter.setExporterOutput(new SimpleWriterExporterOutput(outputFile));
+ } else if ( output.equalsIgnoreCase( "odt" ) ) {
+ exporter = new JROdtExporter();
+ exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputFile));
+ } else if ( output.equalsIgnoreCase( "ods" ) ) {
+ exporter = new JROdsExporter();
+ exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputFile));
+ } else if ( output.equalsIgnoreCase( "txt" ) ) {
+ // exporter.setParameter(TextReportConfiguration.getPageWidthInChars(), new Integer(80));
+ // exporter.setParameter(TextReportConfiguration.getPageHeightInChars(), new Integer(150));
+ exporter = new JRTextExporter();
+ SimpleTextReportConfiguration configuration = new SimpleTextReportConfiguration();
+ configuration.setPageWidthInChars(Integer.valueOf(80));
+ configuration.setPageHeightInChars(Integer.valueOf(150));
+ exporter.setConfiguration(configuration);
+ exporter.setExporterOutput(new SimpleWriterExporterOutput(outputFile));
+ } else {
+ exporter = new JRPdfExporter();
+ exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputFile));
+ }
+ // exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
+ // exporter.setParameter(JRExporterParameter.OUTPUT_FILE, outputFile);
+ exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
+
+ exporter.exportReport();
+ System.out.println( "JasperServer: Exported." );
+ return jasperPrint.getPages().size();
+ }
+
+ public static Connection getConnection( Hashtable datasource ) throws java.lang.ClassNotFoundException, java.sql.SQLException {
+ Connection connection;
+ Class.forName("org.postgresql.Driver");
+ connection = DriverManager.getConnection( (String)datasource.get("dsn"), (String)datasource.get("user"),
+ (String)datasource.get("password") );
+ connection.setAutoCommit(true);
+ return connection;
+ }
+
+ public static void main (String [] args) {
+ try {
+ int port = 8090;
+ if ( args.length > 0 ) {
+ port = java.lang.Integer.parseInt( args[0] );
+ }
+ java.net.InetAddress localhost = java.net.Inet4Address.getByName("localhost");
+ System.out.println("JasperServer: Attempting to start XML-RPC Server at " + localhost.toString() + ":" + port + "...");
+ WebServer server = new WebServer( port, localhost );
+ XmlRpcServer xmlRpcServer = server.getXmlRpcServer();
+
+ PropertyHandlerMapping phm = new PropertyHandlerMapping();
+ phm.addHandler("Report", JasperServer.class);
+ xmlRpcServer.setHandlerMapping(phm);
+
+ server.start();
+ System.out.println("JasperServer: Started successfully.");
+ System.out.println("JasperServer: Accepting requests. (Halt program to stop.)");
+ } catch (Exception exception) {
+ System.err.println("Jasper Server: " + exception);
+ }
+ }
+}
diff --git a/jasper_reports/java/com/nantic/jasperreports/LanguageTable.java b/jasper_reports/java/com/nantic/jasperreports/LanguageTable.java
new file mode 100755
index 0000000..b196f57
--- /dev/null
+++ b/jasper_reports/java/com/nantic/jasperreports/LanguageTable.java
@@ -0,0 +1,49 @@
+/*
+Copyright (c) 2008-2012 NaN Projectes de Programari Lliure, S.L.
+ http://www.NaN-tic.com
+
+WARNING: This program as such is intended to be used by professional
+programmers who take the whole responsability of assessing all potential
+consequences resulting from its eventual inadequacies and bugs
+End users who are looking for a ready-to-use solution with commercial
+garantees and support are strongly adviced to contract a Free Software
+Service Company
+
+This program is Free Software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+package com.nantic.jasperreports;
+
+import java.util.Hashtable;
+
+/*
+This class overrides Hashtable's get() function to return
+the default language when the language (key) doesn't exist.
+*/
+public class LanguageTable extends Hashtable {
+ private String defaultLanguage;
+
+ public LanguageTable(String defaultLanguage) {
+ super();
+ this.defaultLanguage = defaultLanguage;
+ }
+ public Object get(Object key) {
+ if ( containsKey(key) )
+ return super.get(key);
+ else
+ return super.get(defaultLanguage);
+ }
+}
+
+
diff --git a/jasper_reports/java/com/nantic/jasperreports/ReportCompiler.java b/jasper_reports/java/com/nantic/jasperreports/ReportCompiler.java
new file mode 100755
index 0000000..3a9c028
--- /dev/null
+++ b/jasper_reports/java/com/nantic/jasperreports/ReportCompiler.java
@@ -0,0 +1,51 @@
+/*
+Copyright (c) 2008-2012 NaN Projectes de Programari Lliure, S.L.
+ http://www.NaN-tic.com
+
+WARNING: This program as such is intended to be used by professional
+programmers who take the whole responsability of assessing all potential
+consequences resulting from its eventual inadequacies and bugs
+End users who are looking for a ready-to-use solution with commercial
+garantees and support are strongly adviced to contract a Free Software
+Service Company
+
+This program is Free Software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+package com.nantic.jasperreports;
+
+import net.sf.jasperreports.engine.JasperCompileManager;
+import java.util.*;
+
+public class ReportCompiler {
+
+ public static void compile( String src, String dst )
+ {
+ try {
+ JasperCompileManager.compileReportToFile( src, dst );
+ } catch (Exception e){
+ e.printStackTrace();
+ System.out.println( e.getMessage() );
+ }
+ }
+
+ public static void main( String[] args )
+ {
+ if ( args.length == 2 )
+ compile( args[0], args[1] );
+ else
+ System.out.println( "Two arguments needed. Example: java ReportCompiler src.jrxml dst.jasper" );
+ }
+}
+
diff --git a/jasper_reports/java/com/nantic/jasperreports/Translator.java b/jasper_reports/java/com/nantic/jasperreports/Translator.java
new file mode 100755
index 0000000..44cb72e
--- /dev/null
+++ b/jasper_reports/java/com/nantic/jasperreports/Translator.java
@@ -0,0 +1,206 @@
+/*
+Copyright (c) 2008-2012 NaN Projectes de Programari Lliure, S.L.
+ http://www.NaN-tic.com
+
+WARNING: This program as such is intended to be used by professional
+programmers who take the whole responsability of assessing all potential
+consequences resulting from its eventual inadequacies and bugs
+End users who are looking for a ready-to-use solution with commercial
+garantees and support are strongly adviced to contract a Free Software
+Service Company
+
+This program is Free Software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+package com.nantic.jasperreports;
+
+import java.io.FileInputStream;
+import java.util.PropertyResourceBundle;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.Enumeration;
+
+import org.xnap.commons.i18n.I18n;
+
+public class Translator {
+ private Hashtable<Locale, I18n> resources = null;
+ private String baseName = null;
+ private Locale defaultLocale = null;
+ private Hashtable<Locale, Boolean> unavailableResources = null;
+
+ public Translator(String baseName, Locale defaultLocale) {
+ resources = new Hashtable<Locale, I18n>();
+ this.baseName = baseName;
+ this.defaultLocale = defaultLocale;
+ unavailableResources = new Hashtable<Locale, Boolean>();
+ }
+ /* Ensures the given locale is loaded */
+ protected boolean loadLocale( Locale locale ) {
+ // If the resource wasn't available don't try to load it each time.
+ if ( baseName == null || locale == null )
+ return false;
+ if ( unavailableResources.containsKey( locale ) )
+ return false;
+ if ( ! resources.containsKey( locale ) ) {
+
+ String fileName = baseName + "_" + locale.toString() + ".properties";
+ ResourceBundle bundle;
+ try {
+ FileInputStream fis = new FileInputStream( fileName );
+ bundle = new PropertyResourceBundle(fis);
+ resources.put( locale, new I18n( bundle ) );
+ } catch (Exception e) {
+ //e.printStackTrace();
+ unavailableResources.put( locale, true );
+ System.out.println( "JasperServer: No bundle file named: " + fileName );
+ return false;
+ }
+ }
+ return true;
+ }
+ public Locale stringToLocale(String localeCode) {
+ Locale locale;
+ String[] locales = localeCode.split( "_" );
+ if ( locales.length == 1 )
+ locale = new Locale( locales[0] );
+ else if ( locales.length == 2 )
+ locale = new Locale( locales[0], locales[1] );
+ else
+ locale = new Locale( locales[0], locales[1], locales[2] );
+ return locale;
+ }
+ /* tr(Locale..) and tr(Locale..Object) functions */
+ public String tr(Locale locale, String text) {
+ if ( ! loadLocale( locale ) ) {
+ return text;
+ }
+ return resources.get( locale ).tr( text );
+ }
+ public String tr(Locale locale, String text, Object o) {
+ if ( ! loadLocale( locale ) )
+ return text;
+ return resources.get( locale ).tr( text, o );
+ }
+ public String tr(Locale locale, String text, Object o1, Object o2) {
+ if ( ! loadLocale( locale ) )
+ return text;
+ return resources.get( locale ).tr( text, o1, o2 );
+ }
+ public String tr(Locale locale, String text, Object o1, Object o2, Object o3) {
+ if ( ! loadLocale( locale ) )
+ return text;
+ return resources.get( locale ).tr( text, o1, o2, o3 );
+ }
+ public String tr(Locale locale, String text, Object o1, Object o2, Object o3, Object o4) {
+ if ( ! loadLocale( locale ) )
+ return text;
+ return resources.get( locale ).tr( text, o1, o2, o3, o4 );
+ }
+ public String tr(Locale locale, String text, Object[] objects) {
+ if ( ! loadLocale( locale ) )
+ return text;
+ return resources.get( locale ).tr( text, objects );
+ }
+ /* trl() and trl(..Object) functions */
+ public String trl(String localeCode, String text) {
+ return tr(stringToLocale(localeCode), text);
+ }
+ public String trl(String localeCode, String text, Object o) {
+ return tr(stringToLocale(localeCode), text, o);
+ }
+ public String trl(String localeCode, String text, Object o1, Object o2) {
+ return tr(stringToLocale(localeCode), text, o1, o2);
+ }
+ public String trl(String localeCode, String text, Object o1, Object o2, Object o3) {
+ return tr(stringToLocale(localeCode), text, o1, o2, o3);
+ }
+ public String trl(String localeCode, String text, Object o1, Object o2, Object o3, Object o4) {
+ return tr(stringToLocale(localeCode), text, o1, o2, o3, o4);
+ }
+ public String trl(String localeCode, String text, Object[] objects) {
+ return tr(stringToLocale(localeCode), text, objects);
+ }
+ /* tr(..) and tr(..Object) functions */
+ public String tr(String text) {
+ return tr(defaultLocale, text);
+ }
+ public String tr(String text, Object o) {
+ return tr(defaultLocale, text, o);
+ }
+ public String tr(String text, Object o1, Object o2) {
+ return tr(defaultLocale, text, o1, o2);
+ }
+ public String tr(String text, Object o1, Object o2, Object o3) {
+ return tr(defaultLocale, text, o1, o2, o3);
+ }
+ public String tr(String text, Object o1, Object o2, Object o3, Object o4) {
+ return tr(defaultLocale, text, o1, o2, o3, o4);
+ }
+ public String tr(String text, Object[] objects) {
+ return tr(defaultLocale, text, objects);
+ }
+ /* trn(Locale..) and trn(Locale..Object) functions */
+ public String trn(Locale locale, String text, String pluralText, long n) {
+ if ( ! loadLocale( locale ) )
+ return text;
+ return resources.get( locale ).trn( text, pluralText, n );
+ }
+ public String trn(Locale locale, String text, String pluralText, long n, Object o) {
+ if ( ! loadLocale( locale ) )
+ return text;
+ return resources.get( locale ).trn( text, pluralText, n, o );
+ }
+ public String trn(Locale locale, String text, String pluralText, long n, Object o1, Object o2) {
+ if ( ! loadLocale( locale ) )
+ return text;
+ return resources.get( locale ).trn( text, pluralText, n, o1, o2 );
+ }
+ public String trn(Locale locale, String text, String pluralText, long n, Object o1, Object o2, Object o3) {
+ if ( ! loadLocale( locale ) )
+ return text;
+ return resources.get( locale ).trn( text, pluralText, n, o1, o2, o3 );
+ }
+ public String trn(Locale locale, String text, String pluralText, long n, Object o1, Object o2, Object o3, Object o4) {
+ if ( ! loadLocale( locale ) )
+ return text;
+ return resources.get( locale ).trn( text, pluralText, n, o1, o2, o3, o4 );
+ }
+ public String trn(Locale locale, String text, String pluralText, long n, Object[] objects) {
+ if ( ! loadLocale( locale ) )
+ return text;
+ return resources.get( locale ).trn( text, pluralText, n, objects );
+ }
+ /* trn(..) and trn(..Object) functions */
+ public String trn(String text, String pluralText, long n) {
+ return trn(defaultLocale, text, pluralText, n);
+ }
+ public String trn(String text, String pluralText, long n, Object o) {
+ return trn(defaultLocale, text, pluralText, n, o);
+ }
+ public String trn(String text, String pluralText, long n, Object o1, Object o2) {
+ return trn(defaultLocale, text, pluralText, n, o1, o2);
+ }
+ public String trn(String text, String pluralText, long n, Object o1, Object o2, Object o3) {
+ return trn(defaultLocale, text, pluralText, n, o1, o2, o3);
+ }
+ public String trn(String text, String pluralText, long n, Object o1, Object o2, Object o3, Object o4) {
+ return trn(defaultLocale, text, pluralText, n, o1, o2, o3, o4);
+ }
+ public String trn(String text, String pluralText, long n, Object[] objects) {
+ return trn(defaultLocale, text, pluralText, n, objects);
+ }
+}
+
diff --git a/jasper_reports/java/com/nantic/jasperreports/XmlMultiLanguageDataSource.java b/jasper_reports/java/com/nantic/jasperreports/XmlMultiLanguageDataSource.java
new file mode 100755
index 0000000..61d733a
--- /dev/null
+++ b/jasper_reports/java/com/nantic/jasperreports/XmlMultiLanguageDataSource.java
@@ -0,0 +1,78 @@
+/*
+Copyright (c) 2008-2012 NaN Projectes de Programari Lliure, S.L.
+ http://www.NaN-tic.com
+
+WARNING: This program as such is intended to be used by professional
+programmers who take the whole responsability of assessing all potential
+consequences resulting from its eventual inadequacies and bugs
+End users who are looking for a ready-to-use solution with commercial
+garantees and support are strongly adviced to contract a Free Software
+Service Company
+
+This program is Free Software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+package com.nantic.jasperreports;
+
+import net.sf.jasperreports.engine.JRRewindableDataSource;
+import net.sf.jasperreports.engine.JRException;
+import net.sf.jasperreports.engine.data.JRCsvDataSource;
+import net.sf.jasperreports.engine.JRField;
+import net.sf.jasperreports.engine.data.JRXmlDataSource;
+import net.sf.jasperreports.engine.design.JRDesignField;
+
+import java.io.*;
+import java.text.NumberFormat;
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+
+
+/*
+This class overrides getFieldValue() from JRXmlDataSource to parse
+java.lang.Object fields that will come from Python coded with data
+for each language.
+*/
+public class XmlMultiLanguageDataSource extends JRXmlDataSource {
+ public XmlMultiLanguageDataSource(String uri, String selectExpression) throws JRException {
+ super(uri, selectExpression);
+ }
+
+ public Object getFieldValue(JRField jrField) throws JRException {
+ Object value;
+ if ( jrField.getValueClassName().equals( "java.lang.Object" ) ) {
+ JRDesignField fakeField = new JRDesignField();
+ fakeField.setName( jrField.getName() );
+ fakeField.setDescription( jrField.getDescription() );
+ fakeField.setValueClassName( "java.lang.String" );
+ fakeField.setValueClass( String.class );
+ value = super.getFieldValue( fakeField );
+
+ LanguageTable values = new LanguageTable("en_US");
+ String v = (String) value;
+ String[] p = v.split( "\\|" );
+ for( int j=0; j < p.length ; j++ ) {
+ //System.out.println( p[j] );
+ String[] map = p[j].split( "~" );
+ if ( map.length == 2 )
+ values.put( map[0], map[1] );
+ }
+ value = (Object)values;
+ } else {
+ value = super.getFieldValue(jrField);
+ }
+ return value;
+ }
+}
+
+