/** Get the full resource path of this file object starting from the filesystem root. * Folders are separated with forward slashes. File extensions, if present, * are included. The root folder's path is the empty string. The path of a folder * never ends with a slash. * <p>Subclasses are strongly encouraged to override this method. * <p>Never use this to get a display name for the file! Use {@link FileUtil#getFileDisplayName}. * <p>Do not use this method to find a file path on disk! Use {@link FileUtil#toFile}. * @return the path, for example <samp>path/from/root.ext</samp> * @see FileSystem#findResource * @since 3.7 */ public String getPath() { StringBuilder[] buf = { null }; constructName(buf, '/', 0); return buf[0].toString(); }
/** Constructs path of file. * @param arr to place the string buffer * @param sepChar separator character */ private void constructName(StringBuilder[] arr, char sepChar, int lengthSoFar) { String myName = getNameExt(); int myLen = lengthSoFar + myName.length(); FileObject parent = getParent(); if (parent == this) { Object fs; try { fs = getFileSystem(); } catch (IOException ex) { fs = "unknown"; // NOI18N } throw new IllegalStateException("Dangerous self-reproductive parentship: " + this + " type: " + getClass() + " fs: " + fs); // NOI18N } if ((parent != null) && !parent.isRoot()) { parent.constructName(arr, sepChar, myLen + 1); arr[0].append(sepChar); } else { assert arr[0] == null; arr[0] = new StringBuilder(myLen); } arr[0].append(getNameExt()); }
/** Get fully-qualified filename, but without extension. * Like {@link #getPackageNameExt} but omits the extension. * @param separatorChar char to separate folders and files * @return the fully-qualified filename * @deprecated Please use the <a href="@org-netbeans-api-java-classpath@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead. */ @Deprecated public String getPackageName(char separatorChar) { assert false : "Deprecated."; if (isRoot() || getParent().isRoot()) { return (isFolder()) ? getNameExt() : getName(); } StringBuilder[] arr = new StringBuilder[1]; String name = getName(); getParent().constructName(arr, separatorChar, name.length()); arr[0].append(separatorChar).append(name); return arr[0].toString(); }
/** Get fully-qualified filename. Does so by walking through all folders * to the root of the filesystem. Separates files with provided <code>separatorChar</code>. * The extension, if present, is separated from the basename with <code>extSepChar</code>. * <p><strong>Note:</strong> <samp>fo.getPath()</samp> will have the * same effect as using this method with <samp>/</samp> and <samp>.</samp> (the standard * path and extension delimiters). * @param separatorChar char to separate folders and files * @param extSepChar char to separate extension * @return the fully-qualified filename * @deprecated Please use the <a href="@org-netbeans-api-java-classpath@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead. */ @Deprecated public String getPackageNameExt(char separatorChar, char extSepChar) { assert false : "Deprecated."; if (isRoot() || getParent().isRoot()) { return getNameExt(); } StringBuilder[] arr = new StringBuilder[1]; getParent().constructName(arr, separatorChar, 50); String ext = getExt(); if ((ext == null) || ext.equals("")) { // NOI18N arr[0].append(separatorChar).append(getNameExt()); } else { arr[0].append(separatorChar).append(getName()).append(extSepChar).append(getExt()); } return arr[0].toString(); }
/** Get the full resource path of this file object starting from the filesystem root. * Folders are separated with forward slashes. File extensions, if present, * are included. The root folder's path is the empty string. The path of a folder * never ends with a slash. * <p>Subclasses are strongly encouraged to override this method. * <p>Never use this to get a display name for the file! Use {@link FileUtil#getFileDisplayName}. * <p>Do not use this method to find a file path on disk! Use {@link FileUtil#toFile}. * @return the path, for example <samp>path/from/root.ext</samp> * @see FileSystem#findResource * @since 3.7 */ public String getPath() { StringBuffer sb = new StringBuffer (); constructName (sb, '/'); return sb.toString(); }
/** Get the full resource path of this file object starting from the filesystem root. * Folders are separated with forward slashes. File extensions, if present, * are included. The root folder's path is the empty string. The path of a folder * never ends with a slash. * <p>Subclasses are strongly encouraged to override this method. * <p>Never use this to get a display name for the file! Use {@link FileUtil#getFileDisplayName}. * <p>Do not use this method to find a file path on disk! Use {@link FileUtil#toFile}. * @return the path, for example <samp>path/from/root.ext</samp> * @see FileSystem#findResource * @since 3.7 */ public String getPath() { StringBuffer sb = new StringBuffer (); constructName (sb, '/'); return sb.toString(); }
/** Constructs path of file. * @param sb string buffer * @param sepChar separator character */ private void constructName (StringBuffer sb, char sepChar) { FileObject parent = getParent (); if ((parent != null) && !parent.isRoot ()) { parent.constructName (sb, sepChar); sb.append (sepChar); } sb.append (getNameExt ()); }
/** Constructs path of file. * @param sb string buffer * @param sepChar separator character */ private void constructName (StringBuffer sb, char sepChar) { FileObject parent = getParent (); if ((parent != null) && !parent.isRoot ()) { parent.constructName (sb, sepChar); sb.append (sepChar); } sb.append (getNameExt ()); }
/** Get fully-qualified filename. Does so by walking through all folders * to the root of the filesystem. Separates files with provided <code>separatorChar</code>. * The extension, if present, is separated from the basename with <code>extSepChar</code>. * <p><strong>Note:</strong> <samp>fo.getPath()</samp> will have the * same effect as using this method with <samp>/</samp> and <samp>.</samp> (the standard * path and extension delimiters). * @param separatorChar char to separate folders and files * @param extSepChar char to separate extension * @return the fully-qualified filename * @deprecated Please use the <a href="@JAVA/API@/org/netbeans/api/java/classpath/api.html">ClassPath API</a> instead. */ public String getPackageNameExt (char separatorChar, char extSepChar) { assert FileUtil.assertDeprecatedMethod(); StringBuffer sb = new StringBuffer (); if (isRoot () || getParent ().isRoot ()) return getNameExt (); getParent ().constructName (sb, separatorChar); String ext = getExt (); if (ext == null || ext.equals ("")) // NOI18N sb.append (separatorChar).append (getNameExt ()); else sb.append (separatorChar).append (getName ()).append (extSepChar).append (getExt ()); return sb.toString(); }
/** Get fully-qualified filename. Does so by walking through all folders * to the root of the filesystem. Separates files with provided <code>separatorChar</code>. * The extension, if present, is separated from the basename with <code>extSepChar</code>. * <p><strong>Note:</strong> <samp>fo.getPath()</samp> will have the * same effect as using this method with <samp>/</samp> and <samp>.</samp> (the standard * path and extension delimiters). * @param separatorChar char to separate folders and files * @param extSepChar char to separate extension * @return the fully-qualified filename * @deprecated Please use the <a href="@JAVA/API@/org/netbeans/api/java/classpath/api.html">ClassPath API</a> instead. */ public String getPackageNameExt (char separatorChar, char extSepChar) { assert FileUtil.assertDeprecatedMethod(); StringBuffer sb = new StringBuffer (); if (isRoot () || getParent ().isRoot ()) return getNameExt (); getParent ().constructName (sb, separatorChar); String ext = getExt (); if (ext == null || ext.equals ("")) // NOI18N sb.append (separatorChar).append (getNameExt ()); else sb.append (separatorChar).append (getName ()).append (extSepChar).append (getExt ()); return sb.toString(); }
/** Get fully-qualified filename, but without extension. * Like {@link #getPackageNameExt} but omits the extension. * @param separatorChar char to separate folders and files * @return the fully-qualified filename * @deprecated Please use the <a href="@JAVA/API@/org/netbeans/api/java/classpath/api.html">ClassPath API</a> instead. */ public String getPackageName (char separatorChar) { assert FileUtil.assertDeprecatedMethod(); StringBuffer sb = new StringBuffer (); if (isRoot () || getParent ().isRoot ()) return (isFolder ()) ? getNameExt() : getName (); getParent ().constructName (sb, separatorChar); //sb.append (separatorChar).append ((isFolder ()) ? getNameExt() : getName ()); sb.append (separatorChar).append (getName ()); return sb.toString (); }
/** Get fully-qualified filename, but without extension. * Like {@link #getPackageNameExt} but omits the extension. * @param separatorChar char to separate folders and files * @return the fully-qualified filename * @deprecated Please use the <a href="@JAVA/API@/org/netbeans/api/java/classpath/api.html">ClassPath API</a> instead. */ public String getPackageName (char separatorChar) { assert FileUtil.assertDeprecatedMethod(); StringBuffer sb = new StringBuffer (); if (isRoot () || getParent ().isRoot ()) return (isFolder ()) ? getNameExt() : getName (); getParent ().constructName (sb, separatorChar); //sb.append (separatorChar).append ((isFolder ()) ? getNameExt() : getName ()); sb.append (separatorChar).append (getName ()); return sb.toString (); }