package org.jibeframework.core.ui.wrapper.factory;
import groovy.lang.GString;
import org.apache.commons.lang.StringUtils;
import org.jibeframework.core.ui.wrapper.ConditionWrapper;
import org.jibeframework.core.ui.wrapper.IconWrapper;
import org.jibeframework.core.ui.wrapper.MessageWrapper;
import org.jibeframework.core.ui.wrapper.RawWrapper;
import org.jibeframework.core.ui.wrapper.ReferenceWrapper;
import org.jibeframework.core.ui.wrapper.ValueProviderWrapper;
import org.jibeframework.core.ui.wrapper.Wrapper;
public class StringWrapperFactory implements WrapperFactory {
public boolean applies(Object config) {
if (config instanceof String || config instanceof GString) {
String text = config.toString();
return text.contains("::");
}
return false;
}
public Wrapper createWrapper(String scope, String modelScope, Object config) {
String command = StringUtils.substringBefore(config.toString(), "::");
String data = config.toString();
if (command.equals("msg")) {
return new MessageWrapper(scope, modelScope, data);
} else if (command.equals("value")) {
return new ValueProviderWrapper(scope, modelScope, data);
} else if (command.equals("raw")) {
return new RawWrapper(scope, modelScope, data);
} else if (command.equals("condition")) {
return new ConditionWrapper(scope, modelScope, data);
} else if (command.equals("ref")) {
return new ReferenceWrapper(scope, modelScope, data);
} else if (command.equals("icon")) {
return new IconWrapper(scope, modelScope, data);
}
throw new IllegalStateException("Preprocessing command not found: " + command);
}
}