HtmlStatusResponseParser.java
2.69 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Decompiled with CFR 0_118.
*/
package com.day.crx.packaging;
import com.day.crx.packaging.JSONResponse;
import com.day.crx.packaging.impl.proxy.AttributeList;
import com.day.crx.packaging.impl.proxy.DocumentHandler;
import com.day.crx.packaging.impl.proxy.HtmlParser;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class HtmlStatusResponseParser {
private static final Set<String> TAGS;
public static JSONResponse parse(String data) throws IOException {
Handler h = new Handler();
HtmlParser p = new HtmlParser();
p.setDocumentHandler(h);
p.setTagInclusionSet(TAGS);
p.update(data.toCharArray(), 0, data.length());
p.finished();
return h.resp;
}
static {
HashSet<String> tags = new HashSet<String>();
tags.add("A");
tags.add("DIV");
TAGS = Collections.unmodifiableSet(tags);
}
private static class Handler
implements DocumentHandler {
private String id = null;
private int statusCode = 0;
private String statusMessage = "";
private final JSONResponse resp = new JSONResponse();
private Handler() {
}
@Override
public void characters(char[] ch, int off, int len) throws IOException {
if (this.id == null) {
return;
}
String str = new String(ch, off, len);
if ("Status".equals(this.id)) {
this.statusCode = Integer.parseInt(str);
this.resp.setStatus(this.statusCode);
this.resp.setSuccess(this.statusCode == 200);
} else if ("Message".equals(this.id)) {
this.statusMessage = str;
this.resp.setMessage(this.statusMessage);
} else if ("Path".equals(this.id)) {
this.resp.setPath(str);
} else if (!"Referer".equals(this.id)) {
if ("Location".equals(this.id)) {
this.resp.setLocation(str);
} else if ("ParentLocation".equals(this.id)) {
// empty if block
}
}
this.id = null;
}
@Override
public void onStartElement(String name, AttributeList attList, char[] ch, int off, int len, boolean endSlash) throws IOException {
this.id = attList.getValue("id");
}
@Override
public void onEndElement(String name, char[] ch, int off, int len) throws IOException {
}
@Override
public void onStart() throws IOException {
}
@Override
public void onEnd() throws IOException {
}
}
}