]> source.dussan.org Git - poi.git/commitdiff
forbidden apis fixes
authorAndreas Beeker <kiwiwings@apache.org>
Sat, 29 Aug 2015 21:45:08 +0000 (21:45 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sat, 29 Aug 2015 21:45:08 +0000 (21:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1700076 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/usermodel/DataFormatter.java
src/java/org/apache/poi/ss/usermodel/ExcelStyleDateFormatter.java
src/java/org/apache/poi/ss/util/CellReference.java
src/testcases/org/apache/poi/ss/util/AllSSUtilTests.java
src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java

index 766ded18fe7c363b35d7a8d179b120dbaff6af6b..6cb9d4d71ce660f316138b41c69779bcd4a5bd56 100644 (file)
@@ -440,8 +440,8 @@ public class DataFormatter {
 
         Matcher dateMatcher = daysAsText.matcher(formatStr);
         if (dateMatcher.find()) {
-            String match = dateMatcher.group(0);
-            formatStr = dateMatcher.replaceAll(match.toUpperCase().replaceAll("D", "E"));
+            String match = dateMatcher.group(0).toUpperCase(Locale.ROOT).replaceAll("D", "E");
+            formatStr = dateMatcher.replaceAll(match);
         }
 
         // Convert excel date format to SimpleDateFormat.
@@ -903,8 +903,9 @@ public class DataFormatter {
     /**
      * @return a <tt>DecimalFormat</tt> with parseIntegerOnly set <code>true</code>
      */
-    /* package */ static DecimalFormat createIntegerOnlyFormat(String fmt) {
-        DecimalFormat result = new DecimalFormat(fmt);
+    private static DecimalFormat createIntegerOnlyFormat(String fmt) {
+        DecimalFormatSymbols dsf = DecimalFormatSymbols.getInstance(Locale.ROOT);
+        DecimalFormat result = new DecimalFormat(fmt, dsf);
         result.setParseIntegerOnly(true);
         return result;
     }
index 22c8b541ac7738c3e42965b6af67964577955d54..fd2b61da34812da4c1454cc1fcfb17b313c2d492 100644 (file)
@@ -40,13 +40,18 @@ public class ExcelStyleDateFormatter extends SimpleDateFormat {
     public static final char L_BRACKET_SYMBOL = '\ue016';
     public static final char LL_BRACKET_SYMBOL = '\ue017';
 
-    private DecimalFormat format1digit = new DecimalFormat("0");
-    private DecimalFormat format2digits = new DecimalFormat("00");
+    private final DecimalFormat format1digit;
+    private final DecimalFormat format2digits;
 
-    private DecimalFormat format3digit = new DecimalFormat("0");
-    private DecimalFormat format4digits = new DecimalFormat("00");
+    private final DecimalFormat format3digit;
+    private final DecimalFormat format4digits;
 
     {
+        DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(Locale.ROOT);
+        format1digit = new DecimalFormat("0", dfs);
+        format2digits = new DecimalFormat("00", dfs);
+        format3digit = new DecimalFormat("0", dfs);
+        format4digits = new DecimalFormat("00", dfs);
         DataFormatter.setExcelStyleRoundingMode(format1digit, RoundingMode.DOWN);
         DataFormatter.setExcelStyleRoundingMode(format2digits, RoundingMode.DOWN);
         DataFormatter.setExcelStyleRoundingMode(format3digit);
index e2c98d6ef0526d0a26828a1a19a8fb948ed319b9..b4fa2b3ce1fa16a378d7efcdb7ec8c638da5e4ab 100644 (file)
@@ -17,6 +17,7 @@
 
 package org.apache.poi.ss.util;
 
+import java.util.Locale;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -86,7 +87,7 @@ public class CellReference {
      * delimited and escaped as per normal syntax rules for formulas.
      */
     public CellReference(String cellRef) {
-        if(cellRef.toUpperCase().endsWith("#REF!")) {
+        if(cellRef.toUpperCase(Locale.ROOT).endsWith("#REF!")) {
             throw new IllegalArgumentException("Cell reference invalid: " + cellRef);
         }
 
index 5e64f75da59aff0f37df8450801aae71107c12e4..d0935af6ca6a3827d0ac8c9ae89fdcb95ba420cb 100644 (file)
@@ -26,12 +26,17 @@ import org.junit.runners.Suite;
  */
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
+    TestAreaReference.class,
     TestCellRangeAddress.class,
     TestCellReference.class,
+    TestDateFormatConverter.class,
     TestExpandedDouble.class,
     TestNumberComparer.class,
     TestNumberToTextConverter.class,
-    TestRegion.class
+    TestRegion.class,
+    TestSheetBuilder.class,
+    TestSheetUtil.class,
+    TestWorkbookUtil.class
 })
 public class AllSSUtilTests {
 }
index 95042e50f33fbf13dee780a7d1f1205aee64c955..418070f16a56468d355065e193583f423dd42562 100644 (file)
@@ -42,78 +42,82 @@ public final class TestDateFormatConverter extends TestCase {
     private void outputLocaleDataFormats( Date date, boolean dates, boolean times, int style, String styleName ) throws Exception {
 
         Workbook workbook = new HSSFWorkbook();
-        String sheetName;
-        if( dates ) {
-            if( times ) {
-                sheetName = "DateTimes";
+        try {
+            String sheetName;
+            if( dates ) {
+                if( times ) {
+                    sheetName = "DateTimes";
+                } else {
+                    sheetName = "Dates";
+                }
             } else {
-                sheetName = "Dates";
+                sheetName = "Times";
             }
-        } else {
-            sheetName = "Times";
-        }
-        Sheet sheet = workbook.createSheet(sheetName);
-        Row header = sheet.createRow(0);
-        header.createCell(0).setCellValue("locale");
-        header.createCell(1).setCellValue("DisplayName");
-        header.createCell(2).setCellValue("Excel " + styleName);
-        header.createCell(3).setCellValue("java.text.DateFormat");
-        header.createCell(4).setCellValue("Equals");
-        header.createCell(5).setCellValue("Java pattern");
-        header.createCell(6).setCellValue("Excel pattern");
-
-        int rowNum = 1;
-        for( Locale locale : DateFormat.getAvailableLocales() ) {
-            try {
-                Row row = sheet.createRow(rowNum++);
-    
-                row.createCell(0).setCellValue(locale.toString());
-                row.createCell(1).setCellValue(locale.getDisplayName());
+            Sheet sheet = workbook.createSheet(sheetName);
+            Row header = sheet.createRow(0);
+            header.createCell(0).setCellValue("locale");
+            header.createCell(1).setCellValue("DisplayName");
+            header.createCell(2).setCellValue("Excel " + styleName);
+            header.createCell(3).setCellValue("java.text.DateFormat");
+            header.createCell(4).setCellValue("Equals");
+            header.createCell(5).setCellValue("Java pattern");
+            header.createCell(6).setCellValue("Excel pattern");
     
-                DateFormat dateFormat;
-                if( dates ) {
-                    if( times ) {
-                        dateFormat = DateFormat.getDateTimeInstance(style, style, locale);
+            int rowNum = 1;
+            for( Locale locale : DateFormat.getAvailableLocales() ) {
+                try {
+                    Row row = sheet.createRow(rowNum++);
+        
+                    row.createCell(0).setCellValue(locale.toString());
+                    row.createCell(1).setCellValue(locale.getDisplayName());
+        
+                    DateFormat dateFormat;
+                    if( dates ) {
+                        if( times ) {
+                            dateFormat = DateFormat.getDateTimeInstance(style, style, locale);
+                        } else {
+                            dateFormat = DateFormat.getDateInstance(style, locale);
+                        }
                     } else {
-                        dateFormat = DateFormat.getDateInstance(style, locale);
+                        dateFormat = DateFormat.getTimeInstance(style, locale);
                     }
-                } else {
-                    dateFormat = DateFormat.getTimeInstance(style, locale);
+        
+                    Cell cell = row.createCell(2);
+        
+                    cell.setCellValue(date);
+                    CellStyle cellStyle = row.getSheet().getWorkbook().createCellStyle();
+        
+                    String javaDateFormatPattern = ((SimpleDateFormat)dateFormat).toPattern();
+                    String excelFormatPattern = DateFormatConverter.convert(locale, javaDateFormatPattern);
+        
+                    DataFormat poiFormat = row.getSheet().getWorkbook().createDataFormat();
+                    cellStyle.setDataFormat(poiFormat.getFormat(excelFormatPattern));
+                    row.createCell(3).setCellValue(dateFormat.format(date));
+        
+                    cell.setCellStyle(cellStyle);
+        
+                    // the formula returns TRUE is the formatted date in column C equals to the string in column D
+                    row.createCell(4).setCellFormula("TEXT(C"+rowNum+",G"+rowNum+")=D" + rowNum);
+                    row.createCell(5).setCellValue(javaDateFormatPattern);
+                    row.createCell(6).setCellValue(excelFormatPattern);
+                } catch (Exception e) {
+                    throw new RuntimeException("Failed for locale: " + locale + ", having locales: " + 
+                            Arrays.toString(DateFormat.getAvailableLocales()), e);
                 }
+            }
     
-                Cell cell = row.createCell(2);
-    
-                cell.setCellValue(date);
-                CellStyle cellStyle = row.getSheet().getWorkbook().createCellStyle();
-    
-                String javaDateFormatPattern = ((SimpleDateFormat)dateFormat).toPattern();
-                String excelFormatPattern = DateFormatConverter.convert(locale, javaDateFormatPattern);
-    
-                DataFormat poiFormat = row.getSheet().getWorkbook().createDataFormat();
-                cellStyle.setDataFormat(poiFormat.getFormat(excelFormatPattern));
-                row.createCell(3).setCellValue(dateFormat.format(date));
-    
-                cell.setCellStyle(cellStyle);
-    
-                // the formula returns TRUE is the formatted date in column C equals to the string in column D
-                row.createCell(4).setCellFormula("TEXT(C"+rowNum+",G"+rowNum+")=D" + rowNum);
-                row.createCell(5).setCellValue(javaDateFormatPattern);
-                row.createCell(6).setCellValue(excelFormatPattern);
-            } catch (Exception e) {
-                throw new RuntimeException("Failed for locale: " + locale + ", having locales: " + 
-                        Arrays.toString(DateFormat.getAvailableLocales()), e);
+            File outputFile = TempFile.createTempFile("Locale" + sheetName + styleName, ".xlsx");
+            FileOutputStream outputStream = new FileOutputStream(outputFile);
+            try {
+                workbook.write(outputStream);
+            } finally {
+                outputStream.close();
             }
-        }
-
-        File outputFile = TempFile.createTempFile("Locale" + sheetName + styleName, ".xlsx");
-        FileOutputStream outputStream = new FileOutputStream(outputFile);
-        try {
-            workbook.write(outputStream);
+    
+            System.out.println("Open " + outputFile.getAbsolutePath()+" in Excel");
         } finally {
-            outputStream.close();
+            workbook.close();
         }
-
-        System.out.println("Open " + outputFile.getAbsolutePath()+" in Excel");
     }
 
     public void testJavaDateFormatsInExcel() throws Exception {