Fix some Forbidden APIs errors

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1700641 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2015-09-01 18:56:44 +00:00
parent 4fed0c35e9
commit 2015baaad3
15 changed files with 44 additions and 29 deletions

View File

@ -22,6 +22,7 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.Locale;
import org.apache.poi.POIOLE2TextExtractor; import org.apache.poi.POIOLE2TextExtractor;
import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCell;
@ -159,7 +160,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p
if (i >= args.length) { if (i >= args.length) {
throw new CommandParseException("Expected value after '" + args[i-1] + "'"); throw new CommandParseException("Expected value after '" + args[i-1] + "'");
} }
String value = args[i].toUpperCase(); String value = args[i].toUpperCase(Locale.ROOT);
if ("Y".equals(value) || "YES".equals(value) || "ON".equals(value) || "TRUE".equals(value)) { if ("Y".equals(value) || "YES".equals(value) || "ON".equals(value) || "TRUE".equals(value)) {
return true; return true;
} }

View File

@ -21,6 +21,7 @@ import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.LittleEndianOutput;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale;
/** /**
* The HEADERFOOTER record stores information added in Office Excel 2007 for headers/footers. * The HEADERFOOTER record stores information added in Office Excel 2007 for headers/footers.
@ -88,7 +89,7 @@ public final class HeaderFooterRecord extends StandardRecord {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("[").append("HEADERFOOTER").append("] (0x"); sb.append("[").append("HEADERFOOTER").append("] (0x");
sb.append(Integer.toHexString(sid).toUpperCase() + ")\n"); sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT) + ")\n");
sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n"); sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n");
sb.append("[/").append("HEADERFOOTER").append("]\n"); sb.append("[/").append("HEADERFOOTER").append("]\n");
return sb.toString(); return sb.toString();
@ -100,4 +101,4 @@ public final class HeaderFooterRecord extends StandardRecord {
} }
} }

View File

@ -19,6 +19,7 @@ package org.apache.poi.hssf.record;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.util.Locale;
import org.apache.poi.hssf.dev.BiffViewer; import org.apache.poi.hssf.dev.BiffViewer;
import org.apache.poi.hssf.record.crypto.Biff8DecryptingStream; import org.apache.poi.hssf.record.crypto.Biff8DecryptingStream;
@ -51,7 +52,7 @@ public final class RecordInputStream implements LittleEndianInput {
@SuppressWarnings("serial") @SuppressWarnings("serial")
public static final class LeftoverDataException extends RuntimeException { public static final class LeftoverDataException extends RuntimeException {
public LeftoverDataException(int sid, int remainingByteCount) { public LeftoverDataException(int sid, int remainingByteCount) {
super("Initialisation of record 0x" + Integer.toHexString(sid).toUpperCase() super("Initialisation of record 0x" + Integer.toHexString(sid).toUpperCase(Locale.ROOT)
+ "(" + getRecordName(sid) + ") left " + remainingByteCount + "(" + getRecordName(sid) + ") left " + remainingByteCount
+ " bytes remaining still to be read."); + " bytes remaining still to be read.");
} }

View File

@ -17,6 +17,8 @@
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import java.util.Locale;
import org.apache.poi.hssf.record.aggregates.PageSettingsBlock; import org.apache.poi.hssf.record.aggregates.PageSettingsBlock;
import org.apache.poi.util.HexDump; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.LittleEndianOutput;
@ -85,7 +87,8 @@ public final class UnknownRecord extends StandardRecord {
// unknown sids in the range 0x0004-0x0013 are probably 'sub-records' of ObjectRecord // unknown sids in the range 0x0004-0x0013 are probably 'sub-records' of ObjectRecord
// those sids are in a different number space. // those sids are in a different number space.
// TODO - put unknown OBJ sub-records in a different class // TODO - put unknown OBJ sub-records in a different class
System.out.println("Unknown record 0x" + Integer.toHexString(_sid).toUpperCase()); System.out.println("Unknown record 0x" +
Integer.toHexString(_sid).toUpperCase(Locale.ROOT));
} }
} }
@ -114,7 +117,7 @@ public final class UnknownRecord extends StandardRecord {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("[").append(biffName).append("] (0x"); sb.append("[").append(biffName).append("] (0x");
sb.append(Integer.toHexString(_sid).toUpperCase() + ")\n"); sb.append(Integer.toHexString(_sid).toUpperCase(Locale.ROOT) + ")\n");
if (_rawData.length > 0) { if (_rawData.length > 0) {
sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n"); sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n");
} }
@ -213,7 +216,7 @@ public final class UnknownRecord extends StandardRecord {
case 0x1007: return "CHARTLINEFORMAT"; case 0x1007: return "CHARTLINEFORMAT";
} }
if (isObservedButUnknown(sid)) { if (isObservedButUnknown(sid)) {
return "UNKNOWN-" + Integer.toHexString(sid).toUpperCase(); return "UNKNOWN-" + Integer.toHexString(sid).toUpperCase(Locale.ROOT);
} }
return null; return null;

View File

@ -17,10 +17,11 @@
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import java.util.Locale;
import org.apache.poi.util.HexDump; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.LittleEndianOutput;
/** /**
* The UserSViewBegin record specifies settings for a custom view associated with the sheet. * The UserSViewBegin record specifies settings for a custom view associated with the sheet.
* This record also marks the start of custom view records, which save custom view settings. * This record also marks the start of custom view records, which save custom view settings.
@ -76,7 +77,7 @@ public final class UserSViewBegin extends StandardRecord {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("[").append("USERSVIEWBEGIN").append("] (0x"); sb.append("[").append("USERSVIEWBEGIN").append("] (0x");
sb.append(Integer.toHexString(sid).toUpperCase() + ")\n"); sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT) + ")\n");
sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n"); sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n");
sb.append("[/").append("USERSVIEWBEGIN").append("]\n"); sb.append("[/").append("USERSVIEWBEGIN").append("]\n");
return sb.toString(); return sb.toString();
@ -87,4 +88,4 @@ public final class UserSViewBegin extends StandardRecord {
return cloneViaReserialise(); return cloneViaReserialise();
} }
} }

View File

@ -17,6 +17,8 @@
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import java.util.Locale;
import org.apache.poi.util.HexDump; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.LittleEndianOutput;
@ -61,7 +63,7 @@ public final class UserSViewEnd extends StandardRecord {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("[").append("USERSVIEWEND").append("] (0x"); sb.append("[").append("USERSVIEWEND").append("] (0x");
sb.append(Integer.toHexString(sid).toUpperCase() + ")\n"); sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT) + ")\n");
sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n"); sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n");
sb.append("[/").append("USERSVIEWEND").append("]\n"); sb.append("[/").append("USERSVIEWEND").append("]\n");
return sb.toString(); return sb.toString();

View File

@ -18,6 +18,8 @@
package org.apache.poi.hssf.record.cf; package org.apache.poi.hssf.record.cf;
import java.util.Locale;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.BitField; import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.BitFieldFactory;
@ -533,7 +535,7 @@ public final class FontFormatting {
{ {
buffer.append(" .underline type is not modified\n"); buffer.append(" .underline type is not modified\n");
} }
buffer.append(" .color index = ").append("0x"+Integer.toHexString(getFontColorIndex()).toUpperCase()).append("\n"); buffer.append(" .color index = ").append("0x"+Integer.toHexString(getFontColorIndex()).toUpperCase(Locale.ROOT)).append("\n");
buffer.append(" [/Font Formatting]\n"); buffer.append(" [/Font Formatting]\n");
return buffer.toString(); return buffer.toString();

View File

@ -15,17 +15,12 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
/*
* HSSFDataFormat.java
*
* Created on December 18, 2001, 12:42 PM
*/
package org.apache.poi.hssf.usermodel; package org.apache.poi.hssf.usermodel;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Vector; import java.util.Vector;
import org.apache.poi.hssf.model.InternalWorkbook; import org.apache.poi.hssf.model.InternalWorkbook;
@ -95,7 +90,7 @@ public final class HSSFDataFormat implements DataFormat {
public short getFormat(String pFormat) { public short getFormat(String pFormat) {
// Normalise the format string // Normalise the format string
String format; String format;
if (pFormat.toUpperCase().equals("TEXT")) { if (pFormat.toUpperCase(Locale.ROOT).equals("TEXT")) {
format = "@"; format = "@";
} else { } else {
format = pFormat; format = pFormat;

View File

@ -25,6 +25,7 @@ import java.security.Provider;
import java.security.Security; import java.security.Security;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.Mac; import javax.crypto.Mac;
@ -424,7 +425,7 @@ public class CryptoFunctions {
*/ */
public static String xorHashPassword(String password) { public static String xorHashPassword(String password) {
int hashedPassword = createXorVerifier2(password); int hashedPassword = createXorVerifier2(password);
return String.format("%1$08X", hashedPassword); return String.format(Locale.ROOT, "%1$08X", hashedPassword);
} }
/** /**
@ -434,7 +435,7 @@ public class CryptoFunctions {
public static String xorHashPasswordReversed(String password) { public static String xorHashPasswordReversed(String password) {
int hashedPassword = createXorVerifier2(password); int hashedPassword = createXorVerifier2(password);
return String.format("%1$02X%2$02X%3$02X%4$02X" return String.format(Locale.ROOT, "%1$02X%2$02X%3$02X%4$02X"
, ( hashedPassword >>> 0 ) & 0xFF , ( hashedPassword >>> 0 ) & 0xFF
, ( hashedPassword >>> 8 ) & 0xFF , ( hashedPassword >>> 8 ) & 0xFF
, ( hashedPassword >>> 16 ) & 0xFF , ( hashedPassword >>> 16 ) & 0xFF

View File

@ -20,6 +20,7 @@ import org.apache.poi.hssf.util.HSSFColor;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -60,7 +61,7 @@ public class CellFormatPart {
for (HSSFColor color : colors.values()) { for (HSSFColor color : colors.values()) {
Class<? extends HSSFColor> type = color.getClass(); Class<? extends HSSFColor> type = color.getClass();
String name = type.getSimpleName(); String name = type.getSimpleName();
if (name.equals(name.toUpperCase())) { if (name.equals(name.toUpperCase(Locale.ROOT))) {
short[] rgb = color.getTriplet(); short[] rgb = color.getTriplet();
Color c = new Color(rgb[0], rgb[1], rgb[2]); Color c = new Color(rgb[0], rgb[1], rgb[2]);
NAMED_COLORS.put(name, c); NAMED_COLORS.put(name, c);

View File

@ -17,6 +17,7 @@
package org.apache.poi.ss.format; package org.apache.poi.ss.format;
import java.util.Formatter; import java.util.Formatter;
import java.util.Locale;
/** /**
* A formatter for the default "General" cell format. * A formatter for the default "General" cell format.
@ -77,7 +78,7 @@ public class CellGeneralFormatter extends CellFormatter {
} }
} }
} else if (value instanceof Boolean) { } else if (value instanceof Boolean) {
toAppendTo.append(value.toString().toUpperCase()); toAppendTo.append(value.toString().toUpperCase(Locale.ROOT));
} else { } else {
toAppendTo.append(value.toString()); toAppendTo.append(value.toString());
} }

View File

@ -17,10 +17,11 @@
package org.apache.poi.ss.formula.ptg; package org.apache.poi.ss.formula.ptg;
import java.util.Locale;
import org.apache.poi.ss.formula.function.FunctionMetadata; import org.apache.poi.ss.formula.function.FunctionMetadata;
import org.apache.poi.ss.formula.function.FunctionMetadataRegistry; import org.apache.poi.ss.formula.function.FunctionMetadataRegistry;
/** /**
* This class provides the base functionality for Excel sheet functions * This class provides the base functionality for Excel sheet functions
* There are two kinds of function Ptgs - tFunc and tFuncVar * There are two kinds of function Ptgs - tFunc and tFuncVar
@ -119,7 +120,7 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
* <code>false</code> if the name should be assumed to be an external function. * <code>false</code> if the name should be assumed to be an external function.
*/ */
public static final boolean isBuiltInFunctionName(String name) { public static final boolean isBuiltInFunctionName(String name) {
short ix = FunctionMetadataRegistry.lookupIndexByName(name.toUpperCase()); short ix = FunctionMetadataRegistry.lookupIndexByName(name.toUpperCase(Locale.ROOT));
return ix >= 0; return ix >= 0;
} }

View File

@ -16,6 +16,8 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.ss.usermodel; package org.apache.poi.ss.usermodel;
import java.util.Locale;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Color; import org.apache.poi.ss.usermodel.Color;
@ -136,7 +138,7 @@ public abstract class ExtendedColor implements Color {
} }
sb.append(cs); sb.append(cs);
} }
return sb.toString().toUpperCase(); return sb.toString().toUpperCase(Locale.ROOT);
} }
/** /**

View File

@ -17,6 +17,8 @@
package org.apache.poi.ss.util; package org.apache.poi.ss.util;
import java.util.Locale;
import static org.apache.poi.ss.util.IEEEDouble.*; import static org.apache.poi.ss.util.IEEEDouble.*;
/** /**
@ -168,6 +170,6 @@ public final class NumberComparer {
* for formatting double values in error messages * for formatting double values in error messages
*/ */
private static String toHex(double a) { private static String toHex(double a) {
return "0x" + Long.toHexString(Double.doubleToLongBits(a)).toUpperCase(); return "0x" + Long.toHexString(Double.doubleToLongBits(a)).toUpperCase(Locale.ROOT);
} }
} }

View File

@ -22,6 +22,7 @@ import java.awt.font.TextAttribute;
import java.awt.font.TextLayout; import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.text.AttributedString; import java.text.AttributedString;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
@ -148,7 +149,7 @@ public class SheetUtil {
sval = String.valueOf(cell.getNumericCellValue()); sval = String.valueOf(cell.getNumericCellValue());
} }
} else if (cellType == Cell.CELL_TYPE_BOOLEAN) { } else if (cellType == Cell.CELL_TYPE_BOOLEAN) {
sval = String.valueOf(cell.getBooleanCellValue()).toUpperCase(); sval = String.valueOf(cell.getBooleanCellValue()).toUpperCase(Locale.ROOT);
} }
if(sval != null) { if(sval != null) {
String txt = sval + defaultChar; String txt = sval + defaultChar;
@ -315,4 +316,4 @@ public class SheetUtil {
// live within any merged regions // live within any merged regions
return null; return null;
} }
} }