use of org.structr.web.entity.dom.ShadowDocument in project structr by structr.
the class UiSyncCommand method doImport.
private void doImport(final String fileName) throws FrameworkException {
final App app = StructrApp.getInstance();
final DatabaseService graphDb = app.getDatabaseService();
SyncCommand.importFromFile(graphDb, securityContext, fileName, true);
// import done, now the ShadowDocument needs some special care. :(
try (final Tx tx = app.tx()) {
final List<ShadowDocument> shadowDocuments = app.nodeQuery(ShadowDocument.class).includeDeletedAndHidden().getAsList();
if (shadowDocuments.size() > 1) {
final PropertyKey<List<DOMNode>> elementsKey = StructrApp.key(Page.class, "elements");
final List<DOMNode> collectiveChildren = new LinkedList<>();
// sort by node id (higher node ID is newer entity)
Collections.sort(shadowDocuments, new Comparator<ShadowDocument>() {
@Override
public int compare(final ShadowDocument t1, final ShadowDocument t2) {
return Long.valueOf(t2.getId()).compareTo(t1.getId());
}
});
final ShadowDocument previousShadowDoc = shadowDocuments.get(0);
final ShadowDocument newShadowDoc = shadowDocuments.get(1);
// collect children of both shadow documents
collectiveChildren.addAll(previousShadowDoc.getProperty(elementsKey));
collectiveChildren.addAll(newShadowDoc.getProperty(elementsKey));
// delete old shadow document
app.delete(previousShadowDoc);
// add children to new shadow document
newShadowDoc.setProperties(securityContext, new PropertyMap(elementsKey, collectiveChildren));
}
tx.success();
}
}
use of org.structr.web.entity.dom.ShadowDocument in project structr by structr.
the class ListUnattachedNodesCommand method getUnattachedNodes.
/**
* Return list of nodes which are not attached to a page and have no
* parent element (no incoming CONTAINS rel)
*
* @param app
* @param securityContext
* @param webSocketData
* @return
* @throws FrameworkException
*/
protected static List<NodeInterface> getUnattachedNodes(final App app, final SecurityContext securityContext, final WebSocketMessage webSocketData) throws FrameworkException {
final String sortOrder = webSocketData.getSortOrder();
final String sortKey = webSocketData.getSortKey();
Query query;
if (sortKey != null) {
final PropertyKey sortProperty = StructrApp.key(DOMNode.class, sortKey);
query = StructrApp.getInstance(securityContext).nodeQuery().includeDeletedAndHidden().sort(sortProperty).order("desc".equals(sortOrder));
} else {
query = StructrApp.getInstance(securityContext).nodeQuery().includeDeletedAndHidden();
}
query.orTypes(DOMElement.class);
query.orType(Content.class);
query.orType(Template.class);
// do search
final List<NodeInterface> filteredResults = new LinkedList();
List<? extends GraphObject> resultList = null;
try (final Tx tx = app.tx()) {
resultList = query.getAsList();
tx.success();
} catch (FrameworkException fex) {
logger.warn("Exception occured", fex);
}
if (resultList != null) {
// determine which of the nodes have no incoming CONTAINS relationships and no page id
for (GraphObject obj : resultList) {
if (obj instanceof DOMNode) {
DOMNode node = (DOMNode) obj;
if (!node.hasIncomingRelationships(node.getChildLinkType()) && node.getOwnerDocument() == null && !(node instanceof ShadowDocument)) {
filteredResults.add(node);
}
}
}
}
return filteredResults;
}
use of org.structr.web.entity.dom.ShadowDocument in project structr by structr.
the class CreateComponentCommand method create.
public DOMNode create(final DOMNode node) throws FrameworkException {
final DOMNode clonedNode = (DOMNode) node.cloneNode(false);
// Child nodes of a template must stay in page tree
if (!(clonedNode instanceof Template)) {
moveChildNodes(node, clonedNode);
}
final ShadowDocument hiddenDoc = CreateComponentCommand.getOrCreateHiddenDocument();
clonedNode.setOwnerDocument(hiddenDoc);
// Change page (owner document) of all children recursively
for (DOMNode child : DOMNode.getAllChildNodes(clonedNode)) {
child.setOwnerDocument(hiddenDoc);
}
node.setSharedComponent(clonedNode);
return clonedNode;
}
use of org.structr.web.entity.dom.ShadowDocument in project structr by structr.
the class DeploymentTest method test06SimpleTemplateInSharedComponents.
@Test
public void test06SimpleTemplateInSharedComponents() {
// setup
try (final Tx tx = app.tx()) {
final Page page = Page.createNewPage(securityContext, "test06");
final Html html = createElement(page, page, "html");
final Head head = createElement(page, html, "head");
createElement(page, head, "title", "test06");
final Body body = createElement(page, html, "body");
createElement(page, body, "div");
final ShadowDocument shadowDocument = CreateComponentCommand.getOrCreateHiddenDocument();
createTemplate(shadowDocument, null, "template source - öäüÖÄÜß'\"'`");
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
// test
compare(calculateHash(), true);
}
use of org.structr.web.entity.dom.ShadowDocument in project structr by structr.
the class DeploymentTest method calculateHash.
private void calculateHash(final NodeInterface start, final StringBuilder buf, final int depth) {
buf.append(start.getType()).append("{");
hash(start, buf);
// indent
for (int i = 0; i < depth; i++) {
System.out.print(" ");
}
System.out.println(start.getType() + ": " + start.getUuid().substring(0, 5));
if (start instanceof ShadowDocument) {
for (final DOMNode child : ((ShadowDocument) start).getElements()) {
// only include toplevel elements of the shadow document
if (child.getParent() == null) {
calculateHash(child, buf, depth + 1);
}
}
} else if (start instanceof DOMNode) {
for (final DOMNode child : ((DOMNode) start).getChildren()) {
calculateHash(child, buf, depth + 1);
}
}
buf.append("}");
}
Aggregations