0N/A * The contents of this file are subject to the terms of the 407N/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] 1297N/A * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 1356N/A * Portions Copyright 2011, 2012 Jens Elkner. 1185N/A * Class for useful functions. 1469N/A * Replace all HTML special characters '&', '<', '>' in the given String 1469N/A * with their corresponding HTML entity references. 1469N/A * @param s string to htmlize 1469N/A * @return <var>s</var> if it doesn't contain a special character, a new 1469N/A if (c ==
'>' || c ==
'<' || c ==
'&') {
1469N/A // since we can't copy sequences efficiently we copy char by char :( 1469N/A * Replace all HTML special characters '&', '<', '>' AND linefeeds ('\n') 1469N/A * in the given String with their corresponding HTML entity references. 1469N/A * @param s string to htmlize 1469N/A * @param eol the replacement to use for linefeeds ('\n') 1469N/A * @return <var>s</var> if it doesn't contain a special character, a new 1469N/A if (c ==
'>' || c ==
'<' || c ==
'&' || c ==
'\n') {
1469N/A // since we can't copy sequences efficiently we copy char by char :( 1185N/A * used by BUI - CSS needs this parameter for proper cache refresh (per 1185N/A * changeset) in client browser jel: but useless, since the page cached 990N/A * @return html escaped version (hg changeset) 1185N/A * Convinience method for {@code breadcrumbPath(urlPrefix, path, '/')}. 1185N/A * @param urlPrefix prefix to add to each url 1185N/A * @param path path to crack 1185N/A * @return HTML markup fro the breadcrumb or the path itself. 604N/A * @see #breadcrumbPath(String, String, char) 1185N/A * {@code breadcrumbPath(urlPrefix, path, sep, "", false)}. 1185N/A * @param urlPrefix prefix to add to each url 1185N/A * @param path path to crack 1185N/A * @param sep separator to use to crack the given path 1185N/A * @return HTML markup fro the breadcrumb or the path itself. 1185N/A * @see #breadcrumbPath(String, String, char, String, boolean, boolean) 1185N/A * {@code breadcrumbPath(urlPrefix, path, sep, "", false, path.endsWith(sep)}. 1185N/A * @param urlPrefix prefix to add to each url 1185N/A * @param path path to crack 1185N/A * @param sep separator to use to crack the given path 1185N/A * @param urlPostfix suffix to add to each url 1185N/A * @param compact if {@code true} the given path gets transformed into 1190N/A * its canonical form (.i.e. all '.' and '..' and double separators 1190N/A * removed, but not always resolves to an absolute path) before processing 1185N/A * @return HTML markup fro the breadcrumb or the path itself. 1185N/A * @see #breadcrumbPath(String, String, char, String, boolean, boolean) 1185N/A * @see #getCanonicalPath(String, char) 604N/A * Create a breadcrumb path to allow navigation to each element of a path. 1185N/A * Consecutive separators (<var>sep</var>) in the given <var>path</var> are 1185N/A * always collapsed into a single separator automatically. If 1185N/A * <var>compact</var> is {@code true} path gets translated into a canonical 1185N/A * path similar to {@link File#getCanonicalPath()}, however the current 1185N/A * working directory is assumed to be "/" and no checks are done (e.g. 1185N/A * neither whether the path [component] exists nor which type it is). 1185N/A * what should be prepend to the constructed URL 1185N/A * the full path from which the breadcrumb path is built. 1185N/A * the character that separates the path components in 1185N/A * what should be append to the constructed URL 1185N/A * if {@code true}, a canonical path gets constructed before 1185N/A * if {@code true} a "/" gets append to the last path component's 1185N/A * link and <var>sep</var> to its name 1190N/A * @return <var>path</var> if it resolves to an empty or "/" or 1185N/A * {@code null} path, the HTML markup for the breadcrumb path otherwise. 1190N/A * Normalize the given <var>path</var> to its canonical form. I.e. all 1190N/A * separators (<var>sep</var>) are replaced with a slash ('/'), all 1185N/A * double slashes are replaced by a single slash, all single dot path 1190N/A * components (".") of the formed path are removed and all double dot path 1190N/A * components (".." ) of the formed path are replaced with its parent or 1185N/A * '/' if there is no parent. 1185N/A * So the difference to {@link File#getCanonicalPath()} is, that this method 1185N/A * does not hit the disk (just string manipulation), resolves <var>path</var> 1190N/A * always against '/' and thus always returns an absolute path, which may 1190N/A * actually not exist, and which has a single trailing '/' if the given 1190N/A * <var>path</var> ends with the given <var>sep</var>. 1190N/A * @param path path to mangle. If not absolute or {@code null}, the 1185N/A * current working directory is assumed to be '/'. 1185N/A * @param sep file separator to use to crack <var>path</var> into path 1185N/A * @return always a canonical path which starts with a '/'. 1190N/A // since is not a general purpose method. So we waive to handle 1185N/A // || path.endsWith("/..") || path.endsWith("/.") 1297N/A * Get email address of the author. 1297N/A * string containing author and possibly email address. 1384N/A * @return the first email address found in the given parameter, the 1384N/A * parameter otherwise. Returned values are whitespace trimmed. 1185N/A * Remove all empty and {@code null} string elements from the given 1185N/A * <var>names</var> and optionally all redundant information like "." and 1185N/A * if {@code true}, remove redundant elements as well. 1185N/A * @return a possible empty array of names all with a length > 0. 1185N/A * Generate a regex that matches the specified character. Escape it in case 1185N/A * it is a character that has a special meaning in a regex. 1185N/A * the character that the regex should match 604N/A * @return a six-character string on the form <tt>\u</tt><i>hhhh</i> 1185N/A * Convert the given size into a human readable string. 1185N/A * @param num size to convert. 1185N/A * @return a readable string 154N/A }
else if (l <
1048576) {
1185N/A * Generate a string from the given path and date in a way that allows 1190N/A * stable lexicographic sorting (i.e. gives always the same results) as a 1190N/A * walk of the file hierarchy. Thus null character (\u0000) is used both 1185N/A * to separate directory components and to separate the path from the date. 1185N/A * @param path path to mangle. 1185N/A * @param date date string to use. 1185N/A * @return the mangled path. 1190N/A * The reverse operation for {@link #path2uid(String, String)} - re-creates 1185N/A * the unmangled path from the given uid. 1185N/A * @param uid uid to unmangle. 1185N/A * @return the original path. 1469N/A * Append '&name=value" properly URI encoded to the given buffer. If 1469N/A * the given <var>value</var> is {@code null}, this method does nothing. 1185N/A * @param buf where to append the query string 1185N/A * @param key the name of the parameter to add. Append as is! 1469N/A * @param value the decoded value for the given parameter. 1185N/A * @throws NullPointerException if the given buffer is {@code null}. 1469N/A * @see #uriEncodeQueryValue(String) 1469N/A /* ASCII chars 0..63, which need to be escaped in an URI path. The segment 1469N/A * delimiter '/' (47) is not added to this set, because it is used to 1469N/A * encode file pathes which use the same delimiter for path components. 1469N/A * Since we do not use any path parameters we add ';' (59) as well. 1469N/A * Furthermore to avoid the need of a 2nd run to escape '&' for HTML 1469N/A * attributes, we encode '&' (38) as well. 1469N/A * RFC 3986: chars 0..32 34 35 37 60 62 63 */ 1469N/A |
1L<<
'%' |
1L<<
'<' |
1L<<
'>' |
1L<<
'?' |
1L<<
';' |
1L<<
'&';
1469N/A /* RFC 3986: path-noscheme - ':' (58) in the first segment needs to be encoded */ 1469N/A /* ASCII chars 64..127, which need to be escaped in an URI path. 1366N/A * NOTE: URIs allow '~' unescaped, URLs not. 1469N/A * RFC 3986: chars 91 92 93 94 96 123 124 125 127 */ 1366N/A |
1L<<
'^'-
64 |
1L<<
'`'-
64 |
1L<<
'{'-
64 |
1L<<
'|'-
64 |
1L<<
'}'-
64 |
1L<<
63;
1469N/A /* ASCII chars 0..63, which need to be escaped in an URI query string as 1469N/A * RFC 3986: chars 32 34 35 37 60 62 */ 1469N/A /* ASCII chars 64..127, which need to be escaped in an URI query string as 1469N/A * RFC 3986: chars 91 92 93 94 96 123 124 125 127 */ 1469N/A /* Query string starts at the left-most '?', ends at the next '#' or if not 1469N/A * of the form $name['='[$value]] delimited by '&'. So no need to encode '=' 1469N/A * for query values, but for query names. */ 1472N/A /** Loose check, whether we have an entity reference: either #[0-9A-Fa-f]*; 1472N/A if (c ==
'x' || c ==
'X') {
1472N/A if ( ! ((
'0' <= c && c <=
'9') || (
'A' <= c && c <=
'F')
1472N/A || (
'a' <= c && c <=
'f')))
1472N/A if ( ! (
'0' <= c && c <=
'9')) {
1472N/A if ( ! ((
'A' <= c && c <=
'Z') || (
'a' <= c && c <=
'z'))) {
1472N/A * Tries to URI encode a URL. Difference to {@link #uriEncodePath(String)} 1472N/A * is, that this method tries to find out, whether the URL already contains 1472N/A * escaped characters and thus avoids double-encoding HTML special chars. 1472N/A * NOTE: As soon as an entity reference is encountered, encoding stops and 1472N/A * assumes an already encoded URL - the parameter gets returned as is! 1472N/A * @return the URI encoded URL 1469N/A * URI encode the given path using UTF-8 encoding for non-ASCII characters. 1469N/A * In addition ';', '&' (and ':' for relative paths) get encoded as well, 1469N/A * but not '/'. This method should not be used to encode query strings - for 1469N/A * this {@link #uriEncodeQueryName(String)} and 1469N/A * {@link #uriEncodeQueryValue(String)} should be used. 1469N/A * NOTE: Since single quote (') gets not encoded, the encoded result should 1469N/A * be enclosed in double quotes (") when used as attribute values! 1469N/A * @param path path to encode. 1469N/A * @return the encoded path. 1469N/A * @throws NullPointerException if a parameter is {@code null} 1469N/A * URI encode the given value for a URI query string pair using UTF-8 1469N/A * encoding for non-ASCII characters ('&' gets encoded as well). It can also 1469N/A * be used to encode URI fragments properly. 1469N/A * NOTE: Since single quote (') gets not encoded, the encoded result should 1469N/A * be enclosed in double quotes (") when used as attribute values! 1469N/A * @param value value to encode. 1469N/A * @return the encoded value. 1469N/A * @throws NullPointerException if a parameter is {@code null} 1469N/A * @see #uriEncodeQueryName(String) 1469N/A * URI encode the given name for a URI query string pair using UTF-8 1469N/A * encoding for non-ASCII characters ('=' and '&' get encoded as well). 1469N/A * NOTE: Since single quote (') gets not encoded, the encoded result should 1469N/A * be enclosed in double quotes (") when used as attribute values! 1469N/A * @param name name to encode. 1469N/A * @return the encoded name. 1469N/A * @throws NullPointerException if a parameter is {@code null} 1469N/A * @see #uriEncodeQueryValue(String) 1469N/A /* int -> hex encoding helper */ 1469N/A * Replace all quote and ampersand characters (ASCII 0x22, 0x26) with the 1469N/A * corresponding html entity (&quot; , &amp;). 1185N/A * @param q string to escape. 1190N/A * @return an empty string if a parameter is {@code null}, the mangled 1469N/A if (c ==
'"' || c ==
'&') {
1388N/A /** span open tag incl. css class used to tag removed source code */ 1388N/A /** span open tag incl. css class used to tag added source code */ 1185N/A * Tag changes in the given <var>line1</var> and <var>line2</var> 1185N/A * for highlighting. Removed parts are tagged with CSS class {@code d}, 1185N/A * new parts are tagged with CSS class {@code a} using a {@code span} 1185N/A * @param line1 line of the original file 1185N/A * @return the tagged lines (field[0] ~= line1, field[1] ~= line2). 1190N/A * @throws NullPointerException if one of the given parameters is {@code null}. 1124N/A * Dump the configuration as an HTML table. 1185N/A * destination for the HTML output 1185N/A * if an error happens while writing to {@code out} 1185N/A * if the history guru cannot be accesses 1384N/A * Just read the given source and dump as is to the given destination. 1190N/A * Does nothing, if one or more of the parameters is {@code null}. 1185N/A * @param out write destination 1185N/A * @throws NullPointerException if a parameter is {@code null}. 1384N/A * Silently dump a file to the given destination. All {@link IOException}s 1185N/A * gets caught and logged, but not re-thrown. 1185N/A * @param out dump destination 1185N/A * @param dir directory, which should contains the file. 1185N/A * @param filename the basename of the file to dump. 1185N/A * @param compressed if {@code true} the denoted file is assumed to be 1185N/A * @return {@code true} on success (everything read and written). 1185N/A * @throws NullPointerException if a parameter is {@code null}. 1384N/A * Silently dump a file to the given destination. All {@link IOException}s 1185N/A * gets caught and logged, but not re-thrown. 1185N/A * @param out dump destination 1185N/A * @param file file to dump. 1185N/A * @param compressed if {@code true} the denoted file is assumed to be 1185N/A * @return {@code true} on success (everything read and written). 1185N/A * @throws NullPointerException if a parameter is {@code null}. 1124N/A * Print a row in an HTML table. 1185N/A * destination for the HTML output 1185N/A * the values to print in the cells of the row 1185N/A * if an error happens while writing to {@code out} 1124N/A * Print an unordered list (HTML). 1185N/A * destination for the HTML output 1185N/A * if an error happens while writing to {@code out} 1145N/A * Create a string literal for use in JavaScript functions. 1384N/A * @param str the string to be represented by the literal 1384N/A * @return a JavaScript string literal. {@code null} values are converted to ''. 1384N/A * Convert the given array into JSON format and write it to the given stream. 1384N/A * If <var>name</var> is given, the result is {@code name: [ value, ...]}, 1384N/A * otherwise {@code [ value, ... ]}. 1384N/A * @param out where to write the json formatted array 1384N/A * @param name name of the array. Might be {@code null}. 1384N/A * @param values array to convert. {@code null} are converted to ''. 1384N/A * @see #jsStringLiteral(String) 1384N/A * @see #writeJsonArray(Writer, String, String[]) 1384N/A // could just call writeJsonArray(out, name, values.toArray(new String[])) 1384N/A // but this can be an issue for big collections - so we rather 1384N/A * Convert the given array into JSON format and write it to the given stream. 1384N/A * If <var>name</var> is given, the result is {@code name: [ value, ...]}, 1384N/A * otherwise {@code [ value, ... ]}. 1384N/A * @param out where to write the json formatted array 1384N/A * @param name name of the array. Might be {@code null}. 1384N/A * @param values array to convert. {@code null} are converted to ''. 1384N/A * @see #jsStringLiteral(String) 1384N/A * @see #writeJsonArray(Writer, String, Collection)