Example usage for org.apache.commons.lang StringUtils substringBetween

List of usage examples for org.apache.commons.lang StringUtils substringBetween

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substringBetween.

Prototype

public static String substringBetween(String str, String open, String close) 

Source Link

Document

Gets the String that is nested in between two Strings.

Usage

From source file:com.adobe.acs.tools.csv.impl.Column.java

public Column(final String raw, final int index) {
    this.index = index;
    this.raw = StringUtils.trim(raw);

    String paramsStr = StringUtils.substringBetween(raw, "{{", "}}");
    String[] params = StringUtils.split(paramsStr, ":");

    if (StringUtils.isBlank(paramsStr)) {
        this.propertyName = this.getRaw();
    } else {//from  w ww .  j  a va 2s  . c  o m
        this.propertyName = StringUtils.trim(StringUtils.substringBefore(this.getRaw(), "{{"));

        if (params.length == 2) {
            this.dataType = nameToClass(StringUtils.stripToEmpty(params[0]));
            this.multi = StringUtils.equalsIgnoreCase(StringUtils.stripToEmpty(params[1]), MULTI);
        }

        if (params.length == 1) {
            if (StringUtils.equalsIgnoreCase(MULTI, StringUtils.stripToEmpty(params[0]))) {
                this.multi = true;
            } else {
                this.dataType = nameToClass(StringUtils.stripToEmpty(params[0]));
            }
        }
    }
}

From source file:hr.fer.spocc.parser.ParseTreeIOUtils.java

private static ParseTreeNode createNodes(String s, Map<String, TokenType> tokenTypes) {
    if (isTerminal(s)) {

        ParseTreeNode leaf = ParseTree.createNode();
        //         System.err.println("["+s+"]");
        Token token = new Token(tokenTypes.get(Escaper.INSTANCE.unescape(s).trim()), 0, null);
        //         System.err.println(Escaper.INSTANCE.unescape(s));
        //         System.err.println(token);
        leaf.initialize(token); // XXX
        return leaf;
    }/*from w  w w.  j  a v  a  2 s  .  c  om*/
    String var = StringUtils.substringBetween(s, "<", ">");
    int indOfOpenPar = s.indexOf('(', var.length() + 2);
    s = s.substring(indOfOpenPar);
    int indOfClosedPar = s.lastIndexOf(')');
    String rest = s.substring(1, indOfClosedPar);
    //      System.out.println("Var: "+var);
    //      System.out.println("Rest: "+rest);

    String[] tokens = rest.split("\\s+");

    List<String> merged = new ArrayList<String>();
    int k;
    for (int i = 0; i < tokens.length; i = k + 1) {
        int cnt = 0;
        for (k = i; k < tokens.length; ++k) {
            if (k == i && !containsAnyParenthesis(tokens[k])) {
                break;
            }
            if (containsParenthesis(tokens[k], '(')) {
                ++cnt;
            } else if (containsParenthesis(tokens[k], ')')) {
                if (--cnt <= 0) {
                    break;
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        for (int j = i; j <= k && j < tokens.length; ++j) {
            sb.append(tokens[j]).append(' ');
        }
        String part = sb.toString().trim();
        if (!part.isEmpty())
            merged.add(part);
    }

    //      for (int i = 0; i < merged.size(); ++i) {
    //         System.out.println(i+": "+merged.get(i));
    //      }

    ParseTreeNode internal = ParseTree.createNode();
    internal.initialize(new Variable<String>(Escaper.INSTANCE.unescape(var)));

    for (String part : merged) {
        internal.addChild(createNodes(part, tokenTypes));
    }

    return internal;
}

From source file:edu.jhu.pha.vospace.node.VospaceId.java

public VospaceId(String idStr) throws URISyntaxException {
    URI voURI = new URI(idStr);

    if (!validId(voURI)) {
        throw new URISyntaxException(idStr, "InvalidURI");
    }/*from  w  ww.  java2 s.  co m*/

    if (!StringUtils.contains(idStr, "vospace")) {
        throw new URISyntaxException(idStr, "InvalidURI");
    }

    this.uri = StringUtils.substringBetween(idStr, "vos://", "!vospace");

    if (this.uri == null)
        throw new URISyntaxException(idStr, "InvalidURI");

    try {
        String pathStr = URLDecoder.decode(StringUtils.substringAfter(idStr, "!vospace"), "UTF-8");
        this.nodePath = new NodePath(pathStr);
    } catch (UnsupportedEncodingException e) {
        // should not happen
        logger.error(e.getMessage());
    }

}

From source file:de.hybris.platform.addressaddon.forms.validation.ChineseAddressValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final ChineseAddressForm addressForm = (ChineseAddressForm) object;
    for (final ConstraintViolation<ChineseAddressForm> e : VALIDATOR.validate(addressForm)) {
        if (!ArrayUtils.contains(IGNORE_FIELDS, e.getPropertyPath().toString())) {
            final String msgKey = StringUtils.substringBetween(e.getMessage(), "{", "}");
            errors.rejectValue(e.getPropertyPath().toString(), msgKey);
        }//from   w  w w  .ja va 2 s  .  com
    }

    final String postcode = addressForm.getPostcode();
    if (StringUtils.isNotBlank(postcode) && !addressFacade.validatePostcode(postcode)) {
        errors.rejectValue("postcode", "address.post.code.invalid");
    }
}

From source file:com.voa.weixin.task.DownloadFileTask.java

@Override
public void run() {
    generateUrl();/*from  w  ww.  j  a  va2s.  c  o  m*/
    HttpClient client = new HttpClient();
    GetMethod httpGet = new GetMethod(this.url);

    WeixinResult result = new WeixinResult();
    try {
        client.executeMethod(httpGet);
        String contentType = httpGet.getResponseHeader("Content-Type").getValue();
        if (contentType.equals("text/plain")) {
            String json = httpGet.getResponseBodyAsString();
            result.setJson(json);
        } else {
            fileName = StringUtils.substringBetween(httpGet.getResponseHeader("Content-Type").getValue(),
                    "filename=", "\"");
            fileLength = Integer.parseInt(httpGet.getResponseHeader("Content-Length").getValue());
            result.setErrorCode(0);
            this.inputStream = httpGet.getResponseBodyAsStream();
        }
        callbackWork(result);
    } catch (Exception e) {
        e.printStackTrace();
        throw new WorkException("download file error.", e);
    } finally {
        if (inputStream != null)
            try {
                inputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        httpGet.releaseConnection();

    }
}

From source file:io.wcm.tooling.netbeans.sightly.completion.classLookup.MemberLookupResult.java

/**
 *
 * @param variableName//w  w w.  j  a va 2 s. c om
 * @param methodName
 * @param returnType
 */
public MemberLookupResult(String variableName, String methodName, String returnType) {
    this.variableName = variableName;
    this.methodName = methodName;

    //TODO: this is a hack to get support for list, set, map, enumeration, array and collection
    String tmp = returnType;
    if (StringUtils.startsWith(returnType, List.class.getName())
            || StringUtils.startsWith(returnType, Set.class.getName())
            || StringUtils.startsWith(returnType, Map.class.getName())
            || StringUtils.startsWith(returnType, Iterator.class.getName())
            || StringUtils.startsWith(returnType, Enum.class.getName())
            || StringUtils.startsWith(returnType, Collection.class.getName())) {
        while (StringUtils.contains(tmp, "<") && StringUtils.contains(tmp, ">")) {
            tmp = StringUtils.substringBetween(tmp, "<", ">");
        }
        if (StringUtils.contains(tmp, ",")) {
            // we want the first variable
            tmp = StringUtils.substringBefore(tmp, ",");
        }
    } else if (StringUtils.endsWith(returnType, "[]")) {
        tmp = StringUtils.substringBeforeLast(returnType, "[]");
    }

    this.returnType = tmp;
}

From source file:com.intel.cosbench.driver.random.HistogramIntGenerator.java

private static HistogramIntGenerator tryParse(String pattern) {
    pattern = StringUtils.substringBetween(pattern, "(", ")");
    String[] args = StringUtils.split(pattern, ',');
    ArrayList<Bucket> bucketsList = new ArrayList<Bucket>();
    for (String arg : args) {
        String[] values = StringUtils.split(arg, '|');
        if (values.length != 3) {
            throw new IllegalArgumentException();
        }/*from   ww  w.j av a 2  s.c  o  m*/
        int lower = Integer.parseInt(values[0]);
        int upper = Integer.parseInt(values[1]);
        int weight = Integer.parseInt(values[2]);
        bucketsList.add(new Bucket(lower, upper, weight));
    }
    if (bucketsList.isEmpty()) {
        throw new IllegalArgumentException();
    }
    Collections.sort(bucketsList, new LowerComparator());
    final Bucket[] buckets = bucketsList.toArray(new Bucket[0]);
    int cumulativeWeight = 0;
    for (Bucket bucket : buckets) {
        cumulativeWeight += bucket.weight;
        bucket.cumulativeWeight = cumulativeWeight;
    }
    return new HistogramIntGenerator(buckets);
}

From source file:com.intel.cosbench.driver.generator.HistogramIntGenerator.java

private static HistogramIntGenerator tryParse(String pattern) {
    pattern = StringUtils.substringBetween(pattern, "(", ")");
    String[] args = StringUtils.split(pattern, ',');
    ArrayList<Bucket> bucketsList = new ArrayList<Bucket>();
    for (String arg : args) {
        int v1 = StringUtils.indexOf(arg, '|');
        int v2 = StringUtils.lastIndexOf(arg, '|');
        boolean isOpenRange = ((v2 - v1) == 1) ? true : false;
        String[] values = StringUtils.split(arg, '|');
        int lower, upper, weight;
        if (isOpenRange) {
            lower = Integer.parseInt(values[0]);
            upper = UniformIntGenerator.getMAXupper();
            weight = Integer.parseInt(values[1]);
        } else if (values.length != 3) {
            throw new IllegalArgumentException();
        } else {//from  ww  w. ja va  2  s.c om
            lower = Integer.parseInt(values[0]);
            upper = Integer.parseInt(values[1]);
            weight = Integer.parseInt(values[2]);
        }
        bucketsList.add(new Bucket(lower, upper, weight));
    }
    if (bucketsList.isEmpty()) {
        throw new IllegalArgumentException();
    }
    Collections.sort(bucketsList, new LowerComparator());
    final Bucket[] buckets = bucketsList.toArray(new Bucket[0]);
    int cumulativeWeight = 0;
    for (Bucket bucket : buckets) {
        cumulativeWeight += bucket.weight;
        bucket.cumulativeWeight = cumulativeWeight;
    }
    return new HistogramIntGenerator(buckets);
}

From source file:com.mmounirou.spotirss.spotify.tracks.XTracks.java

private String cleanTrackName(String trackName) {
    String[] spotifyExtensions = new String[] { " - Explicit Version", " - Live", " - Radio Edit" };
    String strSong = trackName;//from w w  w.  j  a  v  a2  s  .c  o m

    for (String extensions : spotifyExtensions) {
        if (StringUtils.contains(strSong, extensions)) {
            strSong = "X " + StringUtils.remove(trackName, extensions);
        }
    }

    String[] braces = { "[]", "()" };

    for (String brace : braces) {

        String extendedinfo = null;
        do {
            extendedinfo = StringUtils.defaultString(
                    StringUtils.substringBetween(strSong, brace.charAt(0) + "", brace.charAt(1) + ""));
            if (StringUtils.isNotBlank(extendedinfo)) {
                if (StringUtils.startsWith(extendedinfo, "feat.")) {
                    String strArtist = StringUtils.removeStart("feat.", extendedinfo);
                    strSong = StringUtils.replace(strSong,
                            String.format("%c%s%c", brace.charAt(0), extendedinfo, brace.charAt(1)), "");
                    m_artistsInTrackName.addAll(cleanArtist(strArtist));
                }

                else {
                    strSong = StringUtils.replace(strSong,
                            String.format("%c%s%c", brace.charAt(0), extendedinfo, brace.charAt(1)), "");
                    strSong = "X " + strSong;
                }
            }

        } while (StringUtils.isNotBlank(extendedinfo));

    }

    String[] strSongSplitted = strSong.split("featuring");
    if (strSongSplitted.length > 1) {
        strSong = strSongSplitted[0];
        m_artistsInTrackName.add(strSongSplitted[1]);
    }

    String[] strSongWithFeaturing = strSong.split("-");
    if (strSongWithFeaturing.length > 1 && strSongWithFeaturing[1].contains("feat.")) {
        strSong = strSongWithFeaturing[0];
        m_artistsInTrackName.addAll(cleanArtist(StringUtils.remove(strSongWithFeaturing[1], "feat.")));
    } else {
        strSongWithFeaturing = strSong.split("feat.");
        if (strSongWithFeaturing.length > 1) {
            strSong = strSongWithFeaturing[0];
            m_artistsInTrackName.addAll(cleanArtist(strSongWithFeaturing[1]));
        }
    }

    return strSong.trim().toLowerCase();
}

From source file:info.magnolia.cms.i18n.DefaultI18nContentSupport.java

@Override
protected Locale onDetermineLocale() {
    Locale locale;/*from   ww  w. ja v  a 2s. c  o m*/
    final String i18nURI = MgnlContext.getAggregationState().getCurrentURI();
    String localeStr = StringUtils.substringBetween(i18nURI, "/", "/");
    locale = determineLocalFromString(localeStr);
    return locale;
}