Search in sources :

Example 1 with StringTokenizer

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;
}
Also used : StringTokenizer(org.apache.commons.text.StringTokenizer) DesktopResources(com.haulmont.cuba.desktop.DesktopResources) ArrayList(java.util.ArrayList) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException)

Example 2 with StringTokenizer

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);
    }
}
Also used : StringTokenizer(org.apache.commons.text.StringTokenizer)

Example 3 with StringTokenizer

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));
            }
        }
    }
}
Also used : StringTokenizer(org.apache.commons.text.StringTokenizer) Element(org.dom4j.Element)

Example 4 with StringTokenizer

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();
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StringTokenizer(org.apache.commons.text.StringTokenizer) Element(org.dom4j.Element) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Example 5 with StringTokenizer

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
                }
            }
        }
    }
}
Also used : StringTokenizer(org.apache.commons.text.StringTokenizer) BOMInputStream(org.apache.commons.io.input.BOMInputStream) BOMInputStream(org.apache.commons.io.input.BOMInputStream) Resource(org.springframework.core.io.Resource) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Aggregations

StringTokenizer (org.apache.commons.text.StringTokenizer)43 IOException (java.io.IOException)9 Resource (org.springframework.core.io.Resource)9 ArrayList (java.util.ArrayList)8 InputStream (java.io.InputStream)7 Element (org.dom4j.Element)5 AppContextInitializedEvent (com.haulmont.cuba.core.sys.events.AppContextInitializedEvent)3 File (java.io.File)3 TextStringBuilder (org.apache.commons.text.TextStringBuilder)3 Events (com.haulmont.cuba.core.global.Events)2 Properties (java.util.Properties)2 Nullable (javax.annotation.Nullable)2 Preconditions (com.google.common.base.Preconditions)1 Resources (com.haulmont.cuba.core.global.Resources)1 CubaClassPathXmlApplicationContext (com.haulmont.cuba.core.sys.CubaClassPathXmlApplicationContext)1 DesktopResources (com.haulmont.cuba.desktop.DesktopResources)1 ComponentDecorator (com.haulmont.cuba.desktop.theme.ComponentDecorator)1 Specification (io.github.linuxforhealth.api.Specification)1 Stores (io.jmix.core.Stores)1 Sequence (io.jmix.data.Sequence)1