|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.exln.stylus.io.StylusFileHelpers
A collection of static helpers for use with the Stylus Studio custom file system interfaces
StylusFile
and StylusFileSystem
and the class StylusFileFactory
.
Method Summary | |
static void |
copyFromFile(StylusFile outputStylusFile,
String fileName)
Perform the copyFromFile function of the StylusFile interface. |
static void |
copyFromStream(StylusFile outputStylusFile,
InputStream inStream)
Copy data from an InputStream object to a StylusFile object. |
static void |
copyToFile(StylusFile inputStylusFile,
String fileName)
Perform the copyToFile function of the StylusFile interface. |
static void |
copyToStream(StylusFile inputStylusFile,
OutputStream outStream)
Copy data from a StylusFile object to a Stream object. |
static IOException |
createIOException(Throwable t)
Convert an exception into an IOException. |
static XMLReader |
createXMLReader()
Create an XMLReader implementation instance. |
static void |
doCopy(InputStream is,
OutputStream os)
Copy data from an InputStream to an OutputStream using a 64K buffer. |
static boolean |
doINFO()
Return whether the INFO method will generate any output. |
static boolean |
doTRACE()
Return whether the TRACE method will generate any output. |
static String |
getBinDir()
Get the name of the directory containing CustomFileSystem.jar. |
static Logger |
getLogger()
Get the StylusFileHelpers.Logger object. |
static String |
getResolvedPathname(String uri,
String baseURI)
Resolve a uri and a baseURI to form a local filesystem pathname. |
static String |
getResolvedURI(String uri,
String baseURI)
Convenience routine to resolve a uri with a baseURI using the java URI class. |
static String |
getRootDir()
Get the Stylus Studio installation directory (rootdir). |
static boolean |
isLocalFile(String uri,
String baseURI)
Return whether the parameter represents a local file system file or directory. |
static String |
resolve(String uri,
String baseURI)
Resolve a URI with a base URI. |
static String |
stripFile(String path)
Remove a file:/// prefix from a URL to create a pathname. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static Logger getLogger()
Logger
returned by this method.
When a custom file system
is used inside Stylus Studio, the log messages are displayed in the Stylus Studio Output Window. When a
custom file system is used in a standalone Java program (using StylusFileFactory
), the log messages are
be written to stdout with System.out.println().
The command line utilities StylusXslt, StylusXql, StylusDiff, and XmlValidator do not support logging.
Any calls to
write messages using this logger will be ignored.
There is at most one instance of this class, created by the first call to getLogger()
.
Once you have the Logger object, you can use it to write log messages, or change the filtering
Level
for all subsequent messages.
Each message to be logged has a Level
associated with it.
Two levels are of particular interest:Logger.info(String)
method.Logger.fine(String)
method.Logger
and Level
.
The Logger has a filtering level associated with it. Any message whose level is
lower than the current filtering level is ignored. The filtering level is
set in two ways:
Logger.setLevel(java.util.logging.Level)
method. The new level remains in effect until setLevel
is called again by any class.
...
private static boolean doTRACE = StylusFileHelpers.doTRACE();
private static void TRACE(String msg) {
StylusFileHelpers.getLogger().fine(msg);
}
...
void mymethod() {
if (doTRACE) TRACE("mymethod called");
...
}
This code could be used in a Java application to suppress all logging messages:
StylusFileHelpers.getLogger().setLevel(java.util.logging.Level.OFF);
although it might be preferable to start the JVM with the parameter -DNOINFO.
public static boolean doTRACE()
getLogger()
, then
the simplest way to write a tracing message is with:
TRACE("my message");
Since tracing is usually off, this generates unnecessary overhead,
especially if the parameter to TRACE() is expensive
to evaluate. This technique should, therefore, be modified to improve
performance.
The recommended technique is:
static boolean doTRACE = StylusFileHelpers.doTRACE();
...
void mymethod() {
if (doTRACE) TRACE("mymethod called");
...
}
...
public static boolean doINFO()
static void INFO(String s) { StylusFileHelpers.getLogger().info(s); }
then the simplest way to write a tracing message is with:
INFO("my message");
If INFO is usually turned off, then this technique should be
modified to improve performance.
The recommended technique is:
static boolean doINFO = StylusFileHelpers.doINFO();
...
void mymethod() {
if (doINFO) INFO("mymethod called");
...
}
...
- Returns:
- A boolean value indicating whether INFO output will actually
be written to the log file.
public static void copyToFile(StylusFile inputStylusFile, String fileName) throws IOException
public class myclass implements StylusFile {
...
public void copyToFile(String outputName) throws IOException {
StylusFileHelpers.copyToFile(this, outputName);
}
...
inputStylusFile
- The StylusFile object whose data should be copied to a file.fileName
- The name of the output file which will be created.
IOException
public static void copyToStream(StylusFile inputStylusFile, OutputStream outStream) throws IOException
...
StylusFileHelpers.copyToStream(stylusFileIn, stylusFileOut.getOutputStream());
...
inputStylusFile
- The StylusFile object whose data should be copied.outStream
- The output stream to which the data will be copied.
IOException
public static void copyFromFile(StylusFile outputStylusFile, String fileName) throws IOException
public class myclass implements StylusFile {
...
public void copyFromFile(String inputName) throws IOException {
StylusFileHelpers.copyFromFile(this, inputName);
}
...
outputStylusFile
- The StylusFile object to which data should be copied.fileName
- The name of the input file which will be copied.
IOException
public static void copyFromStream(StylusFile outputStylusFile, InputStream inStream) throws IOException
...
StylusFileHelpers.copyFromStream(stylusFileOut, stylusFileIn.getInputStream());
...
outputStylusFile
- The StylusFile object to which data should be copied.inStream
- The input stream from which the data will be copied.
IOException
public static void doCopy(InputStream is, OutputStream os) throws IOException
InputStream
to an OutputStream
using a 64K buffer.
This method does not close either Stream.
is
- The InputStream.os
- The OutputStream
IOException
public static IOException createIOException(Throwable t)
t
- The Throwable object which is to be converted to an IOException.
public static String stripFile(String path)
path
- the String from which the file: prefix should be stripped.
public static boolean isLocalFile(String uri, String baseURI)
uri
- The URI to be checkedbaseURI
- If the uri parameter is relative, it will be taken as relative to this base.
public static String getResolvedPathname(String uri, String baseURI)
uri
- The URI to be resolved.baseURI
- If the uri parameter is relative, it will be taken as relative to this base.
public static String getResolvedURI(String uri, String baseURI)
URI.resolve(java.lang.String)
to resolve a uri string
relative to a base URI.
uri
- The uri string to be resolved.baseURI
- The base URI to resolve with.
public static String resolve(String uri, String baseURI)
uri
- The URI to be resolvedbaseURI
- The base URI to resolve uri with.
public static String getBinDir()
public static String getRootDir()
public static XMLReader createXMLReader() throws SAXException
SAXException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |