Search in sources :

Example 1 with AbuseFilter

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);
    }
}
Also used : AbuseFilter(org.wikipediacleaner.api.data.AbuseFilter) APIException(org.wikipediacleaner.api.APIException) Element(org.jdom2.Element) JDOMException(org.jdom2.JDOMException)

Example 2 with AbuseFilter

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);
    }
}
Also used : AbuseFilter(org.wikipediacleaner.api.data.AbuseFilter) PageListWorker(org.wikipediacleaner.gui.swing.pagelist.PageListWorker) APIException(org.wikipediacleaner.api.APIException) ArrayList(java.util.ArrayList) API(org.wikipediacleaner.api.API) EnumQueryPage(org.wikipediacleaner.api.constants.EnumQueryPage) Page(org.wikipediacleaner.api.data.Page) ConfigurationValueString(org.wikipediacleaner.utils.ConfigurationValueString)

Aggregations

APIException (org.wikipediacleaner.api.APIException)2 AbuseFilter (org.wikipediacleaner.api.data.AbuseFilter)2 ArrayList (java.util.ArrayList)1 Element (org.jdom2.Element)1 JDOMException (org.jdom2.JDOMException)1 API (org.wikipediacleaner.api.API)1 EnumQueryPage (org.wikipediacleaner.api.constants.EnumQueryPage)1 Page (org.wikipediacleaner.api.data.Page)1 PageListWorker (org.wikipediacleaner.gui.swing.pagelist.PageListWorker)1 ConfigurationValueString (org.wikipediacleaner.utils.ConfigurationValueString)1