コードコピーは次のとおりです。
java.util.hashmapをインポートします。
java.util.mapをインポートします。
org.apache.commons.lang3.stringutilsをインポートします。
Import org.apache.commons.logging.log;
Import org.apache.commons.logging.logfactory;
/**
*静的ファイル処理のための便利なサービス
* @Author Kettas
* 4:27:25 PM
*/
パブリッククラスhtmlservices {
private static log = logfactory.getlog(htmlservices.class);
/**
* HTMLコードをクリアします
* <p> '<'と '>'の間に含まれるすべての内容がクリアされ、</p>に返されます
* @param args
* @return文字列
*/
public static string clearhtmltostring(string args){
clearhtmltostring(args、false)を返します。
}
/**
* HTMLコードをクリアします
* <p> '<'と '>'の間に含まれるすべての内容がクリアされ、</p>に返されます
* @param args
* @param fallingenullスペースなどのタブ文字を交換するかどうか
* @return文字列
*/
public static string clearhtmltostring(string args、boolean fallingenull){
if(stringutils.isempty(args)){
戻る "";
}
args = args.replaceall( "(?as)<(。*?)>"、 "");
if(fallingenull){
args = args.replaceall( "// s*|/t |/r |/n"、 "");
}
argsを返します。
}
/**
* HTMLコードをクリアします
* <p> '<'と '>'の間に含まれるすべての内容がクリアされ、返された長さが指定されます</p>
* @param args
* @return文字列
*/
public static string clearhtmltostring(string args、int maxsize){
clearhtmltostring(args、maxsize、 "")を返します。
}
/**
* HTMLコードをクリアします
* <p> '<'と '>'の間に含まれるすべての内容がクリアされ、返された長さが指定されます</p>
* @param args
* @return文字列
*/
public static string clearhtmltostring(string args、int maxsize、string facking){
args = clearhtmltostring(args);
if(maxsize <= 0){
argsを返します。
}
if(args.length()<= maxsize){
argsを返します。
}
return args.substring(0、maxsize).concat(置き換え);
}
/**
*文字列を指定された長さに挿入します
* @param args
* @param maxsize
* @paramの交換
* @return文字列
*/
public static string clearhtmltosize(string args、int maxsize、string facty){
if(args.length()<= maxsize){
argsを返します。
}
return args.substring(0、maxsize).concat(置き換え);
}
/// **
// * CSSスタイルファイルから<style>スタイルを読み取ります
// * @return文字列
// */
// public static string getStyleToString(ファイルファイル){
// document doc = null;
//要素filelist = null;
//試す{
// doc = jsoup.parse(file、config.default_type);
//FILELIST = DOC.SELECT("Style ");
// string css = doc.data();
//if(css.length()<1){
// CSSを返します。
//}
///*
// *コメントステートメントをフィルタリングします
// */
//css = css.replaceall( "(<[^>]*>)"、 "");
// CSSを返します。
//} catch(例外E){
//log.error(e);
//} ついに{
// doc = null;
// fileList = null;
//}
//戻る "";
//}
/// **
// * CSSスタイルファイルから<style>スタイルを読み取ります
// * @return Map <String、String>
// */
// public static Map <String、string> getStyletomap(file file){
// map <string、string> css = new hashmap <string、string>();
//試す{
// string cssstyle = getStyleToString(file);
//if(cssstyle.trim()。length()<1){
// CSSを返します。
//}
///*
// *
// */
// string [] style = cssstyle.split( "//}");
// string [] map = new String [2];
// for(string _style:style){
//map=_style.split( "// {");
//css.put(map [0]、、map [1]);
//}
// CSSを返します。
//} catch(例外E){
//log.error(e);
//}
// CSSを返します。
//}
/**
*スタイルからCSSプロパティを読み取ります
* <pre>
* string style = "float:left; margin:0px; font-size:12px;";
* string fontsize = htmlservices.getStyleNameValue(style、 "font-size"); </pre>
* @paramスタイル
* @param stylename
* @return文字列
*/
保護された静的文字列getStyleToString(String Style、String Stylename){
試す{
map <string、string> css = csstomap(style);
css.get(stylename)を返します。
} catch(例外e){
log.error(e);
}
戻る "";
}
public static string filterchare(string msg、string ... chars){
for(string _char:chars){
msg = msg.replace(_ char、 "");
}
MSGを返します。
}
public static string maptocss(map <string、string> css){
stringbuffer style = new StringBuffer();
for(map.entry <string、string> entry:css.entryset()){
style.append(style.length()> 0? "、": "");
style.append(entry.getKey())。append( ":")。append(entry.getValue());
}
return style.toString();
}
/**
*スタイルをキー価値のペアにカプセル化します
* <pre>
* string style = "float:left; margin:0px; font-size:12px;";
* map <string、string> css = htmlservices.getStyletomap(style);
* System.out.println( "font-size:"+css.get( "font-size"));
* </pre>
* @paramスタイル
* @returnマップ
*/
public static Map <string、string> csstomap(string style){
map <string、string> map = new hashmap <string、string>();
試す{
if(style == null || stringutils.isempty(style)){
マップを返します。
}
style = style.tolowercase();
style = style.split( "//}")[0];
string [] csss = style.split( "//;");
for(int i = 0、iszie = csss.length; i <iszie; i ++){
string [] cssstyle = csss [i] .split( "//:");
for(int j = 0、jsize = cssstyle.length;(j+1)<jsize; j+= 2){
map.put(cssstyle [j] .replace( "" "、" ").trim()、cssstyle [j+1] .toString()。trim());
}
}
} catch(例外e){
log.error(e);
}
マップを返します。
}
/// **
// * CSSスタイルからCSSNameの属性を読む(CSSは標準CSSであることに注意してください)
// * @param css
// * @param cssname
// * @param stylename
// * @return文字列
// */
// public static string getstylenamevalue(ファイルファイル、文字列cssname、string stylename){
//試す{
// string style = getStyleTomap(file).get(cssname);
// getStylenameValue(style、stylename)を返します。
//} catch(例外E){
//log.error(e);
//}
//戻る "";
//}
}