📄 proxiesimpl.java
字号:
public static void setErrorHandler(ErrorHandler handler) {
errorHandler = handler;
}
public static String getInputEncoding(BufferedReader reader) throws IOException {
String inputEncoding = "utf-8";
String aLine = null;
while ( (aLine = reader.readLine()) != null ) {
aLine = aLine.trim().toLowerCase();
if (aLine.length() == 0)
continue;
if (!aLine.startsWith("<"))
break;
aLine = aLine.substring(1).trim();
if (!aLine.startsWith("?"))
break;
int index = aLine.indexOf("encoding");
if (index == -1)
break;
aLine = aLine.substring(index+8).trim();
if (!aLine.startsWith("="))
break;
aLine = aLine.substring(1).trim();
if (!aLine.startsWith("\""))
break;
if (aLine.indexOf("\"", 1) == -1)
break;
inputEncoding = aLine.substring(1, aLine.indexOf("\"", 1));
break;
}
reader.close();
return inputEncoding;
}
public static Proxies unmarshal(File file) throws IOException {
// Delegate to the unmarshal(Reader) method
String encoding = getInputEncoding( new BufferedReader(new InputStreamReader(new FileInputStream(file), "ISO-8859-1")) );
return unmarshal(new InputStreamReader(new FileInputStream(file), encoding));
}
public static Proxies unmarshal(File file, boolean validate) throws IOException {
// Delegate to the unmarshal(Reader) method
String encoding = getInputEncoding( new BufferedReader(new InputStreamReader(new FileInputStream(file), "ISO-8859-1")) );
return unmarshal(new InputStreamReader(new FileInputStream(file), encoding), validate);
}
public static Proxies unmarshal(InputStream inputStream) throws IOException {
// Delegate to the unmarshal(Reader) method
String encoding = getInputEncoding( new BufferedReader(new InputStreamReader(inputStream, "ISO-8859-1")) );
return unmarshal(new InputStreamReader(inputStream, encoding));
}
public static Proxies unmarshal(InputStream inputStream, boolean validate) throws IOException {
// Delegate to the unmarshal(Reader) method
String encoding = getInputEncoding( new BufferedReader(new InputStreamReader(inputStream, "ISO-8859-1")) );
return unmarshal(new InputStreamReader(inputStream, encoding), validate);
}
public static Proxies unmarshal(Reader reader) throws IOException {
// Delegate with default validation value
return unmarshal(reader, false);
}
public static Proxies unmarshal(Reader reader, boolean validate) throws IOException {
ProxiesImpl proxies = ProxiesImpl.newInstance();
proxies.setValidating(validate);
proxies.setCurrentUNode(proxies);
proxies.setParentUNode(null);
// Load the XML parser
XMLReader parser = null;
String parserClass = System.getProperty("org.xml.sax.driver",
"org.apache.xerces.parsers.SAXParser");
try {
parser = XMLReaderFactory.createXMLReader(parserClass);
// Set entity resolver, if needed
if (entityResolver != null) {
parser.setEntityResolver(entityResolver);
}
// Set error handler
parser.setErrorHandler(proxies);
// Register lexical handler
parser.setProperty("http://xml.org/sax/properties/lexical-handler", proxies);
// Register content handler
parser.setContentHandler(proxies);
} catch (SAXException e) {
throw new IOException("Could not load XML parser: " +
e.getMessage());
}
InputSource inputSource = new InputSource(reader);
try {
parser.setFeature("http://xml.org/sax/features/validation", new Boolean(validate).booleanValue());
parser.setFeature("http://xml.org/sax/features/namespaces", true);
parser.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
parser.parse(inputSource);
} catch (SAXException e) {
throw new IOException("Error parsing XML document: " +
e.getMessage());
}
// Return the resultant object
return proxies;
}
public Unmarshallable getParentUNode() {
return zeus_parentUNode;
}
public void setParentUNode(Unmarshallable parentUNode) {
this.zeus_parentUNode = parentUNode;
}
public Unmarshallable getCurrentUNode() {
return zeus_currentUNode;
}
public void setCurrentUNode(Unmarshallable currentUNode) {
this.zeus_currentUNode = currentUNode;
}
public void setValidating(boolean validate) {
this.validate = validate;
}
public void startDocument() throws SAXException {
// no-op
}
public void setDocumentLocator(Locator locator) {
// no-op
}
public void startPrefixMapping(String prefix, String uri)
throws SAXException {
namespaceMappings.put(prefix, uri);
}
public void startElement(String namespaceURI, String localName,
String qName, org.xml.sax.Attributes atts)
throws SAXException {
// Feed this to the correct ContentHandler
Unmarshallable current = getCurrentUNode();
if (current != this) {
current.startElement(namespaceURI, localName, qName, atts);
return;
}
// See if we handle, or we delegate
if ((localName.equals("Proxies")) && (!zeus_thisNodeHandled)) {
// Handle ourselves
for (int i=0, len=atts.getLength(); i<len; i++) {
String attName= atts.getLocalName(i);
String attValue = atts.getValue(i);
}
zeus_thisNodeHandled = true;
return;
} else {
// Delegate handling
if (localName.equals("Socks5Proxy")) {
Socks5ProxyImpl socks5Proxy = Socks5ProxyImpl.newInstance();
current = getCurrentUNode();
socks5Proxy.setParentUNode(current);
socks5Proxy.setCurrentUNode(socks5Proxy);
this.setCurrentUNode(socks5Proxy);
socks5Proxy.startElement(namespaceURI, localName, qName, atts);
// Add this value in
Socks5ProxyList.add(socks5Proxy);
return;
}
if (localName.equals("HttpProxy")) {
HttpProxyImpl httpProxy = HttpProxyImpl.newInstance();
current = getCurrentUNode();
httpProxy.setParentUNode(current);
httpProxy.setCurrentUNode(httpProxy);
this.setCurrentUNode(httpProxy);
httpProxy.startElement(namespaceURI, localName, qName, atts);
// Add this value in
HttpProxyList.add(httpProxy);
return;
}
}
}
public void endElement(String namespaceURI, String localName,
String qName)
throws SAXException {
Unmarshallable current = getCurrentUNode();
if (current != this) {
current.endElement(namespaceURI, localName, qName);
return;
}
Unmarshallable parent = getCurrentUNode().getParentUNode();
if (parent != null) {
parent.setCurrentUNode(parent);
}
}
public void characters(char[] ch, int start, int len)
throws SAXException {
// Feed this to the correct ContentHandler
Unmarshallable current = getCurrentUNode();
if (current != this) {
current.characters(ch, start, len);
return;
}
String text = new String(ch, start, len);
}
public void comment(char ch[], int start, int len) throws SAXException {
// Currently no-op
}
public void warning(SAXParseException e) throws SAXException {
if (errorHandler != null) {
errorHandler.warning(e);
}
}
public void error(SAXParseException e) throws SAXException {
if ((validate) && (!hasDTD)) {
throw new SAXException("Validation is turned on, but no DTD has been specified in the input XML document. Please supply a DTD through a DOCTYPE reference.");
}
if (errorHandler != null) {
errorHandler.error(e);
}
}
public void fatalError(SAXParseException e) throws SAXException {
if ((validate) && (!hasDTD)) {
throw new SAXException("Validation is turned on, but no DTD has been specified in the input XML document. Please supply a DTD through a DOCTYPE reference.");
}
if (errorHandler != null) {
errorHandler.fatalError(e);
}
}
public void startDTD(String name, String publicID, String systemID)
throws SAXException {
if ((name == null) || (name.equals(""))) {
docTypeString = "";
return;
}
hasDTD = true;
StringBuffer docTypeSB = new StringBuffer();
boolean hasPublic = false;
docTypeSB.append("<!DOCTYPE ")
.append(name);
if ((publicID != null) && (!publicID.equals(""))) {
docTypeSB.append(" PUBLIC \"")
.append(publicID)
.append("\"");
hasPublic = true;
}
if ((systemID != null) && (!systemID.equals(""))) {
if (!hasPublic) {
docTypeSB.append(" SYSTEM");
}
docTypeSB.append(" \"")
.append(systemID)
.append("\"");
}
docTypeSB.append(">");
docTypeString = docTypeSB.toString();
}
public void endDTD() throws SAXException {
// Currently no-op
}
public void startEntity(String name) throws SAXException {
// Currently no-op
}
public void endEntity(String name) throws SAXException {
// Currently no-op
}
public void startCDATA() throws SAXException {
// Currently no-op
}
public void endCDATA() throws SAXException {
// Currently no-op
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -