Search in sources :

Example 16 with StrTokenizer

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());
    }
}
Also used : Resource(org.springframework.core.io.Resource) Properties(java.util.Properties) StrTokenizer(org.apache.commons.lang.text.StrTokenizer) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Example 17 with StrTokenizer

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

Example 18 with StrTokenizer

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;
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) StrTokenizer(org.apache.commons.lang.text.StrTokenizer)

Example 19 with StrTokenizer

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);
}
Also used : Element(org.dom4j.Element) ArrayList(java.util.ArrayList) ComponentDecorator(com.haulmont.cuba.desktop.theme.ComponentDecorator) ArrayList(java.util.ArrayList) List(java.util.List) StrTokenizer(org.apache.commons.lang.text.StrTokenizer)

Example 20 with StrTokenizer

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);
        }
    }
}
Also used : 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