Fix some Forbidden APIs errors

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1700670 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2015-09-01 21:09:20 +00:00
parent 4fba7dbd62
commit aa455c91fd
21 changed files with 58 additions and 38 deletions

View File

@ -20,11 +20,10 @@ package org.apache.poi.poifs.poibrowser;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Locale;
import org.apache.poi.hpsf.ClassID;
/**
* <p>Provides utility methods for encoding and decoding hexadecimal
* data.</p>
@ -181,7 +180,7 @@ public class Codec
("String has odd length " + length);
byte[] b = new byte[length / 2];
char[] c = new char[length];
s.toUpperCase().getChars(0, length, c, 0);
s.toUpperCase(Locale.ROOT).getChars(0, length, c, 0);
for (int i = 0; i < length; i += 2)
b[i/2] = (byte) (decodeNibble(c[i]) << 4 & 0xF0 |
decodeNibble(c[i+1]) & 0x0F);

View File

@ -32,6 +32,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
@ -66,7 +67,7 @@ public class SettingExternalFunction {
}
public FreeRefFunction findFunction(String name) {
return _functionsByName.get(name.toUpperCase());
return _functionsByName.get(name.toUpperCase(Locale.ROOT));
}
}

View File

@ -19,6 +19,7 @@ package org.apache.poi.ss.formula;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
import org.apache.poi.ss.SpreadsheetVersion;
@ -907,7 +908,7 @@ public final class FormulaParser {
* (b) LOG10 + 1
* In (a) LOG10 is a name of a built-in function. In (b) LOG10 is a cell reference
*/
boolean isFunc = FunctionMetadataRegistry.getFunctionByName(str.toUpperCase()) != null;
boolean isFunc = FunctionMetadataRegistry.getFunctionByName(str.toUpperCase(Locale.ROOT)) != null;
if(isFunc){
int savePointer = _pointer;
resetPointer(_pointer + str.length());
@ -974,7 +975,7 @@ public final class FormulaParser {
*/
private ParseNode getFunction(String name, Ptg namePtg, ParseNode[] args) {
FunctionMetadata fm = FunctionMetadataRegistry.getFunctionByName(name.toUpperCase());
FunctionMetadata fm = FunctionMetadataRegistry.getFunctionByName(name.toUpperCase(Locale.ROOT));
int numArgs = args.length;
if(fm == null) {
if (namePtg == null) {
@ -1313,7 +1314,7 @@ public final class FormulaParser {
private int parseErrorLiteral() {
Match('#');
String part1 = parseUnquotedIdentifier().toUpperCase();
String part1 = parseUnquotedIdentifier().toUpperCase(Locale.ROOT);
if (part1 == null) {
throw expected("remainder of error constant literal");
}

View File

@ -13,6 +13,7 @@ package org.apache.poi.ss.formula.atp;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TreeSet;
@ -70,7 +71,7 @@ public final class AnalysisToolPak implements UDFFinder {
// if you save such a .xlsx workbook as .xls
if(name.startsWith("_xlfn.")) name = name.substring(6);
return _functionsByName.get(name.toUpperCase());
return _functionsByName.get(name.toUpperCase(Locale.ROOT));
}
private Map<String, FreeRefFunction> createFunctionsMap() {

View File

@ -368,7 +368,8 @@ public abstract class TextFunction implements Function {
if (_isCaseSensitive) {
result = haystack.indexOf(needle, startIndex);
} else {
result = haystack.toUpperCase().indexOf(needle.toUpperCase(), startIndex);
result = haystack.toUpperCase(Locale.ROOT)
.indexOf(needle.toUpperCase(Locale.ROOT), startIndex);
}
if (result == -1) {
return ErrorEval.VALUE_INVALID;

View File

@ -18,6 +18,7 @@
package org.apache.poi.ss.formula.udf;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
@ -38,12 +39,12 @@ public final class DefaultUDFFinder implements UDFFinder {
}
HashMap<String, FreeRefFunction> m = new HashMap<String, FreeRefFunction>(nFuncs * 3 / 2);
for (int i = 0; i < functionImpls.length; i++) {
m.put(functionNames[i].toUpperCase(), functionImpls[i]);
m.put(functionNames[i].toUpperCase(Locale.ROOT), functionImpls[i]);
}
_functionsByName = m;
}
public FreeRefFunction findFunction(String name) {
return _functionsByName.get(name.toUpperCase());
return _functionsByName.get(name.toUpperCase(Locale.ROOT));
}
}

View File

@ -21,6 +21,7 @@ package org.apache.poi.xssf.usermodel.helpers;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Locale;
import javax.xml.bind.DatatypeConverter;
import javax.xml.namespace.QName;
@ -54,7 +55,8 @@ public class XSSFPaswordHelper {
cur.toFirstContentToken();
if (hashAlgo == null) {
int hash = CryptoFunctions.createXorVerifier1(password);
cur.insertAttributeWithValue(getAttrName(prefix, "password"), Integer.toHexString(hash).toUpperCase());
cur.insertAttributeWithValue(getAttrName(prefix, "password"),
Integer.toHexString(hash).toUpperCase(Locale.ROOT));
} else {
SecureRandom random = new SecureRandom();
byte salt[] = random.generateSeed(16);

View File

@ -17,11 +17,10 @@
package org.apache.poi.hdf.extractor.util;
import java.util.Locale;
/**
* Comment me
*
* @author Ryan Ackley
* TODO Comment me
*/
@Deprecated
public final class NumberFormatter
@ -68,11 +67,11 @@ public final class NumberFormatter
case ARABIC:
return _arabic[num - 1];
case UPPER_ROMAN:
return _roman[num-1].toUpperCase();
return _roman[num-1].toUpperCase(Locale.ROOT);
case LOWER_ROMAN:
return _roman[num-1];
case UPPER_LETTER:
return _letter[num-1].toUpperCase();
return _letter[num-1].toUpperCase(Locale.ROOT);
case LOWER_LETTER:
return _letter[num-1];
case ORDINAL:

View File

@ -17,11 +17,10 @@
package org.apache.poi.hdf.model.util;
import java.util.Locale;
/**
* Comment me
*
* @author Ryan Ackley
* TODO Comment me
*/
@Deprecated
public final class NumberFormatter
@ -68,11 +67,11 @@ public final class NumberFormatter
case ARABIC:
return _arabic[num - 1];
case UPPER_ROMAN:
return _roman[num-1].toUpperCase();
return _roman[num-1].toUpperCase(Locale.ROOT);
case LOWER_ROMAN:
return _roman[num-1];
case UPPER_LETTER:
return _letter[num-1].toUpperCase();
return _letter[num-1].toUpperCase(Locale.ROOT);
case LOWER_LETTER:
return _letter[num-1];
case ORDINAL:

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.dev;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
import org.apache.poi.ddf.DefaultEscherRecordFactory;
import org.apache.poi.ddf.EscherContainerRecord;
@ -192,12 +193,12 @@ public final class SlideShowDumper {
}
public String makeHex(short s) {
String hex = Integer.toHexString(s).toUpperCase();
String hex = Integer.toHexString(s).toUpperCase(Locale.ROOT);
if(hex.length() == 1) { return "0" + hex; }
return hex;
}
public String makeHex(int i) {
String hex = Integer.toHexString(i).toUpperCase();
String hex = Integer.toHexString(i).toUpperCase(Locale.ROOT);
if(hex.length() == 1) { return "000" + hex; }
if(hex.length() == 2) { return "00" + hex; }
if(hex.length() == 3) { return "0" + hex; }

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.dev;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Locale;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.util.HexDump;
@ -109,7 +110,7 @@ public final class SlideShowRecordDumper {
}
public String makeHex(int number, int padding) {
String hex = Integer.toHexString(number).toUpperCase();
String hex = Integer.toHexString(number).toUpperCase(Locale.ROOT);
while(hex.length() < padding) {
hex = "0" + hex;
}

View File

@ -20,6 +20,7 @@ package org.apache.poi.hsmf.datatypes;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Locale;
import org.apache.poi.hsmf.datatypes.Types.MAPIType;
@ -62,7 +63,8 @@ public abstract class Chunk {
String chunkId = Integer.toHexString(this.chunkId);
while(chunkId.length() < 4) chunkId = "0" + chunkId;
return this.namePrefix + chunkId.toUpperCase() + type.toUpperCase();
return this.namePrefix + chunkId.toUpperCase(Locale.ROOT)
+ type.toUpperCase(Locale.ROOT);
}
/**

View File

@ -30,6 +30,7 @@ import static org.apache.poi.hsmf.datatypes.Types.TIME;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.poi.hsmf.datatypes.Types.MAPIType;
@ -1060,7 +1061,7 @@ public class MAPIProperty {
}
public String asFileName() {
String str = Integer.toHexString(id).toUpperCase();
String str = Integer.toHexString(id).toUpperCase(Locale.ROOT);
while(str.length() < 4) {
str = "0" + str;
}

View File

@ -18,6 +18,7 @@
package org.apache.poi.hsmf.datatypes;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
@ -138,7 +139,7 @@ public final class Types {
}
public static String asFileEnding(int type) {
String str = Integer.toHexString(type).toUpperCase();
String str = Integer.toHexString(type).toUpperCase(Locale.ROOT);
while(str.length() < 4) {
str = "0" + str;
}

View File

@ -19,6 +19,8 @@
package org.apache.poi.hwpf.converter;
import java.util.Locale;
import org.apache.poi.util.Beta;
/**
@ -52,11 +54,11 @@ public final class NumberFormatter
switch ( style )
{
case T_UPPER_ROMAN:
return toRoman( num ).toUpperCase();
return toRoman( num ).toUpperCase(Locale.ROOT);
case T_LOWER_ROMAN:
return toRoman( num );
case T_UPPER_LETTER:
return toLetters( num ).toUpperCase();
return toLetters( num ).toUpperCase(Locale.ROOT);
case T_LOWER_LETTER:
return toLetters( num );
case T_ARABIC:

View File

@ -17,6 +17,8 @@
package org.apache.poi.hpsf.basic;
import java.util.Locale;
import junit.framework.Assert;
import junit.framework.TestCase;
@ -115,7 +117,7 @@ public final class TestClassID extends TestCase {
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}
, 0
);
Assert.assertEquals(clsidTest.toString().toUpperCase(),
Assert.assertEquals(clsidTest.toString().toUpperCase(Locale.ROOT),
"{04030201-0605-0807-090A-0B0C0D0E0F10}"
);
}

View File

@ -19,6 +19,7 @@ package org.apache.poi.ss.formula.eval;
import java.io.PrintStream;
import java.util.Collection;
import java.util.Locale;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
@ -211,7 +212,7 @@ public final class TestFormulasFromSpreadsheet extends TestCase {
default:
throw new RuntimeException("unexpected result");
case Result.NO_EVALUATIONS_FOUND: // do nothing
String uname = targetFunctionName.toUpperCase();
String uname = targetFunctionName.toUpperCase(Locale.ROOT);
if(startRowIndex >= SS.START_FUNCTIONS_ROW_INDEX &&
funcs.contains(uname)) {
logger.log(POILogger.WARN, uname + ": function is supported but missing test data");

View File

@ -19,6 +19,7 @@ package org.apache.poi.ss.formula.eval;
import java.io.PrintStream;
import java.util.Collection;
import java.util.Locale;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
@ -201,7 +202,7 @@ public final class TestMultiSheetEval extends TestCase {
default:
throw new RuntimeException("unexpected result");
case Result.NO_EVALUATIONS_FOUND: // do nothing
String uname = targetFunctionName.toUpperCase();
String uname = targetFunctionName.toUpperCase(Locale.ROOT);
if(startRowIndex >= SS.START_FUNCTIONS_ROW_INDEX &&
funcs.contains(uname)) {
logger.log(POILogger.WARN, uname + ": function is supported but missing test data");

View File

@ -26,6 +26,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
@ -229,7 +230,7 @@ public class NumberRenderingSpreadsheetGenerator {
} catch (IOException e) {
throw new RuntimeException(e);
}
return "0x" + Long.toHexString(l).toUpperCase();
return "0x" + Long.toHexString(l).toUpperCase(Locale.ROOT);
}
private static boolean isNaNBytes(byte[] fileContent, int offset) {

View File

@ -16,10 +16,11 @@
==================================================================== */
package org.apache.poi.ss.util;
import java.util.Locale;
/**
* Contains specific examples of <tt>double</tt> values and their rendering in Excel.
*
* @author Josh Micich
*/
final class NumberToTextConversionExamples {
@ -62,7 +63,7 @@ final class NumberToTextConversionExamples {
_doubleValue = d;
}
private static String doubleToHexString(double d) {
return "0x" + Long.toHexString(Double.doubleToLongBits(d)).toUpperCase() + "L";
return "0x" + Long.toHexString(Double.doubleToLongBits(d)).toUpperCase(Locale.ROOT) + "L";
}
public String getJavaRendering() {
return _javaRendering;

View File

@ -21,6 +21,8 @@ import junit.framework.AssertionFailedError;
import junit.framework.ComparisonFailure;
import junit.framework.TestCase;
import java.util.Locale;
import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.ss.formula.constant.ConstantValueParser;
import org.apache.poi.ss.formula.ptg.NumberPtg;
@ -74,7 +76,7 @@ public final class TestNumberToTextConverter extends TestCase {
}
private static String formatExample(ExampleConversion example) {
String hexLong = Long.toHexString(example.getRawDoubleBits()).toUpperCase();
String hexLong = Long.toHexString(example.getRawDoubleBits()).toUpperCase(Locale.ROOT);
String longRep = "0x" + "0000000000000000".substring(hexLong.length()) + hexLong+ "L";
return "ec(" + longRep + ", \"" + example.getJavaRendering() + "\", \"" + example.getExcelRendering() + "\")";
}