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.paladin.mvc.ActionServlet.java

/**
 * ?//from   ww  w  . j  a  va2s.com
 *
 * @param _reqCtxt
 * @param is_post
 * @return
 */
private boolean doProcess(RequestContext _reqCtxt, boolean is_post) {
    try {
        String url = _decodeURL(_reqCtxt.uri(), "UTF-8");
        // split uri
        String[] parts = StringUtils.split(url, '/');
        if (parts.length < 1) {
            _reqCtxt.not_found();
            return false;
        }
        // load action
        Object action = this.loadAction(parts[0]);
        if (action == null) {
            _reqCtxt.not_found();
            return false;
        }
        String method_name = (parts.length > 1) ? parts[1] : "index";// url??index
        Method method_of_action = this.getActionMethod(action, method_name);

        //   ?  
        if (method_of_action == null) {
            method_of_action = this.getActionMethod(action, "index");
        }

        // Action?
        int arg_c = method_of_action.getParameterTypes().length;// ?
        switch (arg_c) {
        case 0: // login()
            method_of_action.invoke(action);
            break;
        case 1:// login(RequestContext)
            method_of_action.invoke(action, _reqCtxt);
            break;
        case 2:// read(RequestContext, id)
            boolean isLong = method_of_action.getParameterTypes()[1].equals(long.class);
            // ?   id,  
            if (parts.length < 3) {
                method_of_action = this.getActionMethod(action, "index");
                method_of_action.invoke(action, _reqCtxt);
            } else
                method_of_action.invoke(action, _reqCtxt,
                        isLong ? NumberUtils.toLong(parts[2], -1L) : parts[2]);
            break;
        case 3:// search(RequestContext, id, q)
               // method_of_action.invoke(action, _reqCtxt,
               // NumberUtils.toLong(parts[2], -1L), parts[3]);
            break;
        default:
            _reqCtxt.not_found();
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.nesscomputing.migratory.maven.AbstractMigratoryMojo.java

protected List<String> parsePersonalities(final String personalityList) {
    final String[] personalities = StringUtils.stripAll(StringUtils.split(personalityList, ","));
    CONSOLE.debug("Found %s as personalities", ((Object[]) personalities));
    return personalities == null ? null : Arrays.asList(personalities);
}

From source file:com.xpn.xwiki.objects.classes.ListClass.java

public static Map<String, ListItem> getMapFromString(String value) {
    Map<String, ListItem> map = new HashMap<String, ListItem>();
    if (value == null) {
        return map;
    }//from  ww  w  . j  ava2  s . c  o m

    String val = StringUtils.replace(value, "\\|", "%PIPE%");
    String[] result = StringUtils.split(val, "|");
    for (int i = 0; i < result.length; i++) {
        String element = StringUtils.replace(result[i], "%PIPE%", "|");
        if (element.indexOf('=') != -1) {
            String[] data = StringUtils.split(element, "=");
            map.put(data[0], new ListItem(data[0], data[1]));
        } else {
            map.put(element, new ListItem(element, element));
        }
    }
    return map;
}

From source file:io.bibleget.BibleGetFrame.java

/**
 *
 * @throws ClassNotFoundException/*from   ww  w . ja v a 2s.  com*/
 */
private void prepareDynamicInformation() throws ClassNotFoundException {
    biblegetDB = BibleGetDB.getInstance();
    String bibleVersionsStr = biblegetDB.getMetaData("VERSIONS");
    JsonReader jsonReader = Json.createReader(new StringReader(bibleVersionsStr));
    JsonObject bibleVersionsObj = jsonReader.readObject();
    Set<String> versionsabbrev = bibleVersionsObj.keySet();
    bibleVersions = new BasicEventList<>();
    if (!versionsabbrev.isEmpty()) {
        for (String s : versionsabbrev) {
            String versionStr = bibleVersionsObj.getString(s); //store these in an array
            String[] array;
            array = versionStr.split("\\|");
            bibleVersions.add(new BibleVersion(s, array[0], array[1],
                    StringUtils.capitalize(new Locale(array[2]).getDisplayLanguage())));
        }
    }

    List<String> preferredVersions = new ArrayList<>();
    String retVal = (String) biblegetDB.getOption("PREFERREDVERSIONS");
    if (null == retVal) {
        //System.out.println("Attempt to retrieve PREFERREDVERSIONS from the Database resulted in null value");
    } else {
        //System.out.println("Retrieved PREFERREDVERSIONS from the Database. Value is:"+retVal);
        String[] favoriteVersions = StringUtils.split(retVal, ',');
        preferredVersions = Arrays.asList(favoriteVersions);
    }
    if (preferredVersions.isEmpty()) {
        preferredVersions.add("NVBSE");
    }
    List<Integer> preferredVersionsIndices = new ArrayList<>();

    versionsByLang = new SeparatorList<>(bibleVersions, new VersionComparator(), 1, 1000);
    int listLength = versionsByLang.size();
    enabledFlags = new boolean[listLength];
    ListIterator itr = versionsByLang.listIterator();
    while (itr.hasNext()) {
        int idx = itr.nextIndex();
        Object next = itr.next();
        enabledFlags[idx] = !(next.getClass().getSimpleName().equals("GroupSeparator"));
        if (next.getClass().getSimpleName().equals("BibleVersion")) {
            BibleVersion thisBibleVersion = (BibleVersion) next;
            if (preferredVersions.contains(thisBibleVersion.getAbbrev())) {
                preferredVersionsIndices.add(idx);
            }
        }
    }
    indices = ArrayUtils
            .toPrimitive(preferredVersionsIndices.toArray(new Integer[preferredVersionsIndices.size()]));
    //System.out.println("value of indices array: "+Arrays.toString(indices));

}

From source file:com.enlight.game.entity.User.java

@Transient
@JsonIgnore//from  w w  w.  java2  s.c o  m
public List<String> getServerZoneList() {
    // ???List.
    return ImmutableList.copyOf(StringUtils.split(serverZone, ","));
}

From source file:net.sf.companymanager.qbe.JpaUtil.java

/**
 * Convert the passed propertyPath into a JPA path. Note: JPA will do joins
 * if the property is in an associated//from w  ww  . j  a  va 2s. co m
 * entity.
 */
private static <E> Path<?> getPropertyPath(final Path<E> root, final String propertyPath) {
    String[] pathItems = StringUtils.split(propertyPath, ".");

    Path<?> path = root.get(pathItems[0]);
    for (int i = 1; i < pathItems.length; i++) {
        path = path.get(pathItems[i]);
    }
    return path;
}

From source file:catchla.yep.util.YepArrayUtils.java

@NonNull
public static float[] parseFloatArray(final String string, final char token) {
    if (TextUtils.isEmpty(string))
        return new float[0];
    final String[] itemsStringArray = StringUtils.split(string, token);
    final float[] array = new float[itemsStringArray.length];
    for (int i = 0, j = itemsStringArray.length; i < j; i++) {
        try {/*from  w w w .ja  v  a2s.  c om*/
            array[i] = Float.parseFloat(itemsStringArray[i]);
        } catch (final NumberFormatException e) {
            return new float[0];
        }
    }
    return array;
}

From source file:io.wcm.handler.commons.dom.HtmlElement.java

/**
 * Html "style" attribute.//from   w  w  w.ja v  a2s .  c  o  m
 * @return Returns map of style key/value pairs.
 */
public final Map<String, String> getStyles() {
    Map<String, String> styleMap = new HashMap<String, String>();

    // de-serialize style string, fill style map
    String styleString = getStyleString();
    if (styleString != null) {
        String[] styles = StringUtils.split(styleString, ";");
        for (String styleSubString : styles) {
            String[] styleParts = StringUtils.split(styleSubString, ":");
            if (styleParts.length > 1) {
                styleMap.put(styleParts[0].trim(), styleParts[1].trim());
            }
        }
    }

    return styleMap;
}

From source file:net.sourceforge.mavenhippo.ClassPathBeanFinder.java

private List<Class<? extends HippoBean>> getAnnotatedClasses(String beansAnnotatedClassesParam)
        throws IOException, SAXException, ParserConfigurationException, MojoExecutionException {
    List<Class<? extends HippoBean>> annotatedClasses;
    if (beansAnnotatedClassesParam.startsWith("classpath*:")) {
        ClasspathResourceScanner scanner;
        scanner = MetadataReaderClasspathResourceScanner.newInstance(projectClassloader);

        String[] split = StringUtils.split(beansAnnotatedClassesParam, ", \t\r\n");
        List<String> packages = new ArrayList<String>();
        packages.addAll(Arrays.asList(split));
        packages.add("classpath*:org/hippoecm/hst/content/beans/standard/**/*.class");
        Thread.currentThread().setContextClassLoader(projectClassloader);
        annotatedClasses = ObjectConverterUtils.getAnnotatedClasses(scanner, projectClassloader,
                packages.toArray(new String[0]));
    } else {/*  w ww  .j  av a  2s.co m*/
        URL xmlConfURL = ClassLoader.getSystemClassLoader().getResource(beansAnnotatedClassesParam);
        if (xmlConfURL == null) {
            throw new MojoExecutionException(BEANS_ANNOTATED_CLASSES_CONF_PARAM_ERROR_MSG);
        }
        annotatedClasses = ObjectConverterUtils.getAnnotatedClasses(xmlConfURL);
    }
    return annotatedClasses;

}

From source file:com.sangupta.shire.domain.BlogResource.java

/**
 * @param list/*  w w w .  j  a  v  a2 s.  c  o  m*/
 * @return
 */
private Collection<TagOrCategory> extractAllTagsOrCategories(final String propertyName) {
    Map<String, TagOrCategory> result = new HashMap<String, TagOrCategory>();

    // create a single re-usable object to prevent excessive
    // garbage collection
    TagOrCategory tagOrCategory; // = new TagOrCategory();

    // build up a list of all details
    for (RenderableResource resource : this.resources) {
        String categoryLine = resource.getFrontMatterProperty(propertyName);
        if (AssertUtils.isEmpty(categoryLine)) {
            continue;
        }

        String[] tokens = StringUtils.split(categoryLine, FrontMatterConstants.TAG_CATEGORY_SEPARATOR);
        for (String token : tokens) {
            token = token.trim();
            if (!token.isEmpty()) {
                tagOrCategory = result.get(token);
                if (tagOrCategory == null) {
                    tagOrCategory = new TagOrCategory(token, propertyName, this);
                    result.put(token, tagOrCategory);
                }

                Page post = resource.getResourcePost();

                tagOrCategory.addPost(post);

                if (propertyName.equals(FrontMatterConstants.TAGS)) {
                    post.getTags().add(tagOrCategory);
                } else {
                    post.getCategories().add(tagOrCategory);
                }
            }
        }
    }

    return result.values();
}