Source Code Cross Referenced for PropertyUtil.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » com » sun » media » jai » 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 » 6.0 JDK Modules » Java Advanced Imaging » com.sun.media.jai.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: PropertyUtil.java,v $
003:         *
004:         * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * Use is subject to license terms.
007:         *
008:         * $Revision: 1.1 $
009:         * $Date: 2005/02/11 04:57:01 $
010:         * $State: Exp $
011:         */
012:        package com.sun.media.jai.util;
013:
014:        import java.io.File;
015:        import java.io.FileInputStream;
016:        import java.io.FileNotFoundException;
017:        import java.io.InputStream;
018:        import java.io.IOException;
019:        import java.util.Hashtable;
020:        import java.util.Iterator;
021:        import java.util.Vector;
022:        import java.util.PropertyResourceBundle;
023:        import java.util.ResourceBundle;
024:        import java.util.StringTokenizer;
025:        import java.util.jar.JarEntry;
026:        import java.util.jar.JarFile;
027:        import java.net.URL;
028:        import java.security.AccessController;
029:        import java.security.PrivilegedAction;
030:
031:        public class PropertyUtil {
032:
033:            private static Hashtable bundles = new Hashtable();
034:            private static String propertiesDir = "javax/media/jai";
035:
036:            public static InputStream getFileFromClasspath(String path)
037:                    throws IOException, FileNotFoundException {
038:                InputStream is;
039:
040:                final String pathFinal = path;
041:                final String sep = File.separator;
042:                String tmpHome = null;
043:                try {
044:                    tmpHome = System.getProperty("java.home");
045:                } catch (Exception e) {
046:                    tmpHome = null; // Redundant
047:                }
048:                final String home = tmpHome;
049:                final String urlHeader = tmpHome == null ? null : home + sep
050:                        + "lib" + sep;
051:
052:                if (home != null) {
053:                    String libExtPath = urlHeader + "ext" + sep + path;
054:                    File libExtFile = new File(libExtPath);
055:                    try {
056:                        if (libExtFile.exists()) {
057:                            is = new FileInputStream(libExtFile);
058:                            if (is != null) {
059:                                return is;
060:                            }
061:                        }
062:                    } catch (java.security.AccessControlException e) {
063:                        // When the files are packed into jar files, the
064:                        // permission to access these files in a security environment
065:                        // isn't granted in the policy files in most of the cases.
066:                        // Thus, this java.security.AccessControlException is 
067:                        // thrown.  To continue the searching in the jar files,
068:                        // catch this exception and do nothing here.
069:                        // The fix of 4531516.
070:                    }
071:                }
072:
073:                is = PropertyUtil.class.getResourceAsStream("/" + path);
074:                if (is != null) {
075:                    return is;
076:                }
077:
078:                // The above call doesn't work if the jai is an installed extension
079:                // in the main jre/lib directory (as of 5-21-1999 the javaplugin
080:                // doesn't look in the ext diretory which is a bug).  We'll
081:                // try to load the file from either $java_home/ext/jai_core.jar
082:                // or $java_home/jai_core.jar.  The ext is where it should be
083:                // when the bug finally gets fixed.  
084:                PrivilegedAction p = new PrivilegedAction() {
085:                    public Object run() {
086:                        String localHome = null;
087:                        String localUrlHeader = null;
088:                        if (home != null) {
089:                            localHome = home;
090:                            localUrlHeader = urlHeader;
091:                        } else {
092:                            localHome = System.getProperty("java.home");
093:                            localUrlHeader = localHome + sep + "lib" + sep;
094:                        }
095:                        String filenames[] = {
096:                                localUrlHeader + "ext" + sep + "jai_core.jar",
097:                                localUrlHeader + "ext" + sep + "jai_codec.jar",
098:                                localUrlHeader + "jai_core.jar",
099:                                localUrlHeader + "jai_codec.jar" };
100:
101:                        for (int i = 0; i < filenames.length; i++) {
102:                            try {
103:                                InputStream tmpIS = getFileFromJar(
104:                                        filenames[i], pathFinal);
105:                                if (tmpIS != null) {
106:                                    return tmpIS;
107:                                }
108:                            } catch (Exception e) {
109:                            }
110:                        }
111:
112:                        return null;
113:                    }
114:                };
115:
116:                return (InputStream) AccessController.doPrivileged(p);
117:            }
118:
119:            private static InputStream getFileFromJar(String jarFilename,
120:                    String path) throws Exception {
121:                // Look in jar file
122:                JarFile f = null;
123:                try {
124:                    f = new JarFile(jarFilename);
125:                } catch (Exception e) {
126:                }
127:                JarEntry ent = f.getJarEntry(path);
128:                if (ent != null) {
129:                    return f.getInputStream(ent);
130:                }
131:                return null;
132:            }
133:
134:            /** Get bundle from .properties files in javax/media/jai dir. */
135:            private static ResourceBundle getBundle(String packageName) {
136:                ResourceBundle bundle = null;
137:
138:                InputStream in = null;
139:                try {
140:                    in = getFileFromClasspath(propertiesDir + "/" + packageName
141:                            + ".properties");
142:                    if (in != null) {
143:                        bundle = new PropertyResourceBundle(in);
144:                        bundles.put(packageName, bundle);
145:                        return bundle;
146:                    }
147:                } catch (Exception e) {
148:                    e.printStackTrace();
149:                }
150:
151:                return null;
152:            }
153:
154:            public static String getString(String packageName, String key) {
155:                ResourceBundle b = (ResourceBundle) bundles.get(packageName);
156:                if (b == null) {
157:                    b = getBundle(packageName);
158:                }
159:                return b.getString(key);
160:            }
161:
162:            /**
163:             * Utility method to search the full list of property names for
164:             * matches.  If <code>propertyNames</code> is <code>null</code>
165:             * then <code>null</code> is returned.
166:             *
167:             * @exception IllegalArgumentException if <code>prefix</code> is
168:             * <code>null</code> and <code>propertyNames</code> is
169:             * non-<code>null</code>.
170:             */
171:            public static String[] getPropertyNames(String[] propertyNames,
172:                    String prefix) {
173:                if (propertyNames == null) {
174:                    return null;
175:                } else if (prefix == null) {
176:                    throw new IllegalArgumentException(JaiI18N
177:                            .getString("PropertyUtil0"));
178:                }
179:
180:                prefix = prefix.toLowerCase();
181:
182:                Vector names = new Vector();
183:                for (int i = 0; i < propertyNames.length; i++) {
184:                    if (propertyNames[i].toLowerCase().startsWith(prefix)) {
185:                        names.addElement(propertyNames[i]);
186:                    }
187:                }
188:
189:                if (names.size() == 0) {
190:                    return null;
191:                }
192:
193:                // Copy the strings from the Vector over to a String array.
194:                String prefixNames[] = new String[names.size()];
195:                int count = 0;
196:                for (Iterator it = names.iterator(); it.hasNext();) {
197:                    prefixNames[count++] = (String) it.next();
198:                }
199:
200:                return prefixNames;
201:            }
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.