一、前言
基于apache的commons-vfs虚拟文件系统中关于文件系统操作访问权限的设计实现、文件系统中常见系统错误提示、常用操作系统映射管理类OS,可以反映文件系统设计需要考虑因素,对于文件系统有更好的认识。
二、系统权限
package org.apache.commons.vfs;@b@@b@public final class Capability@b@{@b@ public static final Capability READ_CONTENT = new Capability("READ_CONTENT");@b@ public static final Capability WRITE_CONTENT = new Capability("WRITE_CONTENT");@b@ public static final Capability RANDOM_ACCESS_READ = new Capability("RANDOM_ACCESS_READ");@b@ public static final Capability RANDOM_ACCESS_WRITE = new Capability("RANDOM_ACCESS_WRITE");@b@ public static final Capability APPEND_CONTENT = new Capability("APPEND_CONTENT");@b@ public static final Capability ATTRIBUTES = new Capability("ATTRIBUTES");@b@ public static final Capability LAST_MODIFIED = new Capability("LAST_MODIFIED");@b@ public static final Capability GET_LAST_MODIFIED = new Capability("GET_LAST_MODIFIED");@b@ public static final Capability SET_LAST_MODIFIED_FILE = new Capability("SET_LAST_MODIFIED_FILE");@b@ public static final Capability SET_LAST_MODIFIED_FOLDER = new Capability("SET_LAST_MODIFIED_FOLDER");@b@ public static final Capability SIGNING = new Capability("SIGNING");@b@ public static final Capability CREATE = new Capability("CREATE");@b@ public static final Capability DELETE = new Capability("DELETE");@b@ public static final Capability RENAME = new Capability("RENAME");@b@ public static final Capability GET_TYPE = new Capability("GET_TYPE");@b@ public static final Capability LIST_CHILDREN = new Capability("LIST_CHILDREN");@b@ public static final Capability URI = new Capability("URI");@b@ public static final Capability FS_ATTRIBUTES = new Capability("FS_ATTRIBUTE");@b@ public static final Capability JUNCTIONS = new Capability("JUNCTIONS");@b@ public static final Capability MANIFEST_ATTRIBUTES = new Capability("MANIFEST_ATTRIBUTES");@b@ public static final Capability DISPATCHER = new Capability("DISPATCHER");@b@ public static final Capability COMPRESS = new Capability("COMPRESS");@b@ public static final Capability VIRTUAL = new Capability("VIRTUAL");@b@ private final String name;@b@@b@ private Capability(String name)@b@ {@b@ this.name = name;@b@ }@b@@b@ public String toString()@b@ {@b@ return this.name;@b@ }@b@}
三、系统问题
# Licensed to the Apache Software Foundation (ASF) under one or more@b@# contributor license agreements. See the NOTICE file distributed with@b@# this work for additional information regarding copyright ownership.@b@# The ASF licenses this file to You under the Apache License, Version 2.0@b@# (the "License"); you may not use this file except in compliance with@b@# the License. You may obtain a copy of the License at@b@#@b@# http://www.apache.org/licenses/LICENSE-2.0@b@#@b@# Unless required by applicable law or agreed to in writing, software@b@# distributed under the License is distributed on an "AS IS" BASIS,@b@# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@b@# See the License for the specific language governing permissions and@b@# limitations under the License.@b@@b@# $Id: Resources.properties 485638 2006-12-11 12:20:55Z niallp $@b@@b@# Factory@b@vfs/create-manager.error=Could not create a file system manager of class "{0}".@b@@b@# AbstractFileObject@b@vfs.provider/delete-not-supported.error=This file type does not support delete.@b@vfs.provider/rename-not-supported.error=This file type does not support rename.@b@vfs.provider/write-append-not-supported.error=The file type does not support append mode.@b@vfs.provider/random-access-not-supported.error=The file type does not support random access.@b@vfs.provider/random-access-read-not-supported.error=The file type does not support read in random access mode.@b@vfs.provider/random-access-write-not-supported.error=The file type does not support write in random access mode.@b@vfs.provider/create-folder-not-supported.error=This file type does not support folder creation.@b@vfs.provider/get-last-modified-not-supported.error=This file type does not support retriving last modified time.@b@vfs.provider/set-last-modified-not-supported.error=This file type does not support setting last modified time.@b@vfs.provider/set-attribute-not-supported.error=This file type does not support setting attributes.@b@vfs.provider/get-attribute-not-supported.error=This file type does not support getting attributes.@b@vfs.provider/write-not-supported.error=This file type cannot be written to.@b@vfs.provider/get-type.error=Could not determine the type of file "{0}".@b@vfs.provider/list-children-not-folder.error=Could not list the contents of "{0}" because it is not a folder.@b@vfs.provider/list-children.error=Could not list the contents of folder "{0}".@b@vfs.provider/delete-read-only.error=Could not delete "{0}" because it is read-only.@b@vfs.provider/rename-read-only.error=Could not rename "{0}" because it is read-only.@b@vfs.provider/rename-parent-read-only.error=Could not rename "{0}" because "{1}" is read-only.@b@vfs.provider/rename-dest-exists.error=Destination "{0}" already existent.@b@vfs.provider/delete.error=Could not delete "{0}".@b@vfs.provider/rename.error=Could not rename "{0}" to "{1}".@b@vfs.provider/create-folder-mismatched-type.error=Could not create folder "{0}" because it already exists and is a file.@b@vfs.provider/create-folder-read-only.error=Could not create folder "{0}" because its parent folder is read-only.@b@vfs.provider/create-folder.error=Could not create folder "{0}".@b@vfs.provider/create-file.error=Could not create file "{0}".@b@vfs.provider/write-read-only.error=Could not write to "{0}" because it is read-only.@b@vfs.provider/write-not-file.error=Could not write to "{0}" because it is not a file.@b@vfs.provider/write.error=Could not write to "{0}".@b@vfs.provider/copy-file.error=Could not copy "{0}" to "{1}".@b@vfs.provider/rename-filename.error=You can only rename within the same folder. Invalid Filename: "{0}".@b@vfs.provider/copy-read-only.error=Could not copy {0} "{1}" to "{2}" because the destination file is read-only.@b@vfs.provider/copy-missing-file.error=Could not copy "{0}" because it does not exist.@b@vfs.provider/find-files.error=Could not find files in "{0}".@b@vfs.provider/check-is-hidden.error=Could not determine if file "{0}" is hidden.@b@vfs.provider/check-is-writeable.error=Could not determine if file "{0}" is writeable.@b@vfs.provider/check-is-readable.error=Could not determine if file "{0}" is readable.@b@vfs.provider/get-url.error=Could not create URL for "{0}".@b@vfs.provider/resync.error=Could not resync "{0}".@b@vfs.provider/close.error=Could not close "{0}".@b@vfs.provider/read.error=Could not read file "{0}".@b@vfs.provider/random-access.error=Could not read/write file "{0}".@b@vfs.provider/read-not-readable.error=File "{0}" is not readable.@b@vfs.provider/read-not-file.error=Could not read from "{0}" because it is a not a file.@b@@b@# DefaultFileContent@b@vfs.provider/get-size-not-file.error=Could not determine the size of "{0}" because it is not a file.@b@vfs.provider/get-size-write.error=Could not determine the size of file "{0}" because it is being written to.@b@vfs.provider/get-size.error=Could not determine the size of file "{0}".@b@vfs.provider/read-in-use.error=Could not read file "{0}" because it is currently being written to.@b@vfs.provider/write-in-use.error=Could not write to "{0}" because it is currently in use.@b@vfs.provider/random-in-use.error=Could not read/write file "{0}" because it is currently in use.@b@vfs.provider/get-last-modified-writing.error=Could not determine the last modified timestamp of "{0}" because it is being written to.@b@vfs.provider/get-last-modified-no-exist.error=Could not determine the last modified timestamp of "{0}" because it does not exist.@b@vfs.provider/get-last-modified.error=Could not determine the last modified timestamp of "{0}".@b@vfs.provider/set-last-modified-writing.error=Could not set the last modified timestamp of "{0}" because it is being written to.@b@vfs.provider/set-last-modified-no-exist.error=Could not set the last modified timestamp of "{0}" because it does not exist.@b@vfs.provider/set-last-modified.error=Could not set the last modified timestamp of "{0}".@b@vfs.provider/get-certificates-no-exist.error=Could not retrieve the certificates of "{0}" because it does not exist.@b@vfs.provider/get-certificates-writing.error=Could not retrieve the certificates of "{0}" because it is being written to.@b@vfs.provider/get-certificates.error=Could not retrieve the certificates of "{0}".@b@vfs.provider/close-instr.error=Could not close the input stream for file "{0}".@b@vfs.provider/close-outstr.error=Could not close the output stream for file "{0}".@b@vfs.provider/get-attributes-no-exist.error=Could not get attributes for file "{0}" because it does not exist.@b@vfs.provider/get-attributes.error=Could not get attributes "{1}".@b@vfs.provider/set-attribute-no-exist.error=Could not set attribute "{0}" of "{1}" because it does not exist.@b@vfs.provider/set-attribute.error=Could not set attribute "{0}" of "{1}".@b@@b@# AbstractFileSystemProvider@b@vfs.provider/invalid-absolute-uri.error=Invalid absolute URI "{0}".@b@vfs.provider/not-layered-fs.error=File system for URL scheme "{0}" is not a layered file system.@b@vfs.provider/no-config-builder.error=File provider for URL scheme "{0}" do not provide a configuration builder.@b@vfs.provider/config-key-invalid.error=The configuration builder for scheme "{0}" has no option "{1}".@b@vfs.provider/config-value-invalid.error=The delegating configuration builder cant convert value "{2}" for key "{1}" scheme "{0}".@b@vfs.provider/config-too-many-values.error=Too many values for configuration builder for scheme "{0}" key "{1}".@b@vfs.provider/config-unexpected-primitive.error=Unexpected primitive "{0}".@b@vfs.provider/config-unexpected-value-class.error=Cant convert a "{0}" value for scheme "{1}" key "{2}".@b@@b@# AbstractFileSystem@b@vfs.provider/files-cache-missing.error=No files-cache implementation set.@b@vfs.provider/mismatched-fs-for-name.error=Incorrect file system URI "{2}" in name "{0}", was expecting "{1}".@b@vfs.provider/junctions-not-supported.error=Junctions not supported for file system "{0}".@b@vfs.provider/notify-listener.warn=Could not notify listener of change to "{0}".@b@vfs.provider/replicate-missing-file.error=Could not replicate "{0}" as it does not exist.@b@vfs.provider/replicate-file.error=Could not replicate "{0}".@b@vfs.provider/resolve-file.error=Could not resolve file "{0}".@b@@b@# AbstractFileProvider@b@vfs.provider/filename-parser-missing.error=No filename-parser implementation set.@b@@b@# AbstractFileName@b@vfs.provider/filename-type.error=A filename can only be of type FileType.FOLDER or FileType.FILE@b@@b@# Operations@b@vfs.operation/wrong-type.error=Can't lookup operation, wrong type: "{0}"@b@vfs.operation/not-found.error=Operation not found, type: "{0}"@b@vfs.operation/cant-register.error=Can't register operation, wrong type: "{0}"@b@vfs.operation/operation-not-supported.error=Operation "{0}" not supported.@b@vfs.operation/operation-provider-already-added.error=Operation provider already added to scheme "{0}"@b@@b@# RandomAccess@b@vfs.provider/random-access-invalid-position.error=Invalid position: "{0}"@b@vfs.provider/random-access-open-failed.error=Could not access file "{0}" because it does not exist.@b@@b@# UriParser@b@vfs.provider/missing-double-slashes.error=Expecting // to follow the scheme in URI "{0}".@b@vfs.provider/missing-hostname.error=Hostname missing from URI "{0}".@b@vfs.provider/missing-port.error=Port number is missing from URI "{0}".@b@vfs.provider/missing-hostname-path-sep.error=Expecting / to follow the hostname in URI "{0}".@b@vfs.provider/invalid-descendent-name.error=Invalid descendent file name "{0}".@b@vfs.provider/invalid-escape-sequence.error=Invalid URI escape sequence "{0}".@b@vfs.provider/invalid-relative-path.error=Invalid relative file name.@b@@b@# DefaultFileSystemManager@b@vfs.impl/unknown-scheme.error=Unknown scheme "{0}" in URI "{1}".@b@vfs.impl/find-rel-file.error=Could not find file with URI "{0}" because it is a relative path, and no base URI was provided.@b@vfs.impl/multiple-providers-for-scheme.error=Multiple providers registered for URL scheme "{0}".@b@vfs.impl/configuration-already-set.error=FilesCache implementation already set.@b@vfs.impl/configuration-already-in-use.error=The configuration is already attached to an filesystemmanager. You cant change it anymore.@b@vfs.impl/unknown-provider.error=No file provider is registered with URI scheme "{0}" to handle file "{1}".@b@vfs.impl/no-provider-for-file.error=Could not find a file provider that can handle file "{0}".@b@vfs.impl/no-local-file-provider.error=Could not find a file provider which can handle local files.@b@vfs.impl/no-replicator.error=No file replicator configured.@b@vfs.impl/no-temp-file-store.error=No temporary file store configured.@b@vfs.impl/replicate-file.error=Could not replicate "{0}".@b@vfs.impl/delete-temp.warn=Could not clean up temporary file "{0}".@b@vfs.impl/init-replicator.error=Could not initialise file replicator.@b@vfs.impl/already-inited.error=Manager already inited, cant change the configuration now.@b@vfs.impl/invalid-decorator.error="{0}" is not a valid decorator. It has to extend "DecoratedFileObject" and must provide a single argument constructor which takes a "FileObject"@b@vfs.impl/temp-dir.info=Using "{0}" as temporary files store.@b@@b@# StandardFileSystemManager@b@vfs.impl/find-config-file.error=Could not find VFS configuration resource "{0}".@b@vfs.impl/load-config.error=Could not load VFS configuration from "{0}".@b@vfs.impl/create-provider.error=Could not create file provider of class "{0}".@b@vfs.impl/create-files-cache.error=Could not create files-cache implementation of class "{0}".@b@vfs.impl/create-client-factory.error=Could not create client factory of class "{0}".@b@vfs.impl/skipping-provider.debug=Skipping provider "{0}" because required class "{1}" is not available.@b@vfs.impl/skipping-provider-scheme.debug=Skipping provider "{0}" because required scheme "{1}" is not available.@b@@b@# FileTypeMap@b@vfs.impl/multiple-schemes.error=This file requires multiple schemes. Use getSchemes() instead.@b@@b@# VFSClassLoader@b@vfs.impl/pkg-sealing-unsealed=Trying to seal package "{0}" that exists as unsealed.@b@vfs.impl/pkg-sealed-other-url=Package "{0}" exists and is sealed with other URL.@b@@b@# VirtualFileSystem@b@vfs.impl/nested-junction.error=Attempting to create a nested junction at "{0}". Nested junctions are not supported.@b@vfs.impl/create-junction.error=Could not create a junction at "{0}".@b@@b@# SoftRefFilesCache@b@vfs.impl/SoftRefReleaseThread-interrupt.info=SoftRefFilesCache - Release Thread interrupted.@b@vfs.impl/SoftRefReleaseThread-already-running.warn=SoftRefFilesCache - Release Thread already running.@b@@b@# Local Provider@b@vfs.provider.local/get-type.error=Could not determine the type of "{0}".@b@vfs.provider.local/delete-file.error=Could not delete "{0}".@b@vfs.provider.local/rename-file.error=Could not rename file "{0}" to "{1}".@b@vfs.provider.local/create-folder.error=Could not create directory "{0}".@b@vfs.provider.local/not-absolute-file-name.error=URI "{0}" is not an absolute file name.@b@vfs.provider.local/missing-share-name.error=Share name missing from UNC file name "{0}".@b@@b@# Temp Provider@b@vfs.provider.temp/get-type.error=Could not determine the type of "{0}".@b@vfs.provider.temp/delete-file.error=Could not delete "{0}".@b@vfs.provider.temp/rename-file.error=Could not rename file "{0}" to "{1}".@b@vfs.provider.temp/create-folder.error=Could not create directory "{0}".@b@vfs.provider.temp/not-absolute-file-name.error=URI "{0}" is not an absolute file name.@b@vfs.provider.temp/missing-share-name.error=Share name missing from UNC file name "{0}".@b@@b@# SMB Provider@b@vfs.provider.smb/missing-share-name.error=The share name is missing from URI "{0}".@b@vfs.provider.smb/get-type.error=Could not detemine the type of "{0}".@b@@b@# Zip Provider@b@vfs.provider.zip/open-zip-file.error=Could not open Zip file "{0}".@b@vfs.provider.zip/close-zip-file.error=Could not close Zip file "{0}".@b@@b@# Bzip2 Provider@b@vfs.provider.bzip2/not-a-bzip2-file.error=File "{0}" is not bzip2 compressed.@b@@b@# JarFileSystem@b@vfs.provider.jar/open-jar-file.error=Could not open Jar file "{0}".@b@@b@# JarURLConnectionImpl@b@vfs.provider.jar/jar-file-no-access.error=JarURLConnections in VFS does not give access to the JarFile.@b@vfs.provider.jar/jar-entry-no-access.error=JarURLConnections in VFS does not give access to the JarEntry.@b@@b@# FTP Provider@b@vfs.provider.ftp/get-type.error=Could not determine the file type of "{0}".@b@vfs.provider.ftp/delete-file.error=Could not delete FTP file "{0}".@b@vfs.provider.ftp/rename-file.error=Could not rename FTP file "{0}" to "{1}".@b@vfs.provider.ftp/create-folder.error=Could not create FTP directory "{0}".@b@vfs.provider.ftp/finish-get.error=Could not get FTP file "{0}".@b@vfs.provider.ftp/finish-put.error=Could not put FTP file "{0}".@b@vfs.provider.ftp/connect-rejected.error=Connection to FTP server on "{0}" rejected.@b@vfs.provider.ftp/login.error=Could not login to FTP server on "{0}" as user "{1}".@b@vfs.provider.ftp/set-binary.error=Could not switch to binary transfer mode.@b@vfs.provider.ftp/connect.error=Could not connect to FTP server on "{0}".@b@vfs.provider.ftp/close-connection.error=Could not close connection to FTP server.@b@vfs.provider.ftp/change-work-directory.error=Could not change to work directory "{0}".@b@vfs.provider.ftp/invalid-directory-entry.debug=Invalid directory entry at line "{0}" (directory "{1}").@b@vfs.provider.ftp/output-error.debug=Cant open output connection for file "{0}". Reason: "{1}".@b@vfs.provider.ftp/input-error.debug=Cant open input connection for file "{0}". Reason: "{1}".@b@@b@# URL Provider@b@vfs.provider.url/badly-formed-uri.error=Badly formed URI "{0}".@b@@b@# Http Provider@b@vfs.provider.http/get.error=GET method failed for "{0}".@b@vfs.provider.http/head.error=HEAD method failed for "{0}".@b@vfs.provider.http/last-modified.error=No Last-Modified header in HTTP response.@b@vfs.provider.http/get-range.error=GET method failed for "{0}" range "{1}-".@b@vfs.provider.http/connect.error=Could not connect to HTTP server on "{0}".@b@@b@# WebDAV Provider@b@vfs.provider.webdav/write-file.error=Write to file failed with message: "{0}".@b@vfs.provider.webdav/list-children.error=List child resources failed with message: "{0}".@b@vfs.provider.webdav/create-collection.error=Create collection failed with message: "{0}".@b@vfs.provider.webdav/delete-file.error=Delete file failed with message: "{0}".@b@vfs.provider.webdav/create-client.error=Could not create client for server "{0}".@b@vfs.provider.webdav/rename-file.error=Rename file failed with message: "{0}".@b@@b@# SFTP Provider@b@vfs.provider.sftp/connect.error=Could not connect to SFTP server at "{0}".@b@vfs.provider.sftp/change-work-directory.error=Could not change to work directory "{0}".@b@vfs.provider.sftp/unknown-permissions.error=File permissions not fetched.@b@vfs.provider.sftp/unknown-size.error=File size not fetched.@b@vfs.provider.sftp/create-folder.error=Folder creation failed with unknown error.@b@vfs.provider.sftp/delete.error=Delete failed with unknown error.@b@vfs.provider.sftp/list-children.error=List folder contents failed with unknown error.@b@vfs.provider.sftp/put-file.error=Write file contents failed with unknown error.@b@vfs.provider.sftp/get-file.error=Read file contents failed with unknown error.@b@vfs.provider.sftp/load-private-key.error=Could not load private key from "{0}".@b@vfs.provider.sftp/config-sshdir.error=SSH-Folder "{0}" non existent or not a folder.@b@vfs.provider.sftp/unknown-modtime.error=Last modification time not fetched.@b@vfs.provider.sftp/known-hosts.error=Error during processing known-hosts file "{0}".@b@vfs.provider.sftp/StrictHostKeyChecking-arg.error=Illegal argument "{0}" hostKeyChecking can only be "ask", "yes" or "no"@b@@b@# Ant tasks@b@vfs.tasks/sync.no-destination.error=No destination file or directory specified.@b@vfs.tasks/sync.too-many-destinations.error=Cannot specify both a destination file and a destination directory.@b@vfs.tasks/sync.no-source-files.warn=No source files specified.@b@vfs.tasks/sync.no-source-file.error=No source file specified.@b@vfs.tasks/sync.too-many-source-files.error=Too many source files specified.@b@vfs.tasks/sync.source-not-file.error=Source file "{0}" is not a file, or does not exist.@b@vfs.tasks/sync.src-file-no-exist.warn=Source file "{0}" does not exist.@b@vfs.tasks/sync.duplicate-source-files.warn=Multiple source files for destination file "{0}".@b@vfs.tasks/delete.no-source-files.error=No files to delete specified.@b@vfs.tasks/mkdir.create-folder.info=Creating directory "{0}".@b@@b@# Selectors@b@vfs.selectors/filefilter.missing.error=Configure a fileFilter or override accept();@b@@b@# Utils@b@vfs.util/find-abstract-file-object.error=Object didnt extend from AbstractFileObject. Object "{0}"@b@vfs.util/missing-capability.error=The Filesystem do not provide the required capability "{0}"
四、系统操作管理
package org.apache.commons.vfs.util;@b@@b@import java.util.ArrayList;@b@import java.util.HashSet;@b@import java.util.List;@b@import java.util.Locale;@b@import java.util.Set;@b@@b@public final class Os@b@{@b@ private static final String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.US);@b@@b@ private static final String OS_ARCH = System.getProperty("os.arch").toLowerCase(Locale.US);@b@@b@ private static final String OS_VERSION = System.getProperty("os.version").toLowerCase(Locale.US);@b@@b@ private static final String PATH_SEP = System.getProperty("path.separator");@b@ private static final OsFamily OS_FAMILY;@b@ private static final OsFamily[] OS_ALL_FAMILIES;@b@ public static final OsFamily OS_FAMILY_WINDOWS = new OsFamily("windows");@b@@b@ public static final OsFamily OS_FAMILY_DOS = new OsFamily("dos");@b@@b@ public static final OsFamily OS_FAMILY_WINNT = new OsFamily("nt", new OsFamily[] { OS_FAMILY_WINDOWS });@b@@b@ public static final OsFamily OS_FAMILY_WIN9X = new OsFamily("win9x", new OsFamily[] { OS_FAMILY_WINDOWS, OS_FAMILY_DOS });@b@@b@ public static final OsFamily OS_FAMILY_OS2 = new OsFamily("os/2", new OsFamily[] { OS_FAMILY_DOS });@b@@b@ public static final OsFamily OS_FAMILY_NETWARE = new OsFamily("netware");@b@@b@ public static final OsFamily OS_FAMILY_UNIX = new OsFamily("unix");@b@@b@ public static final OsFamily OS_FAMILY_MAC = new OsFamily("mac");@b@@b@ public static final OsFamily OS_FAMILY_OSX = new OsFamily("osx", new OsFamily[] { OS_FAMILY_UNIX, OS_FAMILY_MAC });@b@@b@ private static final OsFamily[] ALL_FAMILIES = { OS_FAMILY_DOS, OS_FAMILY_MAC, OS_FAMILY_NETWARE, OS_FAMILY_OS2, OS_FAMILY_OSX, OS_FAMILY_UNIX, OS_FAMILY_WINDOWS, OS_FAMILY_WINNT, OS_FAMILY_WIN9X };@b@@b@ public static boolean isVersion(String version)@b@ {@b@ return isOs((OsFamily)null, null, null, version);@b@ }@b@@b@ public static boolean isArch(String arch)@b@ {@b@ return isOs((OsFamily)null, null, arch, null);@b@ }@b@@b@ public static boolean isFamily(String family)@b@ {@b@ return isOs(family, null, null, null);@b@ }@b@@b@ public static boolean isFamily(OsFamily family)@b@ {@b@ return isOs(family, null, null, null);@b@ }@b@@b@ public static boolean isName(String name)@b@ {@b@ return isOs((OsFamily)null, name, null, null);@b@ }@b@@b@ public static boolean isOs(String family, String name, String arch, String version)@b@ {@b@ return isOs(getFamily(family), name, arch, version);@b@ }@b@@b@ public static boolean isOs(OsFamily family, String name, String arch, String version)@b@ {@b@ if ((family != null) || (name != null) || (arch != null) || (version != null))@b@ {@b@ boolean isFamily = familyMatches(family);@b@ boolean isName = nameMatches(name);@b@ boolean isArch = archMatches(arch);@b@ boolean isVersion = versionMatches(version);@b@@b@ return ((isFamily) && (isName) && (isArch) && (isVersion));@b@ }@b@@b@ return false;@b@ }@b@@b@ public static OsFamily getFamily(String name)@b@ {@b@ for (int i = 0; i < ALL_FAMILIES.length; ++i)@b@ {@b@ OsFamily osFamily = ALL_FAMILIES[i];@b@ if (osFamily.getName().equalsIgnoreCase(name))@b@ {@b@ return osFamily;@b@ }@b@ }@b@@b@ return null;@b@ }@b@@b@ private static boolean versionMatches(String version)@b@ {@b@ boolean isVersion = true;@b@ if (version != null)@b@ {@b@ isVersion = version.equalsIgnoreCase(OS_VERSION);@b@ }@b@ return isVersion;@b@ }@b@@b@ private static boolean archMatches(String arch)@b@ {@b@ boolean isArch = true;@b@ if (arch != null)@b@ {@b@ isArch = arch.equalsIgnoreCase(OS_ARCH);@b@ }@b@ return isArch;@b@ }@b@@b@ private static boolean nameMatches(String name)@b@ {@b@ boolean isName = true;@b@ if (name != null)@b@ {@b@ isName = name.equalsIgnoreCase(OS_NAME);@b@ }@b@ return isName;@b@ }@b@@b@ private static boolean familyMatches(OsFamily family)@b@ {@b@ if (family == null)@b@ {@b@ return false;@b@ }@b@ for (int i = 0; i < OS_ALL_FAMILIES.length; ++i)@b@ {@b@ OsFamily osFamily = OS_ALL_FAMILIES[i];@b@ if (family == osFamily)@b@ {@b@ return true;@b@ }@b@ }@b@ return false;@b@ }@b@@b@ private static OsFamily[] determineAllFamilies()@b@ {@b@ Set allFamilies = new HashSet();@b@ if (OS_FAMILY != null)@b@ {@b@ List queue = new ArrayList();@b@ queue.add(OS_FAMILY);@b@ while (queue.size() > 0)@b@ {@b@ OsFamily family = (OsFamily)queue.remove(0);@b@ allFamilies.add(family);@b@ OsFamily[] families = family.getFamilies();@b@ for (int i = 0; i < families.length; ++i)@b@ {@b@ OsFamily parent = families[i];@b@ queue.add(parent);@b@ }@b@ }@b@ }@b@ return ((OsFamily[])allFamilies.toArray(new OsFamily[allFamilies.size()]));@b@ }@b@@b@ private static OsFamily determineOsFamily()@b@ {@b@ if (OS_NAME.indexOf("windows") > -1)@b@ {@b@ if ((OS_NAME.indexOf("xp") > -1) || (OS_NAME.indexOf("2000") > -1) || (OS_NAME.indexOf("nt") > -1))@b@ {@b@ return OS_FAMILY_WINNT;@b@ }@b@@b@ return OS_FAMILY_WIN9X;@b@ }@b@@b@ if (OS_NAME.indexOf("os/2") > -1)@b@ {@b@ return OS_FAMILY_OS2;@b@ }@b@ if (OS_NAME.indexOf("netware") > -1)@b@ {@b@ return OS_FAMILY_NETWARE;@b@ }@b@ if (OS_NAME.indexOf("mac") > -1)@b@ {@b@ if (OS_NAME.endsWith("x"))@b@ {@b@ return OS_FAMILY_OSX;@b@ }@b@@b@ return OS_FAMILY_MAC;@b@ }@b@@b@ if (PATH_SEP.equals(":"))@b@ {@b@ return OS_FAMILY_UNIX;@b@ }@b@@b@ return null;@b@ }@b@@b@ static@b@ {@b@ OS_FAMILY = determineOsFamily();@b@ OS_ALL_FAMILIES = determineAllFamilies();@b@ }@b@}
package org.apache.commons.vfs.util;@b@@b@public final class OsFamily@b@{@b@ private final String name;@b@ private final OsFamily[] families;@b@@b@ OsFamily(String name)@b@ {@b@ this.name = name;@b@ this.families = new OsFamily[0];@b@ }@b@@b@ OsFamily(String name, OsFamily[] families)@b@ {@b@ this.name = name;@b@ this.families = families;@b@ }@b@@b@ public String getName()@b@ {@b@ return this.name;@b@ }@b@@b@ public OsFamily[] getFamilies()@b@ {@b@ return this.families;@b@ }@b@}