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

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

Introduction

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

Prototype

public static int indexOf(String str, String searchStr) 

Source Link

Document

Finds the first index within a String, handling null.

Usage

From source file:com.huawei.streaming.cql.DriverContext.java

/**
 * classpathjar//from w  ww  .  jav a2  s.  c o m
 *
 * @param pathsToRemove jar
 * @throws IOException jar
 */
private static void removeFromClassPath(String[] pathsToRemove) throws IOException {
    Thread curThread = Thread.currentThread();
    URLClassLoader loader = (URLClassLoader) curThread.getContextClassLoader();
    Set<URL> newPath = new HashSet<URL>(Arrays.asList(loader.getURLs()));

    if (pathsToRemove != null) {
        for (String onestr : pathsToRemove) {
            if (StringUtils.indexOf(onestr, FILE_PREFIX) == 0) {
                onestr = StringUtils.substring(onestr, CQLConst.I_7);
            }

            URL oneurl = (new File(onestr)).toURI().toURL();
            newPath.remove(oneurl);
        }
    }

    loader = new URLClassLoader(newPath.toArray(new URL[0]));
    curThread.setContextClassLoader(loader);
}

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

/**
 * sqlite? relation? .// ww  w.j a  va  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)) {

            String strFullTextSQL = sqliteRefTableDAO.getSql();
            if (logger.isDebugEnabled())
                logger.debug("\t full text:" + strFullTextSQL);

            int indexKey = StringUtils.indexOf(strFullTextSQL, "FOREIGN KEY");
            if (indexKey == -1) {
                indexKey = StringUtils.indexOf(strFullTextSQL, "foreign key");

                if (indexKey == -1) {
                    if (logger.isDebugEnabled())
                        logger.debug("Not found foreign keys.");
                    continue;
                }
            }

            String forKey = sqliteRefTableDAO.getSql().substring(indexKey);
            if (logger.isDebugEnabled())
                logger.debug("\t=================>[forKeys]\n" + forKey);
            String[] foreignInfo = forKey.split("FOREIGN KEY");
            if (foreignInfo.length == 1)
                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", "(");
                    if ("".equals(refTbName) || null == refTbName)
                        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:jenkins.plugins.tanaguru.TanaguruRunner.java

/**
 * /*from  w  w w .j  a v a 2s  .  co m*/
 * @param logFile
 * @param ps
 * @throws IOException 
 */
public void extractDataAndPrintOut(File logFile, PrintStream ps) throws IOException {
    ps.println("");
    boolean isFirstMark = true;
    boolean isFirstNbPassed = true;
    boolean isFirstNbFailed = true;
    boolean isFirstNbFailedOccurences = true;
    boolean isFirstNbNmi = true;
    boolean isFirstNbNa = true;
    boolean isFirstNbNt = true;
    for (String line : FileUtils.readLines(logFile)) {
        if (StringUtils.startsWith(line, "Subject")) {
            ps.println("");
            ps.println(line);
        } else if (StringUtils.startsWith(line, "Audit terminated")) {
            ps.println(line);
        } else if (StringUtils.startsWith(line, "RawMark")) {
            ps.println(line.replace("RawMark", "Mark"));
            if (isFirstMark) {
                mark = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).replaceAll("%", "")
                        .trim();
                isFirstMark = false;
            }
        } else if (StringUtils.startsWith(line, "Nb Passed")) {
            ps.println(line);
            if (isFirstNbPassed) {
                nbPassed = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
                isFirstNbPassed = false;
            }
        } else if (StringUtils.startsWith(line, "Nb Failed test")) {
            ps.println(line);
            if (isFirstNbFailed) {
                nbFailed = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
                isFirstNbFailed = false;
            }
        } else if (StringUtils.startsWith(line, "Nb Failed occurences")) {
            ps.println(line);
            if (isFirstNbFailedOccurences) {
                nbFailedOccurences = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
                isFirstNbFailedOccurences = false;
            }
        } else if (StringUtils.startsWith(line, "Nb Pre-qualified")) {
            ps.println(line);
            if (isFirstNbNmi) {
                nbNmi = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
                isFirstNbNmi = false;
            }
        } else if (StringUtils.startsWith(line, "Nb Not Applicable")) {
            ps.println(line);
            if (isFirstNbNa) {
                nbNa = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
                isFirstNbNa = false;
            }
        } else if (StringUtils.startsWith(line, "Nb Not Tested")) {
            ps.println(line);
            if (isFirstNbNt) {
                nbNt = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
                isFirstNbNt = false;
            }
        } else if (StringUtils.startsWith(line, "Audit Id")) {
            ps.println(line);
            auditId = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
        }
    }
    ps.println("");
}

From source file:com.inktomi.wxmetar.MetarParser.java

static boolean parseWinds(String token, final Metar metar) {
    boolean rval = Boolean.FALSE;

    // Winds will be the only element that ends in knots
    if (StringUtils.endsWith(token, "KT")) {

        // At this point, we know we should handle this token
        rval = Boolean.TRUE;/*from  w  ww . jav a2s  . c  om*/

        // Remove the KT
        token = StringUtils.remove(token, "KT");

        // Is it variable?
        if (StringUtils.startsWith(token, "VRB")) {
            metar.winds.variable = Boolean.TRUE;

            // Trim of the VRB
            token = StringUtils.remove(token, "VRB");

            metar.winds.windSpeed = Float.parseFloat(token);

            // Stop processing this token
            return rval;
        }

        // At this point, we know the first 3 chars are wind direction
        metar.winds.windDirection = Integer.parseInt(StringUtils.substring(token, 0, 3));

        // Is it gusting? 17012G24
        int postionOfG = StringUtils.indexOf(token, "G");
        if (postionOfG > -1) {
            metar.winds.windGusts = Float
                    .parseFloat(StringUtils.substring(token, postionOfG + 1, token.length()));
            metar.winds.windSpeed = Float.parseFloat(StringUtils.substring(token, 3, postionOfG));
        }

        // Is it just a normal wind measurement?
        // 26006
        if (postionOfG == -1 && !metar.winds.variable) {
            metar.winds.windSpeed = Float.parseFloat(StringUtils.substring(token, 2, token.length()));
        }
    }

    return rval;
}

From source file:com.ewcms.web.pubsub.PubsubServlet.java

private PubsubSenderable createPubsubSender(String path) {
    String name = null;//from   w w  w . j av  a 2s  . co m
    if (StringUtils.indexOf(path, '/') == -1) {
        name = pathSender.get(path);
    } else {
        String root = StringUtils.substringBeforeLast(path, "/");
        name = pathSender.get(root);
        if (name == null) {
            String middle = StringUtils.substringAfter(root, "/");
            name = pathSender.get(middle);
        }
    }
    if (StringUtils.isNotBlank(name)) {
        try {
            Class<?> clazz = Class.forName(name);
            Class<?>[] argsClass = new Class<?>[] { String.class, ServletContext.class };
            Constructor<?> cons = clazz.getConstructor(argsClass);
            return (PubsubSenderable) cons.newInstance(new Object[] { path, this.getServletContext() });
        } catch (Exception e) {
            logger.error("PubsubSender create error:{}", e.toString());
        }
    }

    return new NoneSender();
}

From source file:com.tesora.dve.dbc.ServerDBConnection.java

public int executeUpdate(byte[] sql) throws SQLException {
    initialize();/*from  w  ww . j  a  v  a  2 s .co  m*/

    final MysqlTextResultCollector resultConsumer = new MysqlTextResultCollector();
    try {
        executeInContext(resultConsumer, sql);

        // Not the most optimal but it's the quickest way to use rows affected vs rows changed settings
        int ret = (int) resultConsumer.getNumRowsAffected();
        if (ret == 0 && resultConsumer.getInfoString() != null
                && !StringUtils.startsWithIgnoreCase(resultConsumer.getInfoString(), "Rows matched: 0")) {
            int start = StringUtils.indexOf(resultConsumer.getInfoString(), "Rows matched: ")
                    + "Rows matched: ".length();
            int end = StringUtils.indexOf(resultConsumer.getInfoString(), "Changed:");
            try {
                ret = Integer.valueOf(StringUtils.substring(resultConsumer.getInfoString(), start, end).trim());
            } catch (Exception e) {
                // do nothing take original value
            }
        }

        return ret;
    } catch (SchemaException se) {
        throw ErrorMapper.makeException(se);
    } catch (Throwable t) {
        throw new SQLException(t);
    } finally {
        ssCon.releaseNonTxnLocks();
    }
}

From source file:com.edgenius.core.Global.java

public static void syncTo(GlobalSetting setting) {

    setting.setDefaultDirection(Global.DefaultDirection);
    setting.setDefaultLanguage(Global.DefaultLanguage);
    setting.setDefaultCountry(Global.DefaultCountry);
    setting.setDefaultTimeZone(Global.DefaultTimeZone);
    setting.setDefaultLoginKey(Global.DefaultLoginKey);
    setting.setHostProtocol(Global.SysHostProtocol);
    if (StringUtils.indexOf(Global.SysHostAddress, ':') != -1) {
        String[] addr = StringUtils.split(Global.SysHostAddress, ':');
        setting.setHostName(addr[0]);/*from   w  ww. j av  a2  s  .  com*/
        setting.setHostPort(Integer.parseInt(addr[1]));
    } else {
        setting.setHostName(Global.SysHostAddress);
        if (Global.SysHostProtocol != null && Global.SysHostProtocol.startsWith("https:"))
            setting.setHostPort(443);
        else
            setting.setHostPort(80);
    }

    setting.setPublicSearchEngineAllow(Global.PublicSearchEngineAllow);
    setting.setContextPath(StringUtils.trim(Global.SysContextPath));
    setting.setEncryptAlgorithm(Global.PasswordEncodingAlgorithm);
    setting.setEncryptPassword(Global.EncryptPassword);
    setting.setSpaceQuota(Global.SpaceQuota);
    setting.setDelayRemoveSpaceHours(Global.DelayRemoveSpaceHours);
    setting.setEnableAdminPermControl(Global.EnableAdminPermControl);
    setting.setDelayOfflineSyncMinutes(Global.DelayOfflineSyncMinutes);
    setting.setRegisterMethod(Global.registerMethod);
    setting.setMaintainJobCron(Global.MaintainJobCron);
    setting.setCommentsNotifierCron(Global.CommentsNotifierCron);
    setting.setMaxCommentsNotifyPerDay(Global.MaxCommentsNotifyPerDay);
    setting.setAutoFixLinks(Global.AutoFixLinks);
    setting.setDefaultNotifyMail(Global.DefaultNotifyMail);
    setting.setCcToSystemAdmin(Global.ccToSystemAdmin);
    setting.setDefaultReceiverMailAddress(Global.DefaultReceiverMail);
    setting.setSystemTitle(Global.SystemTitle);

    setting.setAdsense(enable(Global.ADSENSE));
    setting.setTextnut(enable(Global.TEXTNUT));
    setting.setSkin(Global.Skin);

    setting.setWebservice(enable(Global.webServiceEnabled));
    setting.setWebserviceAuthenticaton(
            StringUtils.isBlank(Global.webServiceAuth) ? "basic" : Global.webServiceAuth);

    setting.setRestservice(enable(Global.restServiceEnabled));
    setting.setRestserviceAuthenticaton(
            StringUtils.isBlank(Global.restServiceAuth) ? "basic" : Global.restServiceAuth);

    setting.setDetectLocaleFromRequest(Global.DetectLocaleFromRequest);

    setting.setVersionCheck(Global.VersionCheck);
    setting.setVersionCheckCron(Global.VersionCheckCron);
    setting.setPurgeDaysOldActivityLog(Global.PurgeDaysOldActivityLog);

    //convert suppress value to names 
    StringBuffer supStr = new StringBuffer();
    if (Global.suppress > 0) {
        for (SUPPRESS sup : SUPPRESS.values()) {
            if ((sup.getValue() & Global.suppress) > 0) {
                supStr.append(sup.name()).append(",");
            }
        }
        if (supStr.length() > 0) {
            supStr.deleteCharAt(supStr.length() - 1);
        }
    }
    setting.setSuppress(supStr.toString());

    setting.setTwitterOauthConsumerKey(Global.TwitterOauthConsumerKey);
    setting.setTwitterOauthConsumerSecret(Global.TwitterOauthConsumerSecret);
}

From source file:com.huateng.ebank.framework.web.TransFilter.java

private boolean expiredSystem(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    String uriStr = StringUtils.substringAfterLast(req.getServletPath(), "/");
    if (StringUtils.indexOf(loginRef, uriStr) == -1) {
        resp.setHeader("Pragma", "No-cache");
        resp.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
        resp.setDateHeader("Expires", 1);
        RequestDispatcher rd = (req).getRequestDispatcher(expiredPageName);
        rd.forward(req, resp);/*from w  ww .  j av  a  2 s. c  om*/
        return true;
    }
    return false;
}

From source file:info.magnolia.module.workflow.jcr.JCRWorkItemAPI.java

/**
 * check whether the specified work item exists
 * @param fei expression id of work item
 * @return true if exist, false if not// w ww.j a  v a 2 s .  c  om
 */
public boolean hasWorkItem(FlowExpressionId fei) throws AccessDeniedException, RepositoryException {
    String path = createPathFromId(fei);
    if (StringUtils.isNotEmpty(path) && StringUtils.indexOf(path, "/") != 0) {
        path = "/" + path;
    }
    return this.hm.isExist(path);
}

From source file:com.adobe.acs.commons.wcm.notifications.impl.SystemNotificationsImpl.java

@Override
protected int getInjectIndex(String originalContents) {
    // Inject immediately before the ending body tag
    return StringUtils.indexOf(originalContents, "</body>");
}