String fsPart; try { fsPart = encodeFsPart(fo); } catch (FileStateInvalidException x) { fsPart = "invalid"; final String foPart = encodeFoPart(fo); final String file = combine(fsPart, foPart);
/** * Gets FileObject for passed url. * @param url * @return appropriate FileObject. Can return null for other protocol than nbfs or * if such FileObject isn't reachable via Repository. */ static FileObject getFileObject(URL url) { if (!url.getProtocol().equals(FileURL.PROTOCOL)) { return null; } if (isOldEncoding(url)) { return oldDecode(url); } String[] urlParts = split(url); String fsName = decodeFsPart(urlParts[0]); String foName = decodeFoPart(urlParts[1]); FileSystem fsys = fsName.equals(SYSTEM_FILE_SYSTEM_NAME) ? Repository.getDefault().getDefaultFileSystem() : Repository.getDefault().findFileSystem(fsName); return (fsys == null) ? null : fsys.findResource(foName); }
private static String decodeFsPart(String encodedStr) { return decoder(encodedStr); }
private static String encodeFsPart(FileObject fo) throws FileStateInvalidException { FileSystem fs = fo.getFileSystem(); assert fs != null : "File object " + fo + " returns null from getFileSystem()"; String n = fs.isDefault() ? SYSTEM_FILE_SYSTEM_NAME : fs.getSystemName(); if (n.isEmpty()) { n = String.format("%s.%h", fs.getClass().getName(), fs); } return encoder(n); }
/** Provides a URL to access a file object. * @param fo the file object * @return a URL using the correct syntax and {@link #PROTOCOL protocol} */ public static URL encodeFileObject(FileObject fo) { return NbfsUtil.getURL(fo); }
/** Retrieves the file object specified by an internal URL. * @param u the url to decode * @return the file object that is represented by the URL, or <code>null</code> if the URL is somehow invalid or the file does not exist */ public static FileObject decodeURL(URL u) { return NbfsUtil.getFileObject(u); }
private static String encodeFoPart(FileObject fo) { StringTokenizer elemsEnum; StringBuffer sBuff = new StringBuffer(); elemsEnum = new StringTokenizer(fo.getPath(), String.valueOf(SEPARATOR)); while (elemsEnum.hasMoreElements()) { sBuff.append(SEPARATOR); sBuff.append(encoder((String) elemsEnum.nextElement())); } String retVal = sBuff.toString(); if (retVal.length() == 0 || (fo.isFolder() && retVal.charAt(retVal.length() - 1) != SEPARATOR)) retVal += SEPARATOR; return retVal; }
/** Provides a URL to access a file object. * @param fo the file object * @return a URL using the correct syntax and {@link #PROTOCOL protocol} * @exception FileStateInvalidException if the file object is not valid (typically, if its filesystem is inconsistent or no longer present) */ public static URL encodeFileObject (FileObject fo) throws FileStateInvalidException { return NbfsUtil.getURL (fo); }
/** Retrieves the file object specified by an internal URL. * @param u the url to decode * @return the file object that is represented by the URL, or <code>null</code> if the URL is somehow invalid or the file does not exist */ public static FileObject decodeURL (URL u) { return NbfsUtil.getFileObject(u); }
/** * Gets FileObject for passed url. * @param url * @return appropriate FileObject. Can return null for other protocol than nbfs or * if such FileObject isn't reachable via Repository. */ static FileObject getFileObject(URL url) { if (!url.getProtocol().equals(FileURL.PROTOCOL)) return null; if (isOldEncoding(url)) { return oldDecode(url); } String[] urlParts = split(url); String fsName = decodeFsPart(urlParts[0]) ; String foName = decodeFoPart(urlParts[1]); FileSystem fsys = ExternalUtil.getRepository().findFileSystem(fsName); return (fsys == null) ? null : fsys.findResource(foName); }
/** * Gets URL with nbfs protocol for passes fo * @param fo * @return url with nbfs protocol * @throws FileStateInvalidException if FileObject somehow corrupted */ static URL getURL(FileObject fo) throws FileStateInvalidException { final String fsPart = encodeFsPart(fo); final String foPart = encodeFoPart(fo); final String host = "nbhost";//NOI18N final String file = combine(fsPart, foPart); // #13038: the URL constructor accepting a handler is a security-sensitive // operation. Sometimes a user class loaded internally (customized bean...), // which has no privileges, needs to make and use an nbfs: URL, since this // may be the URL used by e.g. ClassLoader.getResource for resources. try { return (URL) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws Exception { // #30397: the fsPart name cannot be null return new URL(FileURL.PROTOCOL, host, -1, file, FileURL.HANDLER); // NOI18N } }); } catch (PrivilegedActionException pae) { // MalformedURLException is declared but should not happen. IllegalStateException ise = new IllegalStateException(pae.toString()); ExternalUtil.annotate(ise, pae); throw ise; } }
private static String encodeFoPart(FileObject fo) { StringTokenizer elemsEnum; StringBuffer sBuff = new StringBuffer(); elemsEnum = new StringTokenizer(fo.getPath(), String.valueOf(SEPARATOR)); while (elemsEnum.hasMoreElements()) { sBuff.append(SEPARATOR); sBuff.append(encoder((String) elemsEnum.nextElement())); } String retVal = sBuff.toString(); if (retVal.length() == 0 || (fo.isFolder() && retVal.charAt(retVal.length() - 1) != SEPARATOR)) retVal += SEPARATOR; return retVal; }
private static String decodeFsPart(String encodedStr) { return decoder(encodedStr); }
/** Provides a URL to access a file object. * @param fo the file object * @return a URL using the correct syntax and {@link #PROTOCOL protocol} * @exception FileStateInvalidException if the file object is not valid (typically, if its filesystem is inconsistent or no longer present) */ public static URL encodeFileObject (FileObject fo) throws FileStateInvalidException { return NbfsUtil.getURL (fo); }
/** Retrieves the file object specified by an internal URL. * @param u the url to decode * @return the file object that is represented by the URL, or <code>null</code> if the URL is somehow invalid or the file does not exist */ public static FileObject decodeURL (URL u) { return NbfsUtil.getFileObject(u); }
/** * Gets FileObject for passed url. * @param url * @return appropriate FileObject. Can return null for other protocol than nbfs or * if such FileObject isn't reachable via Repository. */ static FileObject getFileObject(URL url) { if (!url.getProtocol().equals(FileURL.PROTOCOL)) return null; if (isOldEncoding(url)) { return oldDecode(url); } String[] urlParts = split(url); String fsName = decodeFsPart(urlParts[0]) ; String foName = decodeFoPart(urlParts[1]); FileSystem fsys = ExternalUtil.getRepository().findFileSystem(fsName); return (fsys == null) ? null : fsys.findResource(foName); }
/** * Gets URL with nbfs protocol for passes fo * @param fo * @return url with nbfs protocol * @throws FileStateInvalidException if FileObject somehow corrupted */ static URL getURL(FileObject fo) throws FileStateInvalidException { final String fsPart = encodeFsPart(fo); final String foPart = encodeFoPart(fo); final String host = "nbhost";//NOI18N final String file = combine(fsPart, foPart); // #13038: the URL constructor accepting a handler is a security-sensitive // operation. Sometimes a user class loaded internally (customized bean...), // which has no privileges, needs to make and use an nbfs: URL, since this // may be the URL used by e.g. ClassLoader.getResource for resources. try { return (URL) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws Exception { // #30397: the fsPart name cannot be null return new URL(FileURL.PROTOCOL, host, -1, file, FileURL.HANDLER); // NOI18N } }); } catch (PrivilegedActionException pae) { // MalformedURLException is declared but should not happen. IllegalStateException ise = new IllegalStateException(pae.toString()); ExternalUtil.annotate(ise, pae); throw ise; } }
private static String encodeFsPart(FileObject fo) throws FileStateInvalidException { FileSystem fs = fo.getFileSystem(); return encoder(fs.getSystemName()); }
private static String decodeFsPart(String encodedStr) { return decoder(encodedStr); }
private static String encodeFsPart(FileObject fo) throws FileStateInvalidException { FileSystem fs = fo.getFileSystem(); return encoder(fs.getSystemName()); }