Search in sources :

Example 6 with DOMException

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

the class ElementImpl method querySelector.

/**
 * {@inheritDoc}
 */
@Override
public Element querySelector(String selectors) {
    try {
        SelectorList selectorList = CSSUtilities.getSelectorList(selectors);
        List<Element> elem = new ArrayList<>();
        if (selectorList != null) {
            NodeListImpl childNodes = (NodeListImpl) getDescendents(new ElementFilter(null), true);
            childNodes.forEach(child -> {
                for (Selector selector : selectorList) {
                    if (child instanceof Element && StyleSheetAggregator.selects(selector, child, null)) {
                        elem.add((Element) child);
                    }
                }
            });
        }
        return elem.size() > 0 ? elem.get(0) : null;
    } 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) HTMLBodyElement(org.loboevolution.html.dom.HTMLBodyElement) ElementFilter(org.loboevolution.html.dom.filter.ElementFilter) DOMException(com.gargoylesoftware.css.dom.DOMException) Selector(com.gargoylesoftware.css.parser.selector.Selector)

Example 7 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.");
    }
    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) ElementFilter(org.loboevolution.html.dom.filter.ElementFilter) HTMLBodyElement(org.loboevolution.html.dom.HTMLBodyElement) DOMException(com.gargoylesoftware.css.dom.DOMException) Selector(com.gargoylesoftware.css.parser.selector.Selector)

Example 8 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 9 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 10 with DOMException

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

the class SVGLengthImpl method setValueAsString.

/**
 * {@inheritDoc}
 */
@Override
public void setValueAsString(String valueAsString) {
    if (valueAsString == null) {
        valueAsString = "0";
    }
    String valueString;
    if (valueAsString.endsWith("cm")) {
        valueString = valueAsString.substring(0, valueAsString.length() - 2);
        this.unitType = SVGLength.SVG_LENGTHTYPE_CM;
    } else if (valueAsString.endsWith("ems")) {
        valueString = valueAsString.substring(0, valueAsString.length() - 3);
        this.unitType = SVGLength.SVG_LENGTHTYPE_EMS;
    } else if (valueAsString.endsWith("exs")) {
        valueString = valueAsString.substring(0, valueAsString.length() - 3);
        this.unitType = SVGLength.SVG_LENGTHTYPE_EXS;
    } else if (valueAsString.endsWith("in")) {
        valueString = valueAsString.substring(0, valueAsString.length() - 2);
        this.unitType = SVGLength.SVG_LENGTHTYPE_IN;
    } else if (valueAsString.endsWith("mm")) {
        valueString = valueAsString.substring(0, valueAsString.length() - 2);
        this.unitType = SVGLength.SVG_LENGTHTYPE_MM;
    } else if (valueAsString.endsWith("pc")) {
        valueString = valueAsString.substring(0, valueAsString.length() - 2);
        this.unitType = SVGLength.SVG_LENGTHTYPE_PC;
    } else if (valueAsString.endsWith("%")) {
        valueString = valueAsString.substring(0, valueAsString.length() - 1);
        this.unitType = SVGLength.SVG_LENGTHTYPE_PERCENTAGE;
    } else if (valueAsString.endsWith("pt")) {
        valueString = valueAsString.substring(0, valueAsString.length() - 2);
        this.unitType = SVGLength.SVG_LENGTHTYPE_PT;
    } else if (valueAsString.endsWith("px")) {
        valueString = valueAsString.substring(0, valueAsString.length() - 2);
        this.unitType = SVGLength.SVG_LENGTHTYPE_PX;
    } else {
        valueString = valueAsString;
        this.unitType = SVGLength.SVG_LENGTHTYPE_NUMBER;
    }
    try {
        this.valueInSpecifiedUnits = Float.parseFloat(valueString);
    } catch (NumberFormatException e) {
        throw new DOMException(DOMException.SYNTAX_ERR, "Invalid value: '" + valueString + "'!");
    }
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException)

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