// removed). An absolute path can be applied anywhere in the clone
// document structure to find the equivalent element. This assumes that
// the clone is really in a fully defined document (such as that
// returned by {@link cloneContainingDeviceLayout}) with just one
// device layout.
XPath path = new XPath(original);
// The device layout predicate must be removed from the path (the clone
// will only have one device layout) if there is one
String pathText = path.getExternalForm();
int secondSeparator = pathText.indexOf('/', 1);
if (secondSeparator > 0) {
secondSeparator = pathText.indexOf('/', secondSeparator + 1);
if (secondSeparator > 0) {
char deviceLayoutPathEnd =
pathText.charAt(secondSeparator - 1);
if (deviceLayoutPathEnd == ']') {
path = new XPath(
new StringBuffer(
pathText.substring(0,
pathText.indexOf('['))).
append(pathText.substring(secondSeparator)).
toString(),
path.getNamespacesString());
}
try {
// Get the equivalent element
equivalent = path.selectSingleElement(clone);
} catch (XPathException e) {
throw new UndeclaredThrowableException(e);
}
}
}