use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode in project BiglyBT by BiglySoftware.
the class UPnPActionInvocationImpl method invoke.
@Override
public UPnPActionArgument[] invoke() throws UPnPException {
UPnPService service = action.getService();
String soap_action = service.getServiceType() + "#" + action.getName();
SimpleXMLParserDocument resp_doc = null;
try {
String request = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" + " <s:Body>\n";
request += " <u:" + action.getName() + " xmlns:u=\"" + service.getServiceType() + "\">\n";
for (int i = 0; i < arg_names.size(); i++) {
String name = (String) arg_names.get(i);
String value = (String) arg_values.get(i);
request += " <" + name + ">" + value + "</" + name + ">\n";
}
request += " </u:" + action.getName() + ">\n";
request += " </s:Body>\n" + "</s:Envelope>";
// try standard POST
resp_doc = ((UPnPDeviceImpl) action.getService().getDevice()).getUPnP().performSOAPRequest(service, soap_action, request);
SimpleXMLParserDocumentNode body = resp_doc.getChild("Body");
SimpleXMLParserDocumentNode faultSection = body.getChild("Fault");
if (faultSection != null) {
String faultValue = faultSection.getValue();
if (faultValue != null && faultValue.length() > 0) {
throw (new UPnPException("Invoke of '" + soap_action + "' failed - fault reported: " + faultValue, soap_action, action, resp_doc, faultValue, -1));
}
SimpleXMLParserDocumentNode faultDetail = faultSection.getChild("detail");
if (faultDetail != null) {
SimpleXMLParserDocumentNode error = faultDetail.getChild("UPnPError");
if (error != null) {
int errCodeNumber = -1;
String errDescValue = null;
SimpleXMLParserDocumentNode errCode = error.getChild("errorCode");
if (errCode != null) {
String errCodeValue = errCode.getValue();
try {
errCodeNumber = Integer.parseInt(errCodeValue);
} catch (Throwable t) {
}
}
SimpleXMLParserDocumentNode errDesc = error.getChild("errorDescription");
if (errDesc != null) {
errDescValue = errDesc.getValue();
if (errDescValue != null && errDescValue.length() == 0) {
errDescValue = null;
}
}
throw (new UPnPException("Invoke of '" + soap_action + "' failed - fault reported: " + errDescValue, soap_action, action, resp_doc, errDescValue, errCodeNumber));
}
}
}
SimpleXMLParserDocumentNode resp_node = body.getChild(action.getName() + "Response");
if (resp_node == null) {
throw (new UPnPException("Invoke of '" + soap_action + "' failed - response missing: " + body.getValue(), soap_action, action, resp_doc, null, -1));
}
SimpleXMLParserDocumentNode[] out_nodes = resp_node.getChildren();
UPnPActionArgument[] resp = new UPnPActionArgument[out_nodes.length];
for (int i = 0; i < out_nodes.length; i++) {
resp[i] = new UPnPActionArgumentImpl(out_nodes[i].getName(), out_nodes[i].getValue());
}
return (resp);
} catch (Throwable e) {
if (e instanceof UPnPException) {
throw ((UPnPException) e);
}
throw new UPnPException("Invoke of '" + soap_action + "' on '" + action.getService().getControlURLs() + "' failed: " + e.getMessage(), e, soap_action, action, resp_doc);
}
}
use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode in project BiglyBT by BiglySoftware.
the class UPnPServiceImpl method parseStateVars.
protected void parseStateVars(SimpleXMLParserDocumentNode action_list) {
state_vars = new ArrayList();
SimpleXMLParserDocumentNode[] kids = action_list.getChildren();
for (int i = 0; i < kids.length; i++) {
state_vars.add(new UPnPStateVariableImpl(this, kids[i]));
}
}
use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode in project BiglyBT by BiglySoftware.
the class UPnPServiceImpl method parseActions.
protected void parseActions(SimpleXMLParserDocumentNode action_list) {
actions = new ArrayList();
SimpleXMLParserDocumentNode[] kids = action_list.getChildren();
for (int i = 0; i < kids.length; i++) {
actions.add(new UPnPActionImpl(this, kids[i]));
}
}
use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode in project BiglyBT by BiglySoftware.
the class RSSItemImpl method getLink.
@Override
public URL getLink() {
SimpleXMLParserDocumentNode link_node = node.getChild("link");
if (link_node != null) {
try {
String value = "";
if (is_atom) {
SimpleXMLParserDocumentAttribute attr = link_node.getAttribute("href");
if (attr == null) {
return (null);
}
value = attr.getValue().trim();
} else {
value = link_node.getValue().trim();
}
if (value.length() == 0) {
return (null);
}
if (value.startsWith("//")) {
value = "http:" + value;
}
return (new URL(value));
} catch (Throwable e) {
Debug.printStackTrace(e);
return (null);
}
}
return (null);
}
use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode in project BiglyBT by BiglySoftware.
the class TOTorrentXMLDeserialiser method decodeRoot.
protected TOTorrent decodeRoot(SimpleXMLParserDocument doc) throws TOTorrentException {
String root_name = doc.getName();
if (root_name.equalsIgnoreCase("TORRENT")) {
TOTorrentImpl torrent = new TOTorrentImpl();
SimpleXMLParserDocumentNode[] kids = doc.getChildren();
URL announce_url = null;
byte[] torrent_hash = null;
byte[] torrent_hash_override = null;
for (int i = 0; i < kids.length; i++) {
SimpleXMLParserDocumentNode kid = kids[i];
String name = kid.getName();
if (name.equalsIgnoreCase("ANNOUNCE_URL")) {
try {
announce_url = new URL(kid.getValue());
} catch (MalformedURLException e) {
throw (new TOTorrentException("ANNOUNCE_URL malformed", TOTorrentException.RT_DECODE_FAILS));
}
} else if (name.equalsIgnoreCase("ANNOUNCE_LIST")) {
SimpleXMLParserDocumentNode[] set_nodes = kid.getChildren();
TOTorrentAnnounceURLGroup group = torrent.getAnnounceURLGroup();
TOTorrentAnnounceURLSet[] sets = new TOTorrentAnnounceURLSet[set_nodes.length];
for (int j = 0; j < sets.length; j++) {
SimpleXMLParserDocumentNode[] url_nodes = set_nodes[j].getChildren();
URL[] urls = new URL[url_nodes.length];
for (int k = 0; k < urls.length; k++) {
try {
urls[k] = new URL(url_nodes[k].getValue());
} catch (MalformedURLException e) {
throw (new TOTorrentException("ANNOUNCE_LIST malformed", TOTorrentException.RT_DECODE_FAILS));
}
}
sets[j] = group.createAnnounceURLSet(urls);
}
group.setAnnounceURLSets(sets);
} else if (name.equalsIgnoreCase("COMMENT")) {
torrent.setComment(readLocalisableString(kid));
} else if (name.equalsIgnoreCase("CREATED_BY")) {
torrent.setCreatedBy(readLocalisableString(kid));
} else if (name.equalsIgnoreCase("CREATION_DATE")) {
torrent.setCreationDate(readGenericLong(kid).longValue());
} else if (name.equalsIgnoreCase("TORRENT_HASH")) {
torrent_hash = readGenericBytes(kid);
} else if (name.equalsIgnoreCase("TORRENT_HASH_OVERRIDE")) {
torrent_hash_override = readGenericBytes(kid);
} else if (name.equalsIgnoreCase("INFO")) {
decodeInfo(kid, torrent);
} else {
mapEntry entry = readGenericMapEntry(kid);
torrent.addAdditionalProperty(entry.name, entry.value);
}
}
if (announce_url == null) {
throw (new TOTorrentException("ANNOUNCE_URL missing", TOTorrentException.RT_DECODE_FAILS));
}
torrent.setAnnounceURL(announce_url);
if (torrent_hash_override != null) {
try {
torrent.setHashOverride(torrent_hash_override);
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
if (torrent_hash != null) {
if (!Arrays.equals(torrent.getHash(), torrent_hash)) {
throw (new TOTorrentException("Hash differs - declared TORRENT_HASH and computed hash differ. If this really is the intent (unlikely) then remove the TORRENT_HASH element", TOTorrentException.RT_DECODE_FAILS));
}
}
return (torrent);
} else {
throw (new TOTorrentException("Invalid root element", TOTorrentException.RT_DECODE_FAILS));
}
}
Aggregations