private static SelectorStep[] _buildSteps(String selectorExpression) throws SAXPathException {
AssertArgument.isNotNull(selectorExpression, "selectorExpression");
String xpathExpression = toXPathExpression(selectorExpression);
XPathReader reader = XPathReaderFactory.createReader();
JaxenHandler handler = new JaxenHandler();
List<SelectorStep> selectorSteps = new ArrayList<SelectorStep>();
boolean isRooted = false;
boolean endsStarStar = false;
if(xpathExpression.startsWith("/")) {
isRooted = true;
} else if(isEncodedToken(xpathExpression)) {
String[] tokens = xpathExpression.split("/");
selectorSteps.add(new SelectorStep(tokens[0]));
StringBuilder reconstructedExpression = new StringBuilder();
for(int i = 1; i < tokens.length; i++) {
if(reconstructedExpression.length() > 0) {
reconstructedExpression.append('/');
}
reconstructedExpression.append(tokens[i]);
}
xpathExpression = reconstructedExpression.toString();
}
if(xpathExpression.endsWith("//")) {
endsStarStar = true;
xpathExpression = xpathExpression.substring(0, xpathExpression.length() - 2);
}
if(xpathExpression.trim().length() > 0) {
reader.setXPathHandler(handler);
reader.parse(xpathExpression);
XPathExpr xpath = handler.getXPathExpr();
Expr expr = xpath.getRootExpr();
if (!(expr instanceof LocationPath)) {
throw new SAXPathException("Invalid XPath expression '" + xpathExpression + "'. Selector must be a LocationPath expression. Is '" + expr.getText() + "'.");
}