|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectccs.utils.SortingFolderEntry
public class SortingFolderEntry
This class assists the rather common pattern whereby there is a "folder" full of filenames, some of which are subfolders, and which must be sorted. This occurs in various guises in pretty much every Checkpoint product there is; historically, all of these have used custom code to address the problem since each case encounters it in a slightly different guise.
This class attempts to common up the directory-sorting section of the problem, while allowing enough flexibility not to break the existing code (which handles the large areas of difference involved).
On notation: pretty much everywhere else, the pattern here called a "folder" is called a "directory", which is the historical term. However, it seems possible that in the not too distant future we'll be wanting to reserve "directory" for the LDAP sense; this is the vanguard of a long and slow terminology migration.
Constructor Summary | |
---|---|
SortingFolderEntry(java.lang.String rawname,
java.lang.Object maino,
boolean isFolder,
boolean isAcceptable)
Create a new SortingFolderEntry. |
Method Summary | |
---|---|
java.lang.String |
getExtn()
|
java.lang.String |
getName()
|
java.lang.String |
getQuery()
|
boolean |
isAcceptable()
|
boolean |
isFolder()
|
static SortingFolderEntry[] |
listFiles(java.io.File folderf,
java.io.FileFilter filter)
A helper method for the common special case where you need to generate a directory listing for a disk directory. |
java.lang.Object |
mainObject()
|
static int |
search(SortingFolderEntry[] contents,
SortingFolderEntry key)
Find the index of the specified entry in the supplied array. |
static void |
sort(SortingFolderEntry[] contents)
Sort this array of folder entries into their proper order. |
java.lang.String |
toEncoded()
|
void |
xmlMarshal(java.io.PrintWriter pw)
Marshal the entry as XML. |
void |
xmlMarshal(java.io.PrintWriter pw,
boolean foldersOnly)
Marshal the entry as XML. |
static void |
xmlMarshalFolder(java.io.PrintWriter pw,
SortingFolderEntry[] sfes,
java.io.File folderf,
java.lang.String filterPattern,
boolean foldersOnly)
A helper method to marshal the current folder as XML, in the common special case where the folder is a disk file. |
static void |
xmlMarshalFolder(java.io.PrintWriter pw,
SortingFolderEntry[] sfes,
java.lang.String folderPath,
char separator,
java.lang.String filterPattern,
boolean includeUp,
boolean foldersOnly)
A helper method to marshal the current folder as XML. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SortingFolderEntry(java.lang.String rawname, java.lang.Object maino, boolean isFolder, boolean isAcceptable)
rawname
- The name portion of the contents' path. This should not contain
any path separators.maino
- The "main object" for which this contains denormalised sorting
information. In general, SortingFolderEntry arrays are used to display
a "folder listing" for the user; when the user then picks an entry, the
app will need to retrieve maino in order to do whatever the user asked for.isFolder
- whether the entry is a subfolder.isAcceptable
- Whether the file meets your filtering requirements. If you
have no filter, set this to true. Directories should always be acceptable.Method Detail |
---|
public java.lang.String getName()
public java.lang.String getExtn()
public java.lang.String getQuery()
public java.lang.String toEncoded()
URLCoding.filepathToUrl(java.lang.String, char, boolean)
public boolean isFolder()
public boolean isAcceptable()
public java.lang.Object mainObject()
public void xmlMarshal(java.io.PrintWriter pw) throws java.io.IOException
java.io.IOException
public void xmlMarshal(java.io.PrintWriter pw, boolean foldersOnly) throws java.io.IOException
java.io.IOException
public static void sort(SortingFolderEntry[] contents)
contents
- The array to sort.public static int search(SortingFolderEntry[] contents, SortingFolderEntry key)
sort
) or the results are
undefined.
contents
- The sorted array to search in.key
- the entry to search for
java.util.Arrays.binarySearch
public static SortingFolderEntry[] listFiles(java.io.File folderf, java.io.FileFilter filter) throws java.io.IOException
folderf
- the folder (directory) whose contents are to be sorted. If null,
the list of filesystem roots is returned.filter
- A FileFilter which determines whether a file is "acceptable" or not.
Unacceptable files sort after acceptable and XML-marshal as badfile
elements. Directories are always acceptable (the filter is bypassed for these).
If the filter is null, all files are acceptable.
java.io.IOException
public static void xmlMarshalFolder(java.io.PrintWriter pw, SortingFolderEntry[] sfes, java.io.File folderf, java.lang.String filterPattern, boolean foldersOnly) throws java.io.IOException
pw
- where to write the XML to.sfes
- The content of the folder.folderf
- The folder being written.filterPattern
- The pattern of any filter applied sfes. May be null.foldersOnly
- Whether to only write subfolders.
java.io.IOException
public static void xmlMarshalFolder(java.io.PrintWriter pw, SortingFolderEntry[] sfes, java.lang.String folderPath, char separator, java.lang.String filterPattern, boolean includeUp, boolean foldersOnly) throws java.io.IOException
pw
- where to write the XML to.sfes
- The content of the folder.folderPath
- The path of the folder being written.separator
- The path-element separator character for the filesystem
this folder lives in.filterPattern
- The pattern of any filter applied sfes. May be null.includeUp
- Whether to include an entry for the "parent" directory, "..");foldersOnly
- Whether to only write subfolders.
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |