DTDDoc
Class Tools

java.lang.Object
  extended by DTDDoc.Tools

public class Tools
extends java.lang.Object

A class that gather some useful tools.

Author:
expertmb (http://www.experts-exchange.com/M_237837.html), stefan schampailler_at_skynet_dot_be

Field Summary
static java.util.List HTML_TAGS
           
 
Constructor Summary
Tools()
           
 
Method Summary
static void copy(java.io.File sourceFile, java.io.File destinationFile)
          Copy one file into antoher.
static void copyFromResource(java.lang.String name, java.io.File destinationFile)
          Copies a resource file (in-jar) to a given destination.
static java.util.List enumerationToList(java.util.Enumeration enumeration)
           
static java.lang.String escapeHTMLUnicode(java.lang.String s, boolean javascript)
          Escape all non-ASCII character in a UNICODE string.
static java.lang.String getFilename(java.lang.String path)
          Extract the file name out of a full path.
static java.lang.String join(java.lang.String[] array, java.lang.String separator)
           
static java.lang.String[] listToArray(java.lang.String s, java.lang.String separator)
          Transform a list into an array.
static void makeFileDir(java.io.File f)
          Will create the directories present in the path of a file.
static java.io.File parent(java.io.File f)
          Get the parent of a given path.
static java.lang.String replace(java.lang.String src, java.lang.String token, java.lang.String with)
           
static java.util.Collection sort(java.util.Collection collection, java.util.Comparator comparator)
          Returns a sorted copy of a given collection.
static boolean startsWithHtmlTag(java.lang.String txt)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTML_TAGS

public static final java.util.List HTML_TAGS
Constructor Detail

Tools

public Tools()
Method Detail

copyFromResource

public static void copyFromResource(java.lang.String name,
                                    java.io.File destinationFile)
                             throws FileCopyException
Copies a resource file (in-jar) to a given destination.

Parameters:
name - Full path to the resource (relative to the jar though).
destinationFile - Where to copy the file.
Throws:
FileCopyException

copy

public static void copy(java.io.File sourceFile,
                        java.io.File destinationFile)
                 throws java.io.IOException
Copy one file into antoher. If the destination file already exists, it is overwritten.

Parameters:
sourceFile - Source path.
destinationFile - Destination path.
Throws:
java.io.IOException

parent

public static java.io.File parent(java.io.File f)
Get the parent of a given path.

Parameters:
f - The path.
Returns:
The path's parent. Null if there's no such parent.

sort

public static java.util.Collection sort(java.util.Collection collection,
                                        java.util.Comparator comparator)
Returns a sorted copy of a given collection.

Parameters:
collection - Colelction to sort.
comparator - Comparator to use while sorting.
Returns:
A sorted copy of the collection.

listToArray

public static java.lang.String[] listToArray(java.lang.String s,
                                             java.lang.String separator)
Transform a list into an array. The list is a string of texts separated by a character called "separator".

Parameters:
s - The list
separator - the separator.
Returns:
An array containing all the elements of the list. Null if the list is empty.

join

public static java.lang.String join(java.lang.String[] array,
                                    java.lang.String separator)

escapeHTMLUnicode

public static java.lang.String escapeHTMLUnicode(java.lang.String s,
                                                 boolean javascript)
Escape all non-ASCII character in a UNICODE string. The "escaping convention" is the one of HTML : &#xxxx;.

Additionally, this function can escape the single quote character for Javascript strings.

Parameters:
s - String to escape. If null, nothing is done.
javascript - If true, escapes the single quote character into \' so that it can appear in a single quote delimited Javascript string.
Returns:
The escaped version of the string. If the parameter is null, returns null.

enumerationToList

public static java.util.List enumerationToList(java.util.Enumeration enumeration)

getFilename

public static java.lang.String getFilename(java.lang.String path)
Extract the file name out of a full path. For example, for "/alpha/bravo/zulu", this function will return "zulu".

Parameters:
path - The full path.
Returns:
The file name part of the path.

makeFileDir

public static void makeFileDir(java.io.File f)
                        throws java.io.IOException
Will create the directories present in the path of a file.

Parameters:
f - The file to get the path from.
Throws:
java.io.IOException

startsWithHtmlTag

public static boolean startsWithHtmlTag(java.lang.String txt)

replace

public static java.lang.String replace(java.lang.String src,
                                       java.lang.String token,
                                       java.lang.String with)


Copyright © 2002-2008 DTDDoc. All Rights Reserved.