01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.rewriter.util.i18n;
06:
07: import com.sun.portal.rewriter.util.ConfigManager;
08: import com.sun.portal.rewriter.util.Constants;
09: import com.sun.portal.rewriter.util.collections.CollectionHelper;
10: import com.sun.portal.rewriter.util.collections.ListMap;
11:
12: import java.util.Map;
13:
14: public final class EncodingHelper {
15: private static ListMap java2IANAEncodingMap;
16: private static ListMap IANA2JavaEncodingMap;
17:
18: public static void init(String aResourceLocation) {
19: if (aResourceLocation != null) {
20: Map lMap = ConfigManager.readProps(aResourceLocation);
21: java2IANAEncodingMap = CollectionHelper.processMAPValues(
22: lMap, Constants.PROPERTY_VALUE_DELIMITERS);
23: IANA2JavaEncodingMap = CollectionHelper
24: .invertArrayValueMAP(java2IANAEncodingMap);
25: }
26: }//init()
27:
28: public static String findEquivalentJAVAEncoding(String aIANAEncoding) {
29: if (aIANAEncoding != null) {
30: Object matcheObject = IANA2JavaEncodingMap
31: .matchesWith(aIANAEncoding);
32:
33: if (matcheObject != null) {
34: return (String) IANA2JavaEncodingMap.get(matcheObject);
35: }
36: }
37:
38: return aIANAEncoding;
39: }//findEquivalentJAVAEncoding()
40:
41: public static String findEquivalentIANAEncoding(String aJavaEncoding) {
42: if (aJavaEncoding != null) {
43: Object matcheObject = java2IANAEncodingMap
44: .matchesWith(aJavaEncoding);
45: if (matcheObject != null) {
46: return (String) ((String[]) java2IANAEncodingMap
47: .get(matcheObject))[0];
48: }
49: }
50: return aJavaEncoding;
51: }//findEquivalentIANAEncoding()
52: }//class EncodingHelper
|