use of org.exoplatform.container.RootContainer in project kernel by exoplatform.
the class Deserializer method resolveVariables.
/**
* Resolve the variables of type ${my.var} for the current context which is composed
* of the system properties, the portal container settings and the given settings
* @param input the input value
* @param props a set of parameters to add for the variable resolution
* @return the resolve value
*/
public static String resolveVariables(String input, Map<String, Object> props) {
final int NORMAL = 0;
final int SEEN_DOLLAR = 1;
final int IN_BRACKET = 2;
if (input == null)
return input;
char[] chars = input.toCharArray();
StringBuilder buffer = new StringBuilder();
boolean properties = false;
int state = NORMAL;
int start = 0;
boolean precedingBackslash = false;
for (int i = 0; i < chars.length; ++i) {
char c = chars[i];
if (c == '$' && state != IN_BRACKET)
state = SEEN_DOLLAR;
else if (c == '{' && state == SEEN_DOLLAR && !precedingBackslash) {
buffer.append(input.substring(start, i - 1));
state = IN_BRACKET;
start = i - 1;
} else if (state == SEEN_DOLLAR)
state = NORMAL;
else if (c == '}' && state == IN_BRACKET && !precedingBackslash) {
if (start + 2 == i) {
buffer.append("${}");
} else {
String value = null;
String key = input.substring(start + 2, i);
String defaultValue = null;
int index = key.indexOf(':');
if (index > -1) {
defaultValue = key.substring(index + 1);
if (defaultValue != null && !defaultValue.isEmpty()) {
defaultValue = defaultValue.replace("\\{", "{").replace("\\}", "}");
}
key = key.substring(0, index);
}
if (key.equals(Deserializer.EXO_CONTAINER_PROP_NAME)) {
// The requested key is the name of current container
ExoContainer container = ExoContainerContext.getCurrentContainerIfPresent();
if (container instanceof PortalContainer) {
// The current container is a portal container
RootContainer rootContainer = (RootContainer) ExoContainerContext.getTopContainer();
value = rootContainer.isPortalContainerConfigAware() ? "_" + container.getContext().getName() : "";
}
} else if (key.startsWith(Deserializer.PORTAL_CONTAINER_VARIABLE_PREFIX)) {
// We try to get a value tied to the current portal container.
ExoContainer container = ExoContainerContext.getCurrentContainerIfPresent();
if (container instanceof PortalContainer) {
// The current container is a portal container
Object oValue = ((PortalContainer) container).getSetting(key.substring(Deserializer.PORTAL_CONTAINER_VARIABLE_PREFIX.length()));
value = oValue == null ? null : oValue.toString();
}
} else {
if (props != null) {
// Some parameters have been given thus we need to check inside first
Object oValue = props.get(key);
value = oValue == null ? null : oValue.toString();
}
if (value == null) {
// No value could be found so far, thus we try to get it from the
// system properties
value = PrivilegedSystemHelper.getProperty(key);
}
}
if (value == null && defaultValue != null) {
value = defaultValue;
}
if (value != null) {
properties = true;
buffer.append(value);
}
}
start = i + 1;
state = NORMAL;
}
if (c == '\\') {
precedingBackslash = !precedingBackslash;
} else {
precedingBackslash = false;
}
}
if (properties == false)
return input;
if (start != chars.length)
buffer.append(input.substring(start, chars.length));
return buffer.toString();
}
use of org.exoplatform.container.RootContainer in project kernel by exoplatform.
the class TestComponentPlugin method testComponentPluginOverloading.
public void testComponentPluginOverloading() {
RootContainer rootContainer = createRootContainer("test-component-plugin-configuration.xml");
A a = (A) rootContainer.getComponentInstanceOfType(A.class);
assertNotNull(a);
assertEquals(1, a.countRegisterCP);
assertEquals(1, a.countRegisterACP);
assertEquals(2, a.countRegisterCP1);
}
use of org.exoplatform.container.RootContainer in project kernel by exoplatform.
the class TestSpringContainer method testIntegrationClass.
public void testIntegrationClass() {
URL rootURL = getClass().getResource("test-exo-container.xml");
URL portalURL = getClass().getResource("test-exo-container2.xml");
assertNotNull(rootURL);
assertNotNull(portalURL);
//
new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).profiledBy("class").build();
RootContainer root = RootContainer.getInstance();
testIntegration(root);
}
use of org.exoplatform.container.RootContainer in project kernel by exoplatform.
the class TestSpringContainer method testIntegrationFile.
public void testIntegrationFile() {
URL rootURL = getClass().getResource("test-exo-container.xml");
URL portalURL = getClass().getResource("test-exo-container2.xml");
assertNotNull(rootURL);
assertNotNull(portalURL);
//
new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).profiledBy("file").build();
RootContainer root = RootContainer.getInstance();
testIntegration(root);
}
use of org.exoplatform.container.RootContainer in project kernel by exoplatform.
the class TestXSD_1_1 method testInitParams.
public void testInitParams() throws Exception {
URL url = getClass().getResource("../../../../xsd_1_1/test-validation.xml");
assertNotNull(url);
RootContainer container = new ContainerBuilder().withRoot(url).build();
container.getComponentInstanceOfType(TestValidation.class);
}
Aggregations