public final class Util
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
appendQuery(java.lang.StringBuilder buf,
java.lang.String key,
java.lang.String value)
Append '&name=value" to the given buffer.
|
static java.lang.String |
breadcrumbPath(java.lang.String urlPrefix,
java.lang.String path)
Convinience method for
breadcrumbPath(urlPrefix, path, '/') . |
static java.lang.String |
breadcrumbPath(java.lang.String urlPrefix,
java.lang.String path,
char sep)
Convenience method for
breadcrumbPath(urlPrefix, path, sep, "", false) . |
static java.lang.String |
breadcrumbPath(java.lang.String urlPrefix,
java.lang.String path,
char sep,
java.lang.String urlPostfix,
boolean compact)
Convenience method for
breadcrumbPath(urlPrefix, path, sep, "", false, path.endsWith(sep) . |
static java.lang.String |
breadcrumbPath(java.lang.String urlPrefix,
java.lang.String path,
char sep,
java.lang.String urlPostfix,
boolean compact,
boolean isDir)
Create a breadcrumb path to allow navigation to each element of a path.
|
static java.lang.String[] |
diffline(java.lang.StringBuilder line1,
java.lang.StringBuilder line2)
Tag changes in the given line1 and line2
for highlighting.
|
static boolean |
dump(java.io.Writer out,
java.io.File file,
boolean compressed)
Silently dump a file to the given destionation.
|
static boolean |
dump(java.io.Writer out,
java.io.File dir,
java.lang.String filename,
boolean compressed)
Silently dump a file to the given destionation.
|
static void |
dump(java.io.Writer out,
java.io.Reader in)
Just read the given source and dump as is to the given destionation.
|
static void |
dumpConfiguration(java.lang.Appendable out)
Dump the configuration as an HTML table.
|
static java.lang.String |
encode(java.lang.String s)
Converts different html special characters into their encodings used in
html.
|
static java.lang.String |
formQuoteEscape(java.lang.String q)
Replace all quote characters (ASCI 0x22) with the corresponding html
entity (").
|
static java.lang.String |
getCanonicalPath(java.lang.String path,
char sep)
Normalize the given path to its canonical form.
|
static java.lang.String |
getEmail(java.lang.String author)
Get email address of the author.
|
static void |
htmlize(char[] cs,
int length,
java.lang.StringBuilder dest)
Append a character array to the given destination whereby
special characters for HTML are escaped accordingly.
|
static java.lang.String |
htmlize(java.lang.CharSequence q)
Return a string which represents a
CharSequence in HTML. |
static void |
htmlize(java.lang.CharSequence q,
java.lang.StringBuilder dest)
Append a character sequence to the given destination whereby
special characters for HTML are escaped accordingly.
|
static java.lang.String |
jsStringLiteral(java.lang.String str)
Create a string literal for use in JavaScript functions.
|
static java.lang.String |
path2uid(java.lang.String path,
java.lang.String date)
Generate a string from the given path and date in a way that allows
stable lexicographic sorting (i.e.
|
static void |
readableLine(int num,
java.io.Writer out,
Annotation annotation,
java.lang.String userPageLink,
java.lang.String userPageSuffix)
Write out line information wrt.
|
static java.lang.String |
readableSize(long num)
Convert the given size into a human readable string.
|
static java.lang.String |
uid2url(java.lang.String uid)
The reverse operation for
path2uid(String, String) - re-creates
the unmangled path from the given uid. |
static java.lang.String |
URIEncode(java.lang.String q)
wrapper arround UTF-8 URL encoding of a string
|
static java.lang.String |
URIEncodePath(java.lang.String path)
URI encode the given path.
|
static java.lang.String |
versionParameter()
used by BUI - CSS needs this parameter for proper cache refresh (per
changeset) in client browser jel: but useless, since the page cached
anyway.
|
public static java.lang.String htmlize(java.lang.CharSequence q)
CharSequence
in HTML.q
- a character sequencepublic static void htmlize(java.lang.CharSequence q, java.lang.StringBuilder dest)
q
- a character sequence to esacpedest
- where to append the character sequence topublic static void htmlize(char[] cs, int length, java.lang.StringBuilder dest)
cs
- characters to esacpelength
- max. number of characters to append, starting from index 0.dest
- where to append the character sequence topublic static java.lang.String versionParameter()
public static java.lang.String breadcrumbPath(java.lang.String urlPrefix, java.lang.String path)
breadcrumbPath(urlPrefix, path, '/')
.urlPrefix
- prefix to add to each urlpath
- path to crackbreadcrumbPath(String, String, char)
public static java.lang.String breadcrumbPath(java.lang.String urlPrefix, java.lang.String path, char sep)
breadcrumbPath(urlPrefix, path, sep, "", false)
.urlPrefix
- prefix to add to each urlpath
- path to cracksep
- separator to use to crack the given pathbreadcrumbPath(String, String, char, String, boolean, boolean)
public static java.lang.String breadcrumbPath(java.lang.String urlPrefix, java.lang.String path, char sep, java.lang.String urlPostfix, boolean compact)
breadcrumbPath(urlPrefix, path, sep, "", false, path.endsWith(sep)
.urlPrefix
- prefix to add to each urlpath
- path to cracksep
- separator to use to crack the given pathurlPostfix
- suffix to add to each urlcompact
- if true
the given path gets transformed into
its canonical form (.i.e. all '.' and '..' and double separators
removed, but not always resolves to an absolute path) before processing
starts.breadcrumbPath(String, String, char, String, boolean, boolean)
,
getCanonicalPath(String, char)
public static java.lang.String breadcrumbPath(java.lang.String urlPrefix, java.lang.String path, char sep, java.lang.String urlPostfix, boolean compact, boolean isDir)
true
path gets translated into a canonical
path similar to File.getCanonicalPath()
, however the current
working directory is assumed to be "/" and no checks are done (e.g.
neither whether the path [component] exists nor which type it is).urlPrefix
- what should be prepend to the constructed URLpath
- the full path from which the breadcrumb path is built.sep
- the character that separates the path components in
pathurlPostfix
- what should be append to the constructed URLcompact
- if true
, a canonical path gets constructed before
processing.isDir
- if true
a "/" gets append to the last path component's
link and sep to its namenull
path, the HTML markup for the breadcrumb path otherwise.public static java.lang.String getCanonicalPath(java.lang.String path, char sep)
So the difference to File.getCanonicalPath()
is, that this method
does not hit the disk (just string manipulation), resolves path
always against '/' and thus always returns an absolute path, which may
actually not exist, and which has a single trailing '/' if the given
path ends with the given sep.
path
- path to mangle. If not absolute or null
, the
current working directory is assumed to be '/'.sep
- file separator to use to crack path into path
componentspublic static java.lang.String getEmail(java.lang.String author)
author
- string containing author and possibly email address.public static java.lang.String readableSize(long num)
num
- size to convert.public static java.lang.String encode(java.lang.String s)
s
- input textpublic static void readableLine(int num, java.io.Writer out, Annotation annotation, java.lang.String userPageLink, java.lang.String userPageSuffix) throws java.io.IOException
Linenumber Blame Author
incl. appropriate links.num
- linenumber to printout
- print destinationannotation
- annotation to use. If null
only the
linenumber gets printed.userPageLink
- see RuntimeEnvironment.getUserPage()
userPageSuffix
- see RuntimeEnvironment.getUserPageSuffix()
java.io.IOException
- depends on the destination (out).public static java.lang.String path2uid(java.lang.String path, java.lang.String date)
path
- path to mangle.date
- date string to use.public static java.lang.String uid2url(java.lang.String uid)
path2uid(String, String)
- re-creates
the unmangled path from the given uid.uid
- uid to unmangle.public static java.lang.String URIEncode(java.lang.String q)
q
- query to be encoded. If null
, an empty string will
be used instead.URLEncoder.encode(String, String)
public static void appendQuery(java.lang.StringBuilder buf, java.lang.String key, java.lang.String value)
null
, this method does nothing.buf
- where to append the query stringkey
- the name of the parameter to add. Append as is!value
- the value for the given parameter. Gets automatically UTF-8
URL encoded.java.lang.NullPointerException
- if the given buffer is null
.URIEncode(String)
public static java.lang.String URIEncodePath(java.lang.String path)
path
- path to encode.java.lang.NullPointerException
- if a parameter is null
public static java.lang.String formQuoteEscape(java.lang.String q)
q
- string to escape.null
, the mangled
string otherwise.public static java.lang.String[] diffline(java.lang.StringBuilder line1, java.lang.StringBuilder line2)
d
,
new parts are tagged with CSS class a
using a span
element.line1
- line of the original fileline2
- line of the changed/new filejava.lang.NullPointerException
- if one of the given parameters is null
.public static void dumpConfiguration(java.lang.Appendable out) throws java.io.IOException, HistoryException
out
- destination for the HTML outputjava.io.IOException
- if an error happens while writing to out
HistoryException
- if the history guru cannot be accessespublic static void dump(java.io.Writer out, java.io.Reader in) throws java.io.IOException
null
.out
- write destinationin
- source to readjava.io.IOException
- as defined by the given reader/writerjava.lang.NullPointerException
- if a parameter is null
.public static boolean dump(java.io.Writer out, java.io.File dir, java.lang.String filename, boolean compressed)
IOException
s
gets caught and logged, but not re-thrown.out
- dump destinationdir
- directory, which should contains the file.filename
- the basename of the file to dump.compressed
- if true
the denoted file is assumed to be
gzipped.true
on success (everything read and written).java.lang.NullPointerException
- if a parameter is null
.public static boolean dump(java.io.Writer out, java.io.File file, boolean compressed)
IOException
s
gets caught and logged, but not re-thrown.out
- dump destinationfile
- file to dump.compressed
- if true
the denoted file is assumed to be
gzipped.true
on success (everything read and written).java.lang.NullPointerException
- if a parameter is null
.public static java.lang.String jsStringLiteral(java.lang.String str)
str
- the string to be represented by the literal