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.");
}
}
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.");
}
}
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;
}
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;
}
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 + "'!");
}
}
Aggregations