Search in sources :

Example 11 with StrTokenizer

use of org.apache.commons.lang.text.StrTokenizer in project zm-mailbox by Zimbra.

the class ContextPathBasedThreadPoolBalancerFilter method parse.

protected void parse(String input) throws ServletException {
    rulesByContextPath.clear();
    for (String str : new StrTokenizer(input, ",").getTokenArray()) {
        String[] array = str.split(":");
        if (array.length != 2) {
            throw new ServletException("Malformed rules: " + input);
        }
        String key = StringUtils.trimToNull(array[0]);
        String value = StringUtils.trimToNull(array[1]);
        if (key == null || value == null) {
            throw new ServletException("Malformed rules: " + input);
        }
        Rules rules = Rules.parse(value);
        rulesByContextPath.put(key, rules);
    }
}
Also used : ServletException(javax.servlet.ServletException) StrTokenizer(org.apache.commons.lang.text.StrTokenizer)

Example 12 with StrTokenizer

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

the class CreditsLoader method load.

public CreditsLoader load() {
    String configProperty = AppContext.getProperty("cuba.creditsConfig");
    if (StringUtils.isBlank(configProperty)) {
        log.info("Property cuba.creditsConfig is empty");
        return this;
    }
    StrTokenizer tokenizer = new StrTokenizer(configProperty);
    String[] locations = tokenizer.getTokenArray();
    for (String location : locations) {
        Resources resources = AppBeans.get(Resources.NAME);
        String xml = resources.getResourceAsString(location);
        if (xml == null) {
            log.debug("Resource {} not found, ignore it", location);
            continue;
        }
        Element rootElement = Dom4j.readDocument(xml).getRootElement();
        loadLicenses(rootElement);
        loadConfig(rootElement);
    }
    Collections.sort(items);
    return this;
}
Also used : Element(org.dom4j.Element) Resources(com.haulmont.cuba.core.global.Resources) StrTokenizer(org.apache.commons.lang.text.StrTokenizer)

Example 13 with StrTokenizer

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

the class AppPropertiesTest method testEmptyStringSubstitution.

@Test
public void testEmptyStringSubstitution() {
    AppProperties appProperties = new AppProperties(new AppComponents("test"));
    appProperties.setProperty("refapp.myConfig", "1.xml ${ext.myConfig} 2.xml");
    appProperties.setProperty("ext.myConfig", "");
    String propValue = appProperties.getProperty("refapp.myConfig");
    log.debug("Property value: '" + propValue + "'");
    StrTokenizer tokenizer = new StrTokenizer(propValue);
    String[] locations = tokenizer.getTokenArray();
    Assert.assertArrayEquals(new String[] { "1.xml", "2.xml" }, locations);
}
Also used : StrTokenizer(org.apache.commons.lang.text.StrTokenizer) Test(org.junit.Test)

Example 14 with StrTokenizer

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

the class MenuConfig method init.

protected void init() {
    rootItems.clear();
    String configName = AppContext.getProperty(MENU_CONFIG_XML_PROP);
    StrTokenizer tokenizer = new StrTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                Element rootElement = Dom4j.readDocument(stream).getRootElement();
                loadMenuItems(rootElement, null);
            } catch (IOException e) {
                throw new RuntimeException("Unable to read menu config", e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource {} not found, ignore it", location);
        }
    }
}
Also used : InputStream(java.io.InputStream) Element(org.dom4j.Element) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) StrTokenizer(org.apache.commons.lang.text.StrTokenizer)

Example 15 with StrTokenizer

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

the class AbstractMessages method searchMessage.

@Nullable
protected String searchMessage(String packs, String key, Locale locale, Locale truncatedLocale, Set<String> passedPacks) {
    StrTokenizer tokenizer = new StrTokenizer(packs);
    // noinspection unchecked
    List<String> list = tokenizer.getTokenList();
    Collections.reverse(list);
    for (String pack : list) {
        if (!enterPack(pack, locale, truncatedLocale, passedPacks))
            continue;
        String msg = searchOnePack(pack, key, locale, truncatedLocale, passedPacks);
        if (msg != null)
            return msg;
        Locale tmpLocale = truncatedLocale;
        while (tmpLocale != null) {
            tmpLocale = truncateLocale(tmpLocale);
            msg = searchOnePack(pack, key, locale, tmpLocale, passedPacks);
            if (msg != null)
                return msg;
        }
    }
    if (log.isTraceEnabled()) {
        String packName = new StrBuilder().appendWithSeparators(list, ",").toString();
        log.trace("Resource '" + makeCacheKey(packName, key, locale, locale) + "' not found");
    }
    return null;
}
Also used : StrTokenizer(org.apache.commons.lang.text.StrTokenizer) StrBuilder(org.apache.commons.lang.text.StrBuilder) Nullable(javax.annotation.Nullable)

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