Search in sources :

Example 1 with DOMException

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

the class ElementImpl 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.");
    }
    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);
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) NodeListImpl(org.loboevolution.html.dom.nodeimpl.NodeListImpl) SelectorList(com.gargoylesoftware.css.parser.selector.SelectorList) ElementFilter(org.loboevolution.html.dom.filter.ElementFilter) HTMLBodyElement(org.loboevolution.html.dom.HTMLBodyElement) Selector(com.gargoylesoftware.css.parser.selector.Selector)

Example 2 with DOMException

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

the class HTMLTableRowElementImpl method insertCell.

/**
 * {@inheritDoc}
 */
@Override
public HTMLTableCellElement insertCell() {
    final Document doc = this.document;
    if (doc == null) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Orphan element");
    }
    HTMLTableCellElementImpl cellElement = (HTMLTableCellElementImpl) doc.createElement("TD");
    appendChild(cellElement);
    return cellElement;
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) Document(org.loboevolution.html.node.Document)

Example 3 with DOMException

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

the class HTMLTableElementImpl method insertRow.

/**
 * {@inheritDoc}
 */
@Override
public HTMLTableRowElement insertRow() {
    final Document doc = this.document;
    if (doc == null) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Orphan element");
    }
    final HTMLTableRowElement rowElement = (HTMLTableRowElement) doc.createElement("TR");
    appendChild(rowElement);
    return rowElement;
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) Document(org.loboevolution.html.node.Document)

Example 4 with DOMException

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

the class XPathExpressionImpl method evaluate.

/**
 * {@inheritDoc}
 */
@Override
public Object evaluate(Node contextNode, short type, Object result) throws XPathException, DOMException {
    // If the XPathEvaluator was determined by "casting" the document
    if (m_doc != null) {
        // Check that the context node is owned by the same document
        if (!Objects.equals(contextNode, m_doc) && !contextNode.getOwnerDocument().equals(m_doc)) {
            String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_WRONG_DOCUMENT, null);
            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, fmsg);
        }
        // Check that the context node is an acceptable node type
        NodeType nodeType = contextNode.getNodeType();
        switch(nodeType) {
            case DOCUMENT_NODE:
            case ELEMENT_NODE:
            case ATTRIBUTE_NODE:
            case TEXT_NODE:
            case CDATA_SECTION_NODE:
            case COMMENT_NODE:
            case PROCESSING_INSTRUCTION_NODE:
                break;
            default:
                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_WRONG_NODETYPE, null);
                throw new UnsupportedOperationException(fmsg);
        }
    }
    if (!XPathResultImpl.isValidType(type)) {
        String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_INVALID_XPATH_TYPE, new Object[] { (int) type });
        throw new XPathException(XPathException.TYPE_ERR, fmsg);
    }
    XPathContext xpathSupport = new XPathContext(false);
    XObject xobj = null;
    return new XPathResultImpl(type, xobj, contextNode, m_xpath);
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) XPathException(org.loboevolution.html.xpath.XPathException) NodeType(org.loboevolution.type.NodeType) XPathContext(org.apache.xpath.XPathContext) XObject(org.apache.xpath.objects.XObject)

Example 5 with DOMException

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

the class CSSStyleSheetImpl method deleteRule.

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

Aggregations

DOMException (com.gargoylesoftware.css.dom.DOMException)28 Test (org.junit.Test)12 LoboUnitTest (org.loboevolution.driver.LoboUnitTest)12 HTMLElement (org.loboevolution.html.dom.HTMLElement)9 HTMLLinkElement (org.loboevolution.html.dom.HTMLLinkElement)9 Document (org.loboevolution.html.node.Document)7 NodeListImpl (org.loboevolution.html.dom.nodeimpl.NodeListImpl)4 Node (org.loboevolution.html.node.Node)3 Selector (com.gargoylesoftware.css.parser.selector.Selector)2 SelectorList (com.gargoylesoftware.css.parser.selector.SelectorList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)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 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 StringTokenizer (java.util.StringTokenizer)1