1782 * second, relative to any directories specified by the java.class.path |
1795 * second, relative to any directories specified by the java.class.path |
1783 * property; finally, in a directory used to store profiles always |
1796 * property; finally, in a directory used to store profiles always |
1784 * available, such as a profile for sRGB. Built-in profiles use .pf as |
1797 * available, such as a profile for sRGB. Built-in profiles use .pf as |
1785 * the file name extension for profiles, e.g. sRGB.pf. |
1798 * the file name extension for profiles, e.g. sRGB.pf. |
1786 */ |
1799 */ |
1787 private static FileInputStream openProfile(final String fileName) { |
1800 private static File getProfileFile(String fileName) { |
1788 return (FileInputStream)java.security.AccessController.doPrivileged( |
|
1789 new java.security.PrivilegedAction() { |
|
1790 public Object run() { |
|
1791 File f = privilegedGetProfileFile(fileName); |
|
1792 if (f != null) { |
|
1793 try { |
|
1794 return new FileInputStream(f); |
|
1795 } catch (FileNotFoundException e) { |
|
1796 } |
|
1797 } |
|
1798 return null; |
|
1799 } |
|
1800 }); |
|
1801 } |
|
1802 |
|
1803 private static File getProfileFile(final String fileName) { |
|
1804 return (File)java.security.AccessController.doPrivileged( |
|
1805 new java.security.PrivilegedAction() { |
|
1806 public Object run() { |
|
1807 return privilegedGetProfileFile(fileName); |
|
1808 } |
|
1809 }); |
|
1810 } |
|
1811 |
|
1812 /* |
|
1813 * this version is called from doPrivileged in openProfile |
|
1814 * or getProfileFile, so the whole method is privileged! |
|
1815 */ |
|
1816 |
|
1817 private static File privilegedGetProfileFile(String fileName) { |
|
1818 String path, dir, fullPath; |
1801 String path, dir, fullPath; |
1819 |
1802 |
1820 File f = new File(fileName); /* try absolute file name */ |
1803 File f = new File(fileName); /* try absolute file name */ |
1821 |
1804 if (f.isAbsolute()) { |
|
1805 /* Rest of code has little sense for an absolute pathname, |
|
1806 so return here. */ |
|
1807 return f.isFile() ? f : null; |
|
1808 } |
1822 if ((!f.isFile()) && |
1809 if ((!f.isFile()) && |
1823 ((path = System.getProperty("java.iccprofile.path")) != null)){ |
1810 ((path = System.getProperty("java.iccprofile.path")) != null)){ |
1824 /* try relative to java.iccprofile.path */ |
1811 /* try relative to java.iccprofile.path */ |
1825 StringTokenizer st = |
1812 StringTokenizer st = |
1826 new StringTokenizer(path, File.pathSeparator); |
1813 new StringTokenizer(path, File.pathSeparator); |
1827 while (st.hasMoreTokens() && (!f.isFile())) { |
1814 while (st.hasMoreTokens() && ((f == null) || (!f.isFile()))) { |
1828 dir = st.nextToken(); |
1815 dir = st.nextToken(); |
1829 fullPath = dir + File.separatorChar + fileName; |
1816 fullPath = dir + File.separatorChar + fileName; |
1830 f = new File(fullPath); |
1817 f = new File(fullPath); |
|
1818 if (!isChildOf(f, dir)) { |
|
1819 f = null; |
|
1820 } |
1831 } |
1821 } |
1832 } |
1822 } |
1833 |
1823 |
1834 if ((!f.isFile()) && |
1824 if (((f == null) || (!f.isFile())) && |
1835 ((path = System.getProperty("java.class.path")) != null)) { |
1825 ((path = System.getProperty("java.class.path")) != null)) { |
1836 /* try relative to java.class.path */ |
1826 /* try relative to java.class.path */ |
1837 StringTokenizer st = |
1827 StringTokenizer st = |
1838 new StringTokenizer(path, File.pathSeparator); |
1828 new StringTokenizer(path, File.pathSeparator); |
1839 while (st.hasMoreTokens() && (!f.isFile())) { |
1829 while (st.hasMoreTokens() && ((f == null) || (!f.isFile()))) { |
1840 dir = st.nextToken(); |
1830 dir = st.nextToken(); |
1841 fullPath = dir + File.separatorChar + fileName; |
1831 fullPath = dir + File.separatorChar + fileName; |
1842 f = new File(fullPath); |
1832 f = new File(fullPath); |
|
1833 if (!isChildOf(f, dir)) { |
|
1834 f = null; |
|
1835 } |
1843 } |
1836 } |
1844 } |
1837 } |
1845 |
1838 if ((f == null) || (!f.isFile())) { |
1846 if (!f.isFile()) { /* try the directory of built-in profiles */ |
1839 /* try the directory of built-in profiles */ |
1847 dir = System.getProperty("java.home") + |
1840 f = getStandardProfileFile(fileName); |
1848 File.separatorChar + "lib" + File.separatorChar + "cmm"; |
1841 } |
1849 fullPath = dir + File.separatorChar + fileName; |
1842 if (f != null && f.isFile()) { |
1850 f = new File(fullPath); |
1843 return f; |
1851 if (!f.isFile()) { |
1844 } |
1852 //make sure file was installed in the kernel mode |
1845 return null; |
1853 try { |
1846 } |
1854 //kernel uses platform independent paths => |
1847 |
1855 // should not use platform separator char |
1848 /** |
1856 sun.jkernel.DownloadManager.downloadFile("lib/cmm/"+fileName); |
1849 * Returns a file object corresponding to a built-in profile |
1857 } catch (IOException ioe) {} |
1850 * specified by fileName. |
|
1851 * If there is no built-in profile with such name, then the method |
|
1852 * returns null. |
|
1853 */ |
|
1854 private static File getStandardProfileFile(String fileName) { |
|
1855 String dir = System.getProperty("java.home") + |
|
1856 File.separatorChar + "lib" + File.separatorChar + "cmm"; |
|
1857 String fullPath = dir + File.separatorChar + fileName; |
|
1858 File f = new File(fullPath); |
|
1859 if (!f.isFile()) { |
|
1860 //make sure file was installed in the kernel mode |
|
1861 try { |
|
1862 //kernel uses platform independent paths => |
|
1863 // should not use platform separator char |
|
1864 sun.jkernel.DownloadManager.downloadFile("lib/cmm/"+fileName); |
|
1865 } catch (IOException ioe) {} |
|
1866 } |
|
1867 return (f.isFile() && isChildOf(f, dir)) ? f : null; |
|
1868 } |
|
1869 |
|
1870 /** |
|
1871 * Checks whether given file resides inside give directory. |
|
1872 */ |
|
1873 private static boolean isChildOf(File f, String dirName) { |
|
1874 try { |
|
1875 File dir = new File(dirName); |
|
1876 String canonicalDirName = dir.getCanonicalPath(); |
|
1877 if (!canonicalDirName.endsWith(File.separator)) { |
|
1878 canonicalDirName += File.separator; |
|
1879 } |
|
1880 String canonicalFileName = f.getCanonicalPath(); |
|
1881 return canonicalFileName.startsWith(canonicalDirName); |
|
1882 } catch (IOException e) { |
|
1883 /* we do not expect the IOException here, because invocation |
|
1884 * of this function is always preceeded by isFile() call. |
|
1885 */ |
|
1886 return false; |
|
1887 } |
|
1888 } |
|
1889 |
|
1890 /** |
|
1891 * Checks whether built-in profile specified by fileName exists. |
|
1892 */ |
|
1893 private static boolean standardProfileExists(final String fileName) { |
|
1894 return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { |
|
1895 public Boolean run() { |
|
1896 return getStandardProfileFile(fileName) != null; |
1858 } |
1897 } |
1859 } |
1898 }); |
1860 |
|
1861 if (f.isFile()) { |
|
1862 return f; |
|
1863 } |
|
1864 return null; |
|
1865 } |
1899 } |
1866 |
1900 |
1867 |
1901 |
1868 /* |
1902 /* |
1869 * Serialization support. |
1903 * Serialization support. |