📄 jspmyadminutil.java
字号:
/*
* jspMyAdminUtil.java 0.6 2001/08/25
* Copyright (c) 2001 zsolyfree@yahoo.com under the GPL (www.gnu.org/copyleft/)
*
* TERMS OF USAGE:
* This file was written and developed by Zsolt Mali (zsolyfree@yahoo.com)
* for educational and demonstration purposes only. You have all rights to use,
* modify, and redistribute this file as you like. The only
* requirement is that you must retain this notice, without modifications, at
* the top of your source code. No warranties or guarantees are expressed or
* implied. DO NOT use this code in a production environment without
* understanding the limitations and weaknesses pretaining to or caused by the
* use of these scripts, directly or indirectly. USE AT YOUR OWN RISK!
*/
package com.jspmyadmin;
public class jspMyAdminUtil {
/**
* Class description goes here.
*
* @version 0.9 2001/06/29
* @author Zsolt Mali
*/
/**
* constructor jspMyAdminUtil
*/
public jspMyAdminUtil() {
}//end constructor --> jspMyAdminUtil()
/**
* Converts > < & " into html equivalents > < & " from a source
* string and returns it.
*
* @author Zsolt Mali
* @param source the source string
*/
public static String htmlSpecialChars(String source) {
if (source == null)
{
return "";
}
StringBuffer dest= new StringBuffer(source.length());
for (int i=0;i<source.length() ;i++ ) {
char c;
c=source.charAt(i);
if (c=='>') {
dest.append(">");
}
else if (c=='<') {
dest.append("<");
}
else if (c=='&') {
dest.append("&");
}
else if (c=='"') {
dest.append(""");
}
else {
dest.append(c);
}
}
return dest.toString();
}//end method --> public String htmlSpecialChars(String source)
/**
* Converts \n into html equivalents <br> from a source
* string and returns it.
* (new line to break)
*
* @author Zsolt Mali
* @param source the source string
*/
public static String nl2Br(String source) {
if (source == null)
{
return "";
}
StringBuffer dest= new StringBuffer(source.length());
for (int i=0;i<source.length() ;i++ ) {
char c;
c=source.charAt(i);
if (c=='\n') {
dest.append("<br>");
}
else {
dest.append(c);
}
}
return dest.toString();
}//end method --> public String nl2Br(String source)
/**
* Converts ',",\,NUL into sql equivalents \',\",\\,\NUL from a source
* string and returns it.
* (new line to break)
*
* @author Zsolt Mali
* @param source the source string
*/
public static String addSlashes(String source) {
if (source == null)
{
return "";
}
StringBuffer dest= new StringBuffer(source.length());
for (int i=0;i<source.length() ;i++ ) {
char c;
c=source.charAt(i);
if (c=='"') {
dest.append("\\\"");
}
else if (c=='\'') {
dest.append("\\\'");
}
else if (c=='\\') {
dest.append("\\\\");
}
else if ((c=='N') && ((i+2)<source.length()) && (source.charAt(i+1) == 'U') && (source.charAt(i+2) == 'L')) {
dest.append("\\N");
}
else {
dest.append(c);
}
}
return dest.toString();
}//end method --> public String addSlashes(String source)
/**
* Converts sql \',\",\\,\NUL into ',",\,NUL from a source
* string and returns it.
* (new line to break)
*
* @author Zsolt Mali
* @param source the source string
*/
public static String stripSlashes(String source) {
if (source == null)
{
return "";
}
StringBuffer dest= new StringBuffer(source.length());
for (int i=0;i<source.length() ;i++ ) {
char c;
c=source.charAt(i);
if ( (c=='\\') && (i+1<source.length()) && ( source.charAt(i+1)=='\'') ) {
dest.append("\'");
i++;
}
else if ( (c=='\\') && (i+1<source.length()) && ( source.charAt(i+1)=='\"') ) {
dest.append("\"");
i++;
}
else if ( (c=='\\') && ((i+3)<source.length()) && (source.charAt(i+1) == 'N') && (source.charAt(i+2) == 'U') && (source.charAt(i+3) == 'L') ) {
dest.append("N");
i++;
}
else if ( (c=='\\') && (i+1<source.length()) && ( source.charAt(i+1)=='\\') ) {
dest.append("\\");
i++;
}
else {
dest.append(c);
}
}
return dest.toString();
}//end method --> public String nl2Br(String source)
/**
* Converts a string to integer. If fails is not throwing a
* NumberFormatException, instead return 0.
*
* @author Zsolt Mali
* @param source the source string
*/
public static int toInt(String source) {
try {
return Integer.parseInt(source);
}
catch(NumberFormatException notint) {
return 0;
}
}//end method --> public int toInt(String source)
/**
* Replace in a String the last occurence of another String with a replacement
* string.
* This occurence must to be at the end of the source.
*
* @author Zsolt Mali
* @param source the source string
* @param occurence the occurence string
* @param replacement the replacement string
*/
public static String replaceLast(String source, String occurence, String replacement) {
if (source.lastIndexOf(occurence)==source.length()-occurence.length())
{
return source.substring(0,source.lastIndexOf(occurence)) + replacement;
}
else {
return source;
}
}//end method --> public static String replaceLast(String source, String occurence, String replacement)
/**
* Replace in a String all occurence of another String with a replacement
* string.
*
* @author Zsolt Mali
* @param source the source string
* @param occurence the occurence string
* @param replacement the replacement string
*/
public static String replaceAll(String source, String occurence, String replacement) {
while (source.indexOf(occurence)!=-1)
{
source = source.substring(0,source.indexOf(occurence)) + replacement +source.substring(source.indexOf(occurence)+occurence.length(), source.length());
}
return source;
}//end method --> public static String replaceAll(String source, String occurence, String replacement)
/**
* Replace in a String a Substring with a replacement
* starting from a specified Substring or char (begin)
* until other specified Substring or char (end).
*
* @author Zsolt Mali
* @param source the source string
* @param begin the begin substring
* @param end the end substring
* @param replacement the replacement string
*/
public static String replaceFromStrToStr(String source, String begin, String end, String replacement) {
while ( (source.indexOf(begin)!=-1) && (source.indexOf(end)!=-1) &&
(source.indexOf(begin)<source.indexOf(end)) )
{
source = source.substring(0,source.indexOf(begin)) + replacement +source.substring(source.indexOf(end)+end.length(), source.length());
}
return source;
}//end method --> public static String replaceFromStrToStr(String source, String begin, String end, String replacement)
}//end class --> public class jspMyAdminUtil
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -