Util.java revision 1297
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * CDDL HEADER START
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * The contents of this file are subject to the terms of the
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * Common Development and Distribution License (the "License").
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * You may not use this file except in compliance with the License.
8b7e19de6d547ab1ad4256316fbf0d2497f724f8humbedooh * See LICENSE.txt included in this distribution for the specific
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * language governing permissions and limitations under the License.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * When distributing Covered Code, include this CDDL HEADER in each
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * file and include the License file at LICENSE.txt.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * If applicable, add the following below this CDDL HEADER, with the
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * fields enclosed by brackets "[]" replaced with your own identifying
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * information: Portions Copyright [yyyy] [name of copyright owner]
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * CDDL HEADER END
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
8b7e19de6d547ab1ad4256316fbf0d2497f724f8humbedooh * Portions Copyright 2011 Jens Elkner.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aendimport org.opensolaris.opengrok.configuration.RuntimeEnvironment;
8b7e19de6d547ab1ad4256316fbf0d2497f724f8humbedoohimport org.opensolaris.opengrok.history.HistoryException;
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * Class for useful functions.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aendpublic final class Util {
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend // singleton
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * Return a string which represents a <code>CharSequence</code> in HTML.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param q
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * a character sequence
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @return a string representing the character sequence in HTML
8b7e19de6d547ab1ad4256316fbf0d2497f724f8humbedooh StringBuilder sb = new StringBuilder(q.length() * 2);
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * Append a character sequence to the given destination whereby
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * special characters for HTML are escaped accordingly.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param q a character sequence to esacpe
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param dest where to append the character sequence to
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend public static void htmlize(CharSequence q, StringBuilder dest) {
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * Append a character array to the given destination whereby
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * special characters for HTML are escaped accordingly.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param cs characters to esacpe
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param length max. number of characters to append, starting from index 0.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param dest where to append the character sequence to
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend public static void htmlize(char[] cs, int length, StringBuilder dest) {
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * Append a character to the given destination whereby special characters
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * special for HTML are escaped accordingly.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param c the character to append
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param dest where to append the character to
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend private static void htmlize(char c, StringBuilder dest) {
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend switch (c) {
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend case '\n':
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend private static String versionP = htmlize(Info.getRevision());
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * used by BUI - CSS needs this parameter for proper cache refresh (per
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * changeset) in client browser jel: but useless, since the page cached
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @return html escaped version (hg changeset)
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * Convinience method for {@code breadcrumbPath(urlPrefix, path, '/')}.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param urlPrefix prefix to add to each url
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param path path to crack
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @return HTML markup fro the breadcrumb or the path itself.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @see #breadcrumbPath(String, String, char)
15e38d431fea66258ef33960b39edee496c3c9c2humbedooh public static String breadcrumbPath(String urlPrefix, String path) {
15e38d431fea66258ef33960b39edee496c3c9c2humbedooh private static final String anchorLinkStart = "<a href=\"";
15e38d431fea66258ef33960b39edee496c3c9c2humbedooh private static final String anchorClassStart = "<a class=\"";
15e38d431fea66258ef33960b39edee496c3c9c2humbedooh * Convenience method for
1050464f9f91f75e7a1c5c3daf3fb7b8aa74592ahumbedooh * {@code breadcrumbPath(urlPrefix, path, sep, "", false)}.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param urlPrefix prefix to add to each url
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param path path to crack
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param sep separator to use to crack the given path
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @return HTML markup fro the breadcrumb or the path itself.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @see #breadcrumbPath(String, String, char, String, boolean, boolean)
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend public static String breadcrumbPath(String urlPrefix, String path, char sep)
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * Convenience method for
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * {@code breadcrumbPath(urlPrefix, path, sep, "", false, path.endsWith(sep)}.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param urlPrefix prefix to add to each url
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param path path to crack
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param sep separator to use to crack the given path
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param urlPostfix suffix to add to each url
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param compact if {@code true} the given path gets transformed into
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * its canonical form (.i.e. all '.' and '..' and double separators
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * removed, but not always resolves to an absolute path) before processing
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @return HTML markup fro the breadcrumb or the path itself.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @see #breadcrumbPath(String, String, char, String, boolean, boolean)
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @see #getCanonicalPath(String, char)
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend public static String breadcrumbPath(String urlPrefix, String path,
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend return breadcrumbPath(urlPrefix, path, sep, urlPostfix, compact,
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * Create a breadcrumb path to allow navigation to each element of a path.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * Consecutive separators (<var>sep</var>) in the given <var>path</var> are
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * always collapsed into a single separator automatically. If
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * <var>compact</var> is {@code true} path gets translated into a canonical
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * path similar to {@link File#getCanonicalPath()}, however the current
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * working directory is assumed to be "/" and no checks are done (e.g.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * neither whether the path [component] exists nor which type it is).
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param urlPrefix
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * what should be prepend to the constructed URL
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param path
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * the full path from which the breadcrumb path is built.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * @param sep
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * the character that separates the path components in
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend * <var>path</var>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd * @param urlPostfix
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * what should be append to the constructed URL
727872d18412fc021f03969b8641810d8896820bhumbedooh * @param compact
0d0ba3a410038e179b695446bb149cce6264e0abnd * if {@code true}, a canonical path gets constructed before
727872d18412fc021f03969b8641810d8896820bhumbedooh * processing.
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh * @param isDir
0d0ba3a410038e179b695446bb149cce6264e0abnd * if {@code true} a "/" gets append to the last path component's
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh * link and <var>sep</var> to its name
727872d18412fc021f03969b8641810d8896820bhumbedooh * @return <var>path</var> if it resolves to an empty or "/" or
0d0ba3a410038e179b695446bb149cce6264e0abnd * {@code null} path, the HTML markup for the breadcrumb path otherwise.
0d0ba3a410038e179b695446bb149cce6264e0abnd public static String breadcrumbPath(String urlPrefix, String path,
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh char sep, String urlPostfix, boolean compact, boolean isDir)
0d0ba3a410038e179b695446bb149cce6264e0abnd String[] pnames = normalize(path.split(escapeForRegex(sep)), compact);
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd StringBuilder pwd = new StringBuilder(path.length() + pnames.length);
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd new StringBuilder( (pnames.length + 3 >> 1) * path.length()
return email;
if (canonical) {
.size()]);
float l = num;
char c = s.charAt(i);
throws IOException
if (enabled) {
if (enabled) {
} catch (UnsupportedEncodingException e) {
Logger.getLogger(EftarFileReader.class.getName()).log(Level.WARNING, "Failed to URL-encode UTF-8: ", e);
return null;
c = q.charAt(i);
return ret;
.getCacheInfo());
boolean compressed)
if (compressed) {
} catch(IOException e) {
throws IOException