Source Code Cross Referenced for NetFileResource.java in  » Portal » Open-Portal » com » sun » portal » netfile » servlet » java2 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.netfile.servlet.java2 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /** 
002:         * $Id: NetFileResource.java,v 1.13 2005/11/30 11:26:39 ss150821 Exp $ 
003:         * Copyright 2002 Sun Microsystems, Inc. All 
004:         * rights reserved. Use of this product is subject 
005:         * to license terms. Federal Acquisitions: 
006:         * Commercial Software -- Government Users 
007:         * Subject to Standard License Terms and 
008:         * Conditions. 
009:         * 
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE 
011:         * are trademarks or registered trademarks of Sun Microsystems, 
012:         * Inc. in the United States and other countries. 
013:         */package com.sun.portal.netfile.servlet.java2;
014:
015:        import java.util.*;
016:        import com.sun.portal.log.common.PortalLogger;
017:        import java.util.logging.*;
018:
019:        import java.text.MessageFormat;
020:        import com.sun.portal.netfile.shared.*;
021:
022:        public class NetFileResource {
023:
024:            private static Logger logger = PortalLogger
025:                    .getLogger(NetFileResource.class);
026:            private java.util.HashMap ht_resource_bundle_entry_set;
027:            private String s_bundle;
028:            private String s_locale;
029:            private static java.util.HashMap ht_locales = new java.util.HashMap(
030:                    6);
031:
032:            public NetFileResource() {
033:            }
034:
035:            public NetFileResource(String bundle, String locale)
036:                    throws NetFileException {
037:                this ();
038:                if ((bundle == null) || (locale == null)) {
039:                    //throw new NetFileException("null bundle name passed");
040:                    throw new NetFileException();
041:                }
042:                s_bundle = bundle;
043:                s_locale = locale;
044:                ht_resource_bundle_entry_set = getLocalisedBundle(bundle,
045:                        s_locale);
046:            }
047:
048:            public NetFileResource(String bundle) throws NetFileException {
049:                this ();
050:                if (bundle == null) {
051:                    //throw new NetFileException("null bundle name passed");
052:                    throw new NetFileException();
053:                }
054:                String s_locale = Locale.getDefault().toString();
055:                if ((s_locale == null) || (s_locale.equals(""))) {
056:                    //throw new NetFileException("There is no key as com.iplanet.am.locale in AMConfig.properties");
057:                    throw new NetFileException();
058:                }
059:
060:                s_bundle = bundle;
061:                this .s_locale = s_locale;
062:                ht_resource_bundle_entry_set = getLocalisedBundle(bundle,
063:                        s_locale);
064:            }
065:
066:            private synchronized HashMap getLocalisedBundle(String bundle,
067:                    String locale) throws NetFileException {
068:                HashMap ht_locale_specific_bundles = getLocaleHashMap(locale);
069:                HashMap ht_locale_specific_bundle = (HashMap) (ht_locale_specific_bundles
070:                        .get(bundle));
071:
072:                if (ht_locale_specific_bundle == null) {
073:                    //                logger.info("HashMap containing bundle "+bundle+" not found for locale "+locale);
074:                    Object[] params0 = { bundle, " not found for locale ",
075:                            locale };
076:                    logger.log(Level.INFO, "PSSRNF_CSPNSJ2091", params0);
077:                    ht_locale_specific_bundle = populatei18nBucket(bundle,
078:                            locale);
079:                    ht_locale_specific_bundles.put(bundle,
080:                            ht_locale_specific_bundle);
081:                    SerializedRequestProcessor.setResourceMap(locale, bundle,
082:                            this );
083:                } else {
084:                    //                logger.info("HashMap containing bundle "+bundle+" found for locale "+locale);
085:                    Object[] params1 = { bundle, " found for locale ", locale };
086:                    logger.log(Level.INFO, "PSSRNF_CSPNSJ2092", params1);
087:                }
088:                return ht_locale_specific_bundle;
089:            }
090:
091:            private HashMap getLocaleHashMap(String locale)
092:                    throws NetFileException {
093:                try {
094:                    HashMap ht_locale_specific_bundles = (HashMap) (ht_locales
095:                            .get(locale));
096:                    if (ht_locale_specific_bundles == null) {
097:                        //                    logger.info("HashMap containing bundles for locale "+locale+" not found");
098:                        Object[] params2 = { locale, " not found" };
099:                        logger.log(Level.INFO, "PSSRNF_CSPNSJ2093", params2);
100:                        ht_locale_specific_bundles = new HashMap(2);
101:                    } else {
102:                        //                    logger.info("HashMap containing bundles for locale "+locale+" found");
103:                        Object[] params3 = { locale, " found" };
104:                        logger.log(Level.INFO, "PSSRNF_CSPNSJ2094", params3);
105:                    }
106:                    ht_locales.put(locale, ht_locale_specific_bundles);
107:                    return ht_locale_specific_bundles;
108:                } catch (Exception e) {
109:                    //                    logger.log(Level.SEVERE, "Exception in searching for HashMap containg bundles in a locale", e);
110:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2095");
111:                    //throw new NetFileException(e);
112:                    throw new NetFileException();
113:                }
114:            }
115:
116:            public String getString(String s_key) {
117:                Object o_value = ht_resource_bundle_entry_set.get(s_key);
118:                if (o_value == null) {
119:                    //                logger.severe("Key "+s_key+" does not exist in bundle "+s_bundle+" for locale "+s_locale);
120:                    Object[] params5 = { s_key, " does not exist in bundle ",
121:                            s_bundle, " for locale ", s_locale };
122:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2096", params5);
123:                    return s_key;
124:                }
125:                return ((String) (o_value));
126:            }
127:
128:            public String getString(String key, Object[] args) {
129:                MessageFormat mf = new MessageFormat("");
130:                Locale loc = getLocale(s_locale);
131:                mf.setLocale(loc);
132:                mf.applyPattern(getString(key));
133:
134:                return mf.format(args, new StringBuffer(), null).toString();
135:            }
136:
137:            public HashMap populatei18nBucket(String bundle, String locale)
138:                    throws NetFileException {
139:                HashMap bucket = new HashMap();
140:                try {
141:                    Object key = null;
142:                    Object value = null;
143:                    Locale loc = getLocale(locale);
144:                    java.util.ResourceBundle resBundle = java.util.ResourceBundle
145:                            .getBundle(bundle, loc);
146:
147:                    for (Enumeration e = resBundle.getKeys(); e
148:                            .hasMoreElements();) {
149:                        key = e.nextElement();
150:                        value = resBundle.getObject((String) key);
151:                        bucket.put(key, value);
152:                    }
153:                } catch (Exception e) {
154:                    //throw new NetFileException(e);
155:                    throw new NetFileException();
156:                }
157:                return bucket;
158:            }
159:
160:            private Locale getLocale(String locale) {
161:                if ((locale == null) || (locale.equals(""))) {
162:                    locale = Locale.getDefault().toString();
163:                }
164:
165:                StringTokenizer locst = new StringTokenizer(locale, "_");
166:                String lang = (locst.hasMoreTokens() ? locst.nextToken() : "");
167:                String country = (locst.hasMoreTokens() ? locst.nextToken()
168:                        : "");
169:                String variant = (locst.hasMoreTokens() ? locst.nextToken()
170:                        : "");
171:
172:                while (locst.hasMoreTokens()) {
173:                    variant += "_" + locst.nextToken();
174:                }
175:
176:                Locale loc = new java.util.Locale(lang, country, variant);
177:
178:                return loc;
179:            }
180:
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.