org.jboss.virtual
Class VFSUtils

java.lang.Object
  extended by org.jboss.virtual.VFSUtils

public class VFSUtils
extends java.lang.Object

VFS Utilities

Version:
$Revision: 1.1 $
Author:
Adrian Brock

Field Summary
static java.lang.String VFS_LINK_NAME
           
static java.lang.String VFS_LINK_PREFIX
           
static java.lang.String VFS_LINK_TARGET
           
 
Constructor Summary
VFSUtils()
           
 
Method Summary
static void addManifestLocations(VirtualFile file, java.util.List<VirtualFile> paths)
          Add manifest paths
static java.lang.String fixName(java.lang.String name)
          Fix a name (removes any trailing slash)
static java.util.jar.Manifest getManifest(VFS archive)
          Get a manifest from a virtual file system, assuming the root of the VFS is the root of an archive
static java.util.jar.Manifest getManifest(VirtualFile archive)
          Get a manifest from a virtual file, assuming the virtual file is the root of an archive
static java.lang.String getName(java.net.URI uri)
           
static java.lang.String getPathsString(java.util.Collection<VirtualFile> paths)
          Get the paths string for a collection of virtual files
static boolean isLink(java.lang.String name)
          Does a vf name contain the VFS link prefix
static void parseLinkProperties(java.io.InputStream is, java.util.List<LinkInfo> info, java.util.Properties props)
          Parse a properties link file
static java.util.Map<java.lang.String,java.lang.String> parseURLQuery(java.lang.String query)
          Take a URL.getQuery string and parse it into name=value pairs
static java.util.List<LinkInfo> readLinkInfo(java.io.InputStream is, java.lang.String name, java.util.Properties props)
          Read the link information from the stream based on the type as determined from the name suffix.
static java.util.jar.Manifest readManifest(VirtualFile manifest)
          Read the manifest from given manifest VirtualFile.
static java.net.URI toURI(java.net.URL url)
          Deal with urls that may include spaces.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VFS_LINK_PREFIX

public static final java.lang.String VFS_LINK_PREFIX
See Also:
Constant Field Values

VFS_LINK_NAME

public static final java.lang.String VFS_LINK_NAME
See Also:
Constant Field Values

VFS_LINK_TARGET

public static final java.lang.String VFS_LINK_TARGET
See Also:
Constant Field Values
Constructor Detail

VFSUtils

public VFSUtils()
Method Detail

getPathsString

public static java.lang.String getPathsString(java.util.Collection<VirtualFile> paths)
Get the paths string for a collection of virtual files

Parameters:
paths - the paths
Returns:
the string
Throws:
java.lang.IllegalArgumentException - for null paths

addManifestLocations

public static void addManifestLocations(VirtualFile file,
                                        java.util.List<VirtualFile> paths)
                                 throws java.io.IOException
Add manifest paths

Parameters:
file - the file
paths - the paths to add to
Throws:
java.io.IOException - if there is an error reading the manifest or the virtual file is closed
java.lang.IllegalStateException - if the file has no parent
java.lang.IllegalArgumentException - for a null file or paths

getManifest

public static java.util.jar.Manifest getManifest(VirtualFile archive)
                                          throws java.io.IOException
Get a manifest from a virtual file, assuming the virtual file is the root of an archive

Parameters:
archive - the root the archive
Returns:
the manifest or null if not found
Throws:
java.io.IOException - if there is an error reading the manifest or the virtual file is closed
java.lang.IllegalArgumentException - for a null archive

readManifest

public static java.util.jar.Manifest readManifest(VirtualFile manifest)
                                           throws java.io.IOException
Read the manifest from given manifest VirtualFile.

Parameters:
manifest - the VF to read from
Returns:
JAR's manifest
Throws:
java.io.IOException - if problems while opening VF stream occur

getManifest

public static java.util.jar.Manifest getManifest(VFS archive)
                                          throws java.io.IOException
Get a manifest from a virtual file system, assuming the root of the VFS is the root of an archive

Parameters:
archive - the vfs
Returns:
the manifest or null if not found
Throws:
java.io.IOException - if there is an error reading the manifest
java.lang.IllegalArgumentException - for a null archive

fixName

public static java.lang.String fixName(java.lang.String name)
Fix a name (removes any trailing slash)

Parameters:
name - the name to fix
Returns:
the fixed name
Throws:
java.lang.IllegalArgumentException - for a null name

getName

public static java.lang.String getName(java.net.URI uri)
Parameters:
uri -
Returns:
name from uri's path

parseURLQuery

public static java.util.Map<java.lang.String,java.lang.String> parseURLQuery(java.lang.String query)
Take a URL.getQuery string and parse it into name=value pairs

Parameters:
query - Possibly empty/null url query string
Returns:
String[] for the name/value pairs in the query. May be empty but never null.

isLink

public static boolean isLink(java.lang.String name)
Does a vf name contain the VFS link prefix

Parameters:
name - - the name portion of a virtual file
Returns:
true if the name starts with VFS_LINK_PREFIX, false otherwise

readLinkInfo

public static java.util.List<LinkInfo> readLinkInfo(java.io.InputStream is,
                                                    java.lang.String name,
                                                    java.util.Properties props)
                                             throws java.io.IOException,
                                                    java.net.URISyntaxException
Read the link information from the stream based on the type as determined from the name suffix.

Parameters:
is - - input stream to the link file contents
name - - the name of the virtual file representing the link
props - the propertes
Returns:
a list of the links read from the stream
Throws:
java.io.IOException - on failure to read/parse the stream
java.net.URISyntaxException - for an error parsing a URI

parseLinkProperties

public static void parseLinkProperties(java.io.InputStream is,
                                       java.util.List<LinkInfo> info,
                                       java.util.Properties props)
                                throws java.io.IOException,
                                       java.net.URISyntaxException
Parse a properties link file

Parameters:
is - - input stream to the link file contents
info - the link infos
props - the propertes
Throws:
java.io.IOException - on failure to read/parse the stream
java.net.URISyntaxException - for an error parsing a URI

toURI

public static java.net.URI toURI(java.net.URL url)
                          throws java.net.URISyntaxException
Deal with urls that may include spaces.

Parameters:
url - the url
Returns:
uri the uri
Throws:
java.net.URISyntaxException - for any error