use of org.structr.web.entity.dom.ShadowDocument in project structr by structr.
the class AbstractCommand method getOrCreateHiddenDocument.
/**
* Search for a hidden page named __ShadowDocument__ of type.
*
* If found, return it, if not, create it.
* The shadow page is the DOM document all reusable components are connected to.
* It is necessary to comply with DOM standards.
*
* @return shadow document
* @throws FrameworkException
*/
public static ShadowDocument getOrCreateHiddenDocument() throws FrameworkException {
final App app = StructrApp.getInstance();
ShadowDocument doc = app.nodeQuery(ShadowDocument.class).includeDeletedAndHidden().getFirst();
if (doc == null) {
final PropertyMap properties = new PropertyMap();
properties.put(AbstractNode.type, ShadowDocument.class.getSimpleName());
properties.put(AbstractNode.name, "__ShadowDocument__");
properties.put(AbstractNode.hidden, true);
properties.put(AbstractNode.visibleToAuthenticatedUsers, true);
doc = app.create(ShadowDocument.class, properties);
}
return doc;
}
use of org.structr.web.entity.dom.ShadowDocument in project structr by structr.
the class ListComponentsCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final int pageSize = webSocketData.getPageSize();
final int page = webSocketData.getPage();
try {
final ShadowDocument hiddenDoc = CreateComponentCommand.getOrCreateHiddenDocument();
List<DOMNode> filteredResults = new LinkedList();
List<DOMNode> resultList = hiddenDoc.getElements();
// Filter list and return only top level nodes
for (DOMNode node : resultList) {
if (Boolean.FALSE.equals(node.hasIncomingRelationships(node.getChildLinkType()))) {
filteredResults.add(node);
}
}
// Sort the components by name
Collections.sort(filteredResults, new Comparator<DOMNode>() {
@Override
public int compare(DOMNode node1, DOMNode node2) {
final String nameNode1 = node1.getProperty(DOMNode.name);
final String nameNode2 = node2.getProperty(DOMNode.name);
if (nameNode1 != null && nameNode2 != null) {
return nameNode1.compareTo(nameNode2);
} else if (nameNode1 == null && nameNode2 == null) {
return 0;
} else if (nameNode1 == null) {
return -1;
} else {
return 1;
}
}
});
// save raw result count
int resultCountBeforePaging = filteredResults.size();
// set full result list
webSocketData.setResult(PagingHelper.subList(filteredResults, pageSize, page));
webSocketData.setRawResultCount(resultCountBeforePaging);
// send only over local connection
getWebSocket().send(webSocketData, true);
} catch (FrameworkException fex) {
logger.warn("Exception occured", fex);
getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
}
}
Aggregations