use of com.gargoylesoftware.css.dom.DOMException in project LoboEvolution by LoboEvolution.
the class HTMLOptionsCollectionImpl method addElements.
private void addElements(HTMLOptionElement element, HTMLElement before) {
List<Node> nodeList = getList();
if (nodeList.size() == 0) {
nodeList.add(0, element);
} else {
boolean found = false;
HTMLOptionElement bef = (HTMLOptionElement) before;
for (int i = 0; i < nodeList.size(); i++) {
HTMLOptionElement elem = (HTMLOptionElement) nodeList.get(i);
if (elem.getText().equals(bef.getText())) {
nodeList.add(i, element);
found = true;
break;
}
}
if (!found)
throw new DOMException(DOMException.NOT_FOUND_ERR, "Record not found");
}
}
use of com.gargoylesoftware.css.dom.DOMException in project LoboEvolution by LoboEvolution.
the class HTMLTableElementImpl method insertRow.
private HTMLTableRowElementImpl insertRow(Object objIndex, String tagName) throws Exception {
final Document doc = this.document;
if (doc == null) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Orphan element");
}
final HTMLTableRowElementImpl rowElement = (HTMLTableRowElementImpl) doc.createElement("TR");
int index = -1;
if (objIndex instanceof Double) {
index = ((Double) objIndex).intValue();
} else {
if (objIndex == null || "".equals(objIndex)) {
index = 0;
} else {
index = Integer.parseInt(objIndex.toString());
}
}
if (index == 0 || index == -1) {
appendChild(rowElement);
AtomicInteger cellIndex = new AtomicInteger(-1);
if (index == -1) {
NodeListImpl childNodes = (NodeListImpl) getChildNodes();
childNodes.forEach(node -> {
if (node instanceof HTMLTableRowElement) {
cellIndex.incrementAndGet();
}
});
}
rowElement.setIndex(index == -1 ? cellIndex.get() : 0);
return rowElement;
}
AtomicInteger trcount = new AtomicInteger();
nodeList.forEach(node -> {
if (node instanceof HTMLTableRowElement) {
trcount.incrementAndGet();
}
});
if (trcount.get() < index) {
throw new DOMException(DOMException.INDEX_SIZE_ERR, "The index is greater than the number of cells in the table ");
} else {
rowElement.setIndex(index);
insertAt(rowElement, index);
}
return rowElement;
}
use of com.gargoylesoftware.css.dom.DOMException in project LoboEvolution by LoboEvolution.
the class HTMLTableRowElementImpl method insertCell.
private HTMLTableCellElementImpl insertCell(Object objIndex, String tagName) {
final Document doc = this.document;
if (doc == null) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Orphan element");
}
HTMLTableCellElementImpl cellElement = (HTMLTableCellElementImpl) doc.createElement(tagName);
int index = -1;
if (objIndex instanceof Double) {
index = ((Double) objIndex).intValue();
} else {
if (objIndex == null || "".equals(objIndex)) {
index = 0;
} else {
index = Integer.parseInt(objIndex.toString());
}
}
if (index == 0 || index == -1) {
appendChild(cellElement);
AtomicInteger cellIndex = new AtomicInteger(-1);
if (index == -1) {
NodeListImpl childNodes = (NodeListImpl) getParentNode().getChildNodes();
childNodes.forEach(node -> {
if (node instanceof HTMLTableCellElementImpl) {
cellIndex.incrementAndGet();
}
});
}
cellElement.setIndex(index == -1 ? cellIndex.get() : 0);
return cellElement;
}
AtomicInteger trcount = new AtomicInteger();
nodeList.forEach(node -> {
if (node instanceof HTMLTableCellElement) {
trcount.incrementAndGet();
}
});
if (trcount.get() < index) {
throw new DOMException(DOMException.INDEX_SIZE_ERR, "The index is greater than the number of cells in the table ");
} else {
cellElement.setIndex(index);
insertAt(cellElement, index);
}
return cellElement;
}
use of com.gargoylesoftware.css.dom.DOMException in project LoboEvolution by LoboEvolution.
the class DOMImplementationTest method testCreateDocument2.
@Test
public void testCreateDocument2() {
DocumentType doctype = domImpl.createDocumentType("html", null, null);
assertNull(doctype.getNextSibling());
assertNull(doctype.getPreviousSibling());
assertNull(doctype.getParentNode());
assertNull(doctype.getOwnerDocument());
Document document = domImpl.createDocument(null, null, doctype);
assertNull(doctype.getNextSibling());
assertNull(doctype.getPreviousSibling());
assertSame(document, doctype.getOwnerDocument());
try {
domImpl.createDocument(null, null, doctype);
fail("Must throw an exception");
} catch (DOMException e) {
assertEquals(DOMException.WRONG_DOCUMENT_ERR, e.getCode());
}
}
use of com.gargoylesoftware.css.dom.DOMException in project LoboEvolution by LoboEvolution.
the class HTMLDocumentTest method testStyleElement.
@Test
public void testStyleElement() {
Element style = (Element) document.getElementsByTagName("style").item(0);
CSSStyleSheetImpl sheet = (CSSStyleSheetImpl) ((HTMLStyleElement) style).getStyleSheet();
assertNotNull(sheet);
assertEquals(0, sheet.getMedia().getLength());
assertTrue(sheet.getCssRules().getLength() > 0);
assertSame(sheet.getOwnerNode(), style);
style.setAttribute("media", "screen");
CSSStyleSheetImpl sheet2 = (CSSStyleSheetImpl) ((HTMLStyleElement) style).getStyleSheet();
assertNotNull(sheet2);
assertSame(sheet2, sheet);
assertEquals(1, sheet2.getMedia().getLength());
assertEquals("screen", sheet2.getMedia().item(0));
assertTrue(sheet2.getCssRules().getLength() > 0);
style.setTextContent("body {font-size: 14pt; margin-left: 7%;} h1 {font-size: 2.4em;}");
sheet = (CSSStyleSheetImpl) ((HTMLLinkElement) style).getSheet();
assertSame(sheet2, sheet);
assertEquals(2, sheet.getCssRules().getLength());
assertSame(sheet.getOwnerNode(), style);
assertEquals(2, sheet.insertRule("h3 {font-family: Arial}", 2));
style.normalize();
assertEquals("body {font-size: 14pt; margin-left: 7%; }h1 {font-size: 2.4em; }h3 {font-family: Arial; }", style.getTextContent());
Attr type = style.getAttributeNode("type");
type.setNodeValue("foo");
assertNull(((HTMLLinkElement) style).getSheet());
assertEquals("body {font-size: 14pt; margin-left: 7%; }h1 {font-size: 2.4em; }h3 {font-family: Arial; }", style.getTextContent());
type.setNodeValue("");
assertNotNull(((HTMLLinkElement) style).getSheet());
assertEquals("body {font-size: 14pt; margin-left: 7%; }h1 {font-size: 2.4em; }h3 {font-family: Arial; }", style.getTextContent());
type.setNodeValue("text/CSS");
sheet = (CSSStyleSheetImpl) ((HTMLLinkElement) style).getSheet();
assertNotNull(sheet);
Attr media = style.getAttributeNode("media");
media.setNodeValue("&%/(*");
assertNull(((HTMLLinkElement) style).getSheet());
media.setNodeValue("screen");
sheet = (CSSStyleSheetImpl) ((HTMLLinkElement) style).getSheet();
assertNotNull(sheet);
long sz = sheet.getCssRules().getLength();
assertEquals(3, sz);
Text text = document.createTextNode("@namespace svg url('http://www.w3.org/2000/svg');\n");
style.insertBefore(text, style.getFirstChild());
long szp1 = sz + 1;
assertEquals(szp1, sheet.getCssRules().getLength());
sheet = (CSSStyleSheetImpl) ((HTMLLinkElement) style).getSheet();
CSSRuleList rules = sheet.getCssRules();
assertEquals(szp1, rules.getLength());
Text text2 = document.createTextNode("@font-feature-values Some Font, Other Font {@swash{swishy:1;flowing:2;}@styleset{double-W:14;sharp-terminals:16 1;}}\n");
style.replaceChild(text2, text);
assertEquals(szp1, sheet.getCssRules().getLength());
sheet = (CSSStyleSheetImpl) ((HTMLLinkElement) style).getSheet();
rules = sheet.getCssRules();
assertEquals(szp1, rules.getLength());
try {
style.removeChild(text);
fail("Must throw exception");
} catch (DOMException e) {
assertEquals(DOMException.NOT_FOUND_ERR, e.getCode());
}
style.removeChild(text2);
assertEquals(sz, sheet.getCssRules().getLength());
sheet = (CSSStyleSheetImpl) ((HTMLLinkElement) style).getSheet();
rules = sheet.getCssRules();
assertEquals(sz, rules.getLength());
style.setTextContent("$@foo{bar}");
type.setNodeValue("text/xsl");
style.setTextContent("<?xml version=\"1.0\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" + "<xsl:output method=\"text\"/><xsl:template match=\"foo\">bar<xsl:value-of select=\".\"/>" + "</xsl:template></xsl:stylesheet>");
assertNull(((HTMLLinkElement) style).getSheet());
assertEquals("<?xml version=\"1.0\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" + "<xsl:output method=\"text\"/><xsl:template match=\"foo\">bar<xsl:value-of select=\".\"/>" + "</xsl:template></xsl:stylesheet>", style.getTextContent());
style.normalize();
assertEquals("<?xml version=\"1.0\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" + "<xsl:output method=\"text\"/><xsl:template match=\"foo\">bar<xsl:value-of select=\".\"/>" + "</xsl:template></xsl:stylesheet>", style.getTextContent());
}
Aggregations