public ResourceIdentifier decode(Database database, DatabaseGroupNode node, RequestParameterVersion versionParameter, RequestURL url, int pathIndex) throws org.dbwiki.exception.WikiException {
// FORMAT: {/[<label>:<key-value>|<key-value>]}+ /[<label>|<label>:<key-value>|<key-value>]
GroupSchemaNode schemaNode = (GroupSchemaNode)node.schema();
String nodeIdentifier = url.get(pathIndex).decodedText();
URLDecodingRule rule = null;
String keyValue = nodeIdentifier;
int pos = nodeIdentifier.indexOf(':');
if (pos != -1) {
String nodeLabel = nodeIdentifier.substring(0, pos);
rule = this.get(schemaNode.children().get(nodeLabel));
keyValue = nodeIdentifier.substring(pos + 1);
} else {
// If it's the last element of the URL path the nodeIdentifier could be the node label
// of an attribute node or a key value for an internal node.
// First check whether the nodeIdentifier is a valid node label for the current
// schema node.
for (int iChild = 0; iChild < schemaNode.children().size(); iChild++) {
SchemaNode childSchema = schemaNode.children().get(iChild);
if ((childSchema.label().equals(nodeIdentifier)) && (childSchema.isAttribute())) {
// Make sure that there is only one child
DatabaseElementList nodes = node.find(childSchema.path().substring(node.schema().path().length() + 1));
if (nodes.size() > 1) {
throw new WikiDataException(WikiDataException.UnknownResource, url.toString());
} else if (nodes.size() == 1) {
if (pathIndex == (url.size() - 1)) {
return nodes.get(0).identifier();
} else {
return this.decode(database, (DatabaseGroupNode)nodes.get(0), versionParameter, url, pathIndex + 1);
}
} else {
throw new WikiDataException(WikiDataException.UnknownResource, url.toString());
}
}
}
// This part of the code is only reached if the nodeIdentifier does not point
// to an attribute node. There should only be one schema node child with a rule defined
// for that node.
for (int iChild = 0; iChild < schemaNode.children().size(); iChild++) {
URLDecodingRule childRule = this.get(schemaNode.children().get(iChild));
if (childRule != null) {
if (rule == null) {
rule = childRule;
} else {
throw new WikiDataException(WikiDataException.UnknownResource, url.toString());