Class XML

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

public class XML extends Object
This defines the ObjectLoader interface and static methods for managing and accessing ObjectLoader implementations.
Version:
1.0
Author:
Douglas Brown
  • Field Details

  • Method Details

    • setLoader

      public static void setLoader(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(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
    • getAttr

      public static String getAttr(String xml, String attr, String def)
    • requiresCDATA

      public static boolean requiresCDATA(String text)
      Determines whether the specified string requires CDATA tags.
      Parameters:
      text - the string
      Returns:
      true if CDATA tags are required
    • getDTD

      public static String getDTD(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(ClassLoader loader)
      Sets the ClassLoader.
      Parameters:
      loader - the classLoader
    • getClassLoader

      public static ClassLoader getClassLoader()
      Gets the ClassLoader. May be null.
      Returns:
      the classLoader
    • forwardSlash

      public static String forwardSlash(String path)
      Replaces backslashes with slashes.
      Parameters:
      path - the path
      Returns:
      the path with forward slashes
    • getName

      public static String getName(String path)
      Gets the name from the specified path.
      Parameters:
      path - the full path
      Returns:
      the name alone
    • getExtension

      public static String getExtension(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 String getSimpleClassName(Class<?> type)
      Gets a simple class name for the specified class type.
      Parameters:
      type - the class
      Returns:
      the simple class name
    • stripExtension

      public static String stripExtension(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 String getPathRelativeTo(String absolutePath, 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 String getRelativePath(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 String getUserDirectory()
      Gets the default user directory.
      Returns:
      the user directory
    • getDirectoryPath

      public static String getDirectoryPath(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
    • getAbsolutePath

      public static String getAbsolutePath(File file)
      Gets the absolute path of the specified file.
      Parameters:
      file - the file
      Returns:
      the absolute path, with forward slashes
    • getResolvedPath

      public static String getResolvedPath(String relativePath, 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(String path)
      Creates any missing folders in the specified path.
      Parameters:
      path - the path to construct
    • removeCDATA

      public static String removeCDATA(String content)