--- /dev/null 2015-11-09 12:41:48.570911013 +0300 +++ new/src/java.desktop/share/classes/java/awt/desktop/FileManager.java 2015-11-19 18:20:39.657554304 +0300 @@ -0,0 +1,281 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.awt.desktop; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; + +/** + * Provides functionality to query and modify Mac-specific file attributes. The methods in this class are based on Finder + * attributes. These attributes in turn are dependent on HFS and HFS+ file systems. As such, it is important to recognize + * their limitation when writing code that must function well across multiple platforms.

+ * + * In addition to file name suffixes, Mac OS X can use Finder attributes like file type and creator codes to + * identify and handle files. These codes are unique 4-byte identifiers. The file type is a string that describes the + * contents of a file. For example, the file type APPL identifies the file as an application and therefore + * executable. A file type of TEXT means that the file contains raw text. Any application that can read raw + * text can open a file of type TEXT. Applications that use proprietary file types might assign their files a proprietary + * file type code. + *

+ * To identify the application that can handle a document, the Finder can look at the creator. For example, if a user + * double-clicks on a document with the ttxt creator, it opens up in Text Edit, the application registered + * with the ttxt creator code. Note that the creator + * code can be set to any application, not necessarily the application that created it. For example, if you + * use an editor to create an HTML document, you might want to assign a browser's creator code for the file rather than + * the HTML editor's creator code. Double-clicking on the document then opens the appropriate browser rather than the + *HTML editor. + *

+ * If you plan to publicly distribute your application, you must register its creator and any proprietary file types with the Apple + * Developer Connection to avoid collisions with codes used by other developers. You can register a codes online at the + * Creator Code Registration site. + */ +public abstract class FileManager { + + /** + * The default. + */ + public static final short kOnAppropriateDisk = -32767; + + /** + * Read-only system hierarchy. + */ + public static final short kSystemDomain = -32766; + + /** + * All users of a single machine have access to these resources. + */ + public static final short kLocalDomain = -32765; + + /** + * All users configured to use a common network server has access to these + * resources. + */ + public static final short kNetworkDomain = -32764; + + /** + * Read/write. Resources that are private to the user. + */ + public static final short kUserDomain = -32763; + + /** + * Converts an OSType (e.g. "macs" from {@literal }) + * into an int. + * + * @param type the 4 character type to convert. + * @return an int representing the 4 character value + */ + public abstract int OSTypeToInt(String type); + + /** + * Sets the file type and creator codes for a file + * or folder. + * + * @param filename file name + * @param type of a file + * @param creator for a file + * @throws java.io.IOException if an I/O exception occurs + */ + public abstract void setFileTypeAndCreator(String filename, int type, int creator) throws IOException; + + /** + * Sets the file type code for a file or folder. + * + * @param filename file name + * @param type of a file + * @throws java.io.IOException if an I/O exception occurs + */ + public abstract void setFileType(String filename, int type) throws IOException; + + /** + * Sets the file creator code for a file or folder. + * + * @param filename file name + * @param creator for a file + * @throws java.io.IOException if an I/O exception occurs + */ + public abstract void setFileCreator(String filename, int creator) throws IOException; + + /** + * Obtains the file type code for a file or folder. + * + * @param filename file name + * @return file or folder type + * @throws java.io.IOException if an I/O exception occurs + */ + public abstract int getFileType(String filename) throws IOException; + + /** + * Obtains the file creator code for a file or folder. + * + * @param filename file name + * @return creator for a file or folder + * @throws java.io.IOException if an I/O exception occurs + */ + public abstract int getFileCreator(String filename) throws IOException; + + /** + * Locates a folder of a particular type. Mac OS X recognizes certain + * specific folders that have distinct purposes. For example, the user's + * desktop or temporary folder. These folders have corresponding codes. + * Given one of these codes, this method returns the path to that particular + * folder. Certain folders of a given type may appear in more than one + * domain. For example, although there is only one root folder, + * there are multiple pref folders. If this method is called to + * find the pref folder, it will return the first one it finds, + * the user's preferences folder in ~/Library/Preferences. To + * explicitly locate a folder in a certain domain use + * findFolder(short domain, int folderType) or findFolder(short domain, int folderType, + * boolean createIfNeeded). + * + * @param folderType folder type + * @return the path to the folder searched for + * @throws java.io.FileNotFoundException if the folder does not exist + */ + public abstract String findFolder(int folderType) throws FileNotFoundException; + + /** + * Locates a folder of a particular type, within a given domain. Similar to + * findFolder(int folderType) except that the domain to look in + * can be specified. Valid values for domaininclude: + *

+ *
user
+ *
The User domain contains resources specific to the user who is + * currently logged in
+ *
local
+ *
The Local domain contains resources shared by all users of the system + * but are not needed for the system itself to run.
+ *
network
+ *
The Network domain contains resources shared by users of a local area + * network.
+ *
system
+ *
The System domain contains the operating system resources installed + * by Apple.
+ *
+ * + * @param domain domain + * @param folderType folder type + * @return the path to the folder searched for + * @throws java.io.FileNotFoundException if the folder does not exist + */ + public abstract String findFolder(short domain, int folderType) throws FileNotFoundException; + + /** + * Locates a folder of a particular type within a given domain and + * optionally creating the folder if it does not exist. The behavior is + * similar to findFolder(int folderType) and + * findFolder(short domain, int folderType) except that it can + * create the folder if it does not already exist. + * + * @param domain domain + * @param folderType folder type + * @param createIfNeeded set to true, by setting to + * false the behavior will be the same as + * findFolder(short domain, int folderType, boolean createIfNeeded) + * @return the path to the folder searched for + * @throws java.io.FileNotFoundException if the folder does not exist + */ + public abstract String findFolder(short domain, int folderType, + boolean createIfNeeded) throws FileNotFoundException; + + + /** + * Returns full pathname for the resource identified by a given name. + * + * @param resourceName resource name + * @return full pathname + * @throws java.io.FileNotFoundException if the resource does not exist + */ + public abstract String getResource(String resourceName) throws FileNotFoundException; + + /** + * Returns full pathname for the resource identified by a given name and + * located in the specified bundle subdirectory. + * + * @param resourceName resource name + * @param subDirName subdirectory name + * @return full pathname + * @throws java.io.FileNotFoundException if the resource does not exist + */ + public abstract String getResource(String resourceName, String subDirName) + throws FileNotFoundException; + + /** + * Returns the full pathname for the resource identified by the given name + * and file extension and located in the specified bundle subdirectory. + * + * If extension is an empty string or null, the returned pathname is the + * first one encountered where the file name exactly matches name. + * + * If subpath is null, this method searches the top-level nonlocalized + * resource directory (typically Resources) and the top-level of any + * language-specific directories. For example, suppose you have a modern + * bundle and specify "Documentation" for the subpath parameter. This method + * would first look in the Contents/Resources/Documentation directory of the + * bundle, followed by the Documentation subdirectories of each + * language-specific .lproj directory. (The search order for the + * language-specific directories corresponds to the user's preferences.) + * This method does not recurse through any other subdirectories at any of + * these locations. For more details see the AppKit NSBundle documentation. + * + * @param resourceName the name of the resource file + * @param subDirName subdirectory + * @param type type + * @return full pathname for the resource identified by the given name and + * file extension and located in the specified bundle subdirectory. + * @throws java.io.FileNotFoundException if the resource does not exist + */ + public abstract String getResource(String resourceName, String subDirName, + String type) throws FileNotFoundException; + + /** + * Obtains the path to the current application's NSBundle, may not return a + * valid path if Java was launched from the command line. + * + * @return full pathname of the NSBundle of the current application + * executable. + */ + public abstract String getPathToApplicationBundle(); + + /** + * Moves the specified file to the Trash + * + * @param file the file + * @return returns true if the NSFileManager successfully moved the file to + * the Trash. + * @throws FileNotFoundException if the file does not exist + */ + public abstract boolean moveToTrash(final File file) throws FileNotFoundException; + + /** + * Reveals the specified file in the Finder + * + * @param file the file to reveal + * @return returns true if the NSFileManager successfully revealed the file + * in the Finder. + * @throws FileNotFoundException if the file does not exist + */ + public abstract boolean revealInFinder(final File file) throws FileNotFoundException; +}