org.xoe.core.content
Class Stash

java.lang.Object
  |
  +--org.xoe.core.content.Stash
All Implemented Interfaces:
Constants

public class Stash
extends Object
implements Constants

The class Stash represents a virtual filesystem implemented as a DOM tree of content elements. The filesystem may be read in from or flushed out to disk. Reading from disk is done in a lazy fashion as the DOM tree is expanded.


Fields inherited from interface org.xoe.core.Constants
ACTION_ATTR, ADD, ADD_APP, AMPERSAND_KEY, AMPERSAND_SYMBOL, AMPERSAND_SYMBOL_STRING, APOSTROPHE_KEY, APOSTROPHE_SYMBOL, ASCENDING_SORT, BACK, BANNER_ATTR, BEEP, BEEP_PROPERTY, CONTEXT_ATTR, COPYRIGHT_KEY, COPYRIGHT_SYMBOL, COUNTRY_PROPERTY, DATA_DOC, DEFAULT_BOOTSTRAP, DEFAULT_NAMESPACE, DEFAULT_THEME, DEFAULT_THEMES_DIR, DEFAULT_VIEW, DELETE, DESCENDING_SORT, DISPLAY, DISPLAY_VIEW, DOCTYPE_NAME_NS_XHTML, DOUBLE_QUOTE_KEY, DOUBLE_QUOTE_SYMBOL, EDIT, EDIT_ITEM_VIEW, EXTENSION_ALL, EXTENSION_DTD, EXTENSION_HTML, EXTENSION_LNK, EXTENSION_WML, EXTENSION_XHTML, EXTENSION_XML, EXTENSION_XOE, EXTENSION_XOE_CONFIG, EXTENSION_ZIP, FEATURE_DOCTYPE_NAME_NS, FEATURE_EXTENSION, FEATURE_MIMETYPE, FILE_PROTOCOL, FORWARD, FUNCTION_CONTENT_HANDLER, GREATER_THAN_KEY, GREATER_THAN_SYMBOL, HIDE_IF_ATTR, HOMEDIR_PROPERTY, HREF_ATTR, INSERT_BEFORE_ATTR, LANGUAGE_PROPERTY, LAUNCH, LESSER_THAN_KEY, LESSER_THAN_SYMBOL, LOADTHEME, LOGGING_PROPERTY, MID_DOT_KEY, MID_DOT_SYMBOL, MIMETYPE_ALL, MIMETYPE_APPLICATION_XOE, MIMETYPE_APPLICATION_ZIP, MIMETYPE_STASHDIR, MIMETYPE_TEXT_HTML, MIMETYPE_TEXT_PLAIN, MIMETYPE_TEXT_VND_TVT_LNK, MIMETYPE_TEXT_WML, MIMETYPE_TEXT_XML, MIMETYPE_TEXT_XML_DTD, MIMETYPE_UNKNOWN, NAME_ATTR, NAMESPACE_SEPARATOR, NEW, NEW_ITEM_VIEW, NO_PATH, NON_BREAKING_SPACE_KEY, NON_BREAKING_SPACE_SYMBOL, NUM_LAST_APPS, ONCHANGE_ATTR, ONCLICK_ATTR, ONKEYPRESS_ATTR, ONLOAD_ATTR, ONMOUSEDOWN_ATTR, ONMOUSEOUT_ATTR, ONMOUSEOVER_ATTR, ONMOUSEUP_ATTR, PACKAGE_ARCHIVE_ROOT, PARENT_FRAME, PKG_ARCHIVE_ATTR, PKG_URI_ATTR, PKG_WORKSPACE_ATTR, PREVIOUS_DIR, PROPERTY_PREFIX, QUERY_DELIMITER, REFRESH, RESET, SAVE, SCREEN_COLORS_PROPERTY, SCREEN_HEIGHT_PROPERTY, SCREEN_TYPE_PROPERTY, SCREEN_WIDTH_PROPERTY, SCRIPT_PROPERTY, SCRIPT_SUPPORT, SELECT, SORT_BANNER_ATTR, SORT_ORDER_ATTR, SRC_ATTR, STASH_DIR_PROPERTY, STASH_FILE_SEPARATOR, STASH_PROTOCOL, STOP, STYLE_ATTR, TEMP_DIR, THEME_PROPERTY, THEMES_DIR_PROPERTY, TOP, TRIGGER_ATTR, UNICODE_DECIMAL_SYMBOL, UNICODE_HEX_SYMBOL, UNKNOWN_ICON, UNSET_NODE_TYPE, URL_CONTEXT_ATTR, USER_NAME, USERDIR_PROPERTY, VALUE_ATTR, WML_NAMESPACE, XHTML_NAMESPACE, XML, XML_PREFIX_NAMESPACE, XMLNS, XMLNS_NAMESPACE, XOE_CONFIG_DOCTYPE_NAME_NS, XOE_LOCALIZE, XPATH_ATTR
 
Constructor Summary
Stash()
           
 
Method Summary
static ContentElement addAlias(String name, ContentElement content)
          Adds an alias to content using the name name.
static boolean contains(String uri)
          Returns true if a ContentElement exists in the Stash for uri.
static boolean contains(URL url)
          Returns true if a ContentElement exists in the Stash for url.
static URL createUniqueFilename(URL baseURL, String filename, String suffix)
          A convenience method which returns an unused Stash URL based on the criteria passed in.
static ContentElement fetch(String uri)
          Returns the ContentElement from the Stash referred to by uri.
static ContentElement fetch(URL url)
          Returns the ContentElement from the Stash referred to by url.
static ContentElement findFirstNode(String query)
          Returns the first content element in the node list returned by evaluating query using the root Stash directory as the context.
static ContentElement findFirstNode(org.xoe.core.xpath.XPath query)
          Returns the first content element in the node list returned by evaluating query using the root Stash directory as the context.
static org.w3c.dom.NodeList findNodes(String query)
          Returns the list of nodes satisfying the location path query using the root Stash directory as the context.
static org.w3c.dom.NodeList findNodes(org.xoe.core.xpath.XPath query)
          Returns the list of nodes satisfying the location path query using the root Stash directory as the context.
static ContentElementFactory getFactory()
          Returns the factory to use for creating a new Stash content element.
static String getPackageArchiveURI(String pkgURI)
          Returns the installed location of the package, known as the package archive, for pkgURI.
static String getPackageWorkspaceURI(String username, String pkgName)
          Returns the package workspace URI for the username and package name passed in.
static String getPath()
          Returns the directory on the filesystem that corresponds to the Stash.
static URL getPkgArchiveRoot()
          Returns the URL of the read-only directory where packages are installed.
static String getUserWorkspaceURI(String username)
          Returns the workspace URI for the user designated by username.
static URL getWorkingDirectory(Class c)
          Returns the workspace URL for the package that loaded c.
static URL getWorkingDirectory(ClassLoader cl)
          Returns the workspace URL for the package that is associated with cl.
static URL getWorkingDirectory(Object o)
          Returns the workspace URL for the package that installed o.
static URL getWorkingDirectory(XoePackage pkg)
          Returns the URL of the package workspace for pkg.
static String getXML()
          Returns the XML representation of the Stash document.
static ContentElement put(ContentElement content)
          Adds a ContentElement to the Stash.
static void putAlias(String name, String uri)
          Adds an alias to the content element referred to by uri using the name name.
static StashDirectory putDirectory(String dirName)
          Adds the directory hierarchy to the Stash specified by dirName.
static ContentElement remove(String uri)
          Removes the content element referred to by uri.
static ContentElement remove(URL url)
          Removes the content element referred to by url.
static void removeAlias(String name)
          Removes the alias specified by name.
static void setPath(String path)
          Assigns the directory to use for the Stash where default files will be loaded from.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Stash

public Stash()
Method Detail

getFactory

public static ContentElementFactory getFactory()
Returns the factory to use for creating a new Stash content element.
Returns:
the factory to use for creating a new Stash content element.

getPkgArchiveRoot

public static URL getPkgArchiveRoot()
Returns the URL of the read-only directory where packages are installed.
Returns:
the URL of the package archive root directory

getWorkingDirectory

public static URL getWorkingDirectory(XoePackage pkg)
Returns the URL of the package workspace for pkg.
Parameters:
pkg - the xoe package in question
Returns:
the URL of the package workspace for pkg.

getWorkingDirectory

public static URL getWorkingDirectory(Object o)
Returns the workspace URL for the package that installed o.
Parameters:
o - the object in question
Returns:
the workspace URL of the package that installed o.

getWorkingDirectory

public static URL getWorkingDirectory(Class c)
Returns the workspace URL for the package that loaded c.
Parameters:
c - the class in question
Returns:
the workspace URL of the package that installed c.

getWorkingDirectory

public static URL getWorkingDirectory(ClassLoader cl)
Returns the workspace URL for the package that is associated with cl.
Parameters:
cl - the class loadeder in question
Returns:
the workspace URL for the package that is associated with cl.

getUserWorkspaceURI

public static String getUserWorkspaceURI(String username)
Returns the workspace URI for the user designated by username.
Parameters:
username - the user in question
Returns:
the user's workspace URI

getPackageArchiveURI

public static String getPackageArchiveURI(String pkgURI)
Returns the installed location of the package, known as the package archive, for pkgURI.
Parameters:
pkgURI - the package URI
Returns:
the package archive URI

getPackageWorkspaceURI

public static String getPackageWorkspaceURI(String username,
                                            String pkgName)
Returns the package workspace URI for the username and package name passed in.
Parameters:
username - the user name
pkgName - the package name
Returns:
the package workspace URI

setPath

public static void setPath(String path)
                    throws StashException
Assigns the directory to use for the Stash where default files will be loaded from.
Parameters:
path - directory to use for the Stash default data
Throws:
StashException - if the Stash has already been initialized; or if path is: null, not a valid file path on disk, or exists but isn't a directory on disk

getPath

public static String getPath()
Returns the directory on the filesystem that corresponds to the Stash.
Returns:
the directory on the filesystem that corresponds to the Stash.

contains

public static boolean contains(URL url)
                        throws IOException
Returns true if a ContentElement exists in the Stash for url.
Parameters:
url - the URL to look for in the Stash
Returns:
true if content is found; false if no content is found
Throws:
IOException - if an I/O error occurs

contains

public static boolean contains(String uri)
                        throws IOException
Returns true if a ContentElement exists in the Stash for uri.
Parameters:
uri - the URI string to look for in the Stash
Returns:
true if content is found; false if no content is found
Throws:
IOException - if an I/O error occurs

fetch

public static ContentElement fetch(URL url)
                            throws StashException
Returns the ContentElement from the Stash referred to by url.
Parameters:
url - the URL of the desired content
Returns:
the content if it is found; null if not found.
Throws:
StashException - if url is null or doesn't use the Stash protocol.

fetch

public static ContentElement fetch(String uri)
                            throws StashException
Returns the ContentElement from the Stash referred to by uri.
Parameters:
uri - the URI string of the desired content
Returns:
the content if it is found; null if not found.
Throws:
StashException - if uri is null or doesn't use the Stash protocol.

put

public static ContentElement put(ContentElement content)
                          throws IOException,
                                 StashException
Adds a ContentElement to the Stash. Only elements whose URL begins with stash:/ can be added. Any existing element at the same URL is removed and returned.

Note: All subdirectories in the path are created if they do not already exist.

Parameters:
content - the content to place in the Stash
Returns:
the pre-existing content, if it is found; null if no content previously existed at that location
Throws:
IOException - if an I/O exception occurs
StashException - if the content's URL refers to a file on disk that has spaces in it's name.

putDirectory

public static StashDirectory putDirectory(String dirName)
                                   throws IOException
Adds the directory hierarchy to the Stash specified by dirName. Walks each level of the path and adds the directories if necessary.
Parameters:
dirName - the path to add to the Stash
Returns:
the final directory created in the process
Throws:
IOException - if an I/O error occurs

putAlias

public static void putAlias(String name,
                            String uri)
                     throws IOException,
                            StashException
Adds an alias to the content element referred to by uri using the name name. Throws a StashException if uri doesn't refer to valid Stash content.
Parameters:
name - the name to use for the alias
uri - the URI string the alias should point to
Throws:
IOException - if an I/O error occurs
StashException - if uri doesn't refer to valid Stash content.

addAlias

public static ContentElement addAlias(String name,
                                      ContentElement content)
                               throws IOException
Adds an alias to content using the name name. .
Parameters:
name - the name to use for the alias
content - the element to which the alias refers
Throws:
IOException - if an I/O error occurs

remove

public static ContentElement remove(URL url)
                             throws StashException
Removes the content element referred to by url.
Parameters:
url - the URL of the content element to remove
Returns:
the element that was removed
Throws:
StashException - if url is null or doesn't use the Stash protocol.

remove

public static ContentElement remove(String uri)
                             throws StashException
Removes the content element referred to by uri.
Parameters:
uri - the URI string of the content element to remove
Returns:
the element that was removed
Throws:
StashException - if uri is null or doesn't use the Stash protocol.

removeAlias

public static void removeAlias(String name)
                        throws StashException
Removes the alias specified by name.
Parameters:
name - the name of the alias to remove
Throws:
StashException - if name is null or doesn't use the Stash protocol.

findFirstNode

public static ContentElement findFirstNode(String query)
Returns the first content element in the node list returned by evaluating query using the root Stash directory as the context.
Parameters:
query - the string representing the location path to evaluate
Returns:
the first content element that satisfies query

findFirstNode

public static ContentElement findFirstNode(org.xoe.core.xpath.XPath query)
Returns the first content element in the node list returned by evaluating query using the root Stash directory as the context.
Parameters:
query - the compiled XPath representing the location path to evaluate
Returns:
the first content element that satisfies query

findNodes

public static org.w3c.dom.NodeList findNodes(String query)
Returns the list of nodes satisfying the location path query using the root Stash directory as the context.
Parameters:
query - the string representing the location path to evaluate
Returns:
the resulting list of nodes

findNodes

public static org.w3c.dom.NodeList findNodes(org.xoe.core.xpath.XPath query)
Returns the list of nodes satisfying the location path query using the root Stash directory as the context.
Parameters:
query - the compiled XPath representing the location path to evaluate
Returns:
the resulting list of nodes

createUniqueFilename

public static URL createUniqueFilename(URL baseURL,
                                       String filename,
                                       String suffix)
                                throws IOException
A convenience method which returns an unused Stash URL based on the criteria passed in.
Parameters:
baseURL - the Stash directory to look in
filename - the initial filename to try
suffix - the file suffix to use for the URL returned
Returns:
a URL representing the unique file name.
Throws:
IOException - if an I/O error occurs

getXML

public static String getXML()
Returns the XML representation of the Stash document.
Returns:
the XML representation of the Stash document.