use of org.apache.commons.text.StringTokenizer in project cuba by cuba-platform.
the class DesktopThemeLoaderImpl method loadTheme.
@Override
public DesktopTheme loadTheme(String themeName) {
String themeLocations = config.getResourceLocations();
StringTokenizer tokenizer = new StringTokenizer(themeLocations);
String[] locationList = tokenizer.getTokenArray();
List<String> resourceLocationList = new ArrayList<>();
DesktopThemeImpl theme = createTheme(themeName, locationList);
theme.setName(themeName);
for (String location : locationList) {
resourceLocationList.add(getResourcesDir(themeName, location));
String xmlLocation = getConfigFileName(themeName, location);
Resource resource = resources.getResource(xmlLocation);
if (resource.exists()) {
try {
loadThemeFromXml(theme, resource);
} catch (IOException e) {
log.error("Error", e);
}
} else {
log.warn("Resource " + location + " not found, ignore it");
}
}
DesktopResources desktopResources = new DesktopResources(resourceLocationList, resources);
theme.setResources(desktopResources);
return theme;
}
use of org.apache.commons.text.StringTokenizer in project cuba by cuba-platform.
the class DesktopThemeImpl method applyStyle.
@Override
public void applyStyle(Object component, String styleNameString, Set<String> state) {
// split string into individual style names
StringTokenizer tokenizer = new StringTokenizer(styleNameString);
String[] styleNames = tokenizer.getTokenArray();
for (String styleName : styleNames) {
applyStyleName(component, state, styleName);
}
}
use of org.apache.commons.text.StringTokenizer in project cuba by cuba-platform.
the class MetadataBuildSupport method loadFromPersistenceConfig.
protected void loadFromPersistenceConfig(Map<String, List<EntityClassInfo>> packages, String db) {
String persistenceConfig = getPersistenceConfig(db);
if (persistenceConfig == null) {
return;
}
StringTokenizer persistenceFilesTokenizer = new StringTokenizer(persistenceConfig);
for (String fileName : persistenceFilesTokenizer.getTokenArray()) {
Element root = readXml(fileName);
Element puEl = root.element("persistence-unit");
if (puEl == null) {
throw new IllegalStateException(String.format("File %s has no persistence-unit element", fileName));
}
for (Element classEl : puEl.elements("class")) {
String className = classEl.getText().trim();
boolean included = false;
for (Map.Entry<String, List<EntityClassInfo>> entry : packages.entrySet()) {
if (className.startsWith(entry.getKey() + ".")) {
List<EntityClassInfo> classNames = entry.getValue();
if (classNames == null) {
classNames = new ArrayList<>();
packages.put(entry.getKey(), classNames);
}
classNames.add(new EntityClassInfo(db, className, true));
included = true;
break;
}
}
if (!included) {
String rootPackages = String.join(",\n", packages.keySet());
throw new IllegalStateException(String.format("Can not find a model for class %s. The class's package must be inside of some model's root package. " + "Move the class to one of the following model's root packages: \n%s.", className, rootPackages));
}
}
}
}
use of org.apache.commons.text.StringTokenizer in project cuba by cuba-platform.
the class AbstractViewRepository method init.
protected void init() {
StopWatch initTiming = new Slf4JStopWatch("ViewRepository.init." + getClass().getSimpleName());
storage.clear();
readFileNames.clear();
String configName = AppContext.getProperty("cuba.viewsConfig");
if (!StringUtils.isBlank(configName)) {
Element rootElem = DocumentHelper.createDocument().addElement("views");
StringTokenizer tokenizer = new StringTokenizer(configName);
for (String fileName : tokenizer.getTokenArray()) {
addFile(rootElem, fileName);
}
viewLoader.checkDuplicates(rootElem);
for (Element viewElem : Dom4j.elements(rootElem, "view")) {
deployView(rootElem, viewElem, new HashSet<>());
}
}
initTiming.stop();
}
use of org.apache.commons.text.StringTokenizer in project cuba by cuba-platform.
the class AbstractWebAppContextLoader method loadPropertiesFromConfig.
protected void loadPropertiesFromConfig(ServletContext sc, Properties properties, String propsConfigName) {
SpringProfileSpecificNameResolver nameResolver = new SpringProfileSpecificNameResolver(sc);
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
StringTokenizer tokenizer = new StringTokenizer(propsConfigName);
tokenizer.setQuoteChar('"');
for (String str : tokenizer.getTokenArray()) {
log.trace("Processing properties location: {}", str);
String baseName = StringSubstitutor.replaceSystemProperties(str);
for (String name : nameResolver.getDerivedNames(baseName)) {
InputStream stream = null;
try {
if (ResourceUtils.isUrl(name) || name.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX)) {
Resource resource = resourceLoader.getResource(name);
if (resource.exists())
stream = resource.getInputStream();
} else {
stream = sc.getResourceAsStream(name);
}
if (stream != null) {
log.info("Loading app properties from {}", name);
BOMInputStream bomInputStream = new BOMInputStream(stream);
try (Reader reader = new InputStreamReader(bomInputStream, StandardCharsets.UTF_8)) {
properties.load(reader);
}
} else {
log.trace("Resource {} not found, ignore it", name);
}
} catch (IOException e) {
throw new RuntimeException("Unable to read properties from stream", e);
} finally {
try {
if (stream != null) {
stream.close();
}
} catch (final IOException ioe) {
// ignore
}
}
}
}
}
Aggregations