}
}
}
private DocumentNode getPasteInsertNode(GroupSchemaNode parentSchemaNode, PasteElementNode sourceNode, DatabaseSchema schema) throws org.dbwiki.exception.WikiException {
SchemaNode schemaNode = null;
if (parentSchemaNode != null) {
for (int i = 0; i < parentSchemaNode.children().size(); i++) {
// TODO: we probably need to be careful about which bits of the
// schema are current
if (parentSchemaNode.children().get(i).label().equals(sourceNode.label())) {
schemaNode = parentSchemaNode.children().get(i);
break;
}
}
if (schemaNode == null) {
if (_wiki.getAutoSchemaChanges() == DatabaseWikiProperties.AutoSchemaChangesAllow) {
if (sourceNode.isAttribute()) {
schemaNode = new AttributeSchemaNode(schema.size(), sourceNode.label(), parentSchemaNode, null);
} else {
schemaNode = new GroupSchemaNode(schema.size(), sourceNode.label(), parentSchemaNode, null);
}
schema.add(schemaNode);
} else if (_wiki.getAutoSchemaChanges() == DatabaseWikiProperties.AutoSchemaChangesNever) {
throw new WikiDataException(WikiDataException.UnknownSchemaNode, sourceNode.label() + " not allowed under " + parentSchemaNode.label());
}
}
} else if (schema.root() != null) {
schemaNode = schema.root();
if (!schemaNode.label().equals(sourceNode.label())) {
throw new WikiDataException(WikiDataException.InvalidPasteTarget, "Node label does not match root label");
}
} else {
if (_wiki.getAutoSchemaChanges() == DatabaseWikiProperties.AutoSchemaChangesAllow) {
schemaNode = new GroupSchemaNode(schema.size(), sourceNode.label(), null, null);
schema.add(schemaNode);
} else if (_wiki.getAutoSchemaChanges() == DatabaseWikiProperties.AutoSchemaChangesNever) {
throw new WikiDataException(WikiDataException.UnknownSchemaNode, sourceNode.label() + " not allowed as schema root");
}
}
if (schemaNode != null) {
if (schemaNode.isAttribute()) {
return new DocumentAttributeNode((AttributeSchemaNode)schemaNode, ((PasteAttributeNode)sourceNode).getValue().getValue());
} else {
DocumentGroupNode group = new DocumentGroupNode((GroupSchemaNode)schemaNode);
for (int iChild = 0; iChild < ((PasteGroupNode)sourceNode).children().size(); iChild++) {
DocumentNode insertChild = getPasteInsertNode((GroupSchemaNode)schemaNode, (PasteElementNode)((PasteGroupNode)sourceNode).children().get(iChild), schema);