Util.java revision 1145
0N/A * The contents of this file are subject to the terms of the 0N/A * Common Development and Distribution License (the "License"). 0N/A * You may not use this file except in compliance with the License. 0N/A * language governing permissions and limitations under the License. 0N/A * When distributing Covered Code, include this CDDL HEADER in each 0N/A * If applicable, add the following below this CDDL HEADER, with the 0N/A * fields enclosed by brackets "[]" replaced with your own identifying 0N/A * information: Portions Copyright [yyyy] [name of copyright owner] 0N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 561N/A * File for useful functions 0N/A * Return a string which represents a <code>CharSequence</code> in HTML. 493N/A * @param q a character sequence 493N/A * @return a string representing the character sequence in HTML 493N/A // Util class, should not be constructed 493N/A * Append a character sequence to an <code>Appendable</code> object. Escape 493N/A * special characters for HTML. 493N/A * @param q a character sequence 493N/A * @param out the object to append the character sequence to 0N/A * @exception IOException if an I/O error occurs 493N/A * Append a character sequence to a <code>StringBuilder</code> 493N/A * object. Escape special characters for HTML. This method is identical to 493N/A * <code>htmlize(CharSequence,Appendable)</code>, except that it is 493N/A * guaranteed not to throw <code>IOException</code> because it uses a 493N/A * <code>StringBuilder</code>. 0N/A * @param q a character sequence 0N/A * @param out the object to append the character sequence to 0N/A * @see #htmlize(CharSequence, Appendable) 561N/A // StringBuilder's append methods are not declared to throw 561N/A // IOException, so this should never happen. 561N/A * Append a character to a an <code>Appendable</code> object. If the 561N/A * character has special meaning in HTML, append a sequence of characters 561N/A * representing the special character. 561N/A * @param c the character to append 561N/A * @param out the object to append the character to 561N/A * @exception IOException if an I/O error occurs 0N/A * used by BUI - CSS needs this parameter for proper cache refresh (per changeset) in client browser 493N/A * @return html escaped version (hg changeset) 493N/A * Same as {@code breadcrumbPath(urlPrefix, l, '/')}. 493N/A * @see #breadcrumbPath(String, String, char) 493N/A * Same as {@code breadcrumbPath(urlPrefix, l, sep, "", false)}. 561N/A * @see #breadcrumbPath(String, String, char, String, boolean) 493N/A * Create a breadcrumb path to allow navigation to each element of a path. 493N/A * @param urlPrefix what comes before the path in the URL 493N/A * @param l the full path from which the breadcrumb path is built 493N/A * @param sep the character that separates the path elements in {@code l} 493N/A * @param urlPostfix what comes after the path in the URL 493N/A * @param compact if {@code true}, remove {@code ..} and empty path 493N/A * elements from the path in the links 493N/A * @return HTML markup for the breadcrumb path 0N/A * Leave a breadcrumb to allow navigation to one of the parent directories. 0N/A * Write a hyperlink to the specified {@code StringBuilder}. 493N/A * @param urlPrefix what comes before the path in the URL 355N/A * @param sep the character that separates path elements 493N/A * @param urlPostfix what comes after the path in the URL 493N/A * @param compact if {@code true}, remove {@code ..} and empty path 493N/A * elements from the path in the link 493N/A * @param hyperl a string builder to which the hyperlink is written 493N/A * @param path all the elements of the full path 493N/A * @param index which path element to create a link to 493N/A // Only generate the link if the path element is non-empty. Empty 493N/A // path elements could occur if the path contains two consecutive 368N/A // separator characters, or if the path begins or ends with a path 595N/A // Add a separator between each path element, but not after the last 0N/A // one. If the original path ended with a separator, the last element 493N/A // of the path array is an empty string, which means that the final 0N/A // separator will be printed. 0N/A * Append parts of a file path to a {@code StringBuilder}. Separate each 0N/A * element in the path with "/". The path elements from index 0 up to 493N/A * index {@code lastIndex} (inclusive) are used. 0N/A * @param path array of path elements 0N/A * @param lastIndex the index of the last path element to use 0N/A * @param out the {@code StringBuilder} to which the path is appended 0N/A * @param compact if {@code true}, remove {@code ..} and empty path 493N/A * elements from the path in the link 493N/A // Copy the relevant part of the path. If compact is false, just 561N/A // copy the lastIndex first elements. If compact is true, remove empty 561N/A // path elements, and follow .. up to the parent directory. Occurrences 561N/A // of .. at the beginning of the path will be removed. 493N/A // Print the path with / between each element. No separator before 493N/A // the first element or after the last element. 0N/A * Generate a regex that matches the specified character. Escape it in 0N/A * case it is a character that has a special meaning in a regex. 0N/A * @param c the character that the regex should match 493N/A * @return a six-character string on the form <tt>\u</tt><i>hhhh</i> 0N/A }
else if (l <
1048576) {
* Converts different html special characters into their encodings used in html * currently used only for tooltips of annotation revision number view * @return encoded text for use in <a title=""> tag for (
int i =
0; i < s.
length(); i++) {
out.
write((
num >
999 ?
" " : (
num >
99 ?
" " : (
num >
9 ?
" " :
" "))));
out.
write(
"<span class=\"blame\"><span class=\"l\"> ");
* 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 // Should not happen. UTF-8 must be supported by JVMs. for (
int i =
0; i < q.
length(); i++) {
* Highlight the diffs between line1 and line2 * @return new strings with html tags highlighting the diffs * Dump the configuration as an HTML table. * @param out destination for the HTML output * @throws IOException if an error happens while writing to {@code out} * @throws HistoryException if the history guru cannot be accesses out.
append(
"<table border=\"1\" width=\"100%\">");
out.
append(
"<tr><th>Variable</th><th>Value</th></tr>");
out.
append(
"<tr><td>Ignored files</td><td>");
* Print a row in an HTML table. * @param out destination for the HTML output * @param cells the values to print in the cells of the row * @throws IOException if an error happens while writing to {@code out} * Print an unordered list (HTML). * @param out destination for the HTML output * @param items the list items * @throws IOException if an error happens while writing to {@code out} * Create a string literal for use in JavaScript functions. * @param str the string to be represented by the literal * @return a JavaScript string literal