lib/jasper-rails.rb in jasper-rails-0.1.2 vs lib/jasper-rails.rb in jasper-rails-1.0.0
- old
+ new
@@ -1,18 +1,42 @@
+#
+# Copyright (C) 2012 Marlus Saraiva, Rodrigo Maia
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
require "jasper-rails/version"
require "rails"
require "rjb"
-Mime::Type.register "application/pdf", :pdf
+if Mime::Type.lookup_by_extension("pdf").nil?
+ Mime::Type.register "application/pdf", :pdf
+end
module JasperRails
classpath = '.'
Dir["#{File.dirname(__FILE__)}/java/*.jar"].each do |jar|
classpath << File::PATH_SEPARATOR + File.expand_path(jar)
end
-
+
Dir["lib/*.jar"].each do |jar|
classpath << File::PATH_SEPARATOR + File.expand_path(jar)
end
Rjb::load( classpath, ['-Djava.awt.headless=true','-Xms128M', '-Xmx256M'] )
@@ -21,11 +45,12 @@
JasperCompileManager = Rjb::import 'net.sf.jasperreports.engine.JasperCompileManager'
JasperExportManager = Rjb::import 'net.sf.jasperreports.engine.JasperExportManager'
JasperFillManager = Rjb::import 'net.sf.jasperreports.engine.JasperFillManager'
JasperPrint = Rjb::import 'net.sf.jasperreports.engine.JasperPrint'
JRXmlUtils = Rjb::import 'net.sf.jasperreports.engine.util.JRXmlUtils'
- JRXPathQueryExecuterFactory = Rjb::import 'net.sf.jasperreports.engine.query.JRXPathQueryExecuterFactory'
+ # This is here to avoid the "already initialized constant QUERY_EXECUTER_FACTORY_PREFIX" warnings.
+ JRXPathQueryExecuterFactory = silence_warnings{Rjb::import 'net.sf.jasperreports.engine.query.JRXPathQueryExecuterFactory'}
InputSource = Rjb::import 'org.xml.sax.InputSource'
StringReader = Rjb::import 'java.io.StringReader'
HashMap = Rjb::import 'java.util.HashMap'
ByteArrayInputStream = Rjb::import 'java.io.ByteArrayInputStream'
JavaString = Rjb::import 'java.lang.String'
@@ -54,10 +79,9 @@
# Fill the report
input_source = InputSource.new
input_source.setCharacterStream(StringReader.new(datasource.to_xml(options).to_s))
data_document = silence_warnings do
# This is here to avoid the "already initialized constant DOCUMENT_POSITION_*" warnings.
- # It's harmless. But pretty annoying.
JRXmlUtils._invoke('parse', 'Lorg.xml.sax.InputSource;', input_source)
end
jasper_params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, data_document)
jasper_print = JasperFillManager.fillReport(jasper_file, jasper_params)