Search in sources :

Example 6 with StrTokenizer

use of org.apache.commons.lang.text.StrTokenizer 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;
    StrTokenizer persistenceFilesTokenizer = new StrTokenizer(persistenceConfig);
    for (String fileName : persistenceFilesTokenizer.getTokenArray()) {
        Element root = readXml(fileName);
        Element puEl = root.element("persistence-unit");
        if (puEl == null)
            throw new IllegalStateException("File " + fileName + " has no persistence-unit element");
        for (Element classEl : Dom4j.elements(puEl, "class")) {
            String className = classEl.getText().trim();
            boolean included = false;
            for (String rootPackage : packages.keySet()) {
                if (className.startsWith(rootPackage + ".")) {
                    List<EntityClassInfo> classNames = packages.get(rootPackage);
                    if (classNames == null) {
                        classNames = new ArrayList<>();
                        packages.put(rootPackage, classNames);
                    }
                    classNames.add(new EntityClassInfo(db, className, true));
                    included = true;
                    break;
                }
            }
            if (!included)
                throw new IllegalStateException("Can not find a model for class " + className + ". The class's package must be inside of some model's root package.");
        }
    }
}
Also used : Element(org.dom4j.Element) StrTokenizer(org.apache.commons.lang.text.StrTokenizer)

Example 7 with StrTokenizer

use of org.apache.commons.lang.text.StrTokenizer 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
    StrTokenizer tokenizer = new StrTokenizer(styleNameString);
    String[] styleNames = tokenizer.getTokenArray();
    for (String styleName : styleNames) {
        applyStyleName(component, state, styleName);
    }
}
Also used : StrTokenizer(org.apache.commons.lang.text.StrTokenizer)

Example 8 with StrTokenizer

use of org.apache.commons.lang.text.StrTokenizer in project cuba by cuba-platform.

the class DesktopThemeLoaderImpl method loadTheme.

@Override
public DesktopTheme loadTheme(String themeName) {
    String themeLocations = config.getResourceLocations();
    StrTokenizer tokenizer = new StrTokenizer(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 : DesktopResources(com.haulmont.cuba.desktop.DesktopResources) ArrayList(java.util.ArrayList) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) StrTokenizer(org.apache.commons.lang.text.StrTokenizer)

Example 9 with StrTokenizer

use of org.apache.commons.lang.text.StrTokenizer in project cuba by cuba-platform.

the class DesktopAppContextLoader method initAppProperties.

protected void initAppProperties() {
    AppContext.setProperty(AppConfig.CLIENT_TYPE_PROP, ClientType.DESKTOP.toString());
    String appPropertiesConfig = System.getProperty(APP_PROPERTIES_CONFIG_SYS_PROP);
    if (StringUtils.isBlank(appPropertiesConfig))
        appPropertiesConfig = defaultAppPropertiesConfig;
    final Properties properties = new Properties();
    StrTokenizer tokenizer = new StrTokenizer(appPropertiesConfig);
    for (String str : tokenizer.getTokenArray()) {
        InputStream stream = null;
        try {
            stream = getClass().getResourceAsStream(str);
            if (stream != null) {
                Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8.name());
                properties.load(reader);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(stream);
        }
    }
    for (String arg : args) {
        arg = arg.trim();
        int pos = arg.indexOf('=');
        if (pos > 0) {
            String key = arg.substring(0, pos);
            String value = arg.substring(pos + 1);
            properties.setProperty(key, value);
        }
    }
    for (Object key : properties.keySet()) {
        AppContext.setProperty((String) key, properties.getProperty((String) key).trim());
    }
    List<String> list = new ArrayList<>();
    for (String key : AppContext.getPropertyNames()) {
        list.add(key + "=" + AppContext.getProperty(key));
    }
    Collections.sort(list);
    log.info(new StrBuilder("AppProperties:\n").appendWithSeparators(list, "\n").toString());
}
Also used : ArrayList(java.util.ArrayList) Properties(java.util.Properties) StrTokenizer(org.apache.commons.lang.text.StrTokenizer) StrBuilder(org.apache.commons.lang.text.StrBuilder)

Example 10 with StrTokenizer

use of org.apache.commons.lang.text.StrTokenizer in project iaf by ibissource.

the class MessageStoreListener method getRawMessage.

@Override
public Object getRawMessage(Map threadContext) throws ListenerException {
    Object rawMessage = super.getRawMessage(threadContext);
    if (rawMessage != null && sessionKeys != null) {
        MessageWrapper messageWrapper = (MessageWrapper) rawMessage;
        StrTokenizer strTokenizer = StrTokenizer.getCSVInstance().reset(messageWrapper.getText());
        messageWrapper.setText((String) strTokenizer.next());
        int i = 0;
        while (strTokenizer.hasNext()) {
            threadContext.put(sessionKeysList.get(i), strTokenizer.next());
            i++;
        }
    }
    return rawMessage;
}
Also used : MessageWrapper(nl.nn.adapterframework.receivers.MessageWrapper) StrTokenizer(org.apache.commons.lang.text.StrTokenizer)

Aggregations

StrTokenizer (org.apache.commons.lang.text.StrTokenizer)32 Resource (org.springframework.core.io.Resource)10 IOException (java.io.IOException)9 InputStream (java.io.InputStream)8 File (java.io.File)5 Element (org.dom4j.Element)5 ArrayList (java.util.ArrayList)3 EntityManager (com.haulmont.cuba.core.EntityManager)2 AppContextInitializedEvent (com.haulmont.cuba.core.sys.events.AppContextInitializedEvent)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 StrBuilder (org.apache.commons.lang.text.StrBuilder)2 Events (com.haulmont.cuba.core.global.Events)1 Resources (com.haulmont.cuba.core.global.Resources)1 DesktopResources (com.haulmont.cuba.desktop.DesktopResources)1 ComponentDecorator (com.haulmont.cuba.desktop.theme.ComponentDecorator)1 List (java.util.List)1