Java Code Examples for org.apache.commons.text.StringTokenizer#getTokenArray()

The following examples show how to use org.apache.commons.text.StringTokenizer#getTokenArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractViewRepository.java    From cuba with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 2
Source File: AbstractAppContextLoader.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected void initAppContext(ServletContext sc) {
    String configProperty = AppContext.getProperty(SPRING_CONTEXT_CONFIG);
    if (StringUtils.isBlank(configProperty)) {
        throw new IllegalStateException("Missing " + SPRING_CONTEXT_CONFIG + " application property");
    }

    StringTokenizer tokenizer = new StringTokenizer(configProperty);
    String[] locations = tokenizer.getTokenArray();
    replaceLocationsFromConf(locations);

    ApplicationContext appContext = createApplicationContext(locations, sc);
    AppContext.Internals.setApplicationContext(appContext);

    Events events = appContext.getBean(Events.NAME, Events.class);
    events.publish(new AppContextInitializedEvent(appContext));

    log.debug("AppContext initialized");
}
 
Example 3
Source File: ThemeConstantsRepository.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected void init() {
    String configName = AppContext.getProperty("cuba.themeConfig");
    if (!StringUtils.isBlank(configName)) {
        Map<String, Map<String, String>> themeProperties = new HashMap<>();

        StringTokenizer tokenizer = new StringTokenizer(configName);
        for (String fileName : tokenizer.getTokenArray()) {
            String themeName = parseThemeName(fileName);
            if (StringUtils.isNotBlank(themeName)) {
                Map<String, String> themeMap = themeProperties.computeIfAbsent(themeName, k -> new HashMap<>());

                loadThemeProperties(fileName, themeMap);
            }
        }

        Map<String, ThemeConstants> themes = new LinkedHashMap<>();

        for (Map.Entry<String, Map<String, String>> entry : themeProperties.entrySet()) {
            themes.put(entry.getKey(), new ThemeConstants(entry.getValue()));
        }

        this.themeConstantsMap = Collections.unmodifiableMap(themes);
    } else {
        this.themeConstantsMap = Collections.emptyMap();
    }
}
 
Example 4
Source File: WindowConfig.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected void loadScreensXml() {
    String configName = AppContext.getProperty(WINDOW_CONFIG_XML_PROP);
    StringTokenizer tokenizer = new StringTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            try (InputStream stream = resource.getInputStream()) {
                loadConfig(dom4JTools.readDocument(stream).getRootElement());
            } catch (IOException e) {
                throw new RuntimeException("Unable to read window config from " + location, e);
            }
        } else {
            log.warn("Resource {} not found, ignore it", location);
        }
    }
}
 
Example 5
Source File: PermissionConfig.java    From cuba with Apache License 2.0 6 votes vote down vote up
private void compileSpecific() {
    Node<BasicPermissionTarget> root = new Node<>(
            new BasicPermissionTarget("category:specific", getMessage("permissionConfig.specificRoot"), null));
    specific = new Tree<>(root);

    final String configName = AppContext.getProperty(PERMISSION_CONFIG_XML_PROP);
    StringTokenizer tokenizer = new StringTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            try (InputStream stream = resource.getInputStream()) {
                String xml = IOUtils.toString(stream, StandardCharsets.UTF_8);
                compileSpecific(xml, root);
            } catch (IOException e) {
                throw new RuntimeException("Unable to read permission config", e);
            }
        } else {
            log.warn("Resource {} not found, ignore it", location);
        }
    }
}
 
Example 6
Source File: MenuConfig.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected void init() {
    rootItems.clear();

    String configName = AppContext.getProperty(MENU_CONFIG_XML_PROP);

    StringTokenizer tokenizer = new StringTokenizer(configName);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            try (InputStream stream = resource.getInputStream()) {
                Element rootElement = dom4JTools.readDocument(stream).getRootElement();
                loadMenuItems(rootElement, null);
            } catch (IOException e) {
                throw new RuntimeException("Unable to read menu config", e);
            }
        } else {
            log.warn("Resource {} not found, ignore it", location);
        }
    }
}
 
Example 7
Source File: CreditsLoader.java    From cuba with Apache License 2.0 6 votes vote down vote up
public CreditsLoader load() {
    String configProperty = AppContext.getProperty("cuba.creditsConfig");
    if (StringUtils.isBlank(configProperty)) {
        log.info("Property cuba.creditsConfig is empty");
        return this;
    }

    StringTokenizer tokenizer = new StringTokenizer(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 = AppBeans.get(Dom4jTools.class).readDocument(xml).getRootElement();
        loadLicenses(rootElement);
        loadConfig(rootElement);
    }

    Collections.sort(items);

    return this;
}
 
Example 8
Source File: DesktopExternalUIComponentsSource.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void _registerAppComponents() {
    String configNames = AppContext.getProperty(DESKTOP_COMPONENTS_CONFIG_XML_PROP);

    if (Strings.isNullOrEmpty(configNames)) {
        return;
    }

    log.debug("Loading UI components from {}", configNames);

    StringTokenizer tokenizer = new StringTokenizer(configNames);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                _registerComponent(stream);
            } catch (ClassNotFoundException | IOException e) {
                throw new RuntimeException("Unable to load components config " + location, e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource {} not found, ignore it", location);
        }
    }
}
 
Example 9
Source File: RemotingServlet.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public String getContextConfigLocation() {
    String configProperty = AppContext.getProperty(SPRING_CONTEXT_CONFIG);
    if (StringUtils.isBlank(configProperty)) {
        throw new IllegalStateException("Missing " + SPRING_CONTEXT_CONFIG + " application property");
    }
    File baseDir = new File(AppContext.getProperty("cuba.confDir"));

    StringTokenizer tokenizer = new StringTokenizer(configProperty);
    String[] tokenArray = tokenizer.getTokenArray();
    StringBuilder locations = new StringBuilder();
    for (String token : tokenArray) {
        String location;
        if (ResourceUtils.isUrl(token)) {
            location = token;
        } else {
            if (token.startsWith("/"))
                token = token.substring(1);
            File file = new File(baseDir, token);
            if (file.exists()) {
                location = file.toURI().toString();
            } else {
                location = "classpath:" + token;
            }
        }
        locations.append(location).append(" ");
    }
    return locations.toString();
}
 
Example 10
Source File: DefaultPermissionValuesConfig.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void init() {
    permissionValues.clear();

    String configName = AppContext.getProperty("cuba.defaultPermissionValuesConfig");
    if (!StringUtils.isBlank(configName)) {
        StringTokenizer tokenizer = new StringTokenizer(configName);
        for (String fileName : tokenizer.getTokenArray()) {
            parseConfigFile(fileName);
        }
    }
}
 
Example 11
Source File: DesktopThemeImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 12
Source File: DesktopThemeLoaderImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 13
Source File: CubaDispatcherServlet.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public String getContextConfigLocation() {
    String configProperty = AppContext.getProperty(SPRING_CONTEXT_CONFIG);
    if (StringUtils.isBlank(configProperty)) {
        throw new IllegalStateException("Missing " + SPRING_CONTEXT_CONFIG + " application property");
    }
    File baseDir = new File(AppContext.getProperty("cuba.confDir"));

    StringTokenizer tokenizer = new StringTokenizer(configProperty);
    String[] tokenArray = tokenizer.getTokenArray();
    StringBuilder locations = new StringBuilder();
    for (String token : tokenArray) {
        String location;
        if (ResourceUtils.isUrl(token)) {
            location = token;
        } else {
            if (token.startsWith("/"))
                token = token.substring(1);
            File file = new File(baseDir, token);
            if (file.exists()) {
                location = file.toURI().toString();
            } else {
                location = "classpath:" + token;
            }
        }
        locations.append(location).append(" ");
    }
    return locations.toString();
}
 
Example 14
Source File: AppPropertiesTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@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 + "'");

    StringTokenizer tokenizer = new StringTokenizer(propValue);
    String[] locations = tokenizer.getTokenArray();

    Assertions.assertArrayEquals(new String[] {"1.xml", "2.xml"}, locations);
}
 
Example 15
Source File: MetadataBuildSupport.java    From cuba with Apache License 2.0 5 votes vote down vote up
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));
            }
        }
    }
}
 
Example 16
Source File: MetadataBuildSupport.java    From cuba with Apache License 2.0 5 votes vote down vote up
public List<XmlFile> init() {
    List<XmlFile> metadataXmlList = new ArrayList<>();
    StringTokenizer metadataFilesTokenizer = new StringTokenizer(getMetadataConfig());
    for (String fileName : metadataFilesTokenizer.getTokenArray()) {
        metadataXmlList.add(new XmlFile(fileName, readXml(fileName)));
    }
    return metadataXmlList;
}
 
Example 17
Source File: AbstractWebAppContextLoader.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void initAppProperties(ServletContext sc) {
    // get properties from web.xml
    String appProperties = sc.getInitParameter(APP_PROPS_PARAM);
    if (appProperties != null) {
        StringTokenizer tokenizer = new StringTokenizer(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();
    loadPropertiesFromConfig(sc, properties, propsConfigName);

    for (Object key : properties.keySet()) {
        AppContext.setProperty((String) key, properties.getProperty((String) key).trim());
    }

    if (log.isTraceEnabled()) {
        String props = Arrays.stream(AppContext.getPropertyNames())
                .map(key -> key + "=" + AppContext.getProperty(key))
                .sorted()
                .collect(Collectors.joining("\n"));
        log.trace("AppProperties of the '{}' block:\n{}", getBlock(), props);
    }
}
 
Example 18
Source File: PortalDispatcherServlet.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public String getContextConfigLocation() {
    String configProperty = AppContext.getProperty(SPRING_CONTEXT_CONFIG);
    if (StringUtils.isBlank(configProperty)) {
        throw new IllegalStateException("Missing " + SPRING_CONTEXT_CONFIG + " application property");
    }
    File baseDir = new File(AppContext.getProperty("cuba.confDir"));

    StringTokenizer tokenizer = new StringTokenizer(configProperty);
    String[] tokenArray = tokenizer.getTokenArray();
    StringBuilder locations = new StringBuilder();
    for (String token : tokenArray) {
        String location;
        if (ResourceUtils.isUrl(token)) {
            location = token;
        } else {
            if (token.startsWith("/"))
                token = token.substring(1);
            File file = new File(baseDir, token);
            if (file.exists()) {
                location = file.toURI().toString();
            } else {
                location = "classpath:" + token;
            }
        }
        locations.append(location).append(" ");
    }
    return locations.toString();
}
 
Example 19
Source File: WebExternalUIComponentsSource.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void _registerAppComponents() {
    String configNames = AppContext.getProperty(WEB_COMPONENTS_CONFIG_XML_PROP);

    if (Strings.isNullOrEmpty(configNames)) {
        return;
    }

    log.debug("Loading UI components from {}", configNames);

    StringTokenizer tokenizer = new StringTokenizer(configNames);
    for (String location : tokenizer.getTokenArray()) {
        Resource resource = resources.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                _registerComponent(stream);
            } catch (ClassNotFoundException | IOException e) {
                throw new RuntimeException("Unable to load components config " + location, e);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        } else {
            log.warn("Resource {} not found, ignore it", location);
        }
    }
}
 
Example 20
Source File: AbstractWebAppContextLoader.java    From cuba with Apache License 2.0 4 votes vote down vote up
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
                }
            }
        }
    }
}