com.greenpepper.extensions.selenium.Expression Maven / Gradle / Ivy
The newest version!
package com.greenpepper.extensions.selenium;
import java.util.Scanner;
import java.util.regex.MatchResult;
/**
* Expression class.
*
* @author oaouattara
* @version $Id: $Id
*/
public class Expression {
private String asString;
/**
* Constructor for Expression.
*
* @param asString a {@link java.lang.String} object.
*/
public Expression(String asString) {
super();
this.asString = asString;
}
/**
* parseVariableName.
*
* @return a {@link java.lang.String} object.
*/
public String parseVariableName() {
if(asString == null)
return null;
String var = asString.trim();
if(!var.startsWith("$"))
throw new IllegalStateException("This expression is not a variable reference");
Scanner scanner = new Scanner(var.substring(1));
scanner.findInLine("\\{\\s*(\\w+)\\s*\\}");
MatchResult matchResults = scanner.match();
if(matchResults.groupCount() != 1)
throw new IllegalStateException("Malformed variable name expression.");
return matchResults.group(1);
}
}