Fix some Forbidden APIs errors

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1700672 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2015-09-01 21:18:33 +00:00
parent 498f0b20e6
commit c1b2bab50e
3 changed files with 16 additions and 9 deletions

View 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;

View 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;
}

View File

@ -337,8 +337,8 @@ public class DateFormatConverter {
result = localePrefixes.get( localeString.substring( 0, 2 ) );
if( result == null ) {
Locale parentLocale = new Locale(localeString.substring( 0, 2 ));
logger.log( POILogger.ERROR, "Unable to find prefix for " + locale + "(" + locale.getDisplayName() + ") or "
+ localeString.substring( 0, 2 ) + "(" + parentLocale.getDisplayName() + ")" );
logger.log( POILogger.ERROR, "Unable to find prefix for " + locale + "(" + locale.getDisplayName(Locale.ROOT) + ") or "
+ localeString.substring( 0, 2 ) + "(" + parentLocale.getDisplayName(Locale.ROOT) + ")" );
return "";
}
}