Fix some Forbidden APIs errors

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1700644 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2015-09-01 19:06:53 +00:00
parent 533e1c8dcb
commit 47fb9df1a1
11 changed files with 34 additions and 21 deletions

View File

@ -20,6 +20,7 @@ package org.apache.poi.hssf.usermodel.examples;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Locale;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
@ -198,7 +199,7 @@ public final class HSSFReadWrite {
}
}
} else if (args.length == 2) {
if (args[1].toLowerCase().equals("write")) {
if (args[1].toLowerCase(Locale.ROOT).equals("write")) {
System.out.println("Write mode");
long time = System.currentTimeMillis();
HSSFReadWrite.testCreateSampleSheet(fileName);
@ -213,7 +214,7 @@ public final class HSSFReadWrite {
wb.write(stream);
stream.close();
}
} else if (args.length == 3 && args[2].toLowerCase().equals("modify1")) {
} else if (args.length == 3 && args[2].toLowerCase(Locale.ROOT).equals("modify1")) {
// delete row 0-24, row 74 - 99 && change cell 3 on row 39 to string "MODIFIED CELL!!"
HSSFWorkbook wb = HSSFReadWrite.readFile(fileName);

View File

@ -23,6 +23,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Locale;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
@ -382,7 +383,7 @@ public class AddDimensionedImage {
// the image files location is identified by interrogating the URL passed
// to the method, the images type is identified before it is added to the
// sheet.
String sURL = imageFile.toString().toLowerCase();
String sURL = imageFile.toString().toLowerCase(Locale.ROOT);
if( sURL.endsWith(".png") ) {
imageType = Workbook.PICTURE_TYPE_PNG;
}
@ -1043,4 +1044,4 @@ public class AddDimensionedImage {
return points / 72D * 25.4;
}
}
}
}

View File

@ -17,6 +17,8 @@
package org.apache.poi.ss.formula.functions;
import java.util.Locale;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.*;
@ -119,7 +121,7 @@ public final class Dec2Hex extends Var1or2ArgFunction implements FreeRefFunction
hex = "FF"+ hex.substring(2);
}
return new StringEval(hex.toUpperCase());
return new StringEval(hex.toUpperCase(Locale.ROOT));
}
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) {

View File

@ -142,7 +142,7 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
* @return the standard worksheet function index if found, otherwise <tt>FUNCTION_INDEX_EXTERNAL</tt>
*/
protected static short lookupIndex(String name) {
short ix = FunctionMetadataRegistry.lookupIndexByName(name.toUpperCase());
short ix = FunctionMetadataRegistry.lookupIndexByName(name.toUpperCase(Locale.ROOT));
if (ix < 0) {
return FUNCTION_INDEX_EXTERNAL;
}

View File

@ -17,6 +17,8 @@
package org.apache.poi.openxml4j.opc;
import java.util.Locale;
/**
* Open Packaging Convention content types (see Annex F : Standard Namespaces
* and Content Types).
@ -110,7 +112,7 @@ public final class ContentTypes {
public static String getContentTypeFromFileExtension(String filename) {
String extension = filename.substring(filename.lastIndexOf(".") + 1)
.toLowerCase();
.toLowerCase(Locale.ROOT);
if (extension.equals(EXTENSION_JPG_1)
|| extension.equals(EXTENSION_JPG_2))
return IMAGE_JPEG;

View File

@ -20,6 +20,7 @@ package org.apache.poi.openxml4j.opc;
import java.math.BigInteger;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Locale;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException;
@ -479,9 +480,9 @@ public final class PackagePartName implements Comparable<PackagePartName> {
public boolean equals(Object other) {
if (other instanceof PackagePartName) {
// String.equals() is compatible with our compareTo(), but cheaper
return this.partNameURI.toASCIIString().toLowerCase().equals
return this.partNameURI.toASCIIString().toLowerCase(Locale.ROOT).equals
(
((PackagePartName) other).partNameURI.toASCIIString().toLowerCase()
((PackagePartName) other).partNameURI.toASCIIString().toLowerCase(Locale.ROOT)
);
} else {
return false;
@ -490,7 +491,7 @@ public final class PackagePartName implements Comparable<PackagePartName> {
@Override
public int hashCode() {
return this.partNameURI.toASCIIString().toLowerCase().hashCode();
return this.partNameURI.toASCIIString().toLowerCase(Locale.ROOT).hashCode();
}
@Override
@ -543,8 +544,8 @@ public final class PackagePartName implements Comparable<PackagePartName> {
return compare
(
obj1.getURI().toASCIIString().toLowerCase(),
obj2.getURI().toASCIIString().toLowerCase()
obj1.getURI().toASCIIString().toLowerCase(Locale.ROOT),
obj2.getURI().toASCIIString().toLowerCase(Locale.ROOT)
);
}

View File

@ -20,6 +20,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
import java.util.TreeMap;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@ -343,7 +344,7 @@ public final class PackageRelationshipCollection implements
Attr targetModeAttr = element.getAttributeNode(PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME);
TargetMode targetMode = TargetMode.INTERNAL;
if (targetModeAttr != null) {
targetMode = targetModeAttr.getValue().toLowerCase()
targetMode = targetModeAttr.getValue().toLowerCase(Locale.ROOT)
.equals("internal") ? TargetMode.INTERNAL
: TargetMode.EXTERNAL;
}

View File

@ -22,6 +22,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.TreeMap;
@ -150,7 +151,7 @@ public abstract class ContentTypeManager {
*/
public void addContentType(PackagePartName partName, String contentType) {
boolean defaultCTExists = this.defaultContentType.containsValue(contentType);
String extension = partName.getExtension().toLowerCase();
String extension = partName.getExtension().toLowerCase(Locale.ROOT);
if ((extension.length() == 0)
|| (this.defaultContentType.containsKey(extension) && !defaultCTExists))
this.addOverrideContentType(partName, contentType);
@ -184,7 +185,7 @@ public abstract class ContentTypeManager {
private void addDefaultContentType(String extension, String contentType) {
// Remark : Originally the latest parameter was :
// contentType.toLowerCase(). Change due to a request ID 1996748.
defaultContentType.put(extension.toLowerCase(), contentType);
defaultContentType.put(extension.toLowerCase(Locale.ROOT), contentType);
}
/**
@ -327,7 +328,7 @@ public abstract class ContentTypeManager {
&& this.overrideContentType.containsKey(partName))
return this.overrideContentType.get(partName);
String extension = partName.getExtension().toLowerCase();
String extension = partName.getExtension().toLowerCase(Locale.ROOT);
if (this.defaultContentType.containsKey(extension))
return this.defaultContentType.get(extension);

View File

@ -22,6 +22,7 @@ import static org.junit.Assert.assertNotNull;
import java.io.FileOutputStream;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.codec.binary.Hex;
@ -104,7 +105,7 @@ public class TestThemesTable {
ThemeElement themeElem = ThemeElement.byId(expectedThemeIdx);
assertEquals(
"Wrong theme at " + ref + " in " + whatWorkbook,
themeElem.name.toLowerCase(), cell.getStringCellValue());
themeElem.name.toLowerCase(Locale.ROOT), cell.getStringCellValue());
// Fonts are theme-based in their colours
XSSFFont font = cell.getCellStyle().getFont();
@ -235,7 +236,8 @@ public class TestThemesTable {
}
private static void assertCellContents(String expected, XSSFCell cell) {
assertNotNull(cell);
assertEquals(expected.toLowerCase(), cell.getStringCellValue().toLowerCase());
assertEquals(expected.toLowerCase(Locale.ROOT),
cell.getStringCellValue().toLowerCase(Locale.ROOT));
}
@Test

View File

@ -18,6 +18,7 @@
package org.apache.poi.xwpf.extractor;
import java.io.IOException;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -349,7 +350,7 @@ public class TestXWPFWordExtractor extends TestCase {
"endnote_sdt"
};
XWPFWordExtractor ex = new XWPFWordExtractor(doc);
String s = ex.getText().toLowerCase();
String s = ex.getText().toLowerCase(Locale.ROOT);
int hits = 0;
for (String targ : targs) {
@ -371,7 +372,7 @@ public class TestXWPFWordExtractor extends TestCase {
"test user\n",
};
ex = new XWPFWordExtractor(doc);
s = ex.getText().toLowerCase();
s = ex.getText().toLowerCase(Locale.ROOT);
//At one point in development there were three copies of the text.
//This ensures that there is only one copy.

View File

@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@ -65,7 +66,7 @@ public abstract class BaseXLSIteratingTest {
String[] files = new File(dir).list(new FilenameFilter() {
@Override
public boolean accept(File arg0, String arg1) {
return arg1.toLowerCase().endsWith(".xls");
return arg1.toLowerCase(Locale.ROOT).endsWith(".xls");
}
});