use of org.structr.web.entity.dom.DOMElement in project structr by structr.
the class SimpleTest method test01DOMChildren.
@Test
public void test01DOMChildren() {
final String pageName = "page-01";
final String pageTitle = "Page Title";
try (final Tx tx = app.tx()) {
Page page = Page.createNewPage(securityContext, pageName);
if (page != null) {
DOMElement html = (DOMElement) page.createElement("html");
DOMElement head = (DOMElement) page.createElement("head");
DOMElement title = (DOMElement) page.createElement("title");
Text titleText = page.createTextNode(pageTitle);
for (AbstractRelationship r : page.getIncomingRelationships()) {
System.out.println("============ Relationship: " + r.toString());
assertEquals("PAGE", r.getRelType().name());
}
html.appendChild(head);
for (AbstractRelationship r : head.getIncomingRelationships()) {
System.out.println("============ Relationship: " + r.toString());
assertEquals("CONTAINS", r.getRelType().name());
}
head.appendChild(title);
title.appendChild(titleText);
for (AbstractRelationship r : ((DOMNode) titleText).getIncomingRelationships()) {
System.out.println("============ Relationship: " + r.toString());
assertEquals("CONTAINS", r.getRelType().name());
}
}
tx.success();
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.web.entity.dom.DOMElement in project structr by structr.
the class SimpleTest method testPagePath.
@Test
public void testPagePath() {
final String pageName = "page-01";
try (final Tx tx = app.tx()) {
Page page = Page.createNewPage(securityContext, pageName);
assertTrue(page != null);
assertTrue(page instanceof Page);
DOMElement html = (DOMElement) page.createElement("html");
DOMElement head = (DOMElement) page.createElement("head");
DOMElement body = (DOMElement) page.createElement("body");
DOMElement title = (DOMElement) page.createElement("title");
DOMElement div = (DOMElement) page.createElement("div");
DOMElement div_2 = (DOMElement) page.createElement("div");
DOMElement div_3 = (DOMElement) page.createElement("div");
DOMElement h1 = (DOMElement) page.createElement("h1");
DOMElement h1_2 = (DOMElement) page.createElement("h1");
try {
// add HTML element to page
page.appendChild(html);
// add HEAD and BODY elements to HTML
html.appendChild(head);
html.appendChild(body);
// add TITLE element to HEAD
head.appendChild(title);
title.appendChild(page.createTextNode("Test Page"));
// add DIVs to BODY
body.appendChild(div);
body.appendChild(div_2);
body.appendChild(div_3);
// add H1 elements to DIV
div_3.appendChild(h1);
div_3.appendChild(h1_2);
h1.appendChild(page.createTextNode("Page Title"));
} catch (DOMException dex) {
throw new FrameworkException(422, dex.getMessage());
}
assertEquals(html.getPositionPath(), "/0");
assertEquals(head.getPositionPath(), "/0/0");
assertEquals(title.getPositionPath(), "/0/0/0");
assertEquals(body.getPositionPath(), "/0/1");
assertEquals(div.getPositionPath(), "/0/1/0");
assertEquals(div_2.getPositionPath(), "/0/1/1");
assertEquals(div_3.getPositionPath(), "/0/1/2");
assertEquals(h1.getPositionPath(), "/0/1/2/0");
assertEquals(h1_2.getPositionPath(), "/0/1/2/1");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception");
}
}
use of org.structr.web.entity.dom.DOMElement in project structr by structr.
the class XPathTest method testSimpleXPath.
@Test
public void testSimpleXPath() {
final String pageName = "page-01";
try (final Tx tx = app.tx()) {
Page page = Page.createNewPage(securityContext, pageName);
assertTrue(page != null);
assertTrue(page instanceof Page);
DOMElement html = (DOMElement) page.createElement("html");
DOMElement head = (DOMElement) page.createElement("head");
DOMElement body = (DOMElement) page.createElement("body");
DOMElement title = (DOMElement) page.createElement("title");
DOMElement h1 = (DOMElement) page.createElement("h1");
try {
// add HTML element to page
page.appendChild(html);
// add HEAD and BODY elements to HTML
html.appendChild(head);
html.appendChild(body);
// add TITLE element to HEAD
head.appendChild(title);
title.appendChild(page.createTextNode("Test Page"));
// add H1 element to BODY
body.appendChild(h1);
h1.appendChild(page.createTextNode("Page Title"));
} catch (DOMException dex) {
throw new FrameworkException(422, dex.getMessage());
}
assertEquals(html, page.getChildNodes().item(1));
assertEquals(head, html.getChildNodes().item(0));
assertEquals(body, html.getChildNodes().item(1));
// test XPath support of structr nodes..
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
// let xpath cache first..
assertEquals("Page Title", xpath.evaluate("/html/body/h1/text()", page, XPathConstants.STRING));
assertEquals(h1, xpath.evaluate("/html/body/h1", page, XPathConstants.NODE));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception");
} catch (XPathExpressionException xpeex) {
logger.warn("", xpeex);
fail("Unexpected exception");
}
}
use of org.structr.web.entity.dom.DOMElement in project structr by structr.
the class DeploymentTest method hash.
private void hash(final NodeInterface node, final StringBuilder buf) {
// AbstractNode
buf.append(valueOrEmpty(node, AbstractNode.type));
buf.append(valueOrEmpty(node, AbstractNode.name));
buf.append(valueOrEmpty(node, AbstractNode.visibleToPublicUsers));
buf.append(valueOrEmpty(node, AbstractNode.visibleToAuthenticatedUsers));
// include owner in content hash generation!
final Principal owner = node.getOwnerNode();
if (owner != null) {
buf.append(valueOrEmpty(owner, AbstractNode.name));
}
// include grants in content hash generation!
for (final Security r : node.getSecurityRelationships()) {
if (r != null) {
buf.append(r.getSourceNode().getName());
buf.append(r.getPermissions());
}
}
// DOMNode
buf.append(valueOrEmpty(node, StructrApp.key(DOMNode.class, "showConditions")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMNode.class, "hideConditions")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMNode.class, "showForLocales")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMNode.class, "hideForLocales")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMNode.class, "hideOnIndex")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMNode.class, "hideOnDetail")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMNode.class, "renderDetails")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMNode.class, "sharedComponentConfiguration")));
if (node instanceof DOMNode) {
final Page ownerDocument = ((DOMNode) node).getOwnerDocument();
if (ownerDocument != null) {
buf.append(valueOrEmpty(ownerDocument, AbstractNode.name));
}
}
// DOMElement
buf.append(valueOrEmpty(node, StructrApp.key(DOMElement.class, "dataKey")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMElement.class, "restQuery")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMElement.class, "cypherQuery")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMElement.class, "xpathQuery")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMElement.class, "functionQuery")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMElement.class, "data-structr-reload")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMElement.class, "data-structr-confirm")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMElement.class, "data-structr-action")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMElement.class, "data-structr-attributes")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMElement.class, "data-structr-attr")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMElement.class, "data-structr-name")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMElement.class, "data-structr-hide")));
buf.append(valueOrEmpty(node, StructrApp.key(DOMElement.class, "data-structr-raw-value")));
// Content
buf.append(valueOrEmpty(node, StructrApp.key(Content.class, "contentType")));
buf.append(valueOrEmpty(node, StructrApp.key(Content.class, "content")));
// Page
buf.append(valueOrEmpty(node, StructrApp.key(Page.class, "cacheForSeconds")));
buf.append(valueOrEmpty(node, StructrApp.key(Page.class, "dontCache")));
buf.append(valueOrEmpty(node, StructrApp.key(Page.class, "pageCreatesRawData")));
buf.append(valueOrEmpty(node, StructrApp.key(Page.class, "position")));
buf.append(valueOrEmpty(node, StructrApp.key(Page.class, "showOnErrorCodes")));
// HTML attributes
if (node instanceof DOMElement) {
for (final PropertyKey key : ((DOMElement) node).getHtmlAttributes()) {
buf.append(valueOrEmpty(node, key));
}
}
for (final PropertyKey key : node.getPropertyKeys(PropertyView.All)) {
if (!key.isPartOfBuiltInSchema()) {
buf.append(valueOrEmpty(node, key));
}
}
}
use of org.structr.web.entity.dom.DOMElement in project structr by structr.
the class XPathTest method testXPathAttributes.
@Test
public void testXPathAttributes() {
final String pageName = "page-02";
try (final Tx tx = app.tx()) {
Page page = Page.createNewPage(securityContext, pageName);
assertTrue(page != null);
assertTrue(page instanceof Page);
DOMElement html = (DOMElement) page.createElement("html");
DOMElement head = (DOMElement) page.createElement("head");
DOMElement body = (DOMElement) page.createElement("body");
DOMElement title = (DOMElement) page.createElement("title");
DOMElement div = (DOMElement) page.createElement("div");
DOMElement p1 = (DOMElement) page.createElement("p");
DOMElement p2 = (DOMElement) page.createElement("p");
DOMElement p3 = (DOMElement) page.createElement("p");
try {
// add HTML element to page
page.appendChild(html);
// add HEAD and BODY elements to HTML
html.appendChild(head);
html.appendChild(body);
// add TITLE element to HEAD
head.appendChild(title);
title.appendChild(page.createTextNode("Test Page"));
// add H1 element to BODY
body.appendChild(div);
div.appendChild(p1);
div.appendChild(p2);
div.appendChild(p3);
// test
p2.setAttribute("blah", "wurst");
p3.setAttribute("index", "42");
} catch (DOMException dex) {
throw new FrameworkException(422, dex.getMessage());
}
// test XPath support of structr nodes..
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
// let xpath cache first..
assertEquals(div, xpath.evaluate("/html/body/div", page, XPathConstants.NODE));
assertEquals(p2, xpath.evaluate("/html/body/div/p[@blah='wurst']", page, XPathConstants.NODE));
assertEquals(p3, xpath.evaluate("/html/body/div/p[@index=42]", page, XPathConstants.NODE));
assertEquals(p3, xpath.evaluate("/html/body/div/p[@index>40]", page, XPathConstants.NODE));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception");
} catch (XPathExpressionException xpeex) {
logger.warn("", xpeex);
fail("Unexpected exception");
}
}
Aggregations