]> source.dussan.org Git - poi.git/commitdiff
Fix some Forbidden APIs errors
authorNick Burch <nick@apache.org>
Tue, 1 Sep 2015 21:18:33 +0000 (21:18 +0000)
committerNick Burch <nick@apache.org>
Tue, 1 Sep 2015 21:18:33 +0000 (21:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1700672 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/dev/RecordGenerator.java
src/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java
src/java/org/apache/poi/ss/util/DateFormatConverter.java

index 588724d06f75f3be5e71d5ca97807a5cd4a53479..b442b8e7adf6f380e7d94d96071b5690f8400f24 100644 (file)
@@ -19,8 +19,9 @@
 package org.apache.poi.dev;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
+import java.io.InputStreamReader;
 import java.io.Reader;
 import java.util.Locale;
 import java.util.Properties;
@@ -35,6 +36,7 @@ import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.poi.util.StringUtil;
 import org.apache.poi.util.XMLHelper;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -128,7 +130,7 @@ public class RecordGenerator {
     private static void transform(final File in, final File out, final File xslt)
     throws FileNotFoundException, TransformerException
     {
-        final Reader r = new FileReader(xslt);
+        final Reader r = new InputStreamReader(new FileInputStream(xslt), StringUtil.UTF8);
         final StreamSource ss = new StreamSource(r);
         final TransformerFactory tf = TransformerFactory.newInstance();
         final Transformer t;
index 4b7ecf0fb444ca8960d7bd932d02a864464355fa..ada303436e6356740bc1e9865ee92e260ce4bad5 100644 (file)
@@ -19,15 +19,20 @@ package org.apache.poi.ss.formula.atp;
 
 import java.util.Calendar;
 import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
 
 import org.apache.poi.ss.usermodel.DateUtil;
 
 /**
  * A calculator for workdays, considering dates as excel representations.
- * 
- * @author jfaenomoto@gmail.com
  */
 public class WorkdayCalculator {
+    /**
+     * Excel doesn't store TimeZone information in the file, so if in doubt,
+     *  use UTC to perform calculations
+     */
+    private static final TimeZone DEFAULT_TIMEZONE = TimeZone.getTimeZone("UTC");
 
     public static final WorkdayCalculator instance = new WorkdayCalculator();
 
@@ -64,7 +69,7 @@ public class WorkdayCalculator {
        public Date calculateWorkdays(double start, int workdays, double[] holidays) {
                Date startDate = DateUtil.getJavaDate(start);
                int direction = workdays < 0 ? -1 : 1;
-               Calendar endDate = Calendar.getInstance();
+               Calendar endDate = Calendar.getInstance(DEFAULT_TIMEZONE, Locale.ROOT);
                endDate.setTime(startDate);
                double excelEndDate = DateUtil.getExcelDate(endDate.getTime());
                while (workdays != 0) {
@@ -92,7 +97,7 @@ public class WorkdayCalculator {
         int startDay = (int) Math.floor(start < end ? start : end);
         int endDay = (int) Math.floor(end > start ? end : start);
         for (; startDay <= endDay; startDay++) {
-            Calendar today = Calendar.getInstance();
+            Calendar today = Calendar.getInstance(DEFAULT_TIMEZONE, Locale.ROOT);
             today.setTime(DateUtil.getJavaDate(startDay));
             if (today.get(Calendar.DAY_OF_WEEK) == dayOfWeek) {
                 pastDaysOfWeek++;
@@ -128,7 +133,7 @@ public class WorkdayCalculator {
      * @return <code>true</code> if date is weekend, <code>false</code> otherwise.
      */
     protected boolean isWeekend(double aDate) {
-        Calendar date = Calendar.getInstance();
+        Calendar date = Calendar.getInstance(DEFAULT_TIMEZONE, Locale.ROOT);
         date.setTime(DateUtil.getJavaDate(aDate));
         return date.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || date.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
     }
index 7d9248b164db9f973c702de816be4c6c87bd811b..aa343f3722344666f4b2cbf3db30a1f4ff9787bd 100644 (file)
@@ -337,8 +337,8 @@ public class DateFormatConverter  {
                        result = localePrefixes.get( localeString.substring( 0, 2 ) );\r
                        if( result ==  null ) {\r
                                Locale parentLocale = new Locale(localeString.substring( 0, 2 ));\r
-                               logger.log( POILogger.ERROR, "Unable to find prefix for " + locale + "(" + locale.getDisplayName() + ") or " \r
-                                               + localeString.substring( 0, 2 ) + "(" + parentLocale.getDisplayName() + ")" );\r
+                               logger.log( POILogger.ERROR, "Unable to find prefix for " + locale + "(" + locale.getDisplayName(Locale.ROOT) + ") or " \r
+                                               + localeString.substring( 0, 2 ) + "(" + parentLocale.getDisplayName(Locale.ROOT) + ")" );\r
                                return "";\r
                        }\r
                }\r