DTDDoc
Class Tools

java.lang.Object
  extended by DTDDoc.Tools

public class Tools
extends 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 List HTML_TAGS
           
 
Constructor Summary
Tools()
           
 
Method Summary
static void copy(File sourceFile, File destinationFile)
          Copy one file into antoher.
static void copyFromResource(String name, File destinationFile)
          Copies a resource file (in-jar) to a given destination.
static List enumerationToList(Enumeration enumeration)
           
static String escapeHTMLUnicode(String s, boolean javascript)
          Escape all non-ASCII character in a UNICODE string.
static String getFilename(String path)
          Extract the file name out of a full path.
static String join(String[] array, String separator)
           
static String[] listToArray(String s, String separator)
          Transform a list into an array.
static void makeFileDir(File f)
          Will create the directories present in the path of a file.
static File parent(File f)
          Get the parent of a given path.
static String replace(String src, String token, String with)
           
static Collection sort(Collection collection, Comparator comparator)
          Returns a sorted copy of a given collection.
static boolean startsWithHtmlTag(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 List HTML_TAGS
Constructor Detail

Tools

public Tools()
Method Detail

copyFromResource

public static void copyFromResource(String name,
                                    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(File sourceFile,
                        File destinationFile)
                 throws IOException
Copy one file into antoher. If the destination file already exists, it is overwritten.

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

parent

public static File parent(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 Collection sort(Collection collection,
                              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 String[] listToArray(String s,
                                   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 String join(String[] array,
                          String separator)

escapeHTMLUnicode

public static String escapeHTMLUnicode(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 List enumerationToList(Enumeration enumeration)

getFilename

public static String getFilename(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(File f)
                        throws IOException
Will create the directories present in the path of a file.

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

startsWithHtmlTag

public static boolean startsWithHtmlTag(String txt)

replace

public static String replace(String src,
                             String token,
                             String with)


Copyright © 2002-2011 DTDDoc. All Rights Reserved.