Example usage for org.apache.commons.lang3 StringUtils split

List of usage examples for org.apache.commons.lang3 StringUtils split

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils split.

Prototype

public static String[] split(final String str, final String separatorChars) 

Source Link

Document

Splits the provided text into an array, separators specified.

Usage

From source file:com.thinkbiganalytics.alerts.spi.defaults.DefaultAlertCriteria.java

protected BooleanBuilder orFilter(QJpaAlert alert) {
    BooleanBuilder globalFilter = new BooleanBuilder();
    if (StringUtils.isNotBlank(getOrFilter())) {
        Lists.newArrayList(StringUtils.split(getOrFilter(), ",")).stream().forEach(filter -> {
            filter = StringUtils.trim(filter);
            if (filter != null) {
                BooleanBuilder booleanBuilder = new BooleanBuilder();
                List<Predicate> preds = new ArrayList<>();
                try {
                    Alert.State state = Alert.State.valueOf(filter.toUpperCase());
                    preds.add(alert.state.eq(state));
                } catch (IllegalArgumentException e) {

                }/*from   www  . ja  v a 2s  .  c om*/

                preds.add(alert.typeString.like(filter.concat("%")));
                preds.add(alert.subtype.like(filter.concat("%")));
                booleanBuilder.andAnyOf(preds.toArray(new Predicate[preds.size()]));
                globalFilter.and(booleanBuilder);
            }
        });

    }
    return globalFilter;
}

From source file:com.adobe.acs.commons.mcp.form.AbstractResourceImpl.java

@Override
public Resource getChild(String relPath) {
    if (relPath.startsWith("/")) {
        relPath = relPath.replace(getPath(), "");
    }//from   ww  w.  j av a  2  s.co m
    Resource current = this;
    for (String name : StringUtils.split(relPath, "/")) {
        if (current instanceof AbstractResourceImpl) {
            current = ((AbstractResourceImpl) current).getChildNamed(name);
            if (current == null) {
                return null;
            }
        } else if (current.getChild(name) == null) {
            return null;
        } else {
            current = current.getChild(name);
        }
    }
    return current;
}

From source file:ca.simplegames.micro.Micro.java

public Micro(String path, ServletContext servletContext, String userClassPaths) throws Exception {
    final File applicationPath = new File(path);
    final File webInfPath = new File(applicationPath, "WEB-INF");

    showBanner();//from ww  w  .j  ava2  s .  c  o m

    site = new SiteContext(new MapContext<String>().with(Globals.SERVLET_CONTEXT, servletContext)
            .with(Globals.SERVLET_PATH_NAME, path).with(Globals.SERVLET_PATH, applicationPath)
            .with(Globals.WEB_INF_PATH, webInfPath));

    welcomeFile = site.getWelcomeFile();

    //initialize the classpath
    StringBuilder cp = new StringBuilder();
    if (new File(webInfPath, "/lib").exists()) {
        cp.append(webInfPath.toString()).append("/lib,");
    }

    if (new File(webInfPath, "/classes").exists()) {
        cp.append(webInfPath.toString()).append("/classes,");
    }

    if (StringUtils.isNotBlank(userClassPaths)) {
        cp.append(",").append(userClassPaths);
    }

    String resources = ClassUtils.configureClasspath(webInfPath.toString(),
            StringUtils.split(cp.toString(), "," + File.pathSeparatorChar));
    if (log.isDebugEnabled()) {
        log.info("classpath: " + resources);
    }
    configureBSF();

    site.loadApplication(webInfPath.getAbsolutePath() + "/config");
    // done with the init phase
    //log.info("\n");

    // Registers a new virtual-machine shutdown hook.
    // For more details, see:  http://goo.gl/L9k1YT
    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            shutdown();
        }
    });
}

From source file:com.bekwam.mavenpomupdater.data.FavoritesJNLPPersistenceServiceDAO.java

public void addFavoriteRootDir(String favorite) {

    if (log.isDebugEnabled()) {
        log.debug("[ADD FAV] f=" + favorite);
    }//from  ww  w . ja  va2 s.  c o m

    if (ps != null && bs != null) {

        if (log.isDebugEnabled()) {
            log.debug("[ADD FAV] persistence and basic service have been initialized");
        }

        try {

            URL codebase = bs.getCodeBase();

            if (log.isDebugEnabled()) {
                log.debug("[ADD FAV] codebase=" + codebase);
            }

            //
            // Could return subdirectories as distinct names for sharing
            // muffins among apps
            //
            // Ex, getNames(codebase) -> { codebase, codebase + "/app2" };
            //
            String[] muffins = ps.getNames(codebase);

            if (muffins == null || muffins.length == 0) {

                if (log.isDebugEnabled()) {
                    log.debug("[ADD FAV] creating new datastore for codebase=" + codebase);
                }

                ps.create(codebase, FC_MAX_SIZE);

                //
                // Can either be CACHED (default), DIRTY, or TEMPORARY
                //
                // Since there's no server-side component, using TEMPORARY
                //

                ps.setTag(codebase, PersistenceService.TEMPORARY);
            }

            FileContents fc = ps.get(codebase);

            Properties properties = ioUtils.getProperties(fc);

            String favoritesCSV = properties.getProperty(KEY_FAVORITES_CSV);

            if (StringUtils.isNotEmpty(favoritesCSV)) {

                String[] favs = StringUtils.split(favoritesCSV, ",");
                if (!ArrayUtils.contains(favs, favorite)) {
                    if (log.isDebugEnabled()) {
                        log.debug("[ADD FAV] appending favorite");
                    }
                    favoritesCSV += ",";
                    favoritesCSV += favorite;
                } else {
                    if (log.isDebugEnabled()) {
                        log.debug("[ADD FAV] favorite already exists; skipping output writing");
                    }
                    return;
                }

            } else {
                favoritesCSV = favorite;
            }

            if (log.isDebugEnabled()) {
                log.debug("[ADD FAV] saving csv=" + favoritesCSV);
            }

            ioUtils.setProperties(fc, KEY_FAVORITES_CSV, favoritesCSV, "jnlp muffins from mpu app");

        } catch (Exception exc) {
            log.error("error writing muffin", exc);
        }
    }

}

From source file:com.jredrain.tag.Page.java

/**
 * ???./*from   www . j  a  va2  s  . c o m*/
 *
 * @param order
 *            ?descasc,?','.
 */
public void setOrder(final String order) {
    // order?
    String[] orders = StringUtils.split(StringUtils.lowerCase(order), ',');
    for (String orderStr : orders) {
        if (!StringUtils.equals(DESC, orderStr) && !StringUtils.equals(ASC, orderStr))
            throw new IllegalArgumentException("??" + orderStr + "??");
    }

    this.order = StringUtils.lowerCase(order);
}

From source file:de.micromata.tpsb.project.TpsbProjectCatalog.java

/**
 * Inits the from local settings./*from w w  w  . j  av  a  2  s  . c  om*/
 */
public void initFromLocalSettings() {
    readGlobalOptions();
    LocalSettings ls = LocalSettings.get();
    List<String> pns = ls.getKeysPrefixWithInfix("genome.tpsb.project", "name");
    for (String k : pns) {

        String key = k + ".name";
        String name = ls.get(key);
        key = k + ".projectroot";
        String projectRoot = ls.get(key);
        if (StringUtils.isBlank(projectRoot) == true) {
            log.warn(" No projektroot defined for: " + key);
            continue;
        }
        File projectRootFile = new File(projectRoot);
        if (projectRootFile.exists() == false) {
            log.warn(" Projectroot does not exists: " + projectRootFile.getAbsolutePath());
            continue;
        }
        key = k + ".srcprojectroots";
        String sources = ls.get(key);
        List<String> sourceList = new ArrayList<String>();
        if (StringUtils.isBlank(sources) == false) {
            List<String> tl = Arrays.asList(StringUtils.split(sources, ','));
            for (String s : tl) {
                File srcDir = new File(s);
                if (srcDir.exists() == false) {
                    log.warn("Source dir defined in localsettings doesn't exist: " + srcDir.getAbsolutePath());
                    continue;
                }
                sourceList.add(s);
            }
        } else {
            sourceList = getDirsIfExists(projectRootFile, "src/test/java", "src/main/java");
        }
        key = k + ".tpsbrepo";
        String repos = ls.get(key);
        if (StringUtils.isBlank(repos) == true) {
            repos = new File(projectRootFile, "tpsbrepo").getAbsolutePath();
        }
        List<String> repoLista = Arrays.asList(StringUtils.split(repos, ','));
        List<String> repoList = new ArrayList<String>();
        repoList.addAll(repoLista);
        for (String repo : repoList) {
            File repoFile = new File(repo);
            if (repoFile.exists() == false) {
                log.warn("Repo defined in localsettings doesn't exist: " + repoFile.getAbsolutePath());
                continue;
            }
        }

        if (repoList.isEmpty() == true) {
            log.warn("No Repositories are defined");
            continue;
        }

        key = k + ".srcgentarget";
        String sourcegen = ls.get(key);
        if (StringUtils.isBlank(sourcegen) == true) {
            sourcegen = new File(projectRootFile, "src/test/java").getAbsolutePath();
        }

        key = k + ".imports";
        String imports = ls.get(key);

        List<String> importList = new ArrayList<String>();
        if (StringUtils.isNotBlank(imports) == true) {
            importList = Arrays.asList(StringUtils.split(imports, ','));
        }

        String first = repoList.get(0);
        repoList.remove(0);
        TpsbProject project = new TpsbProject(name, projectRoot, first, repoList, sourceList, sourcegen);
        project.getImportedProjects().addAll(importList);

        key = k + ".noTestCases";
        project.setNoTestCases(ls.getBooleanValue(key, false));

        key = k + ".addcp";
        String adcp = ls.get(key);
        if (StringUtils.isNotBlank(adcp) == true) {
            List<String> addcp = Arrays.asList(StringUtils.split(adcp, ','));
            for (String a : addcp) {
                a = StringUtils.trim(a);
                File srcDir = new File(a);
                if (srcDir.exists() == false) {
                    log.warn("Cp dir or jar defined in localsettings doesn't exist: "
                            + srcDir.getAbsolutePath());
                    continue;
                }
                project.getRuntimeCps().add(a);
            }
        }
        projects.put(name, project);
    }
    resolveProjectDeps();
}

From source file:com.xpn.xwiki.render.XWikiMacrosMappingRenderer.java

public void loadPreferences(XWiki xwiki, XWikiContext context) {
    this.macros_libraries = new HashMap<String, String>();
    this.macros_mappings = new HashMap<String, XWikiVirtualMacro>();

    if ((xwiki != null) && (context != null)) {
        String[] macrolanguages = StringUtils
                .split(xwiki.getXWikiPreference("macros_languages", "velocity,groovy", context), ", ");
        for (int i = 0; i < macrolanguages.length; i++) {
            String language = macrolanguages[i];
            this.macros_libraries.put(language,
                    xwiki.getXWikiPreference("macros_" + language, "XWiki."
                            + language.substring(0, 1).toUpperCase() + language.substring(1) + "Macros",
                            context));//w ww .j  ava2 s.  co  m
        }

        String macrosmapping = xwiki.getMacroList(context);
        String[] mappings = StringUtils.split(macrosmapping, "\r\n");
        for (int i = 0; i < mappings.length; i++) {
            try {
                XWikiVirtualMacro macro = new XWikiVirtualMacro(mappings[i]);
                if (!macro.getName().equals("")) {
                    if (!macro.getFunctionName().equals("")) {
                        this.macros_mappings.put(macro.getName(), macro);
                    } else {
                        this.macros_mappings.remove(macro.getName());
                    }
                }
            } catch (Exception e) {
                LOGGER.error("Error reading macro mapping " + mappings[i], e);
            }
        }
    }
}

From source file:com.datatorrent.stram.client.ConfigPackage.java

/**
 * Creates an Config Package object.// www .j  a v  a  2  s . c  o  m
 *
 * @param file
 * @throws java.io.IOException
 * @throws net.lingala.zip4j.exception.ZipException
 */
public ConfigPackage(File file) throws IOException, ZipException {
    super(file);
    Manifest manifest = getManifest();
    if (manifest == null) {
        throw new IOException("Not a valid config package. MANIFEST.MF is not present.");
    }
    Attributes attr = manifest.getMainAttributes();
    configPackageName = attr.getValue(ATTRIBUTE_DT_CONF_PACKAGE_NAME);
    appPackageName = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_NAME);
    appPackageGroupId = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_GROUP_ID);
    appPackageMinVersion = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_MIN_VERSION);
    appPackageMaxVersion = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_MAX_VERSION);
    configPackageDescription = attr.getValue(ATTRIBUTE_DT_CONF_PACKAGE_DESCRIPTION);
    String classPathString = attr.getValue(ATTRIBUTE_CLASS_PATH);
    String filesString = attr.getValue(ATTRIBUTE_FILES);
    if (configPackageName == null) {
        throw new IOException("Not a valid config package.  DT-Conf-Package-Name is missing from MANIFEST.MF");
    }
    if (!StringUtils.isBlank(classPathString)) {
        classPath.addAll(Arrays.asList(StringUtils.split(classPathString, " ")));
    }
    if (!StringUtils.isBlank(filesString)) {
        files.addAll(Arrays.asList(StringUtils.split(filesString, " ")));
    }

    ZipFile zipFile = new ZipFile(file);
    if (zipFile.isEncrypted()) {
        throw new ZipException("Encrypted conf package not supported yet");
    }
    File newDirectory = Files.createTempDirectory("dt-configPackage-").toFile();
    newDirectory.mkdirs();
    directory = newDirectory.getAbsolutePath();
    zipFile.extractAll(directory);
    processPropertiesXml();
}

From source file:com.thinkgem.jeesite.modules.sys.security.PhoneAuthorizingRealm.java

/**
 * ?, ???/*from ww  w .j a  v a2s.  co m*/
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    Principal principal = (Principal) getAvailablePrincipal(principals);
    //      Long userId = (Long) principals.fromRealm(getName()).iterator().next();
    //      User user = getSystemService().getUserByPhone(userId+"");
    User user = getSystemService().getUserByPhone(principal.getLoginName());
    if (user != null) {
        UserUtils.putCache("user", user);
        SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
        List<Menu> list = UserUtils.getMenuList();
        for (Menu menu : list) {
            if (StringUtils.isNotBlank(menu.getPermission())) {
                // Permission???
                for (String permission : StringUtils.split(menu.getPermission(), ",")) {
                    info.addStringPermission(permission);
                }
            }
        }
        // IP
        getSystemService().updateUserLoginInfo(user.getId());
        return info;
    } else {
        return null;
    }
}

From source file:com.github.dactiv.orm.core.PageRequest.java

/**
 * ??./*  w ww .j a  va2s. c o m*/
 */
@SuppressWarnings("unchecked")
public List<Sort> getSort() {
    if (orderBy == null || orderDir == null) {
        return Collections.EMPTY_LIST;
    }
    String[] orderBys = StringUtils.split(orderBy, ',');
    String[] orderDirs = StringUtils.split(orderDir, ',');
    Assert.isTrue(orderBys.length == orderDirs.length,
            "???,????");

    List<Sort> orders = new ArrayList<PageRequest.Sort>();
    for (int i = 0; i < orderBys.length; i++) {
        orders.add(new Sort(orderBys[i], orderDirs[i]));
    }

    return orders;
}