FileLookup.java revision 5c099afa7c9361afc2f4477fec0e3018588d7840
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
*
* 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.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: FileLookup.java,v 1.4 2008/06/25 05:53:05 qcheng Exp $
*
*/
/**
* This class provides a generic file path generation utility for
* data file types, be it template, JSP, or property.
*
* FileLookup should follow the same look up pattern of the Java
* Resource Bundle Lookup. Failure to do so results in messages in mixed
* languages. With the Java lookup mechanism, if the platform locale is
* ja_JP and the Resource Bundle locale is zh_CN, the lookup
* sequence is rb_zh_CN, rb_zh, rb_JA_JP, rb_ja, rb. We can not fall
* back to rb if the zh resource bundle is not found. Hence, we have
* added more steps to file lookup
*/
public class FileLookup {
private static int numberOfPlatformLocales = 0;
private static String[] platformLocales;
static {
numberOfPlatformLocales++; // one for the entire localename
int idx = 0;
while (idx != -1) {
if (idx != -1) {
numberOfPlatformLocales++; // and one for each variant
}
}
idx = 0;
int i = 1;
while (idx != -1) {
if (idx != -1) {
platformLocales[i++] = thisPartOfStr;
}
}
}
/**
* Returns all possible paths for the specified file in an ordered array.
* If all parameters specified are non-null, then the order of the
* filepaths is generated in the following manner:
* <type>_<locale>/<component>/<clientPath>/<filename>
* <type>_<locale>/<component>/<filename>
* <type>_<locale>/<component>/<orgPath>/<clientPath>/<filename>
* <type>_<locale>/<component>/<orgPath>/<filename>
* <type>_<locale>/<clientPath>/<filename>
* <type>_<locale>/<filename>
* Repeat pattern above, taking off the ending "_xx" portion
* of the locale. For example, if the original <locale> value
* was "jp_JP_WIN", then the above would be <type>_jp_JP_WIN.
* The next groups would be <type>_jp_JP and <type>_jp.
*
* If the platform locale is different from the specified locale,
* then the pattern for <locale> is repeated with the platform
* locale, with the addition of using no "_<locale>" (i.e.,
* the last set consists of "<type>/...").
*
* Additionally, "default" is used as "<type>", and the above
* patterns are repeated.
*
*
* @param type The base filepath to begin the search. If null, "default"
* is the start of the filepath.
* @param locale The locale for the file of interest.
* @param component The component part of the filepath, if any.
* @param orgPath The organization part of the filepath, if any.
* @param clientPath The client type for that part of the filepath
* @param filename The filename of interest
* @throws FileLookupException
* @return <code>File[]</code> of ordered search paths.
*/
public static File[] getOrderedPaths(
) throws FileLookupException {
throw new FileLookupException("filename is null");
}
if (debug.messageEnabled()) {
+ filename);
}
int numberOfTypes = 1;
boolean haveType = false;
int orderedPathLength;
/*
* probably would be easier to add type = "default" automatically, then
* we wouldn't have to process it separately later... you get "type" (if
* it's not null or == "default") and "default"
*/
haveType = true;
}
if (haveType) {
orderedPathLength = 2;
} else {
orderedPathLength = 1;
}
/*
* see how many parts to the locale. one part: e.g., "fr"; or two part:
* e.g., "fr_FR" three part: e.g., "jp_JP_WIN"
*/
int indexOfLastUS = 0;
int i = 1;
if (debug.messageEnabled()) {
}
// locale specified
numberOfLocales++; // one for the entire localename
while (indexOfLastUS != -1) {
if (indexOfLastUS != -1) {
numberOfLocales++; // and one for each variant
}
}
frontOfStr = locale;
// add one for dummy null locale
indexOfLastUS = 0;
while (indexOfLastUS != -1) {
if (indexOfLastUS != -1) {
locales[i++] = thisPartOfStr;
}
}
} else {
i = 0;
}
// add platform locale to the locale array
for (int j = 0; j < numberOfPlatformLocales; j++) {
locales[i++] = platformLocales[j];
}
locales[i++] = NULL_LOCALE;
if (numberOfLocales > 1) {
}
boolean haveClientPath = false;
haveClientPath = true;
}
boolean haveComponent = false;
haveComponent = true;
orderedPathLength *= 2;
}
boolean haveOrgPath = false;
haveOrgPath = true;
}
int numberOfOrderedPaths = 0;
for (i = 0; i < numberOfTypes; i++) {
for (int j = 0; j < numberOfLocales; j++) {
} else {
+ (UNDERSCORE + locales[j]);
}
}
if (haveComponent) {
if (haveClientPath) {
while (len > 0) {
len--;
}
}
/*
* no clientPath specified thisFilePath =
*/
}
/*
* if orgPath is not null do the following this is used by auth
*/
if (haveOrgPath) {
int z = 0;
while (orgKeys > 0) {
if (haveClientPath) {
while (len > 0) {
len);
len--;
}
}
filename);
orgKeys--;
}
}
/*
* have a component, but don't include it. use the clientPath,
* if specified
*/
if (haveClientPath) {
while (len > 0) {
} else {
+ locales[j];
}
len--;
}
}
// no component, no orgPath ,no clientkeys
} else {
}
filename);
} // end for (int j = 0; j < numberOfLocales; j++)
} // end for (int i = 0; i < numberOfTypes; i++)
return orderedPaths;
}
/**
* Return the first existing file in the ordered search paths.
*
* @param type An arbitrary profile-stored string
* @param locale The locale for the file of interest.
* @param component The component part of the filepath, if any.
* @param clientPath The client type for that part of the filepath
* @param filename The filename of interest
* @param templateDir
* @param enableCache
* @return first existing file in the ordered search paths.
* @throws FileLookupException
*/
public static File getFirstExisting(
boolean enableCache
) throws FileLookupException {
}
/**
* Returns the first existing file in the ordered search paths.
*
* @param type The base filepath to begin the search.
* @param locale The locale for the file of interest.
* @param component The component part of the filepath, if any.
* @param clientPath The client type for that part of the filepath.
* @param orgFilePath The organization part of the filepath.
* @param filename The filename of interest
* @param templateDir The base template filepath to prepend.
* @param enableCache True if the File object is to be cached.
* @return first existing file in the ordered search paths.
* @throws FileLookupException
*/
public static File getFirstExisting(
boolean enableCache
) throws FileLookupException {
+ templateDir;
if (debug.messageEnabled()) {
}
if (enableCache) {
if (debug.messageEnabled()) {
}
return temp0;
}
}
if (debug.messageEnabled()) {
+ orderedPaths.length);
}
if (debug.messageEnabled()) {
+ orderedPaths[i].toString());
}
if (debug.messageEnabled()) {
}
if (enableCache) {
synchronized (fileTable) {
} else {
}
}
}
return file;
}
}
return null;
}
/**
* Returns the first existing url found on the remote server. The search is
* done based on the users locale. If no document is found in the users
* locale the default locale will be searched.
*
* @param server Server where document is located
* @param type The base filepath to begin the search.
* @param locale The locale for the file of interest.
* @param filename The filename of interest.
* @return url of document, or null if no document was found.
* @throws FileLookupException
*/
public static String getFirstExistingRemote(
) throws FileLookupException {
filename);
// make sure the path starts with a '/'
}
if (debug.messageEnabled()) {
}
int responseCode = -1;
try {
} catch (MalformedURLException m) {
} catch (IOException ioerror) {
}
if (debug.messageEnabled()) {
}
return document;
}
}
if (debug.messageEnabled()) {
+ "; returning null");
}
return null;
}
/*
* Build client path based on the client keys.
*/
for (int i = 0; i < len; i++) {
}
}
/*
* Tokenize clientPath on "/".
*/
for (int i = 0; i < numTokens; i++) {
}
return keyArray;
}
for (int i = 0; i < numTokens; i++) {
if (k != -1) {
}
}
return keyArray;
}
return filePath;
}
}