EncodingScanner.java
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.rewriter.htmlparser.AttributeList
* com.day.cq.rewriter.htmlparser.DocumentHandler
* com.day.cq.rewriter.htmlparser.HtmlParser
*/
package com.day.cq.wcm.foundation.impl;
import com.day.cq.rewriter.htmlparser.AttributeList;
import com.day.cq.rewriter.htmlparser.DocumentHandler;
import com.day.cq.rewriter.htmlparser.HtmlParser;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
class EncodingScanner
implements DocumentHandler {
private final byte[] buf;
private final int off;
private final int len;
private String encoding;
private EncodingScanner(byte[] buf, int off, int len) {
this.buf = buf;
this.off = off;
this.len = len;
}
public static String scan(byte[] buf, int off, int len) throws IOException {
return new EncodingScanner(buf, off, len).scan();
}
private String scan() throws IOException {
HashSet<String> set = new HashSet<String>();
set.add("META");
char[] ch = new String(this.buf, this.off, this.len, "8859_1").toCharArray();
HtmlParser parser = new HtmlParser();
parser.setTagInclusionSet(set);
parser.setDocumentHandler((DocumentHandler)this);
parser.update(ch, 0, ch.length);
parser.finished();
return this.encoding;
}
public void characters(char[] ch, int off, int len) {
}
public void onStartElement(String name, AttributeList attList, char[] ch, int off, int len, boolean endSlash) {
String contentType;
int index;
if (name.equalsIgnoreCase("META") && (contentType = attList.getValue("CONTENT")) != null && (index = contentType.indexOf("charset=")) != -1) {
this.encoding = contentType.substring(index + "charset=".length()).trim();
}
}
public void onEndElement(String name, char[] ch, int off, int len) {
}
public void onStart() throws IOException {
}
public void onEnd() throws IOException {
}
}