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:de.xirp.io.logging.XirpTextFieldAppender.java

/**
 * Extracts the robot name and the original message from the given
 * message./*from w  ww  .  j  a  v a 2s. c  om*/
 * 
 * @param message
 *            the original message to extract the robot name and
 *            original message from
 * @return a string array with the robot name and original message
 */
private String[] extractRobot(String message) {
    String robot = StringUtils.substringBetween(message, RobotLogger.ROBOT_IDENTIFIER,
            RobotLogger.ROBOT_DELIMITER);

    if (StringUtils.isEmpty(robot)) {
        return null;
    }

    String origMessage = StringUtils.substringBefore(message, RobotLogger.ROBOT_IDENTIFIER);
    origMessage += StringUtils.substringAfterLast(message, RobotLogger.ROBOT_DELIMITER);
    return new String[] { robot, origMessage };
}

From source file:ddf.security.samlp.SystemCrypto.java

private String decryptPassword(String password) {
    if (password.startsWith(Merlin.ENCRYPTED_PASSWORD_PREFIX)
            && password.endsWith(Merlin.ENCRYPTED_PASSWORD_SUFFIX)) {
        return passwordEncryption.decrypt(StringUtils.substringBetween(password,
                Merlin.ENCRYPTED_PASSWORD_PREFIX, Merlin.ENCRYPTED_PASSWORD_SUFFIX));
    }/*from   w  w  w . j a v  a  2s .  co m*/

    return password;
}

From source file:com.gs.tools.doc.extractor.core.html.HTMLDocumentExtractor.java

private long processBody(final File rootDir, final String rootLocation, final String bodyContent)
        throws Exception {
    long fileCount = 0;
    String imgLinks[] = StringUtils.substringsBetween(bodyContent, "<img", ">");
    if (null != imgLinks && imgLinks.length > 0) {
        for (String imgLink : imgLinks) {
            String img = StringUtils.substringBetween(imgLink, "src=\"", "\"");
            if (null != img && img.length() > 0) {
                File imgFile = new File(rootDir, img);
                File imgFolder = new File(rootDir.getAbsolutePath());
                String hrefLocation = rootLocation;
                if (img.contains("/")) {
                    String path = img.substring(0, img.lastIndexOf("/"));
                    hrefLocation += "/" + path;
                    String name = img.substring(img.lastIndexOf("/") + 1);
                    imgFolder = new File(rootDir, path);
                    if (!imgFolder.exists()) {
                        imgFolder.mkdirs();
                    }/*w w  w  . j  av a  2  s  .c om*/
                    imgFile = new File(imgFolder, name);
                }
                if (!sourceUrlCache.contains(rootLocation + "/" + img)) {
                    sourceUrlCache.add(rootLocation + "/" + img);
                    byte[] cssContentByte = downloadManager.readContentFromGET(rootLocation + "/" + img);
                    if (null != cssContentByte && cssContentByte.length > 0) {
                        logger.info("Save to: " + imgFile.getAbsolutePath());
                        writeTo(cssContentByte, new BufferedOutputStream(new FileOutputStream(imgFile)));
                        fileCount++;
                    }
                }
            }
        }
    }
    String[] anchors = StringUtils.substringsBetween(bodyContent, "<a", "</a>");
    if (null != anchors && anchors.length > 0) {
        for (String anchor : anchors) {
            String href = StringUtils.substringBetween(anchor, "href=\"", "\"");
            if (null != href && href.length() > 0 && href.endsWith(getFileExtension())) {
                File hrefFile = new File(rootDir, href);
                File hrefFolder = new File(rootDir.getAbsolutePath());
                String hrefLocation = rootLocation;
                if (href.contains("/")) {
                    String path = href.substring(0, href.lastIndexOf("/"));
                    hrefLocation += "/" + path;
                    String name = href.substring(href.lastIndexOf("/") + 1);
                    hrefFolder = new File(rootDir, path);
                    if (!hrefFolder.exists()) {
                        hrefFolder.mkdirs();
                    }
                    hrefFile = new File(hrefFolder, name);
                }
                if (!sourceUrlCache.contains(rootLocation + "/" + href)) {
                    sourceUrlCache.add(rootLocation + "/" + href);
                    byte[] cssContentByte = downloadManager.readContentFromGET(rootLocation + "/" + href);
                    if (null != cssContentByte && cssContentByte.length > 0) {
                        logger.info("Save to: " + hrefFile.getAbsolutePath());
                        writeTo(cssContentByte, new BufferedOutputStream(new FileOutputStream(hrefFile)));
                        fileCount++;
                        logger.info("File count: " + fileCount);
                        String hrefContent = new String(cssContentByte, Charset.forName("UTF-8"));
                        String bodySection = StringUtils.substringBetween(hrefContent, "<body", "</body>");
                        fileCount += processBody(hrefFolder, hrefLocation, bodySection);
                    }
                }
            }
        }
    }

    return fileCount;
}

From source file:com.safetys.framework.jmesa.limit.LimitActionFactory.java

public SortSet getSortSet() {
    SortSet sortSet = new SortSet();

    for (Object param : parameters.keySet()) {
        String parameter = (String) param;
        if (parameter.startsWith(prefixId + Action.SORT.toParam())) {
            String value = LimitUtils.getValue(parameters.get(parameter));
            if (StringUtils.isNotBlank(value)) {
                String position = StringUtils.substringBetween(parameter, prefixId + Action.SORT.toParam(),
                        "_");
                String property = StringUtils.substringAfter(parameter,
                        prefixId + Action.SORT.toParam() + position + "_");
                Order order = Order.valueOfParam(value);
                Sort sort = new Sort(new Integer(position), property, order);
                sortSet.addSort(sort);//from  www  .  j a v a  2  s. c o m
            }
        }
    }

    return sortSet;
}

From source file:com.kstenschke.shifter.models.shiftertypes.Dictionary.java

/**
 * Check whether the given term exists in any section of shift-lists of the dictionary,
 * looking only at lists in blocks having assigned the given extension
 * + Stores first matching line containing the term for use in shifting later
 *
 * @param   term         String to be looked for in shifter dictionary
 * @param   fileExtension   Extension of edited file
 * @return   boolean//from w w  w .  j av a2  s .  com
 */
public boolean isTermInDictionary(String term, String fileExtension) {
    if (fileExtension != null && this.dictionaryContents.contains("|" + fileExtension + "|")) {
        this.fileExtension = fileExtension;

        // Reduce to first term-list of terms-block(s) of the given file extension, containing the given term
        Object[] blocksOfExtension = getAllFileExtensionsBlockStarts(fileExtension);

        // Go over all blocks of lists of shift-terms, fetch first one containing the term
        for (Object aBlocksOfExtension : blocksOfExtension) {
            String curExtsList = aBlocksOfExtension.toString();
            String curShiftTermsBlock = StringUtils.substringBetween(this.dictionaryContents, curExtsList, "}");

            // Term is contained? store list of shifting neighbours
            if (curShiftTermsBlock.contains("|" + term + "|")) {
                this.relevantTermsList = extractFirstMatchingTermsLine(curShiftTermsBlock, term);
                return true;
            }
        }
    }

    return false;
}

From source file:com.kstenschke.shifter.models.shiftertypes.DictionaryTerm.java

/**
 * Check whether the given term exists in any section of shift-lists of the dictionary,
 * looking only at lists in blocks having assigned the given extension
 * + Stores first matching line containing the term for use in shifting later
 *
 * @param  term            String to be looked for in shifter dictionary
 * @param  fileExtension   Extension of edited file
 * @return boolean/*from w ww . ja v a  2 s.c  om*/
 */
public boolean isTermInDictionary(String term, String fileExtension) {
    if (fileExtension != null && this.dictionaryContents.contains("|" + fileExtension + "|")) {
        this.fileExtension = fileExtension;

        // Reduce to first term-list of terms-block(s) of the given file extension, containing the given term
        Object[] blocksOfExtension = getAllFileExtensionsBlockStarts(fileExtension);

        // Go over all blocks of lists of shift-terms, fetch first one containing the term
        for (Object aBlocksOfExtension : blocksOfExtension) {
            String curExtensionsList = aBlocksOfExtension.toString();
            String curShiftTermsBlock = StringUtils.substringBetween(this.dictionaryContents, curExtensionsList,
                    "}");

            // Term is contained? store list of shifting neighbours
            if (UtilsTextual.containsCaseInSensitive(curShiftTermsBlock, "|" + term + "|")) {
                this.relevantTermsList = extractFirstMatchingTermsLine(curShiftTermsBlock, term);
                return true;
            }
        }
    }

    return false;
}

From source file:com.jaeksoft.searchlib.web.SearchServlet.java

private String getIndexName() {
    String use = null;/*w ww.  j a v  a2s . co  m*/
    if (StringUtils.substringBetween(serverURL, "search/", "/") != null)
        use = StringUtils.substringBetween(serverURL, "search/", "/");
    else
        use = StringUtils.substringBetween(serverURL, "search/", "?");
    return use;
}

From source file:com.baidu.cc.common.SysUtils.java

/**
 * authCheck??userId./*from  w ww  . j av a 2  s.c om*/
 * 
 * @param authCheck
 *            authCheck
 * @return userId
 */
public static Long getUserIdFromAuthcheck(String authCheck) {
    String value = Security.DESDecrypt(authCheck, AUTHCHECK_DES_KEY);
    return NumberUtils.toLong(StringUtils.substringBetween(value, "userId=", ";projectId"));
}

From source file:com.hangum.tadpole.erd.core.relation.RelationUtil.java

/**
 * sqlite? relation? ./*from   w ww  .  jav  a 2  s .c o m*/
 * 
 * @param userDB
 * @return
 */
private static List<ReferencedTableDAO> makeSQLiteRelation(UserDBDAO userDB) {
    List<ReferencedTableDAO> listRealRefTableDAO = new ArrayList<ReferencedTableDAO>();

    try {
        //  ? ?.
        for (SQLiteRefTableDAO sqliteRefTableDAO : getSQLiteRefTbl(userDB)) {

            int indexKey = StringUtils.indexOf(sqliteRefTableDAO.getSql(), "FOREIGN KEY");
            String forKey = sqliteRefTableDAO.getSql().substring(indexKey);
            if (logger.isDebugEnabled())
                logger.debug("\t full text:" + sqliteRefTableDAO.getSql());
            if (logger.isDebugEnabled())
                logger.debug("\t=================>[forKeys]\n" + forKey);
            String[] foreignInfo = forKey.split("FOREIGN KEY");

            for (int i = 1; i < foreignInfo.length; i++) {
                try {
                    String strForeign = foreignInfo[i];
                    if (logger.isDebugEnabled())
                        logger.debug("\t ==========================> sub[\n" + strForeign + "]");
                    ReferencedTableDAO ref = new ReferencedTableDAO();

                    // ? 
                    ref.setTable_name(sqliteRefTableDAO.getTbl_name());

                    // ,  (   ) ??...
                    String colName = StringUtils.substringBetween(strForeign, "(", ")");

                    //  ?,  REFERENCES    ?  (
                    String refTbName = StringUtils.substringBetween(strForeign, "REFERENCES", "(");

                    //  ,  refTbName? ??  ) ...
                    String refCol = StringUtils.substringBetween(strForeign, refTbName + "(", ")");

                    ref.setColumn_name(moveSpec(colName));
                    ref.setReferenced_table_name(moveSpec(refTbName));
                    ref.setReferenced_column_name(moveSpec(refCol));

                    // sqlite ?? ? .... ?.
                    ref.setConstraint_name(ref.toString());

                    listRealRefTableDAO.add(ref);

                } catch (Exception e) {
                    logger.error("SQLLite Relation making", e);
                }
            } // inner if

        } // last for
    } catch (Exception e) {
        logger.error("SQLite Relation check 2", e);
    }

    return listRealRefTableDAO;
}

From source file:eu.annocultor.tagger.server.controllers.SolrTaggerController.java

private List<String[]> readFile(String url) throws IOException {
    FileInputStream fStream = new FileInputStream(new File(url));
    StringBuffer sb = new StringBuffer();
    BufferedInputStream bin = new BufferedInputStream(fStream);
    byte[] contents = new byte[1024];
    int bytesRead = 0;
    while ((bytesRead = bin.read(contents)) != -1) {
        sb.append(new String(contents, 0, bytesRead));
    }/*from w  w  w  .  jav a 2s.co  m*/
    String toImport = StringUtils.substringBetween(sb.toString(), "Import\n", "Delete\n");
    List<String[]> collections = new ArrayList<String[]>();
    String[] collectionsToImport = StringUtils.split(toImport, "\n");
    collections.add(collectionsToImport);
    String toDelete = StringUtils.substringAfter(sb.toString(), "Delete\n");
    String[] collectionsToDelete = StringUtils.split(toDelete, "\n");
    collections.add(collectionsToDelete);
    return collections;
}