Author: toad
Date: 2007-09-14 15:18:46 +0000 (Fri, 14 Sep 2007)
New Revision: 15166
Modified:
trunk/freenet/src/freenet/clients/http/filter/HTMLFilter.java
Log:
Avoid some work if we're only checking the charset
Modified: trunk/freenet/src/freenet/clients/http/filter/HTMLFilter.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/filter/HTMLFilter.java
2007-09-14 15:04:07 UTC (rev 15165)
+++ trunk/freenet/src/freenet/clients/http/filter/HTMLFilter.java
2007-09-14 15:18:46 UTC (rev 15166)
@@ -60,7 +60,7 @@
strm.close();
throw UnknownCharsetException.create(e, charset);
}
- HTMLParseContext pc = new HTMLParseContext(r, w, charset, cb);
+ HTMLParseContext pc = new HTMLParseContext(r, w, charset, cb,
false);
pc.run(temp);
r.close();
w.close();
@@ -88,7 +88,7 @@
strm.close();
throw e;
}
- HTMLParseContext pc = new HTMLParseContext(r, w, null, new
NullFilterCallback());
+ HTMLParseContext pc = new HTMLParseContext(r, w, null, new
NullFilterCallback(), true);
try {
pc.run(null);
} catch (IOException e) {
@@ -114,12 +114,14 @@
String charset;
String detectedCharset;
final FilterCallback cb;
+ final boolean noOutput;
- HTMLParseContext(Reader r, Writer w, String charset,
FilterCallback cb) {
+ HTMLParseContext(Reader r, Writer w, String charset,
FilterCallback cb, boolean noOutput) {
this.r = r;
this.w = w;
this.charset = charset;
this.cb = cb;
+ this.noOutput = noOutput;
}
Bucket run(Bucket temp) throws IOException, DataFilterException
{
@@ -335,6 +337,8 @@
void saveText(StringBuffer s, String tagName, Writer w,
HTMLParseContext pc)
throws IOException {
+
+ if(pc.noOutput) return;
if(logDEBUG) Logger.debug(this, "Saving text: "+s.toString());
if (pc.killText) {
@@ -382,6 +386,7 @@
ParsedTag t = new ParsedTag(splitTag);
if (!pc.killTag) {
t = t.sanitize(pc);
+ if(pc.noOutput) return; // sanitize has done all the
work we are interested in
if (t != null) {
if (pc.writeStyleScriptWithTag) {
pc.writeStyleScriptWithTag = false;
@@ -407,6 +412,7 @@
void saveComment(StringBuffer s, Writer w, HTMLParseContext pc)
throws IOException {
+ if(pc.noOutput) return;
if((s.length() > 3) && (s.charAt(0) == '!') && (s.charAt(1) ==
'-') && (s.charAt(2) == '-')) {
s.delete(0, 3);
if(s.charAt(s.length()-1) == '-')
@@ -1303,7 +1309,7 @@
void processStyle(HTMLParseContext pc) {
try {
pc.currentStyleScriptChunk =
-
sanitizeStyle(pc.currentStyleScriptChunk, pc.cb);
+
sanitizeStyle(pc.currentStyleScriptChunk, pc.cb, pc);
} catch (DataFilterException e) {
Logger.error(this, "Error parsing style: "+e,
e);
pc.currentStyleScriptChunk = "";
@@ -1380,7 +1386,7 @@
}
String style = getHashString(h, "style");
if (style != null) {
- style = sanitizeStyle(style, pc.cb);
+ style = sanitizeStyle(style, pc.cb, pc);
if (style != null)
style = escapeQuotes(style);
if (style != null)
@@ -1828,8 +1834,9 @@
}
- static String sanitizeStyle(String style, FilterCallback cb) throws
DataFilterException {
+ static String sanitizeStyle(String style, FilterCallback cb,
HTMLParseContext hpc) throws DataFilterException {
if(style == null) return null;
+ if(hpc.noOutput) return null;
Reader r = new StringReader(style);
Writer w = new StringWriter();
style = style.trim();