Util.java revision 1025
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/**
* File for useful functions
*/
public final class Util {
/**
* Return a string which represents a <code>CharSequence</code> in HTML.
*
* @param q a character sequence
* @return a string representing the character sequence in HTML
*/
private Util() {
// Util class, should not be constructed
}
}
/**
* Append a character sequence to an <code>Appendable</code> object. Escape
* special characters for HTML.
*
* @param q a character sequence
* @param out the object to append the character sequence to
* @exception IOException if an I/O error occurs
*/
throws IOException {
for (int i = 0; i < q.length(); i++) {
}
}
/**
* Append a character sequence to a <code>StringBuilder</code>
* object. Escape special characters for HTML. This method is identical to
* <code>htmlize(CharSequence,Appendable)</code>, except that it is
* guaranteed not to throw <code>IOException</code> because it uses a
* <code>StringBuilder</code>.
*
* @param q a character sequence
* @param out the object to append the character sequence to
* @see #htmlize(CharSequence, Appendable)
*/
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
try {
} catch (IOException ioe) {
// StringBuilder's append methods are not declared to throw
// IOException, so this should never happen.
}
}
throws IOException {
}
}
/**
* Append a character to a an <code>Appendable</code> object. If the
* character has special meaning in HTML, append a sequence of characters
* representing the special character.
*
* @param c the character to append
* @param out the object to append the character to
* @exception IOException if an I/O error occurs
*/
switch (c) {
case '&':
break;
case '>':
break;
case '<':
break;
case '\n':
break;
default:
}
}
/**
* used by BUI - CSS needs this parameter for proper cache refresh (per changeset) in client browser
* @return html escaped version (hg changeset)
*/
public static String versionParameter() {
return versionP;
}
/**
* Same as {@code breadcrumbPath(urlPrefix, l, '/')}.
* @see #breadcrumbPath(String, String, char)
*/
}
/**
* Same as {@code breadcrumbPath(urlPrefix, l, sep, "", false)}.
* @see #breadcrumbPath(String, String, char, String, boolean)
*/
}
/**
* Create a breadcrumb path to allow navigation to each element of a path.
*
* @param urlPrefix what comes before the path in the URL
* @param l the full path from which the breadcrumb path is built
* @param sep the character that separates the path elements in {@code l}
* @param urlPostfix what comes after the path in the URL
* @param compact if {@code true}, remove {@code ..} and empty path
* elements from the path in the links
* @return HTML markup for the breadcrumb path
*/
public static String breadcrumbPath(
boolean compact) {
return l;
}
}
}
/**
* Leave a breadcrumb to allow navigation to one of the parent directories.
* Write a hyperlink to the specified {@code StringBuilder}.
*
* @param urlPrefix what comes before the path in the URL
* @param sep the character that separates path elements
* @param urlPostfix what comes after the path in the URL
* @param compact if {@code true}, remove {@code ..} and empty path
* elements from the path in the link
* @param hyperl a string builder to which the hyperlink is written
* @param path all the elements of the full path
* @param index which path element to create a link to
*/
private static void leaveBreadcrumb(
// Only generate the link if the path element is non-empty. Empty
// path elements could occur if the path contains two consecutive
// separator characters, or if the path begins or ends with a path
// separator.
}
// Add a separator between each path element, but not after the last
// one. If the original path ended with a separator, the last element
// of the path array is an empty string, which means that the final
// separator will be printed.
}
}
/**
* Append parts of a file path to a {@code StringBuilder}. Separate each
* element in the path with "/". The path elements from index 0 up to
* index {@code lastIndex} (inclusive) are used.
*
* @param path array of path elements
* @param lastIndex the index of the last path element to use
* @param out the {@code StringBuilder} to which the path is appended
* @param compact if {@code true}, remove {@code ..} and empty path
* elements from the path in the link
*/
private static void appendPath(
// Copy the relevant part of the path. If compact is false, just
// copy the lastIndex first elements. If compact is true, remove empty
// path elements, and follow .. up to the parent directory. Occurrences
// of .. at the beginning of the path will be removed.
for (int i = 0; i <= lastIndex; i++) {
if (compact) {
}
}
} else {
}
}
// Print the path with / between each element. No separator before
// the first element or after the last element.
}
}
}
/**
* Generate a regex that matches the specified character. Escape it in
* case it is a character that has a special meaning in a regex.
*
* @param c the character that the regex should match
* @return a six-character string on the form <tt>\u</tt><i>hhhh</i>
*/
private static String escapeForRegex(char c) {
}
}
float l = (float) num;
if (l < 1024) {
} else if (l < 1048576) {
} else {
}
}
/**
* Converts different html special characters into their encodings used in html
* currently used only for tooltips of annotation revision number view
* @param s input text
* @return encoded text for use in <a title=""> tag
*/
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
switch (c) {
case '"':
break; // \\\"
case '&':
break;
case '>':
break;
case '<':
break;
case ' ':
break;
case '\t':
break;
case '\n':
break;
case '\r':
break;
default:
break;
}
}
}
throws IOException {
if (num > 1) {
}
out.write((num > 999 ? " " : (num > 99 ? " " : (num > 9 ? " " : " "))));
if (annotation != null) {
}
if (enabled) {
}
}
if (enabled) {
}
}
} else {
}
}
}
/**
* Append path and date into a string in such a way that lexicographic
* sorting gives the same results as a walk of the file hierarchy. Thus
* null (\u0000) is used both to separate directory components and to
* separate the path from the date.
*/
}
}
/**
* wrapper arround UTF-8 URL encoding of a string
* @param q query to be encoded
* @return null if fail, otherwise the encoded string
*/
try {
} catch (UnsupportedEncodingException e) {
// Should not happen. UTF-8 must be supported by JVMs.
return null;
}
}
try {
return uri.getRawPath();
} catch (URISyntaxException ex) {
return "";
}
}
if (q == null) {
return "";
}
char c;
for (int i = 0; i < q.length(); i++) {
c = q.charAt(i);
if (c == '"') {
} else {
}
}
}
/**
* Highlight the diffs between line1 and line2
* @param line1
* @param line2
* @return new strings with html tags highlighting the diffs
*/
int s=0;
{ s++; }
{ m--;n--; }
if(s <= m) {
} else {
}
if(s <= n) {
} else {
}
return ret;
}
}