Source Code Cross Referenced for ResourceLookup.java in  » Portal » Open-Portal » com » sun » mobile » util » 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.mobile.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: ResourceLookup.java,v 1.2 2004/01/21 20:41:45 sathyakn Exp $
003:         * Copyright © 2002 Sun Microsystems, Inc. All rights reserved. 
004:         * 
005:         * U.S. Government Rights - Commercial software. Government users are subject 
006:         * to the Sun Microsystems, Inc. standard license agreement and applicable 
007:         * provisions of the FAR and its supplements. 
008:         * 
009:         * Use is subject to license terms. 
010:         * 
011:         * This distribution may include materials developed by third parties.Sun, Sun 
012:         * Microsystems, the Sun logo and Java are trademarks or registered trademarks 
013:         * of Sun Microsystems, Inc. in the U.S. and other countries. 
014:         * 
015:         * Copyright © 2002 Sun Microsystems, Inc. Tous droits réservés.  
016:         * 
017:         * Droits du gouvernement américain, utlisateurs gouvernmentaux - logiciel 
018:         * commercial. Les utilisateurs gouvernmentaux sont soumis au contrat de licence
019:         * standard de Sun Microsystems, Inc., ainsi qu aux dispositions en vigueur de 
020:         * la FAR [ (Federal Acquisition Regulations) et des suppléments à 
021:         * celles-ci. 
022:         * 
023:         * Distribué par des licences qui en restreignent l'utilisation.  
024:         * 
025:         * Cette distribution peut comprendre des composants développés pardes 
026:         * tierces parties.Sun, Sun Microsystems, le logo Sun et Java sont des marques 
027:         * de fabrique ou des marques déposées de Sun Microsystems, Inc. aux 
028:         * Etats-Unis et dans d'autres pays. 
029:         */package com.sun.mobile.util;
030:
031:        import java.util.*;
032:        import java.io.*;
033:        import java.net.*;
034:        import javax.servlet.*;
035:        import com.iplanet.am.util.*;
036:
037:        /**
038:         * ResourceLookup is a partial replacement for the IS implementation of
039:         * FileLookup.  It performs the equivalent of "fstat" using ServletContext.getResource(),
040:         * thus increasing web container independence.  It also adds an additional qualifying
041:         * parameter, "subComponent", which is intended to further qualify the "component"
042:         * parameter, e.g. mail/exchange, cal/notes, ab/sun-one, etc.
043:         *
044:         * ResourceLookup should follow same look up pattern of Java Resource Bundle Lookup
045:         * Failure to do so results in messages in mixed languages
046:         * Java lookup mechansim is if platform locale is ja_JP
047:         * Resource Bundle locale is zh_CN
048:         * the lookup sequence is rb_zh_CN, rb_zh, rb_JA_JP, rb_ja, rb
049:         * ie we can't fall back to rb if zh resource bundle is not found
050:         * Hence We have added more steps to file lookup
051:         */
052:        public class ResourceLookup {
053:
054:            private static Map resourceNameCache = new HashMap();
055:
056:            /**
057:             * The getFirstExisting() method will return the first existing file
058:             * in the ordered search paths. 
059:             * @param type (an arbitrary profile-stored string)
060:             * @param locale
061:             * @param component
062:             * @param subComponent
063:             * @param clientPath
064:             * @param filename
065:             * @param resourceDir (absolute path of template base directory)
066:             * @param enableCache (boolean on whether to cache previously returned files, restart required for changes when false)
067:             * @return <code>String</code> first existing resource in the ordered search paths.
068:             */
069:            public static String getFirstExisting(ServletContext context,
070:                    String type, String locale, String component,
071:                    String subComponent, String clientPath, String filename,
072:                    String resourceDir, boolean enableCache) {
073:                return getFirstExisting(context, type, locale, component,
074:                        subComponent, null, clientPath, filename, resourceDir,
075:                        enableCache);
076:            }
077:
078:            /**
079:             * The getFirstExisting() method will return the first existing file
080:             * in the ordered search paths.
081:             * @param type (an arbitrary profile-stored string)
082:             * @param locale
083:             * @param component
084:             * @param subComponent
085:             * @param clientPath
086:             * @param orgFilePath
087:             * @param filename
088:             * @param resourceDir (absolute path of template base directory)
089:             * @param enableCache (boolean on whether to cache previously returned files, restart required for changes when false)
090:             * @return <code>String</code> first existing resource in the ordered search paths.
091:             */
092:            public static String getFirstExisting(ServletContext context,
093:                    String type, String locale, String component,
094:                    String subComponent, String orgFilePath, String clientPath,
095:                    String filename, String resourceDir, boolean enableCache) {
096:                String resourceName = null;
097:
098:                //
099:                // TODO:  This is a temporary hack until an optimized implementation
100:                //        that supports the new "type" encoding is possible...
101:                //
102:                if (type != null) {
103:                    int i = type.indexOf(',');
104:                    if (i != -1) {
105:                        type = type.substring(0, i);
106:                    }
107:                }
108:
109:                String cacheKey = type + ":" + locale + ":" + component + ":"
110:                        + subComponent + ":" + orgFilePath + ":" + clientPath
111:                        + ":" + filename + ":" + resourceDir;
112:
113:                if (enableCache) {
114:                    resourceName = (String) resourceNameCache.get(cacheKey);
115:                    if (resourceName != null) {
116:                        return resourceName;
117:                    }
118:                }
119:
120:                URL resourceUrl = null;
121:
122:                if (subComponent != null && subComponent.length() != 0) {
123:                    String newClientPath;
124:
125:                    if (clientPath == null || clientPath.length() == 0) {
126:                        newClientPath = subComponent;
127:                    } else {
128:                        newClientPath = subComponent + "/" + clientPath;
129:                    }
130:
131:                    //
132:                    // Try lookup using subComponent...
133:                    //
134:                    try {
135:                        File[] orderedPaths = FileLookup.getOrderedPaths(type,
136:                                locale, component, orgFilePath, newClientPath,
137:                                filename);
138:
139:                        for (int i = 0; i < orderedPaths.length; i++) {
140:                            resourceName = resourceDir + "/"
141:                                    + orderedPaths[i].toString();
142:                            try {
143:                                resourceUrl = context.getResource(resourceName);
144:                            } catch (Exception e) {
145:                            }
146:                            if (resourceUrl != null)
147:                                break;
148:                        }
149:                    } catch (Exception e) {
150:                    }
151:                }
152:
153:                if (resourceUrl == null) {
154:                    //
155:                    // Try lookup w/o subComponent...
156:                    //
157:                    try {
158:                        File[] orderedPaths = FileLookup.getOrderedPaths(type,
159:                                locale, component, orgFilePath, clientPath,
160:                                filename);
161:
162:                        for (int i = 0; i < orderedPaths.length; i++) {
163:                            resourceName = resourceDir + "/"
164:                                    + orderedPaths[i].toString();
165:                            try {
166:                                resourceUrl = context.getResource(resourceName);
167:                            } catch (Exception e) {
168:                            }
169:                            if (resourceUrl != null)
170:                                break;
171:                        }
172:                    } catch (Exception e) {
173:                    }
174:                }
175:
176:                if (resourceUrl != null) {
177:                    if (enableCache) {
178:                        synchronized (resourceNameCache) {
179:                            resourceNameCache.put(cacheKey, resourceName);
180:                        }
181:                    }
182:                } else {
183:                    return null;
184:                }
185:
186:                return resourceName;
187:            }
188:
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.