org.apache.commons.text.StringTokenizer Java Examples

The following examples show how to use org.apache.commons.text.StringTokenizer. 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: 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 #2
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 #3
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 #4
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 #5
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 #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: TestContainer.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected void initAppContext() {
    EclipseLinkCustomizer.initTransientCompatibleAnnotations();

    String configProperty = AppContext.getProperty(AbstractAppContextLoader.SPRING_CONTEXT_CONFIG);

    StringTokenizer tokenizer = new StringTokenizer(configProperty);
    List<String> locations = tokenizer.getTokenList();

    StringTokenizer configTokenizer = new StringTokenizer(getSpringConfig());
    locations.addAll(configTokenizer.getTokenList());

    springAppContext = new CubaClassPathXmlApplicationContext(locations.toArray(new String[0]));
    AppContext.Internals.setApplicationContext(springAppContext);

    Events events = springAppContext.getBean(Events.NAME, Events.class);
    events.publish(new AppContextInitializedEvent(springAppContext));
}
 
Example #9
Source File: TestContainer.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected void initAppContext() {
    EclipseLinkCustomizer.initTransientCompatibleAnnotations();

    String configProperty = AppContext.getProperty(AbstractAppContextLoader.SPRING_CONTEXT_CONFIG);

    StringTokenizer tokenizer = new StringTokenizer(configProperty);
    List<String> locations = tokenizer.getTokenList();
    String springConfig = getSpringConfig();
    if (!Strings.isNullOrEmpty(springConfig) && !locations.contains(springConfig)) {
        locations.add(springConfig);
    }

    springAppContext = new CubaCoreApplicationContext(locations.toArray(new String[0]));
    AppContext.Internals.setApplicationContext(springAppContext);

    Events events = springAppContext.getBean(Events.class);
    events.publish(new AppContextInitializedEvent(springAppContext));
}
 
Example #10
Source File: CompileCommandParser.java    From synopsys-detect with Apache License 2.0 5 votes vote down vote up
public List<String> parseCommandString(String commandString, Map<String, String> optionOverrides) {
    logger.trace(String.format("origCompileCommand         : %s", commandString));
    String quotesRemovedCompileCommand = encodeQuotedWhitespace(commandString);
    logger.trace(String.format("quotesRemovedCompileCommand: %s", quotesRemovedCompileCommand));
    StringTokenizer tokenizer = new StringTokenizer(quotesRemovedCompileCommand);
    tokenizer.setQuoteMatcher(StringMatcherFactory.INSTANCE.quoteMatcher());
    List<String> commandList = new ArrayList<>();
    String lastPart = "";
    int partIndex = 0;
    while (tokenizer.hasNext()) {
        String token = tokenizer.nextToken();
        String part = restoreWhitespace(token);
        if (partIndex > 0) {
            String optionValueOverride = null;
            for (Map.Entry<String, String> optionToOverride : optionOverrides.entrySet()) {
                if (optionToOverride.getKey().equals(lastPart)) {
                    optionValueOverride = optionToOverride.getValue();
                }
            }
            if (optionValueOverride != null) {
                commandList.add(optionValueOverride);
            } else {
                commandList.add(part);
            }
        } else {
            commandList.add(part);
        }
        lastPart = part;
        partIndex++;
    }
    return commandList;
}
 
Example #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
Source File: TokenizedStringListFactory.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public Object build(String value) {
    if (value == null) {
        return null;
    }
    return new StringTokenizer(value).getTokenList();
}
 
Example #18
Source File: AbstractMessages.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Nullable
protected String searchMessage(String packs, String key, Locale locale, Locale truncatedLocale, Set<String> passedPacks) {
    StringTokenizer tokenizer = new StringTokenizer(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 TextStringBuilder().appendWithSeparators(list, ",").toString();
        log.trace("Resource '{}' not found", makeCacheKey(packName, key, locale, locale));
    }
    return null;
}
 
Example #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
Source File: ClangCompileCommandParser.java    From hub-detect with Apache License 2.0 5 votes vote down vote up
public List<String> getCompilerArgsForGeneratingDepsMkFile(final String origCompileCommand, final String depsMkFilePath, final Map<String, String> optionOverrides) {
    logger.trace(String.format("origCompileCommand         : %s", origCompileCommand));
    String quotesRemovedCompileCommand = escapeQuotedWhitespace(origCompileCommand.trim());
    logger.trace(String.format("quotesRemovedCompileCommand: %s", quotesRemovedCompileCommand));
    StringTokenizer tokenizer = new StringTokenizer(quotesRemovedCompileCommand);
    tokenizer.setQuoteMatcher(StringMatcherFactory.INSTANCE.quoteMatcher());
    final List<String> argList = new ArrayList<>();
    String lastPart = "";
    int partIndex = 0;
    while (tokenizer.hasNext()) {
        String part = unEscapeDoubleQuotes(restoreWhitespace(tokenizer.nextToken()));
        if (partIndex > 0) {
            String optionValueOverride = null;
            for (String optionToOverride : optionOverrides.keySet()) {
                if (optionToOverride.equals(lastPart)) {
                    optionValueOverride = optionOverrides.get(optionToOverride);
                }
            }
            if (optionValueOverride != null) {
                argList.add(optionValueOverride);
            } else {
                argList.add(part);
            }
        }
        lastPart = part;
        partIndex++;
    }
    argList.add("-M");
    argList.add("-MF");
    argList.add(depsMkFilePath);
    return argList;
}
 
Example #26
Source File: SaltToken.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
public static SaltToken fromString(String str) {
    String[] splitString = new StringTokenizer(str, SALT_TOKEN_DELIMITER).setIgnoreEmptyTokens(false)
            .getTokenArray();
    if (splitString.length != 4) {
        throw new IllegalArgumentException("Cannot parse into SaltToken object from this String");
    }

    return new SaltToken(splitString[1], splitString[2]);
}
 
Example #27
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
                }
            }
        }
    }
}
 
Example #28
Source File: JsonUtils.java    From genie with Apache License 2.0 3 votes vote down vote up
/**
 * Given a flat string of command line arguments this method will attempt to tokenize the string and split it for
 * use in DTOs. The split will occur on whitespace (tab, space, new line, carriage return) while respecting
 * single quotes to keep those elements together.
 * <p>
 * Example:
 * {@code "/bin/bash -xc 'echo "hello" world!'"} results in {@code ["/bin/bash", "-xc", "echo "hello" world!"]}
 *
 * @param commandArgs The original string representation of the command arguments
 * @return An ordered list of arguments
 */
@Nonnull
public static List<String> splitArguments(final String commandArgs) {
    final StringTokenizer tokenizer = new StringTokenizer(
        commandArgs,
        StringMatcherFactory.INSTANCE.splitMatcher(),
        StringMatcherFactory.INSTANCE.quoteMatcher()
    );

    return tokenizer.getTokenList();
}