Created
May 30, 2009 10:20
-
-
Save talios/120467 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EvalCommand extends AbstractCommand { | |
@Override | |
public void execute(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder) { | |
Check.isFalse(commandCall.hasChildCommands(), "Nesting commands inside an 'eval' is not supported"); | |
Element element = commandCall.getElement(); | |
String evalString = element.getText(); | |
Check.notNull(evalString, "The body must be set for an element containing smx:eval"); | |
try { | |
evaluator.evaluate(convertToCamel(evalString) + "()"); | |
element.addStyleClass("success"); | |
} catch (Exception e) { | |
element.addStyleClass("failure"); | |
throw new RuntimeException(e); | |
} | |
} | |
public String convertToCamel(String s) { | |
StringBuilder sb = new StringBuilder(); | |
String[] parts = s.split(" "); | |
for (String part : parts) { | |
if (sb.length() == 0) { | |
sb.append(part.toLowerCase()); | |
} else { | |
sb.append(part.substring(0, 1).toUpperCase()).append(part.substring(1).toLowerCase()); | |
} | |
} | |
return sb.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment