return mapReader.getCurrentNodeTreeCreator().getMapChild();
}
private void registerAttributeHandlers(final ReadManager reader) {
reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeBuilder.XML_NODE_ENCRYPTED_CONTENT,
new IAttributeHandler() {
private void createEncryptedNode(final NodeModel node, final String additionalInfo) {
final EncryptionModel encryptionModel = new EncryptionModel(node, additionalInfo);
node.addExtension(encryptionModel);
}
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
createEncryptedNode(node, value);
node.setFolded(true);
}
});
reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeBuilder.XML_NODE_HISTORY_CREATED_AT,
new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
if (node.getHistoryInformation() == null) {
node.setHistoryInformation(new HistoryInformationModel());
}
node.getHistoryInformation().setCreatedAt(TreeXmlReader.xmlToDate(value));
}
});
reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeBuilder.XML_NODE_HISTORY_LAST_MODIFIED_AT,
new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
if (node.getHistoryInformation() == null) {
node.setHistoryInformation(new HistoryInformationModel());
}
node.getHistoryInformation().setLastModifiedAt(TreeXmlReader.xmlToDate(value));
}
});
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "FOLDED", new IAttributeHandler() {
public void setAttribute(Object userObject, String value) {
}
});
reader.addAttributeHandler(NodeBuilder.XML_NODE, "FOLDED", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
final Object mode = mapReader.getCurrentNodeTreeCreator().getHint(Hint.MODE);
if (mode.equals(Mode.FILE)) {
final String loadFolding = ResourceController.getResourceController().getProperty(
NodeBuilder.RESOURCES_LOAD_FOLDING);
if (loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_FOLD_ALL_AFTER_LOAD)
|| loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_UNFOLD_ALL_AFTER_LOAD)) {
return;
}
mapReader.getCurrentNodeTreeCreator().setHint(FOLDING_LOADED, Boolean.TRUE);
}
if (value.equals("true")) {
node.setFolded(true);
}
}
});
reader.addReadCompletionListener(new IReadCompletionListener() {
private int foldAll(final NodeModel node, int nodeCount) {
if (node.getChildCount() == 0) {
return nodeCount;
}
if (nodeCount <= 0) {
node.setFolded(true);
}
else{
nodeCount -= node.getChildCount();
}
for (final NodeModel child : node.getChildren()) {
nodeCount = foldAll(child, nodeCount);
}
return nodeCount;
}
public void readingCompleted(final NodeModel topNode, final Map<String, String> newIds) {
if (!Mode.FILE.equals(mapReader.getCurrentNodeTreeCreator().getHint(Hint.MODE))) {
return;
}
if (Boolean.TRUE.equals(mapReader.getCurrentNodeTreeCreator().getHint(NodeBuilder.FOLDING_LOADED))) {
return;
}
final ResourceController resourceController = ResourceController.getResourceController();
final String loadFolding = resourceController.getProperty(NodeBuilder.RESOURCES_LOAD_FOLDING);
if (loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_FOLD_ALL_AFTER_LOAD)
|| loadFolding.equals(NodeBuilder.RESOURCES_LOAD_FOLDING_FROM_MAP_DEFAULT_FOLD_ALL)) {
int nodeCount = resourceController.getIntProperty(NodeBuilder.MAX_DISPLAYED_NODE_COUNT, 20);
final List<NodeModel> children = topNode.getChildren();
nodeCount = nodeCount - 1 - children.size();
for (final NodeModel child : children) {
nodeCount = foldAll(child, nodeCount);
}
}
}
});
final IAttributeHandler positionHandler = new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
node.setLeft(value.equals("left"));
}
};
reader.addAttributeHandler(NodeBuilder.XML_NODE, "POSITION", positionHandler);
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "POSITION", positionHandler);
reader.addAttributeHandler(NodeBuilder.XML_NODE, "ID", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
final String realId = getMap().generateNodeID(value);
node.setID(realId);
if (!realId.equals(value)) {
mapReader.getCurrentNodeTreeCreator().substituteNodeID(value, realId);
}
}
});
reader.addAttributeHandler(NodeBuilder.XML_NODE, "REFERENCE_ID", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String proposedReferenceId) {
final NodeModel node = (NodeModel) userObject;
final String realReference = mapReader.getCurrentNodeTreeCreator().substitutedID(proposedReferenceId);
node.convertToClone(getMap().getNodeForID(realReference));
}