use of org.adempiere.pipo2.Element in project wpcleaner by WPCleaner.
the class ApiXmlPagesWithPropResult method executePagesWithProp.
/**
* Execute pages with property request.
*
* @param properties Properties defining request.
* @param list List to be filled with protected titles.
* @return True if request should be continued.
* @throws APIException Exception thrown by the API.
*/
@Override
public boolean executePagesWithProp(Map<String, String> properties, List<Page> list) throws APIException {
try {
Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS);
// Retrieve embedding pages
XPathExpression<Element> xpa = XPathFactory.instance().compile("/api/query/pageswithprop/page", Filters.element());
List<Element> results = xpa.evaluate(root);
Iterator<Element> iter = results.iterator();
while (iter.hasNext()) {
Element currentNode = iter.next();
Integer pageId = null;
try {
String tmp = currentNode.getAttributeValue("pageid");
if (tmp != null) {
pageId = Integer.valueOf(tmp);
}
} catch (NumberFormatException e) {
//
}
Page page = DataManager.getPage(getWiki(), currentNode.getAttributeValue("title"), pageId, null, null);
page.setNamespace(currentNode.getAttributeValue("ns"));
list.add(page);
}
// Retrieve continue
return shouldContinue(root, "/api/query-continue/pageswithprop", properties);
} catch (JDOMException e) {
log.error("Error loading protected titles list", e);
throw new APIException("Error parsing XML", e);
}
}
use of org.adempiere.pipo2.Element in project wpcleaner by WPCleaner.
the class ApiXmlProtectedTitlesResult method executeProtectedTitles.
/**
* Execute protected titles request.
*
* @param properties Properties defining request.
* @param list List to be filled with protected titles.
* @return True if request should be continued.
* @throws APIException Exception thrown by the API.
*/
@Override
public boolean executeProtectedTitles(Map<String, String> properties, List<Page> list) throws APIException {
try {
Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS);
// Retrieve embedding pages
XPathExpression<Element> xpa = XPathFactory.instance().compile("/api/query/protectedtitles/pt", Filters.element());
List<Element> results = xpa.evaluate(root);
Iterator<Element> iter = results.iterator();
while (iter.hasNext()) {
Element currentNode = iter.next();
if ("infinity".equals(currentNode.getAttributeValue("expiry"))) {
Page page = DataManager.getPage(getWiki(), currentNode.getAttributeValue("title"), null, null, null);
page.setNamespace(currentNode.getAttributeValue("ns"));
list.add(page);
}
}
// Retrieve continue
return shouldContinue(root, "/api/query-continue/protectedtitles", properties);
} catch (JDOMException e) {
log.error("Error loading protected titles list", e);
throw new APIException("Error parsing XML", e);
}
}
use of org.adempiere.pipo2.Element in project wpcleaner by WPCleaner.
the class ApiXmlQueryPageResult method executeQueryPage.
/**
* Execute query page request.
*
* @param properties Properties defining request.
* @param list List to be filled with query pages.
* @return True if request should be continued.
* @throws APIException Exception thrown by the API.
*/
@Override
public boolean executeQueryPage(Map<String, String> properties, List<Page> list) throws APIException {
try {
Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS);
// Retrieve query pages
XPathExpression<Element> xpa = XPathFactory.instance().compile("/api/query/querypage/results/page", Filters.element());
List<Element> results = xpa.evaluate(root);
Iterator<Element> iter = results.iterator();
while (iter.hasNext()) {
Element currentNode = iter.next();
Page page = DataManager.getPage(getWiki(), currentNode.getAttributeValue("title"), null, null, null);
page.setNamespace(currentNode.getAttributeValue("ns"));
list.add(page);
}
// Retrieve continue
return shouldContinue(root, "/api/query-continue/querypage", properties);
} catch (JDOMException e) {
log.error("Error loading query page list", e);
throw new APIException("Error parsing XML", e);
}
}
use of org.adempiere.pipo2.Element in project wpcleaner by WPCleaner.
the class MediaWikiAPI method checkForError.
/**
* Check for errors reported by the API.
*
* @param root Document root.
* @throws APIException Exception thrown by the API.
*/
private void checkForError(Element root) throws APIException {
if (root == null) {
return;
}
// Check for errors
XPathExpression<Element> xpa = XPathFactory.instance().compile("/api/error", Filters.element());
List<Element> listErrors = xpa.evaluate(root);
if (listErrors != null) {
Iterator<Element> iterErrors = listErrors.iterator();
while (iterErrors.hasNext()) {
Element currentNode = iterErrors.next();
String text = "Error reported: " + currentNode.getAttributeValue("code") + " - " + currentNode.getAttributeValue("info");
log.warn(text);
throw new APIException(text, currentNode.getAttributeValue("code"));
}
}
// Check for warnings
xpa = XPathFactory.instance().compile("/api/warnings/*", Filters.element());
List<Element> listWarnings = xpa.evaluate(root);
if (listWarnings != null) {
Iterator iterWarnings = listWarnings.iterator();
while (iterWarnings.hasNext()) {
Element currentNode = (Element) iterWarnings.next();
log.warn("Warning reported: " + currentNode.getName() + " - " + currentNode.getValue());
}
}
}
use of org.adempiere.pipo2.Element in project wpcleaner by WPCleaner.
the class MediaWikiAPI method constructEdit.
/**
* @param root Root element in MediaWiki answer.
*
* @param query Path to the answer.
* @return Result of the query.
* @throws APIException Exception thrown by the API.
* @throws CaptchaException Captcha.
*/
private QueryResult constructEdit(Element root, String query) throws APIException, CaptchaException {
XPathExpression<Element> xpa = XPathFactory.instance().compile(query, Filters.element());
Element node = xpa.evaluateFirst(root);
if (node != null) {
String result = node.getAttributeValue("result");
if ("Success".equalsIgnoreCase(result)) {
Integer pageId = null;
try {
pageId = Integer.valueOf(node.getAttributeValue("pageid"));
} catch (NumberFormatException e) {
//
}
Integer pageOldRevId = null;
try {
pageOldRevId = Integer.valueOf(node.getAttributeValue("oldrevid"));
} catch (NumberFormatException e) {
//
}
Integer pageNewRevId = null;
try {
pageNewRevId = Integer.valueOf(node.getAttributeValue("newrevid"));
} catch (NumberFormatException e) {
//
}
return QueryResult.createCorrectQuery(pageId, node.getAttributeValue("title"), pageOldRevId, pageNewRevId);
} else if ("Failure".equalsIgnoreCase(result)) {
XPathExpression<Element> xpaCaptcha = XPathFactory.instance().compile("./captcha", Filters.element());
Element captcha = xpaCaptcha.evaluateFirst(node);
if (captcha != null) {
CaptchaException exception = new CaptchaException("Captcha", captcha.getAttributeValue("type"));
exception.setMime(captcha.getAttributeValue("mime"));
exception.setId(captcha.getAttributeValue("id"));
exception.setURL(captcha.getAttributeValue("url"));
throw exception;
}
String spamBlacklist = node.getAttributeValue("spamblacklist");
if (spamBlacklist != null) {
throw new APIException(GT._T("URL {0} is blacklisted", spamBlacklist));
}
throw new APIException(xmlOutputter.outputString(node));
}
return QueryResult.createErrorQuery(result, node.getAttributeValue("details"), node.getAttributeValue("wait"));
}
return QueryResult.createErrorQuery(null, null, null);
}
Aggregations