Search in sources :

Example 21 with DOMException

use of com.gargoylesoftware.css.dom.DOMException in project LoboEvolution by LoboEvolution.

the class CSSStyleSheetImpl method insertRule.

/**
 * {@inheritDoc}
 */
@Override
public long insertRule(String rule, int index) {
    try {
        this.cssStyleSheet.insertRule(rule, index);
        this.cssRuleList.addStyleRule(cssStyleSheet.getCssRules());
    } catch (Exception e) {
        throw new DOMException(DOMException.INDEX_SIZE_ERR, e.getMessage());
    }
    return index;
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) DOMException(com.gargoylesoftware.css.dom.DOMException)

Example 22 with DOMException

use of com.gargoylesoftware.css.dom.DOMException in project LoboEvolution by LoboEvolution.

the class HTMLAllCollectionImpl method tags.

/**
 * Returns all tags by name.
 *
 * @param tag the name of tag
 * @return a {@link HTMLAllCollection} object.
 */
@Override
public HTMLAllCollection tags(String tag) {
    final Document doc = this.rootNode.getOwnerDocument();
    if (doc == null) {
        return null;
    }
    final HTMLAllCollection list = (HTMLAllCollection) doc.getElementsByTagName(tag);
    if (list.getLength() == 0) {
        throw new DOMException(DOMException.NOT_FOUND_ERR, "is not a valid tag name.");
    }
    return list;
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) HTMLAllCollection(org.loboevolution.html.dom.HTMLAllCollection) Document(org.loboevolution.html.node.Document)

Example 23 with DOMException

use of com.gargoylesoftware.css.dom.DOMException in project LoboEvolution by LoboEvolution.

the class DOMTokenListImpl method setValue.

/**
 * {@inheritDoc}
 */
@Override
public void setValue(String value) throws DOMException {
    if (value == null) {
        throw new DOMException(DOMException.SYNTAX_ERR, "Token cannot be null");
    }
    tokenset.clear();
    StringTokenizer st = new StringTokenizer(value);
    while (st.hasMoreTokens()) {
        tokenset.add(st.nextToken());
    }
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) StringTokenizer(java.util.StringTokenizer)

Example 24 with DOMException

use of com.gargoylesoftware.css.dom.DOMException in project LoboEvolution by LoboEvolution.

the class DocumentImpl method createTextNode.

/**
 * {@inheritDoc}
 */
@Override
public Text createTextNode(String data) {
    if (data == null) {
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "null data");
    }
    final TextImpl node = new TextImpl(data);
    node.setOwnerDocument(this);
    return node;
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) TextImpl(org.loboevolution.html.dom.nodeimpl.TextImpl)

Example 25 with DOMException

use of com.gargoylesoftware.css.dom.DOMException in project LoboEvolution by LoboEvolution.

the class DocumentImpl method querySelectorAll.

/**
 * {@inheritDoc}
 */
@Override
public NodeList querySelectorAll(String selector) {
    final ArrayList<Node> al = new ArrayList<>();
    if (selector == null) {
        return new NodeListImpl(al);
    }
    if (selector.isEmpty()) {
        throw new DOMException(DOMException.NOT_FOUND_ERR, "The provided selector is empty.");
    }
    if (selector.trim().isEmpty()) {
        throw new DOMException(DOMException.NOT_FOUND_ERR, "is not a valid selector.");
    }
    try {
        SelectorList selectorList = CSSUtilities.getSelectorList(selector);
        if (selectorList != null) {
            NodeListImpl childNodes = (NodeListImpl) getDescendents(new ElementFilter(null), true);
            childNodes.forEach(child -> {
                for (Selector select : selectorList) {
                    if (child instanceof Element && StyleSheetAggregator.selects(select, child, null)) {
                        al.add(child);
                    }
                }
            });
        }
        return new NodeListImpl(al);
    } catch (Exception e) {
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "Is not a valid selector.");
    }
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) NodeListImpl(org.loboevolution.html.dom.nodeimpl.NodeListImpl) SelectorList(com.gargoylesoftware.css.parser.selector.SelectorList) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DOMException(com.gargoylesoftware.css.dom.DOMException) Selector(com.gargoylesoftware.css.parser.selector.Selector)

Aggregations

DOMException (com.gargoylesoftware.css.dom.DOMException)31 Test (org.junit.Test)12 LoboUnitTest (org.loboevolution.driver.LoboUnitTest)12 HTMLElement (org.loboevolution.html.dom.HTMLElement)8 HTMLLinkElement (org.loboevolution.html.dom.HTMLLinkElement)8 Document (org.loboevolution.html.node.Document)8 NodeListImpl (org.loboevolution.html.dom.nodeimpl.NodeListImpl)6 Selector (com.gargoylesoftware.css.parser.selector.Selector)4 SelectorList (com.gargoylesoftware.css.parser.selector.SelectorList)4 Node (org.loboevolution.html.node.Node)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 HTMLBodyElement (org.loboevolution.html.dom.HTMLBodyElement)2 ElementFilter (org.loboevolution.html.dom.filter.ElementFilter)2 DocumentType (org.loboevolution.html.node.DocumentType)2 UserAgentContext (org.loboevolution.http.UserAgentContext)2 CSSStyleDeclarationImpl (com.gargoylesoftware.css.dom.CSSStyleDeclarationImpl)1 CSSOMParser (com.gargoylesoftware.css.parser.CSSOMParser)1 CSS3Parser (com.gargoylesoftware.css.parser.javacc.CSS3Parser)1