Search in sources :

Example 1 with StrTokenizer

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

the class RestJsonTransformations method init.

protected void init() {
    String configName = AppContext.getProperty(CUBA_REST_JSON_TRANSFORMATION_CONFIG_PROP_NAME);
    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();
                loadConfig(Dom4j.readDocument(stream).getRootElement());
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource " + location + " not found, ignore it");
        }
    }
}
Also used : InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) StrTokenizer(org.apache.commons.lang.text.StrTokenizer)

Example 2 with StrTokenizer

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

the class WindowConfig method init.

protected void init() {
    screens.clear();
    Map<String, ScreenAgent> agentMap = AppBeans.getAll(ScreenAgent.class);
    Map<String, ScreenAgent> screenAgents = new LinkedHashMap<>();
    List<ScreenAgent> availableAgents = new ArrayList<>(agentMap.values());
    AnnotationAwareOrderComparator.sort(availableAgents);
    for (ScreenAgent screenAgent : availableAgents) {
        screenAgents.put(screenAgent.getAlias(), screenAgent);
    }
    this.activeScreenAgents = screenAgents;
    String configName = AppContext.getProperty(WINDOW_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();
                loadConfig(Dom4j.readDocument(stream).getRootElement());
            } catch (IOException e) {
                throw new RuntimeException("Unable to read window config from " + location, e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource {} not found, ignore it", location);
        }
    }
}
Also used : InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) StrTokenizer(org.apache.commons.lang.text.StrTokenizer)

Example 3 with StrTokenizer

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

the class UniqueNumbers method executeScript.

protected Object executeScript(String domain, String sqlScript) {
    EntityManager em = persistence.getEntityManager(getDataStore(domain));
    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 4 with StrTokenizer

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

the class AbstractAppContextLoader method initAppContext.

protected void initAppContext() {
    String configProperty = AppContext.getProperty(SPRING_CONTEXT_CONFIG);
    if (StringUtils.isBlank(configProperty)) {
        throw new IllegalStateException("Missing " + SPRING_CONTEXT_CONFIG + " application property");
    }
    StrTokenizer tokenizer = new StrTokenizer(configProperty);
    String[] locations = tokenizer.getTokenArray();
    replaceLocationsFromConf(locations);
    ApplicationContext appContext = createApplicationContext(locations);
    AppContext.Internals.setApplicationContext(appContext);
    Events events = AppBeans.get(Events.NAME);
    events.publish(new AppContextInitializedEvent(appContext));
    log.debug("AppContext initialized");
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) Events(com.haulmont.cuba.core.global.Events) AppContextInitializedEvent(com.haulmont.cuba.core.sys.events.AppContextInitializedEvent) StrTokenizer(org.apache.commons.lang.text.StrTokenizer)

Example 5 with StrTokenizer

use of org.apache.commons.lang.text.StrTokenizer 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");
        StrTokenizer tokenizer = new StrTokenizer(configName);
        for (String fileName : tokenizer.getTokenArray()) {
            addFile(rootElem, fileName);
        }
        checkDuplicates(rootElem);
        for (Element viewElem : Dom4j.elements(rootElem, "view")) {
            deployView(rootElem, viewElem, new HashSet<>());
        }
    }
    initTiming.stop();
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) Element(org.dom4j.Element) StrTokenizer(org.apache.commons.lang.text.StrTokenizer) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

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