cbutility.java
来自「JAVA开源LDAP浏览器jxplorer的源码!」· Java 代码 · 共 1,500 行 · 第 1/4 页
JAVA
1,500 行
// END XXX
return rawText;
}
char C;
StringBuffer temp = new StringBuffer(rawText);
for (int pos = 0; pos < temp.length(); pos++)
{
C = temp.charAt(pos);
switch (C)
{
case '<':
CBParse.replaceChar(temp, pos, "<");
break;
case '>':
CBParse.replaceChar(temp, pos, ">");
break;
case '&':
CBParse.replaceChar(temp, pos, "&");
break;
case '\"':
CBParse.replaceChar(temp, pos, """);
break;
case '#':
CBParse.replaceChar(temp, pos, "#");
pos++;
break;
}
}
return temp.toString();
}
/**
* Deletes a character in <i>text</i> at position <i>pos<i> and replaces
* it with the string <i>replacement</i>.
*
* @param text the text to be modified
* @param pos the position of the character to be deleted
* @param replacement the string the character is to be replaced with.
* @deprecated use CBParse method instead
*/
public static int replaceChar(StringBuffer text, int pos, String replacement)
{
text.deleteCharAt(pos);
text.insert(pos, replacement);
return (pos + replacement.length());
}
/**
* Deletes all characters <i>c</i> in <i>text</i> replaces
* it with the string <i>replacement</i>.
*
* @param text the text to be modified
* @param replacement the string the character is to be replaced with.
* @deprecated use CBParse method instead
*/
public static String replaceAllChar(StringBuffer text, char c, String replacement)
{
return CBParse.replaceAllBufferChar(text, c, replacement).toString();
}
/**
* Deletes all characters <i>c</i> in <i>text</i> replaces
* it with the string <i>replacement</i>.
*
* @param text the text to be modified
* @param replacement the string the character is to be replaced with.
* @deprecated use CBParse method instead
*/
public static StringBuffer replaceAllBufferChar(StringBuffer text, char c, String replacement)
{
int pos = 0;
while (pos != -1)
{
pos = text.toString().indexOf(c, pos);
if (pos != -1)
pos = CBParse.replaceChar(text, pos, replacement);
}
return text;
}
/**
* Deletes a substring in <i>text</i> at position <i>pos<i>, of length <i>len</i> and replaces
* it with the string <i>replacement</i>.
*
* @param text the text to be modified
* @param pos the position of the character to be deleted
* @param replacement the string the character is to be replaced with.
* @deprecated use CBParse method instead
*/
public static int replaceString(StringBuffer text, int pos, int len, String replacement)
{
text.replace(pos, pos + len, replacement);
//text.delete(pos, pos+len);
//text.insert(pos, replacement);
return (pos + replacement.length());
}
/**
* Deletes all characters <i>orig</i> in <i>text</i> and replaces
* it with the string <i>replacement</i>.
*
* @param text the text to be modified
* @param orig the original text substring to be changed
* @param replacement the string the original substring is to be replaced with.
* @deprecated use CBParse method instead
*/
public static String replaceAllString(StringBuffer text, String orig, String replacement)
{
return CBParse.replaceAllBufferString(text, orig, replacement).toString();
}
/**
* Deletes all characters <i>orig</i> in <i>text</i> replaces
* it with the string <i>replacement</i>.
*
* @param text the text to be modified
* @param orig the original text substring to be changed
* @param replacement the string the original substring is to be replaced with.
* @deprecated use CBParse method instead
*/
public static StringBuffer replaceAllBufferString(StringBuffer text, String orig, String replacement)
{
int pos = 0;
while (pos != -1)
{
pos = text.toString().indexOf(orig, pos);
if (pos != -1)
pos = CBParse.replaceString(text, pos, orig.length(), replacement);
}
return text;
}
/**
* Utility for micro-parser. Gets the next character pos in a string
* after an initial offset that either matches, or does not match, <i>any</i>
* of a set of comparison characters.
*
* @param pos the position to start searching from
* @param searchMe the string to search
* @param compare a string containing characters to compare against
* @param match whether the match is for characters in the compare string (true)
* or <i>not</i> in the compare string (false)
* @return the position found, or -1 if no position is found.
* @deprecated use CBParse method instead
*/
public static int nextCharIn(int pos, String searchMe, String compare, boolean match)
{
char test;
int length = searchMe.length();
while (pos < length)
{
test = searchMe.charAt(pos);
if ((compare.indexOf(test) != -1) == match)
return pos;
pos++;
}
return -1;
}
/**
* Reads a directory, returning all file names of the given extension.
*
* @param dirPath directory to read
* @param extension the file extension to filter files with.
* @return list of full file names
*/
public static String[] readFilteredDirectory(String dirPath, String extension)
{
String[] extensions = new String[1];
extensions[0] = extension;
return readFilteredDirectory(dirPath, extensions);
}
/**
* Reads a directory, returning all file names of the given extensions
*
* @param dirPath directory to read
* @param fileExtensions extension a list of file extensions to filter files with.
* @return list of full file names
*/
public static String[] readFilteredDirectory(String dirPath, String[] fileExtensions)
{
final String[] extensions = fileExtensions;
File dir = new File(dirPath);
//XXX Could use CBFileFilter here?
String[] templates = dir.list(new FilenameFilter()
{
public boolean accept(File dir, String name)
{
for (int i = 0; i < extensions.length; i++)
{
if (name.endsWith(extensions[i]))
return true;
}
return false;
}
});
return templates;
}
/**
* Sets the cursor to the wait cursor.
*
* @param C the owning component.
*/
public static void setWaitCursor(Component C)
{
C.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
/**
* Sets the cursor to the normal cursor.
*
* @param C the owning component.
*/
public static void setNormalCursor(Component C)
{
C.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
/**
* Sets the cursor to the hand cursor.
*
* @param C the owning component.
*/
public static void setHandCursor(Component C)
{
C.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
/**
* Saves a cursor. One cursor. That's all. Just one. Try to
* save another one, it'll overwrite this one. So don't.
*
* @param C the owning component.
*/
public static void saveCursor(Component C)
{
savedCursor = C.getCursor();
}
/**
* Gets the cursor back that you just saved. Probably better
* make sure it's the same component you saved it from. Wouldn't
* care to guess what happens if it isn't...
*
* @param C the owning component.
*/
public static void restoreCursor(Component C)
{
if (savedCursor != null)
C.setCursor(savedCursor);
else
log.info("graphics error: can't restore cursor; no cursor saved...");
}
/**
* Sets the level of logging on a scale of 0 (none) to 10 (everything).
* @param L the log level.
*/
//public static void setLogDebugLevel(int L) { debugLevel = L; }
/**
* Returns the global debug level.
*/
//public static int getLogDebugLevel() { return debugLevel; }
/**
* Sets the type of logging, using the strings 'none', 'console' or 'file'.
* @param logType the type of logging to use.
*/
//public static void setLogType(String logType) {setLogType(logType, null);}
/**
* Sets the type of logging, using the strings 'none', 'console' or 'file'.
* @param logType the type of logging to use.
* @param fileName the name of the log file to use, (unused if logType != 'file')
*/
/*
public static void setLogType(String logType, String fileName)
{
if (logType.equalsIgnoreCase("none")) loggingStyle = NOLOG;
else if (logType.equalsIgnoreCase("console")) loggingStyle = CONSOLE;
else if (logType.equalsIgnoreCase("file") || logType.equalsIgnoreCase("both"))
{
String logFileName = (fileName==null)?"jxplorer.log":fileName;
try
{
logfile = new FileWriter(logFileName);
if (logType.equalsIgnoreCase("both"))
loggingStyle=CONSOLEANDFILE;
else
loggingStyle = FILE;
}
catch (Exception e)
{
CBUtility.log("unable to open log file " + logFileName + "\nreverting to console logging");
loggingStyle = CONSOLE;
}
}
else loggingStyle = CONSOLE; // console is default...
log("Logging Initialised to " + logType, 1);
}
*/
/**
* Closes the log file.
*/
/*
public static void closeLog()
{
try
{
if (logfile != null) logfile.close();
}
catch (Exception e)
{
CBUtility.log("error shutting log file " + e.toString());
}
}
*/
/**
* logs if the global debug level equal to or greater than the
* passed int value.<p>
*
* <b>Log Levels</b><br>
* <ul>
* <li>0 - error logging only
* <li>1
* <li>2
* <li>3
* <li>4 - entry level logging of all delete/copy/move operations
* <li>5
* <li>6
* <li>7
* <li>8
* <li>9 - full BER logging
* </ul>
*
*
* @param S the string to log
* @param level the debug level at which the string starts
* being printed
*/
/*
public static void log(String S, int level)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?