in taverna-rest-activity/src/main/java/org/apache/taverna/activities/rest/URISignatureHandler.java [79:141]
public static LinkedHashMap<String, Integer> extractPlaceholdersWithPositions(
String uriSignature) {
// no signature - nothing to process
if (uriSignature == null || uriSignature.isEmpty())
throw new URISignatureParsingException(
"URI signature is null or empty - nothing to process.");
LinkedHashMap<String, Integer> foundPlaceholdersWithPositions = new LinkedHashMap<>();
int nestingLevel = 0;
int startSymbolIdx = -1;
// go through the signature character by character trying to extract
// placeholders
for (int i = 0; i < uriSignature.length(); i++) {
switch (uriSignature.charAt(i)) {
case PLACEHOLDER_START_SYMBOL:
if (++nestingLevel != 1)
throw new URISignatureParsingException(
"Malformed URL: at least two parameter placeholder opening\n" +
"symbols follow each other without being closed appropriately\n" +
"(possibly the signature contains nested placeholders).");
startSymbolIdx = i;
break;
case PLACEHOLDER_END_SYMBOL:
if (--nestingLevel < 0)
throw new URISignatureParsingException(
"Malformed URL: parameter placeholder closing symbol found before the opening one.");
if (nestingLevel == 0) {
// correctly opened and closed placeholder found; check if
// it is a "fresh" one
String placeholderCandidate = uriSignature.substring(
startSymbolIdx + 1, i);
if (!foundPlaceholdersWithPositions
.containsKey(placeholderCandidate)) {
foundPlaceholdersWithPositions.put(
placeholderCandidate, startSymbolIdx + 1);
} else {
throw new URISignatureParsingException(
"Malformed URL: duplicate parameter placeholder \""
+ placeholderCandidate + "\" found.");
}
}
break;
default:
continue;
}
}
// the final check - make sure that after traversing the string, we are
// not "inside" one of the placeholders (e.g. this could happen if a
// placeholder
// opening symbol was found, but the closing one never occurred after
// that)
if (nestingLevel > 0)
throw new URISignatureParsingException(
"Malformed URL: parameter placeholder opening symbol found,\n"
+ "but the closing one has not been encountered.");
return foundPlaceholdersWithPositions;
}