Die Codekopie lautet wie folgt:
import Java.util.hashMap;
import Java.util.map;
import org.apache.commons.lang3.stringutils;
import org.apache.commons.logging.log;
import org.apache.commons.logging.logfactory;
/**
* Einige bequeme Dienste für die statische Dateiverarbeitung
* @Author Kettas
* 4:27:25 Uhr
*/
öffentliche Klasse htmlservices {
private static log log = logFactory.getLog (htmlservices.class);
/**
* HTML -Code löschen
* <p> Alle Inhalte zwischen '<' und '>' werden gelöscht und zu </p> zurückgegeben
* @param args
* @return String
*/
public static String clearHtmltoString (String args) {
return clearHtmltoString (args, falsch);
}
/**
* HTML -Code löschen
* <p> Alle Inhalte zwischen '<' und '>' werden gelöscht und zu </p> zurückgegeben
* @param args
* @Param Ersatz, ob Tabellenzeichen wie Leerzeichen ersetzt werden sollen
* @return String
*/
public static String clearHtmltoString (String args, boolean ersetzull) {
if (stringutils.isempty (args)) {
zurückkehren "";
}
args = args.replaceall ("(? ist) <(.*?)>", "");
if (Ersatznull) {
args = args.replaceall ("// s*|/t |/r |/n", "");
}
Rückkehr Args;
}
/**
* HTML -Code löschen
* <p> Alle Inhalte zwischen '<' und '>' werden gelöscht und die zurückgegebene Länge wird angegeben </p>
* @param args
* @return String
*/
public static String clearHtmltoString (String args, int maxSize) {
return clearHtmltoString (args, maxSize, "");
}
/**
* HTML -Code löschen
* <p> Alle Inhalte zwischen '<' und '>' werden gelöscht und die zurückgegebene Länge wird angegeben </p>
* @param args
* @return String
*/
public static String clearHtmltoString (String args, int maxSize, String ersetzen) {
args = clearHtmltoString (args);
if (maxSize <= 0) {
Rückkehr Args;
}
if (args.length () <= maxSize) {
Rückkehr Args;
}
return args.substring (0, maxSize) .Concat (ersetzen);
}
/**
* Fangen Sie die Zeichenfolge in die angegebene Länge ab
* @param args
* @param maxSize
* @param ersetzen
* @return String
*/
public static String clearHtmltosize (String args, int maxSize, String ersetzen) {
if (args.length () <= maxSize) {
Rückkehr Args;
}
return args.substring (0, maxSize) .Concat (ersetzen);
}
/// **
// * Lesen Sie <Styles> Stil aus der CSS -Style -Datei
// * @return String
// */
// public statische Zeichenfolge getStyletoString (Dateidatei) {
// document doc = null;
// Elements filelist = null;
//versuchen{
// doc = jsoup.parse (Datei, config.Default_type);
//filelist=doc.select("Style ");
// String CSS = doc.data ();
//if(cs.length () <1) {
// CSS zurückgeben;
//}
///*
// * Kommentaranweisungen herausfiltern
// */
//css=css.replaceall ("(<[^>]*>)", "");
// CSS zurückgeben;
//} catch (Ausnahme e) {
//log.Error(E);
//} Endlich{
// doc = null;
// filelist = null;
//}
//zurückkehren "";
//}
/// **
// * Lesen Sie <Styles> Stil aus der CSS -Style -Datei
// * @return map <String, String>
// */
// öffentliche statische Karte <String, String> getStyletomap (Dateidatei) {
// map <string, string> css = new HashMap <String, String> ();
//versuchen{
// String csStyle = getStyletOstring (Datei);
//if(csSstyle.trim (). Länge () <1) {
// CSS zurückgeben;
//}
///*
// *
// */
// String [] style = csStyle.split ("//}");
// String [] map = new String [2];
// für (String _style: style) {
//map=_style.split ("// {");
//css.put(map -0..,mapente 1]);
//}
// CSS zurückgeben;
//} catch (Ausnahme e) {
//log.Error(E);
//}
// CSS zurückgeben;
//}
/**
* Lesen Sie CSS -Eigenschaften aus dem Stil
* <pre>
* String style = "float: links; margin: 0px; Schriftgröße: 12px;";
* String fontSize = htmlServices.getStyNameValue (Stil, "Schriftgröße"); </pre>
* @param style
* @param stylename
* @return String
*/
Protected Static String getStyletOstring (String Style, String StyleName) {
versuchen{
Karte <String, String> CSS = CSSTOMAP (STYLE);
return CSS.get (Stylename);
} catch (Ausnahme e) {
log.Error (e);
}
zurückkehren "";
}
public static String Filterchare (String msg, String ... chars) {
für (string _char: chars) {
msg = msg.replace (_char, "");
}
MSG zurückgeben;
}
public static String maptocss (MAP <String, String> CSS) {
StringBuffer style = new StringBuffer ();
für (map.entry <String, String> Eintrag: CSS.EntrySet ()) {
style.Append (style.length ()> 0? ",": "");
style.Append (Eintrag.getKey ()). append (":"). append (Entry.getValue ());
}
return style.toString ();
}
/**
* In Schlüsselwertpaare in den Stil einkapseln
* <pre>
* String style = "float: links; margin: 0px; Schriftgröße: 12px;";
* Map <string, string> css = htmlservices.getStyletomap (style);
* System.out.println ("Schriftgröße:"+css.get ("Schriftgröße");
* </pre>
* @param style
* @return map
*/
öffentliche statische Karte <String, String> cSstomap (String Style) {
Karte <String, String> map = new HashMap <String, String> ();
versuchen{
if (style == null || Stringutils.isempty (style)) {
Rückgabekarte;
}
style = style.tolowerCase ();
style = style.split ("//}") [0];
String [] CSSS = style.split ("//;");
für (int i = 0, iszie = css.length; i <iszie; i ++) {
String [] csStyle = CSSS [i] .Split ("//:");
für (int j = 0, jSize = csStyle.length; (j+1) <jsize; j+= 2) {
map.put (csSstyle [j] .Replace ("", "") .trim (), csStyle [j+1] .ToString (). trim ());
}
}
} catch (Ausnahme e) {
log.Error (e);
}
Rückgabekarte;
}
/// **
// * Lesen Sie das Attribut von CSSName aus dem CSS -Stil (Beachten Sie, dass CSS Standard -CSS ist).
// * @param CSS
// * @param cssname
// * @param stylename
// * @return String
// */
// public static String getStyNameValue (Dateidatei, String -CSSName, String Stylename) {
//versuchen{
// String style = getStyletomap (Datei) .get (cssname);
// return getStylenameValue (Stil, Stylename);
//} catch (Ausnahme e) {
//log.Error(E);
//}
//zurückkehren "";
//}
}