uk.ac.cam.spectra
Class Util

java.lang.Object
  extended by uk.ac.cam.spectra.Util

public class Util
extends java.lang.Object

Usual grab bag of utility functions that don't fit anywhere else conveniently.

Author:
Jim Downing

Method Summary
static java.lang.String buildPath(java.lang.String... parts)
          Builds a platform specific file path from the path name parts passed in.
static void copy(java.io.File from, java.io.File to)
          DEWISOTT.
static void move(java.io.File from, java.io.File to)
          Yet another method that java.io.File should possess, performs an atomic move if possible, otherwise a non-atomic one.
static java.util.Date parseDate(java.lang.String dateStr)
          Parse a date according to a number of standard formats.
static void print(nu.xom.Document doc, java.io.OutputStream out, boolean pretty)
          Prints a XOM document to an outputstream without having to remember the serializer voodoo.
static nu.xom.Attribute queryUniqueAttribute(nu.xom.Document doc, java.lang.String query, nu.xom.XPathContext xpathContext)
          Utility method to return the result of an xpath query you know is going to return a single text node.
static void rmr(java.io.File dir)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

buildPath

public static java.lang.String buildPath(java.lang.String... parts)
Builds a platform specific file path from the path name parts passed in. An obvious thing to do now we have varargs - why hasn't java.io.File got this?

Parameters:
parts - directory names and an optional file name
Returns:
platform specific path string.

copy

public static void copy(java.io.File from,
                        java.io.File to)
                 throws java.io.IOException
DEWISOTT.

Parameters:
from - source file
to - target file
Throws:
java.io.IOException
java.io.IOException - rethrown from java.io.

move

public static void move(java.io.File from,
                        java.io.File to)
                 throws java.io.IOException
Yet another method that java.io.File should possess, performs an atomic move if possible, otherwise a non-atomic one.

Parameters:
from - source file
to - target file
Throws:
java.io.IOException - rethrown from java.io

queryUniqueAttribute

public static nu.xom.Attribute queryUniqueAttribute(nu.xom.Document doc,
                                                    java.lang.String query,
                                                    nu.xom.XPathContext xpathContext)
Utility method to return the result of an xpath query you know is going to return a single text node.

Parameters:
doc - XOM document to query
query - the XPath query
xpathContext - the XPath context to resolve namespaces
Returns:
String of Text node, untrimmed.
Throws:
java.lang.RuntimeException - if the query doesn't return a single node, or if the node returned is not a text node.

print

public static void print(nu.xom.Document doc,
                         java.io.OutputStream out,
                         boolean pretty)
Prints a XOM document to an outputstream without having to remember the serializer voodoo.

Parameters:
doc - the XOM DOcument to print
out - where to print to
pretty - should it be pretty printed?
Throws:
java.io.IOException - rethrown from the XOM serializer

parseDate

public static java.util.Date parseDate(java.lang.String dateStr)
Parse a date according to a number of standard formats.

Parameters:
dateStr - the date as a string
Returns:
a parsed date object, or null if none of the standard formats can parse the string.

rmr

public static void rmr(java.io.File dir)


Copyright © 2006-2007 The SPECTRa Project. All Rights Reserved.