|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectFileUtils
public class FileUtils
Provides file-related utilities to be called by XSLT stylesheets through Saxon's extension function mechanism.
Field Summary | |
---|---|
private static HashMap |
dateFormatCache
Used to avoid recreating SimpleDateFormat objects all the time |
private static long |
MILLISECS_PER_DAY
Number of leap seconds per day except on 1. days when a leap second has been inserted, e.g. 1999 JAN 1. |
private static long |
MILLISECS_PER_HOUR
Number of milliseconds per hour, except when a leap second is inserted. |
private static long |
MILLISECS_PER_MINUTE
All minutes have this many milliseconds except the last minute of the day on a day defined with a leap second. |
private static ThreadLocal<ArrayList<File>> |
tempFiles
Used to track temp files, per thread |
Constructor Summary | |
---|---|
FileUtils()
|
Method Summary | |
---|---|
private static long |
adjustedMillis(Calendar cal)
Gets the time in milliseconds from a Calendar, adjusting for timezone so that day subtraction works properly. |
static String |
createTempFile(XPathContext context,
String prefix,
String suffix)
Generates a temporary file in the default temporary-file directory, using the given prefix and suffix to generate the name. |
static String |
curDateTime(XPathContext context,
String formatStr)
Gets the current date and time. |
static void |
deleteTempFiles()
Deletes all temporary files created by the current thread using createTempFile(net.sf.saxon.expr.XPathContext, java.lang.String, java.lang.String) . |
static boolean |
exists(XPathContext context,
String filePath)
Checks whether a file with the given path exists (that is, if it can be read.) |
private static SimpleDateFormat |
getDateFormat(String formatStr)
Get a SimpleDateFormatter for the given format string. |
private static String |
getSystemId(XPathContext context)
Unfortunately the interface for getting systemId from an XPath context changed between Saxon 9.0 and Saxon 9.1, so we jump through hoops to be compatible with both. |
static String |
humanFileSize(Long longFileSize)
Converts the size of a file to a human-readable string, e.g |
static String |
lastModified(XPathContext context,
String filePath,
String formatStr)
Gets the last-modified time of the file with the given path exists (that is, if it can be read.) |
static long |
length(XPathContext context,
String filePath)
Gets the size in bytes of the file with the given path (that is, if it can be read.) |
static String |
md5Hash(String inputString)
Calculate the MD5 digest of a string. |
static DocumentInfo |
readHTMLPage(XPathContext context,
String urlStr)
Reads in an HTML page (specified by URL), and uses JTidy to make it into XML that can be subsequently processed by a stylesheet. |
static DocumentInfo |
readXMLStub(XPathContext context,
String filePath)
Reads in the first part of an XML file, stopping at the first close-element marker. |
static File |
resolveFile(XPathContext context,
String filePath)
Resolve the location of a file given the stylesheet context. |
static String |
resolvePath(XPathContext context,
String filePath)
Resolve the location of a file given the stylesheet context. |
static long |
timeSince(XPathContext context,
String targetDateStr,
String units,
String formatStr)
Compute the number of days, hours, or minutes that have elapsed between the given time and now. |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static HashMap dateFormatCache
private static ThreadLocal<ArrayList<File>> tempFiles
private static final long MILLISECS_PER_MINUTE
private static final long MILLISECS_PER_HOUR
private static final long MILLISECS_PER_DAY
Constructor Detail |
---|
public FileUtils()
Method Detail |
---|
public static boolean exists(XPathContext context, String filePath)
context
- Context used to figure out which stylesheet is calling
the function.filePath
- Path to the file in question
public static String lastModified(XPathContext context, String filePath, String formatStr)
context
- Context used to figure out which stylesheet is calling
the function.filePath
- Path to the file in questionformatStr
- A simple format string; see SimpleDateFormat
.
public static long length(XPathContext context, String filePath)
context
- Context used to figure out which stylesheet is calling
the function.filePath
- Path to the file in question
public static String humanFileSize(Long longFileSize)
longFileSize
- The size to convert
public static String md5Hash(String inputString)
inputString
- String to digest
private static String getSystemId(XPathContext context)
public static File resolveFile(XPathContext context, String filePath)
public static String resolvePath(XPathContext context, String filePath)
public static String curDateTime(XPathContext context, String formatStr)
context
- Context used to figure out which stylesheet is calling
the function.formatStr
- A simple format string; see SimpleDateFormat
.
public static long timeSince(XPathContext context, String targetDateStr, String units, String formatStr)
context
- Context used to figure out which stylesheet is calling
the function.targetDateStr
- The target dateunits
- Units to return: 'days', 'hours', or 'minutes'. Plural
is optional, and single-letter abbreviations are accepted.formatStr
- The format of the target date; see SimpleDateFormat
.
private static long adjustedMillis(Calendar cal)
private static SimpleDateFormat getDateFormat(String formatStr)
formatStr
- is the format string to use
public static String createTempFile(XPathContext context, String prefix, String suffix) throws IOException
context
- Context used to figure out which stylesheet is calling
the function.prefix
- Prefix for the resulting file name.suffix
- Suffix for the resulting file name.
IOException
public static void deleteTempFiles()
createTempFile(net.sf.saxon.expr.XPathContext, java.lang.String, java.lang.String)
.
public static DocumentInfo readXMLStub(XPathContext context, String filePath) throws IOException, XPathException
IOException
- if the file can't be read
XPathException
- if the document cannot be parsedpublic static DocumentInfo readHTMLPage(XPathContext context, String urlStr) throws IOException, XPathException
IOException
- if the file can't be read
XPathException
- if the document cannot be parsed
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |