use of org.wikipediacleaner.api.data.AbuseFilter in project wpcleaner by WPCleaner.
the class ApiXmlAbuseFiltersResult method executeAbuseFilters.
/**
* Execute abuse filters request.
*
* @param properties Properties defining request.
* @param list List to be filled with abuse filters.
* @return True if request should be continued.
* @throws APIException Exception thrown by the API.
*/
@Override
public boolean executeAbuseFilters(Map<String, String> properties, List<AbuseFilter> list) throws APIException {
try {
Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS);
// Retrieve category members
XPathExpression<Element> xpa = XPathFactory.instance().compile("/api/query/abusefilters/filter", Filters.element());
List<Element> results = xpa.evaluate(root);
Iterator<Element> iter = results.iterator();
while (iter.hasNext()) {
Element currentNode = iter.next();
Integer id = Integer.valueOf(0);
try {
String tmp = currentNode.getAttributeValue("id");
if (tmp != null) {
id = Integer.parseInt(tmp);
}
} catch (NumberFormatException e) {
//
}
String description = currentNode.getAttributeValue("description");
AbuseFilter filter = new AbuseFilter(id, description);
filter.setDeleted(currentNode.getAttribute("deleted") != null);
filter.setEnabled(currentNode.getAttribute("enabled") != null);
list.add(filter);
}
// Retrieve continue
return shouldContinue(root, "/api/query-continue/abusefilters", properties);
} catch (JDOMException e) {
log.error("Error loading abuse filters list", e);
throw new APIException("Error parsing XML", e);
}
}
use of org.wikipediacleaner.api.data.AbuseFilter in project wpcleaner by WPCleaner.
the class MainWindow method actionAbuseFilters.
/**
* Action called when Abuse Filters button is pressed.
*/
public void actionAbuseFilters() {
try {
API api = APIFactory.getAPI();
List<AbuseFilter> abuseFilters = api.retrieveAbuseFilters(getWikipedia());
if ((abuseFilters != null) && (abuseFilters.size() > 0)) {
Object filter = Utilities.askForValue(getParentComponent(), GT._T("What abuse filter are you interested in?"), abuseFilters.toArray(), abuseFilters.get(0));
if ((filter != null) && (filter instanceof AbuseFilter)) {
AbuseFilter abuseFilter = (AbuseFilter) filter;
List<Page> pages = api.retrieveAbuseLog(getWikipedia(), abuseFilter.getId(), null);
if ((pages != null) && (!pages.isEmpty())) {
List<String> pageNames = new ArrayList<>(pages.size());
for (Page page : pages) {
if (!pageNames.contains(page.getTitle())) {
pageNames.add(page.getTitle());
}
}
new PageListWorker(getWikipedia(), this, null, pageNames, PageListWorker.Mode.DIRECT, false, GT._T("Hits for filter {0}", filter.toString())).start();
}
}
}
} catch (APIException e) {
displayError(e);
}
}
Aggregations