Skip to content

Commit 16695ca

Browse files
committed
Provide a locate on case conversion methods to avoid issues in turkish environment
See http://http://echo.nextapp.com/site/node/6840 wher dikai provided this excellent explanation: This is caused by Locale in FontKit._getFontStyle. It tries to use styleName.toUpperCase() for style name lookup. In Turkish Locale, the upper case of "plain" is "PLAİN" (with İ) which doesn't match "PLAIN". So, to fix this, you could try update the code to styleName.toUpperCase(Locale.ENGLISH), or simply set english as default locale if that doesn't affect your system. (See attachment for fixed version of FontKit.java) Alternative: If you use the upper case "PLAIN" in your font text, it'd be fine too. like "Verdana, PLAIN, 9pt"... but that means you'll need to locate all of those default fonts in EPNG code and make all the changes. Here's a reference for a good read about the Locale issue: http://mattryall.net/blog/2009/02/the-infamous-turkish-locale-bug P.S. This is not a BUG in Java. It's rather a BUG in everything else except Java, and programmers are usually unaware of the Turkish dotted and dotless "i".
1 parent 33c231d commit 16695ca

File tree

12 files changed

+60
-53
lines changed

12 files changed

+60
-53
lines changed

projects/jar/src/app/java/echopointng/image/URLImageReference.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.io.OutputStream;
4444
import java.net.URL;
4545
import java.util.HashMap;
46+
import java.util.Locale;
4647
import java.util.Map;
4748

4849
import nextapp.echo2.app.ApplicationInstance;
@@ -121,7 +122,7 @@ private static String determineContentType(URL imageURL) {
121122
if (extensionDelimiterPosition == -1) {
122123
throw new IllegalArgumentException("Invalid content type (URL resource has no extension: " + resourceName + ")");
123124
} else {
124-
String extension = resourceName.substring(extensionDelimiterPosition + 1).toLowerCase();
125+
String extension = resourceName.substring(extensionDelimiterPosition + 1).toLowerCase(Locale.ENGLISH);
125126
contentType = (String) extContentType.get(extension);
126127
if (contentType == null) {
127128
throw new IllegalArgumentException("Invalid content type (no matching content type: " + resourceName + ")");

projects/jar/src/app/java/echopointng/stylesheet/propertypeer/AbstractCssPropertyPeer.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@
2828
* the terms of any one of the MPL, the GPL or the LGPL.
2929
*/
3030

31-
import java.util.Iterator;
32-
import java.util.Map;
33-
34-
import nextapp.echo2.app.Extent;
3531
import echopointng.stylesheet.CssInvalidValueException;
3632
import echopointng.stylesheet.CssObjectIntrospector;
3733
import echopointng.stylesheet.CssPropertyPeer;
3834
import echopointng.stylesheet.CssPropertyPeerLoader;
3935
import echopointng.util.ExtentKit;
4036
import echopointng.util.TokenizerKit;
37+
import nextapp.echo2.app.Extent;
38+
39+
import java.util.Iterator;
40+
import java.util.Locale;
41+
import java.util.Map;
4142

4243
/**
4344
* <code>AbstractCssPropertyPeer</code> is a base class for
@@ -132,10 +133,10 @@ protected Object getConstantValue(CssObjectIntrospector ci, Class conversionClas
132133

133134
if (conversionClass.isAssignableFrom(constantValue.getClass()))
134135
return constantValue;
135-
constantValue = ci.getConstantValue(propertyValue.toUpperCase());
136+
constantValue = ci.getConstantValue(propertyValue.toUpperCase(Locale.ENGLISH));
136137
if (conversionClass.isAssignableFrom(constantValue.getClass()))
137138
return constantValue;
138-
constantValue = ci.getConstantValue(propertyValue.toLowerCase());
139+
constantValue = ci.getConstantValue(propertyValue.toLowerCase(Locale.ENGLISH));
139140
if (conversionClass.isAssignableFrom(constantValue.getClass()))
140141
return constantValue;
141142
throw new CssInvalidValueException("No suitable class field constant found for " + propertyValue,null,lineNo);

projects/jar/src/app/java/echopointng/stylesheet/propertypeer/AlignmentPeer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030
import java.util.Collections;
3131
import java.util.HashMap;
32+
import java.util.Locale;
3233
import java.util.Map;
3334

3435
import nextapp.echo2.app.Alignment;
@@ -74,8 +75,8 @@ protected boolean canConvert(CssObjectIntrospector ci, String propertyValue) {
7475
return true;
7576
String[] tokens = CssObjectDeclarationParser.parse(propertyValue);
7677
if (tokens.length == 3 && tokens[0].equalsIgnoreCase("alignment")) {
77-
String h = tokens[1].trim().toUpperCase();
78-
String v = tokens[2].trim().toUpperCase();
78+
String h = tokens[1].trim().toUpperCase(Locale.ENGLISH);
79+
String v = tokens[2].trim().toUpperCase(Locale.ENGLISH);
7980
return HORIZONTAL_CONSTANTS.containsKey(h) && VERTICAL_CONSTANTS.containsKey(v);
8081
}
8182
return false;
@@ -85,8 +86,8 @@ protected Object getObject(CssObjectIntrospector ci, String propertyValue) {
8586
if (isNullString(propertyValue))
8687
return null;
8788
String[] tokens = CssObjectDeclarationParser.parse(propertyValue);
88-
String hs = tokens[1].trim().toUpperCase();
89-
String vs = tokens[2].trim().toUpperCase();
89+
String hs = tokens[1].trim().toUpperCase(Locale.ENGLISH);
90+
String vs = tokens[2].trim().toUpperCase(Locale.ENGLISH);
9091
int ha = Alignment.DEFAULT;
9192
int va = Alignment.DEFAULT;
9293
if (HORIZONTAL_CONSTANTS.containsKey(hs))

projects/jar/src/app/java/echopointng/stylesheet/propertypeer/BorderPeer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030
import java.util.Collections;
3131
import java.util.HashMap;
32+
import java.util.Locale;
3233
import java.util.Map;
3334

3435
import nextapp.echo2.app.Border;
@@ -87,7 +88,7 @@ protected boolean canConvert(CssObjectIntrospector ci, String propertyValue) {
8788
if (tokens.length == 4 && tokens[0].equalsIgnoreCase("border")) {
8889
String size = tokens[1].trim();
8990
String color = tokens[2].trim();
90-
String style = tokens[3].trim().toUpperCase();
91+
String style = tokens[3].trim().toUpperCase(Locale.ENGLISH);
9192

9293
return ExtentKit.isExtent(size) && ColorKit.isColor(color) &&
9394
(STYLE_CONSTANTS.containsKey(style) || STYLE_CONSTANT_ALTERNATES.containsKey(style));
@@ -101,7 +102,7 @@ protected Object getObject(CssObjectIntrospector ci, String propertyValue) {
101102
String[] tokens = CssObjectDeclarationParser.parse(propertyValue);
102103
String size = tokens[1].trim();
103104
String color = tokens[2].trim();
104-
String style = tokens[3].trim().toUpperCase();
105+
String style = tokens[3].trim().toUpperCase(Locale.ENGLISH);
105106

106107
int styleInt = Border.STYLE_NONE;
107108
if (STYLE_CONSTANTS.containsKey(style))

projects/jar/src/app/java/echopointng/stylesheet/propertypeer/ExtentPeer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import echopointng.stylesheet.CssObjectIntrospector;
3232
import echopointng.util.ExtentKit;
3333

34+
import java.util.Locale;
35+
3436
/**
3537
* <code>ExtentPeer</code> works with Extent objects
3638
*/
@@ -45,14 +47,14 @@ protected Class getConversionClass() {
4547

4648
/* --- validity test --- */
4749
protected boolean canConvert(CssObjectIntrospector ci, String propertyValue) {
48-
propertyValue = propertyValue.trim().toLowerCase();
50+
propertyValue = propertyValue.trim().toLowerCase(Locale.ENGLISH);
4951
if (isNullString(propertyValue))
5052
return true;
5153
return ExtentKit.isExtent(propertyValue);
5254
}
5355
/* --- object conversion --- */
5456
protected Object getObject(CssObjectIntrospector ci, String propertyValue) {
55-
propertyValue = propertyValue.trim().toLowerCase();
57+
propertyValue = propertyValue.trim().toLowerCase(Locale.ENGLISH);
5658
if (isNullString(propertyValue))
5759
return null;
5860
return ExtentKit.makeExtent(propertyValue);

projects/jar/src/app/java/echopointng/stylesheet/propertypeer/FillImagePeer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*/
3131
import java.util.Collections;
3232
import java.util.HashMap;
33+
import java.util.Locale;
3334
import java.util.Map;
3435

3536
import nextapp.echo2.app.Extent;
@@ -74,7 +75,7 @@ protected boolean canConvert(CssObjectIntrospector ci, String propertyValue) {
7475
String objType = tokens[0];
7576
String imageRef = tokens[1];
7677

77-
return objType.toLowerCase().equalsIgnoreCase("fillimage") &&
78+
return objType.toLowerCase(Locale.ENGLISH).equalsIgnoreCase("fillimage") &&
7879
imagePeer.canConvert(ci,imageRef);
7980

8081
} else if (tokens.length == 5) {
@@ -83,7 +84,7 @@ protected boolean canConvert(CssObjectIntrospector ci, String propertyValue) {
8384
String horizontalOffset = tokens[2];
8485
String verticalOffset = tokens[3];
8586

86-
return objType.toLowerCase().equals("fillimage") &&
87+
return objType.toLowerCase(Locale.ENGLISH).equals("fillimage") &&
8788
imagePeer.canConvert(ci,imageRef) &&
8889
ExtentKit.isExtent(horizontalOffset) &&
8990
ExtentKit.isExtent(verticalOffset);
@@ -106,7 +107,7 @@ protected Object getObject(CssObjectIntrospector ci, String propertyValue) {
106107
String imageRef = tokens[1];
107108
Extent horizontalOffset = ExtentKit.makeExtent(tokens[2]);
108109
Extent verticalOffset = ExtentKit.makeExtent(tokens[3]);
109-
int repeat = getIntFromMap(REPEAT_CONSTANTS, tokens[4].toUpperCase());
110+
int repeat = getIntFromMap(REPEAT_CONSTANTS, tokens[4].toUpperCase(Locale.ENGLISH));
110111

111112
ImageReference imageRefObj = (ImageReference) imagePeer.getObject(ci, imageRef);
112113
return new FillImage(imageRefObj, horizontalOffset, verticalOffset, repeat);

projects/jar/src/app/java/echopointng/stylesheet/propertypeer/LocalePeer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
* the provisions above, a recipient may use your version of this file under
2828
* the terms of any one of the MPL, the GPL or the LGPL.
2929
*/
30-
import java.util.Locale;
31-
3230
import echopointng.stylesheet.CssObjectIntrospector;
3331

32+
import java.util.Locale;
33+
3434

3535
/**
3636
* <code>LocalePeer</code> maps to Locale
@@ -59,13 +59,13 @@ protected boolean canConvert(CssObjectIntrospector ci, String propertyValue) {
5959
}
6060
/* --- object conversion --- */
6161
protected Object getObject(CssObjectIntrospector ci, String propertyValue) {
62-
propertyValue = propertyValue.trim().toLowerCase();
62+
propertyValue = propertyValue.trim().toLowerCase(Locale.ENGLISH);
6363
if (isNullString(propertyValue))
6464
return null;
6565

6666
Locale locales[] = Locale.getAvailableLocales();
6767
for (int i = 0; i < locales.length; i++) {
68-
if (locales[i].toString().toLowerCase().equals(propertyValue))
68+
if (locales[i].toString().toLowerCase(Locale.ENGLISH).equals(propertyValue))
6969
return locales[i];
7070
}
7171
return null;

projects/jar/src/app/java/echopointng/util/ColorKit.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
* the terms of any one of the MPL, the GPL or the LGPL.
2929
*/
3030
import echopointng.util.collections.ConcurrentReaderHashMap;
31-
32-
import java.util.Map;
33-
3431
import nextapp.echo2.app.Color;
3532
import nextapp.echo2.app.Component;
3633

34+
import java.util.Locale;
35+
import java.util.Map;
36+
3737
/**
3838
* A utility to class to help with Color manipulation
3939
*
@@ -106,7 +106,7 @@ private static String _toHexString(int i) {
106106
String hex = Integer.toHexString(i);
107107
if (hex.length() < 2)
108108
hex = "0" + hex;
109-
return hex.toUpperCase();
109+
return hex.toUpperCase(Locale.ENGLISH);
110110
}
111111

112112
/*
@@ -127,7 +127,7 @@ private static boolean _isInteger(String propertyValue) {
127127
* value.
128128
*/
129129
private static boolean _isHexInteger(String propertyValue) {
130-
propertyValue = propertyValue.trim().toLowerCase();
130+
propertyValue = propertyValue.trim().toLowerCase(Locale.ENGLISH);
131131
if (propertyValue.indexOf("0x") == 0)
132132
propertyValue = propertyValue.substring(2);
133133

@@ -328,7 +328,7 @@ public static String makeCSSColor(Color color) {
328328

329329
b.append("#");
330330
b.append(makeHexColor(color));
331-
return b.toString().toUpperCase();
331+
return b.toString().toUpperCase(Locale.ENGLISH);
332332
}
333333

334334
/**
@@ -365,7 +365,7 @@ public static String makeHexColor(Color color) {
365365
b.append(_toHexString(color.getGreen()));
366366
b.append(_toHexString(color.getBlue()));
367367

368-
return b.toString().toLowerCase();
368+
return b.toString().toLowerCase(Locale.ENGLISH);
369369
}
370370

371371
/**
@@ -393,7 +393,7 @@ public static Color makeColor(String colorString) {
393393
if (colorString == null)
394394
throw new IllegalArgumentException("Illegal null color string");
395395

396-
colorString = colorString.trim().toLowerCase();
396+
colorString = colorString.trim().toLowerCase(Locale.ENGLISH);
397397
Color color = (Color) colorMap.get(colorString);
398398
if (color != null)
399399
return color;
@@ -507,7 +507,7 @@ public static Color makeColor(int r, int g, int b) {
507507
// since we know we have produced a correct
508508
// color string we can go direct to the cache!
509509
//
510-
String colorString = buf.toString().toLowerCase();
510+
String colorString = buf.toString().toLowerCase(Locale.ENGLISH);
511511
Color color = (Color) colorMap.get(colorString);
512512
if (color == null) {
513513
color = new Color(r,g,b);
@@ -534,7 +534,7 @@ public static Color makeColor(int rgb) {
534534
// since we know we have produced a correct
535535
// color string we can go direct to the cache!
536536
//
537-
String colorString = buf.toString().toLowerCase();
537+
String colorString = buf.toString().toLowerCase(Locale.ENGLISH);
538538
Color color = (Color) colorMap.get(colorString);
539539
if (color == null) {
540540
color = new Color(rgb);

projects/jar/src/app/java/echopointng/util/ComponentKit.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
* the terms of any one of the MPL, the GPL or the LGPL.
2929
*/
3030
import java.lang.reflect.Method;
31-
import java.util.ArrayList;
32-
import java.util.Collections;
33-
import java.util.List;
34-
import java.util.Stack;
31+
import java.util.*;
3532

3633
import nextapp.echo2.app.Component;
3734
import nextapp.echo2.app.ApplicationInstance;
@@ -313,7 +310,7 @@ private static Method _getSetter(Class clazz, String propertyName, Object proper
313310

314311
// try setXxxxXxxx
315312
sb = new StringBuffer("set");
316-
sb.append(propertyName.substring(0,1).toUpperCase());
313+
sb.append(propertyName.substring(0,1).toUpperCase(Locale.ENGLISH));
317314
sb.append(propertyName.substring(1));
318315
methodName = sb.toString();
319316
try {
@@ -324,9 +321,9 @@ private static Method _getSetter(Class clazz, String propertyName, Object proper
324321
}
325322
// try setXxxxxx
326323
sb = new StringBuffer("set");
327-
sb.append(propertyName.substring(0,1).toUpperCase());
324+
sb.append(propertyName.substring(0,1).toUpperCase(Locale.ENGLISH));
328325
if (propertyName.length() >= 2) {
329-
sb.append(propertyName.substring(1).toLowerCase());
326+
sb.append(propertyName.substring(1).toLowerCase(Locale.ENGLISH));
330327
}
331328
methodName = sb.toString();
332329
try {

projects/jar/src/app/java/echopointng/util/ExtentKit.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
import nextapp.echo2.app.Extent;
3232

33+
import java.util.Locale;
34+
3335
/**
3436
* <code>ExtentKit</code> is a utility class to help with Extent
3537
* manipulation
@@ -56,7 +58,7 @@ public static Extent makeExtent(String extentString) {
5658
if (! isExtent(extentString))
5759
throw new IllegalArgumentException("The extentString is invalid : " + extentString);
5860

59-
extentString = extentString.trim().toLowerCase();
61+
extentString = extentString.trim().toLowerCase(Locale.ENGLISH);
6062
String digitBit = _parseIntegerPrefix(extentString);
6163
String unitBit = _parseIntegerPostfix(extentString);
6264

@@ -94,7 +96,7 @@ else if (unitBit.equals("pc"))
9496
public static boolean isExtent(String extentString) {
9597
if (extentString == null)
9698
return false;
97-
extentString = extentString.trim().toLowerCase();
99+
extentString = extentString.trim().toLowerCase(Locale.ENGLISH);
98100
String digitBit = _parseIntegerPrefix(extentString);
99101
String unitBit = _parseIntegerPostfix(extentString);
100102
if (! _isInteger(digitBit))

0 commit comments

Comments
 (0)