use of org.apache.commons.lang.text.StrTokenizer in project cuba by cuba-platform.
the class AbstractWebAppContextLoader method initAppProperties.
protected void initAppProperties(ServletContext sc) {
// get properties from web.xml
String appProperties = sc.getInitParameter(APP_PROPS_PARAM);
if (appProperties != null) {
StrTokenizer tokenizer = new StrTokenizer(appProperties);
for (String str : tokenizer.getTokenArray()) {
int i = str.indexOf("=");
if (i < 0)
continue;
String name = StringUtils.substring(str, 0, i);
String value = StringUtils.substring(str, i + 1);
if (!StringUtils.isBlank(name)) {
AppContext.setProperty(name, value);
}
}
}
// get properties from a set of app.properties files defined in web.xml
String propsConfigName = getAppPropertiesConfig(sc);
if (propsConfigName == null)
throw new IllegalStateException(APP_PROPS_CONFIG_PARAM + " servlet context parameter not defined");
final Properties properties = new Properties();
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
StrTokenizer tokenizer = new StrTokenizer(propsConfigName);
tokenizer.setQuoteChar('"');
for (String str : tokenizer.getTokenArray()) {
log.trace("Processing properties location: {}", str);
str = StrSubstitutor.replaceSystemProperties(str);
InputStream stream = null;
try {
if (ResourceUtils.isUrl(str) || str.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX)) {
Resource resource = resourceLoader.getResource(str);
if (resource.exists())
stream = resource.getInputStream();
} else {
stream = sc.getResourceAsStream(str);
}
if (stream != null) {
log.info("Loading app properties from {}", str);
try (Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
properties.load(reader);
}
} else {
log.trace("Resource {} not found, ignore it", str);
}
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(stream);
}
}
for (Object key : properties.keySet()) {
AppContext.setProperty((String) key, properties.getProperty((String) key).trim());
}
}
use of org.apache.commons.lang.text.StrTokenizer in project cuba by cuba-platform.
the class MetadataBuildSupport method init.
public List<XmlFile> init() {
List<XmlFile> metadataXmlList = new ArrayList<>();
StrTokenizer metadataFilesTokenizer = new StrTokenizer(getMetadataConfig());
for (String fileName : metadataFilesTokenizer.getTokenArray()) {
metadataXmlList.add(new XmlFile(fileName, readXml(fileName)));
}
return metadataXmlList;
}
use of org.apache.commons.lang.text.StrTokenizer in project cuba by cuba-platform.
the class NumberIdWorker method executeScript.
protected Object executeScript(String entityName, String sqlScript) {
EntityManager em = persistence.getEntityManager(getDataStore(entityName));
StrTokenizer tokenizer = new StrTokenizer(sqlScript, SequenceSupport.SQL_DELIMITER);
Object value = null;
Connection connection = em.getConnection();
while (tokenizer.hasNext()) {
String sql = tokenizer.nextToken();
try {
PreparedStatement statement = connection.prepareStatement(sql);
try {
if (statement.execute()) {
ResultSet rs = statement.getResultSet();
if (rs.next())
value = rs.getLong(1);
}
} finally {
DbUtils.closeQuietly(statement);
}
} catch (SQLException e) {
throw new IllegalStateException("Error executing SQL for getting next number", e);
}
}
return value;
}
use of org.apache.commons.lang.text.StrTokenizer in project cuba by cuba-platform.
the class DesktopThemeLoaderImpl method loadStyle.
private DesktopStyle loadStyle(Element element) {
final String componentsSubTag = "components";
String styleName = element.attributeValue("name");
List<Class> components = null;
if (element.attributeValue("component") != null) {
String className = element.attributeValue("component");
try {
components = Collections.singletonList((Class) Class.forName(className));
} catch (ClassNotFoundException e) {
log.error("Unknown component class: " + className);
}
} else {
Element componentsElement = element.element(componentsSubTag);
if (componentsElement != null) {
String componentsStr = componentsElement.getTextTrim();
StrTokenizer tokenizer = new StrTokenizer(componentsStr);
components = new ArrayList<>();
for (String className : tokenizer.getTokenArray()) {
try {
components.add(Class.forName(className));
} catch (ClassNotFoundException e) {
log.error("Unknown component class: " + className);
}
}
}
}
List<ComponentDecorator> decorators = new ArrayList<>();
for (Element childElement : (List<Element>) element.elements()) {
if (!componentsSubTag.equals(childElement.getName())) {
ComponentDecorator decorator = loadDecorator(childElement);
if (decorator != null) {
decorators.add(decorator);
}
}
}
return new DesktopStyle(styleName, decorators, components);
}
use of org.apache.commons.lang.text.StrTokenizer in project cuba by cuba-platform.
the class DefaultPermissionValuesConfig method init.
protected void init() {
permissionValues.clear();
String configName = AppContext.getProperty("cuba.defaultPermissionValuesConfig");
if (!StringUtils.isBlank(configName)) {
StrTokenizer tokenizer = new StrTokenizer(configName);
for (String fileName : tokenizer.getTokenArray()) {
parseConfigFile(fileName);
}
}
}
Aggregations