Java Code Examples for org.jsoup.select.Selector.SelectorParseException

The following are top voted examples for showing how to use org.jsoup.select.Selector.SelectorParseException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: catpeds   File: PawpedsDocumentParserTest.java   Source Code and License 6 votes vote down vote up
/**
 * Test that {@link PawpedsDocumentParser#parseSearch(Document)} throws an
 * {@link IllegalArgumentException} if there is an jsoup parsing error.
 */
@Test(expected = IllegalArgumentException.class)
public void testJsoupSelectorUnexpectedError() throws Exception {
	// Given
	Document document = mock(Document.class);

	Elements noErrorElement = mock(Elements.class);
	when(noErrorElement.text()).thenReturn("");
	when(document.select("th.error")).thenReturn(noErrorElement);

	when(document.select("table.searchresult tr.searchresult:has(td.searchresult)")).thenThrow(SelectorParseException.class);

	// When
	pawpedsDocumentParser.parseSearch(document);

	// Then
	// the exception is expected
}
 
Example 2
Project: marmotta   File: CssSelectFunction.java   Source Code and License 5 votes vote down vote up
private LinkedList<String> doFilter(Document jsoup, Set<String> jsoupSelectors) throws IOException {
    LinkedList<String> result = new LinkedList<String>();
    for (String jsoupSel : jsoupSelectors) {
        try {
            for (Element e : jsoup.select(jsoupSel)) {
                result.add(e.outerHtml());
            }
        } catch (SelectorParseException xpe) {
            throw new IllegalArgumentException("error while processing jsoup selector: '" + jsoupSel + "'", xpe);
        }
    }
    return result;
}
 
Example 3
Project: marmotta   File: JsoupFunction.java   Source Code and License 5 votes vote down vote up
private LinkedList<String> doFilter(Document jsoup, Set<String> jsoupSelectors) throws IOException {
    LinkedList<String> result = new LinkedList<String>();
    for (String jsoupSel : jsoupSelectors) {
        try {
            for (Element e : jsoup.select(jsoupSel)) {
                result.add(e.outerHtml());
            }
        } catch (SelectorParseException xpe) {
            throw new IllegalArgumentException("error while processing jsoup selector: '" + jsoupSel + "'", xpe);
        }
    }
    return result;
}
 
Example 4
Project: Tanaguru   File: DOMHandlerImpl.java   Source Code and License 5 votes vote down vote up
/**
 * http://www.ibm.com/developerworks/library/x-javaxpathapi.html
 *
 * @param expr
 * @return
 */
@Override
public DOMHandler cssLikeSelectNodeSet(String expr) {
    if (StringUtils.isNotBlank(expr)) {
        try {
        selectedElements = jsoupDocument.select(expr);
        } catch (SelectorParseException spe) {               
        } catch (IllegalArgumentException iae) {
        }
    }
    return this;
}