← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10698: switched to using dejavu to export jasper-pdfs. now it properly works with unicode characters (as...

 

------------------------------------------------------------
revno: 10698
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-04-26 20:15:53 +0700
message:
  switched to using dejavu to export jasper-pdfs. now it properly works with unicode characters (as long as they are contained in the dejavu sans font).
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/help/DefaultHelpManager.java
  dhis-2/dhis-services/dhis-service-reporting/pom.xml
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/StreamUtils.java
  dhis-2/pom.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java	2013-02-12 06:55:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java	2013-04-26 13:15:53 +0000
@@ -27,15 +27,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import net.sf.jasperreports.engine.JasperPrint;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.period.Period;
+
 import java.io.OutputStream;
 import java.util.Collection;
 import java.util.List;
 
-import net.sf.jasperreports.engine.JasperPrint;
-
-import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.period.Period;
-
 /**
  * @author Lars Helge Overland
  */
@@ -52,29 +51,29 @@
     final String PARAM_ORGANISATIONUNIT_LEVEL_COLUMN = "organisationunit_level_column";
     final String PARAM_ORGANISATIONUNIT_COLUMN_NAME = "organisationunit_name";
     final String PARAM_PERIOD_NAME = "period_name";
-    
+
     /**
-     * Renders a Jasper Report. 
-     * 
+     * Renders a Jasper Report.
+     * <p/>
      * Will make the following params available:
-     * 
+     * <p/>
      * "periods" String of relative period ids (String)
      * "organisationunits" String of selected organisation unit ids (String)
      * "period_name" Name of the selected period (String)
      * "organisationunit_name" Name of the selected organisation unit (String)
      * "organisationunit_level" Level of the selected organisation unit (int)
-     * "organisationunit_level_column" Name of the relevant level column in 
-     *     table _orgunitstructure (String)
-     * 
-     * @param out the OutputStream to write the report to.
-     * @param reportUid the uid of the report to render.
-     * @param period the period to use as parameter.
+     * "organisationunit_level_column" Name of the relevant level column in
+     * table _orgunitstructure (String)
+     *
+     * @param out                 the OutputStream to write the report to.
+     * @param reportUid           the uid of the report to render.
+     * @param period              the period to use as parameter.
      * @param organisationUnitUid the uid of the org unit to use as parameter.
-     * @param type the type of the report, can be "xls" and "pdf".
-     * @param format the I18nFormat to use.
+     * @param type                the type of the report, can be "xls" and "pdf".
+     * @param format              the I18nFormat to use.
      */
     JasperPrint renderReport( OutputStream out, String reportUid, Period period,
-                       String organisationUnitUid, String type, I18nFormat format );
+        String organisationUnitUid, String type, I18nFormat format );
 
     /**
      * Saves a Report.
@@ -101,11 +100,12 @@
     Report getReport( String uid );
 
     /**
-     * Returns the total number of reports. 
+     * Returns the total number of reports.
+     *
      * @return the total number of reports.
      */
     int getReportCount();
-    
+
     /**
      * Returns the number of reports which names are like the given name.
      * Returns the number of reports which names are like the given name.
@@ -115,9 +115,9 @@
     /**
      * Retrieves the given number of maximum reports starting at the given start
      * index. Reports are sorted on the name property.
-     * 
+     *
      * @param first the start index.
-     * @param max the maximum number of reports.
+     * @param max   the maximum number of reports.
      * @return a collection of reports.
      */
     List<Report> getReportsBetween( int first, int max );
@@ -125,9 +125,9 @@
     /**
      * Retrieves the given number of maximum reports starting at the given start
      * index. Reports are sorted on the name property.
-     * 
+     *
      * @param first the start index.
-     * @param max the maximum number of reports.
+     * @param max   the maximum number of reports.
      * @return a collection of reports.
      */
     List<Report> getReportsBetweenByName( String name, int first, int max );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/help/DefaultHelpManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/help/DefaultHelpManager.java	2012-01-22 05:29:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/help/DefaultHelpManager.java	2013-04-26 13:15:53 +0000
@@ -27,7 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.system.util.StreamUtils.ENCODING_UTF;
+import static org.hisp.dhis.system.util.StreamUtils.ENCODING_UTF8;
 
 import java.io.OutputStream;
 
@@ -38,7 +38,6 @@
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
-import org.hisp.dhis.help.HelpManager;
 import org.springframework.core.io.ClassPathResource;
 
 /**
@@ -55,7 +54,7 @@
     {
         try
         {
-            Source source = new StreamSource( new ClassPathResource( "help_content.xml" ).getInputStream(), ENCODING_UTF );
+            Source source = new StreamSource( new ClassPathResource( "help_content.xml" ).getInputStream(), ENCODING_UTF8 );
             
             Result result = new StreamResult( out );
             
@@ -75,7 +74,7 @@
     {
         try
         {
-            Source source = new StreamSource( new ClassPathResource( "help_content.xml" ).getInputStream(), ENCODING_UTF );
+            Source source = new StreamSource( new ClassPathResource( "help_content.xml" ).getInputStream(), ENCODING_UTF8 );
             
             Result result = new StreamResult( out );
             
@@ -94,7 +93,7 @@
     private Transformer getTransformer( String stylesheetName )
         throws Exception
     {
-        Source stylesheet = new StreamSource( new ClassPathResource( stylesheetName ).getInputStream(), ENCODING_UTF );
+        Source stylesheet = new StreamSource( new ClassPathResource( stylesheetName ).getInputStream(), ENCODING_UTF8 );
         
         return TransformerFactory.newInstance().newTransformer( stylesheet );
     }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/pom.xml'
--- dhis-2/dhis-services/dhis-service-reporting/pom.xml	2013-03-22 13:47:40 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/pom.xml	2013-04-26 13:15:53 +0000
@@ -45,6 +45,10 @@
       <artifactId>jasperreports</artifactId>
     </dependency>
     <dependency>
+      <groupId>net.sf.jasperreports</groupId>
+      <artifactId>jasperreports-fonts</artifactId>
+    </dependency>
+    <dependency>
       <groupId>jfree</groupId>
       <artifactId>jfreechart</artifactId>
     </dependency>
@@ -77,7 +81,7 @@
     </dependency>
     
   </dependencies>
-  <properties>
-    <rootDir>../../</rootDir>
-  </properties>
+  <properties>
+    <rootDir>../../</rootDir>
+  </properties>
 </project>

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java	2013-04-15 19:04:24 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java	2013-04-26 13:15:53 +0000
@@ -45,6 +45,7 @@
 import net.sf.jasperreports.engine.JasperPrint;
 import net.sf.jasperreports.engine.JasperReport;
 
+import net.sf.jasperreports.engine.util.JRProperties;
 import org.amplecode.quick.StatementManager;
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.common.Grid;
@@ -166,6 +167,9 @@
 
         try
         {
+            JRProperties.setProperty("net.sf.jasperreports.awt.ignore.missing.font", "true");
+            JRProperties.setProperty( "net.sf.jasperreports.default.font.name", "DejaVu Sans" );
+
             JasperReport jasperReport = JasperCompileManager.compileReport( StreamUtils.getInputStream( report.getDesignContent() ) );
 
             if ( report.hasReportTable() ) // Use JR data source

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/StreamUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/StreamUtils.java	2013-04-15 17:06:42 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/StreamUtils.java	2013-04-26 13:15:53 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.system.comparator.FileLastModifiedComparator;
+
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
@@ -55,8 +57,6 @@
 import java.util.zip.ZipInputStream;
 import java.util.zip.ZipOutputStream;
 
-import org.hisp.dhis.system.comparator.FileLastModifiedComparator;
-
 /**
  * @author Lars Helge Overland
  * @version $Id$
@@ -64,18 +64,18 @@
 public class StreamUtils
 {
     public static final String LINE_BREAK = "\n";
-    public static final String ENCODING_UTF = "UTF8";
-    
+    public static final String ENCODING_UTF8 = "UTF-8";
+
     /**
      * Loads a resorce from the classpath defined by the name parameter.
-     * 
+     *
      * @param name the name of the resource.
      * @return an InputStream.
      */
     public static InputStream loadResource( String name )
     {
         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-            
+
         return classLoader.getResourceAsStream( name );
     }
 
@@ -85,7 +85,7 @@
 
         try
         {
-           while ( ( b = in.read() ) != -1 )
+            while ( (b = in.read()) != -1 )
             {
                 out.write( b );
             }
@@ -100,10 +100,11 @@
             closeOutputStream( out );
         }
     }
+
     /**
      * Writes the content of the first File to the second File.
-     * 
-     * @param inFile the input File.
+     *
+     * @param inFile  the input File.
      * @param outFile the output File.
      */
     public static void write( File inFile, File outFile )
@@ -111,11 +112,12 @@
         BufferedInputStream in = null;
         BufferedOutputStream out = null;
 
-        try {
+        try
+        {
             in = new BufferedInputStream( new FileInputStream( inFile ) );
             out = new BufferedOutputStream( new FileOutputStream( outFile ) );
 
-            streamcopy(in, out);
+            streamcopy( in, out );
         }
         catch ( IOException ex )
         {
@@ -125,14 +127,14 @@
         {
             closeInputStream( in );
             closeOutputStream( out );
-        }        
+        }
     }
 
     /**
      * Returns all Files in the given directory.
-     * 
+     *
      * @param directory a File representing the relevant directory.
-     * @param sort indicates whether to sort chronologically on the lastModified property.
+     * @param sort      indicates whether to sort chronologically on the lastModified property.
      * @return a List of Files.
      */
     public static List<File> getFileList( File directory, boolean sort )
@@ -143,28 +145,28 @@
         {
             files = Arrays.asList( directory.listFiles() );
         }
-        
+
         if ( sort )
         {
             Collections.sort( files, new FileLastModifiedComparator() );
         }
-        
+
         return files;
     }
 
     /**
      * Writes the content of the StringBuffer to the file.
-     * 
-     * @param file the file to write to.
+     *
+     * @param file    the file to write to.
      * @param content the content to write.
      * @throws IOException
      */
     public static void writeContent( File file, StringBuffer content )
         throws IOException
     {
-        BufferedWriter writer = new BufferedWriter( 
-            new OutputStreamWriter( new FileOutputStream( file ), ENCODING_UTF ) );
-        
+        BufferedWriter writer = new BufferedWriter(
+            new OutputStreamWriter( new FileOutputStream( file ), ENCODING_UTF8 ) );
+
         try
         {
             writer.write( content.toString() );
@@ -176,22 +178,22 @@
                 writer.flush();
             }
             catch ( Exception ex )
-            {   
+            {
             }
-            
+
             try
             {
                 writer.close();
             }
             catch ( Exception ex )
-            {   
+            {
             }
         }
     }
-    
+
     /**
      * Get an InputStream for the String.
-     * 
+     *
      * @param string the String.
      * @return the InputStream.
      */
@@ -199,17 +201,17 @@
     {
         try
         {
-            return new BufferedInputStream( new ByteArrayInputStream( string.getBytes( ENCODING_UTF ) ) );
+            return new BufferedInputStream( new ByteArrayInputStream( string.getBytes( ENCODING_UTF8 ) ) );
         }
         catch ( UnsupportedEncodingException ex )
         {
             throw new RuntimeException( ex );
         }
     }
-    
+
     /**
      * Creates a FileWriter.
-     * 
+     *
      * @param file the name of the file.
      * @return a FileWriter.
      */
@@ -224,10 +226,10 @@
             throw new RuntimeException( ex );
         }
     }
-    
+
     /**
      * Returns the content of the File as a String.
-     * 
+     *
      * @param file the File.
      * @return the String.
      */
@@ -236,27 +238,27 @@
         try
         {
             BufferedInputStream in = new BufferedInputStream( new FileInputStream( file ) );
-            
-            byte[] bytes = new byte[(int)file.length()];
-            
+
+            byte[] bytes = new byte[(int) file.length()];
+
             in.read( bytes );
-            
-            return new String( bytes, ENCODING_UTF );
+
+            return new String( bytes, ENCODING_UTF8 );
         }
         catch ( IOException ex )
         {
             throw new RuntimeException( ex );
         }
     }
-    
+
     /**
      * Reads the content of the file to a StringBuffer. Each line is compared to
-     * the keys of the argument map. If a line is matched, the line is replaced 
+     * the keys of the argument map. If a line is matched, the line is replaced
      * with the keys corresponding value. Passing null as replace map argument skips
-     * value replacement. The reading will stop at the first match for a single 
-     * line. 
-     * 
-     * @param file the file to read from.
+     * value replacement. The reading will stop at the first match for a single
+     * line.
+     *
+     * @param file       the file to read from.
      * @param replaceMap a map containing keys to be matched and values with replacements.
      * @return a StringBuffer with the content of the file replaced according to the Map.
      * @throws IOException
@@ -265,16 +267,16 @@
         throws IOException
     {
         StringBuffer content = new StringBuffer();
-        
-        BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream( file ), ENCODING_UTF ) );
-        
+
+        BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream( file ), ENCODING_UTF8 ) );
+
         String line = null;
-        
+
         String currentEndString = null;
-        
+
         try
-        {   
-            while ( ( line = reader.readLine() ) != null )
+        {
+            while ( (line = reader.readLine()) != null )
             {
                 if ( currentEndString != null )
                 {
@@ -282,25 +284,25 @@
                     {
                         currentEndString = null;
                     }
-                    
+
                     continue;
                 }
-                
+
                 if ( replaceMap != null )
                 {
                     for ( Entry<String[], String> entry : replaceMap.entrySet() )
                     {
                         if ( line.contains( entry.getKey()[0] ) )
                         {
-                            currentEndString = ( entry.getKey()[1] != null && !line.contains( entry.getKey()[1] ) ) ? entry.getKey()[1] : null;
-                            
+                            currentEndString = (entry.getKey()[1] != null && !line.contains( entry.getKey()[1] )) ? entry.getKey()[1] : null;
+
                             line = entry.getValue();
-                            
+
                             break;
                         }
                     }
                 }
-                
+
                 content.append( line + LINE_BREAK );
             }
         }
@@ -311,16 +313,16 @@
                 reader.close();
             }
             catch ( Exception ex )
-            {   
+            {
             }
         }
-        
+
         return content;
     }
-    
+
     /**
      * Closes the given Reader.
-     * 
+     *
      * @param reader the Reader to close.
      */
     public static void closeReader( Reader reader )
@@ -337,10 +339,10 @@
             }
         }
     }
-    
+
     /**
      * Closes the given Writer.
-     * 
+     *
      * @param writer the Writer to close.
      */
     public static void closeWriter( Writer writer )
@@ -355,7 +357,7 @@
             {
                 ex.printStackTrace();
             }
-            
+
             try
             {
                 writer.close();
@@ -366,10 +368,10 @@
             }
         }
     }
-    
+
     /**
      * Closes the given InputStream.
-     * 
+     *
      * @param in the InputStream to close.
      */
     public static void closeInputStream( InputStream in )
@@ -386,10 +388,10 @@
             }
         }
     }
-    
+
     /**
      * Closes and flushes the given OutputStream.
-     * 
+     *
      * @param out the OutputStream to close.
      */
     public static void closeOutputStream( OutputStream out )
@@ -404,7 +406,7 @@
             {
                 ex.printStackTrace();
             }
-            
+
             try
             {
                 out.close();
@@ -419,7 +421,7 @@
     /**
      * Test for ZIP/GZIP stream signature. Wraps the input stream in a
      * BufferedInputStream. If ZIP/GZIP test is true wraps again in ZipInputStream/GZIPInputStream.
-     * 
+     *
      * @param in the InputStream.
      * @return the wrapped InputStream.
      */
@@ -427,29 +429,29 @@
         throws IOException
     {
         BufferedInputStream bufferedIn = new BufferedInputStream( in );
-        
+
         if ( isZip( bufferedIn ) )
         {
             ZipInputStream zipIn = new ZipInputStream( bufferedIn );
             zipIn.getNextEntry();
             return zipIn;
         }
-        else if( isGZip( bufferedIn ) )
+        else if ( isGZip( bufferedIn ) )
         {
             GZIPInputStream gzipIn = new GZIPInputStream( bufferedIn );
             return gzipIn;
         }
-        
+
         return bufferedIn;
     }
-    
+
     /**
      * Test for ZIP stream signature.
-     * 
+     * <p/>
      * Signature of ZIP stream from
      * http://www.pkware.com/documents/casestudies/APPNOTE.TXT Local file
      * header: local file header signature 4 bytes (0x04034b50)
-     * 
+     *
      * @param instream the BufferedInputStream to test.
      */
     public static boolean isZip( BufferedInputStream instream )
@@ -478,17 +480,17 @@
         {
             throw new RuntimeException( "Couldn't reset stream ", ex );
         }
-        
+
         return Arrays.equals( b, zipSig );
     }
 
     /**
      * Test for GZIP stream signature.
-     *
+     * <p/>
      * Signature of GZIP stream from RFC 1952: ID1 (IDentification 1) ID2
      * (IDentification 2) These have the fixed values ID1 = 31 (0x1f, \037),
      * ID2 = 139 (0x8b, \213), to identify the file as being in GZIP format.
-     * 
+     *
      * @param instream the BufferedInputStream to test.
      */
     public static boolean isGZip( BufferedInputStream instream )
@@ -513,13 +515,13 @@
             throw new RuntimeException( "Couldn't reset stream ", ex );
         }
 
-        return ( b[0] == 31 && b[1] == -117 );
+        return (b[0] == 31 && b[1] == -117);
     }
 
     /**
-     * Reads the next ZIP file entry from the ZipInputStream and positions the 
+     * Reads the next ZIP file entry from the ZipInputStream and positions the
      * stream at the beginning of the entry data.
-     * 
+     *
      * @param in the ZipInputStream to read from.
      * @return a ZipEntry.
      */
@@ -534,10 +536,10 @@
             throw new RuntimeException( "Failed to get next entry in ZIP-file", ex );
         }
     }
-    
+
     /**
      * Closes the current ZipEntry and positions the stream for writing the next entry.
-     * 
+     *
      * @param out the ZipOutputStream.
      */
     public static void closeZipEntry( ZipOutputStream out )
@@ -551,10 +553,10 @@
             throw new RuntimeException( "Failed to close the current ZipEntry", ex );
         }
     }
-    
+
     /**
      * Finishes writing the contents of the ZIP output stream without closing the underlying stream.
-     * 
+     *
      * @param out the ZipOutputStream.
      */
     public static void finishZipEntry( ZipOutputStream out )
@@ -568,10 +570,10 @@
             throw new RuntimeException( "Failed to finish the content of the ZipOutputStream", ex );
         }
     }
-    
+
     /**
      * Attempts to delete the File with the given path.
-     * 
+     *
      * @param path the File path.
      * @return true if the operation succeeded, false otherwise.
      */
@@ -579,10 +581,10 @@
     {
         return new File( path ).delete();
     }
-    
+
     /**
      * Tests whether the File with the given path exists.
-     * 
+     *
      * @param path the File path.
      * @return true if the File exists, false otherwise.
      */

=== modified file 'dhis-2/pom.xml'
--- dhis-2/pom.xml	2013-04-15 16:34:57 +0000
+++ dhis-2/pom.xml	2013-04-26 13:15:53 +0000
@@ -687,7 +687,7 @@
       <dependency>
         <groupId>net.sf.jasperreports</groupId>
         <artifactId>jasperreports</artifactId>
-        <version>4.7.0</version>
+        <version>4.7.1</version>
         <exclusions>
           <exclusion>
             <groupId>xalan</groupId>
@@ -700,6 +700,11 @@
         </exclusions>
       </dependency>
       <dependency>
+      	<groupId>net.sf.jasperreports</groupId>
+      	<artifactId>jasperreports-fonts</artifactId>
+      	<version>4.0.0</version>
+      </dependency>
+      <dependency>
         <groupId>jfree</groupId>
         <artifactId>jfreechart</artifactId>
         <version>1.0.13</version>