org.opensourcephysics.controls
Class XML

java.lang.Object
  extended by org.opensourcephysics.controls.XML

public class XML
extends java.lang.Object

This defines the ObjectLoader interface and static methods for managing and accessing ObjectLoader implementations.

Version:
1.0
Author:
Douglas Brown

Nested Class Summary
static interface XML.ObjectLoader
          This defines methods for moving xml data between an XMLControl and a corresponding Java object.
 
Field Summary
static java.lang.String CDATA_POST
           
static java.lang.String CDATA_PRE
           
static int INDENT
           
static java.lang.String NEW_LINE
           
 
Method Summary
static void createFolders(java.lang.String path)
          Creates any missing folders in the specified path.
static java.lang.String forwardSlash(java.lang.String path)
          Replaces backslashes with slashes.
static java.lang.ClassLoader getClassLoader()
          Gets the ClassLoader.
static java.lang.String getDataType(java.lang.Object obj)
          Gets the datatype of the object.
static java.lang.String[] getDataTypes()
          Gets an array containing all supported data types.
static java.lang.String getDirectoryPath(java.lang.String fileName)
          Gets the path of the directory containing the specified file.
static java.lang.String getDTD(java.lang.String doctype)
          Gets the DTD for the specified doctype file name.
static java.lang.String getExtension(java.lang.String fileName)
          Gets the extension of the specified file name.
static XML.ObjectLoader getLoader(java.lang.Class<?> classtype)
          Gets the ObjectLoader for the specified class.
static java.lang.String getName(java.lang.String path)
          Gets the name from the specified path.
static java.lang.String getPathRelativeTo(java.lang.String absolutePath, java.lang.String base)
          Gets the path relative to the specified base directory.
static java.lang.String getRelativePath(java.lang.String absolutePath)
          Gets a path relative to the default user directory.
static java.lang.String getResolvedPath(java.lang.String relativePath, java.lang.String base)
          Resolves the name of a file specified relative to a base path.
static java.lang.String getSimpleClassName(java.lang.Class<?> type)
          Gets a simple class name for the specified class type.
static java.lang.String getUserDirectory()
          Gets the default user directory.
static boolean requiresCDATA(java.lang.String text)
          Determines whether the specified string requires CDATA tags.
static void setClassLoader(java.lang.ClassLoader loader)
          Sets the ClassLoader.
static void setDefaultLoader(XML.ObjectLoader loader)
          Sets the default ObjectLoader.
static void setLoader(java.lang.Class<?> classtype, XML.ObjectLoader loader)
          Sets the ObjectLoader for a specified class.
static java.lang.String stripExtension(java.lang.String fileName)
          Strips the extension from the specified file name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEW_LINE

public static java.lang.String NEW_LINE

CDATA_PRE

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

CDATA_POST

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

INDENT

public static final int INDENT
See Also:
Constant Field Values
Method Detail

setLoader

public static void setLoader(java.lang.Class<?> classtype,
                             XML.ObjectLoader loader)
Sets the ObjectLoader for a specified class.

Parameters:
classtype - the class
loader - the ObjectLoader

getLoader

public static XML.ObjectLoader getLoader(java.lang.Class<?> classtype)
Gets the ObjectLoader for the specified class.

Parameters:
classtype - the class
Returns:
the ObjectLoader

setDefaultLoader

public static void setDefaultLoader(XML.ObjectLoader loader)
Sets the default ObjectLoader. May be set to null.

Parameters:
loader - the ObjectLoader

getDataType

public static java.lang.String getDataType(java.lang.Object obj)
Gets the datatype of the object.

Parameters:
obj - the object
Returns:
the type

getDataTypes

public static java.lang.String[] getDataTypes()
Gets an array containing all supported data types.

Returns:
an array of types

requiresCDATA

public static boolean requiresCDATA(java.lang.String text)
Determines whether the specified string requires CDATA tags.

Parameters:
text - the string
Returns:
true if CDATA tags are required

getDTD

public static java.lang.String getDTD(java.lang.String doctype)
Gets the DTD for the specified doctype file name.

Parameters:
doctype - the doctype file name (e.g., "osp10.dtd")
Returns:
the DTD as a string

setClassLoader

public static void setClassLoader(java.lang.ClassLoader loader)
Sets the ClassLoader.

Parameters:
loader - the classLoader

getClassLoader

public static java.lang.ClassLoader getClassLoader()
Gets the ClassLoader. May be null.

Returns:
the classLoader

forwardSlash

public static java.lang.String forwardSlash(java.lang.String path)
Replaces backslashes with slashes.

Parameters:
path - the path
Returns:
the path with forward slashes

getName

public static java.lang.String getName(java.lang.String path)
Gets the name from the specified path.

Parameters:
path - the full path
Returns:
the name alone

getExtension

public static java.lang.String getExtension(java.lang.String fileName)
Gets the extension of the specified file name.

Parameters:
fileName - the file name with or without path
Returns:
the extension, or null if none

getSimpleClassName

public static java.lang.String getSimpleClassName(java.lang.Class<?> type)
Gets a simple class name for the specified class type.

Parameters:
type - the class
Returns:
the simple class name

stripExtension

public static java.lang.String stripExtension(java.lang.String fileName)
Strips the extension from the specified file name.

Parameters:
fileName - the file name with or without path
Returns:
the file name without extension

getPathRelativeTo

public static java.lang.String getPathRelativeTo(java.lang.String absolutePath,
                                                 java.lang.String base)
Gets the path relative to the specified base directory.

Parameters:
absolutePath - the absolute path
base - the absolute base directory path
Returns:
(with forward slashes) the path relative to the base, or the absolutePath if no relative path is found (eg, different drive) or the absolutePath if it is really a relative path

getRelativePath

public static java.lang.String getRelativePath(java.lang.String absolutePath)
Gets a path relative to the default user directory.

Parameters:
absolutePath - the absolute path
Returns:
the relative path, with forward slashes

getUserDirectory

public static java.lang.String getUserDirectory()
Gets the default user directory.

Returns:
the user directory

getDirectoryPath

public static java.lang.String getDirectoryPath(java.lang.String fileName)
Gets the path of the directory containing the specified file.

Parameters:
fileName - the full file name, including path
Returns:
the directory path, with forward slashes

getResolvedPath

public static java.lang.String getResolvedPath(java.lang.String relativePath,
                                               java.lang.String base)
Resolves the name of a file specified relative to a base path.

Parameters:
relativePath - the relative file name
base - the absolute base path
Returns:
the resolved file name with forward slashes

createFolders

public static void createFolders(java.lang.String path)
Creates any missing folders in the specified path.

Parameters:
path - the path to construct