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

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

Introduction

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

Prototype

public static String substring(String str, int start) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

Usage

From source file:com.fengduo.bee.commons.util.ObjectUtils.java

/**
 * ????// w  w w . j  a v a  2  s.  c  o m
 * 
 * @param annotation
 * @param object
 */
public static void annotationToObject(Object annotation, Object object) {
    if (annotation != null) {
        Class<?> annotationClass = annotation.getClass();
        Class<?> objectClass = object.getClass();
        for (Method m : objectClass.getMethods()) {
            if (StringUtils.startsWith(m.getName(), "set")) {
                try {
                    String s = StringUtils.uncapitalize(StringUtils.substring(m.getName(), 3));
                    Object obj = annotationClass.getMethod(s).invoke(annotation);
                    if (obj != null && !"".equals(obj.toString())) {
                        if (object == null) {
                            object = objectClass.newInstance();
                        }
                        m.invoke(object, obj);
                    }
                } catch (Exception e) {
                    // 
                }
            }
        }
    }
}

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

/**
 * classpathjar/*from   www  .  j  ava2s .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.zhaimi.message.event.DataEventListenerPostProcessor.java

/**
 * ?Listener?????topic, ?Listener/* w w  w  . ja v  a 2 s  . c o  m*/
 * ??: : insertOrder_B, onCompoleteOrder, compoleteOrder, completeOrder_X
 *
 * @param listener
 * @param method
 */
private void registerDataEventListener(Object listener, String dataObjectName, Method method) {
    String methodName = method.getName();

    String topic = null;

    String eventName = methodName;
    if (methodName.startsWith("on")) {
        eventName = StringUtils.substring(methodName, 2);
        eventName = String.valueOf(eventName.charAt(0)).toLowerCase() + eventName.substring(1);
    }

    topic = dataObjectName + "." + eventName;
    //
    registerListener(listener, topic);
}

From source file:jenkins.plugins.tanaguru.TanaguruRunner.java

/**
 * /*from ww  w  .j ava 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.commercehub.dropwizard.BuildInfoServlet.java

private static String getRequestedKey(HttpServletRequest request) {
    return StringUtils.substring(request.getPathInfo(), 1);
}

From source file:com.bsi.summer.core.dao.PropertyFilter.java

public Object getValue(String value) {
    if (value.startsWith("SYS_")) {
        return getRealObj(StringUtils.substring(value, 3));
    } else {//ww w  .  j a  v  a  2s.c o m
        return ConvertUtils.convertStringToObject(value, propertyClass.getValue());
    }
}

From source file:eu.annocultor.context.Namespaces.java

public String makeQualifiedName(String unqualifiedUri) {
    String nick = getNick(unqualifiedUri);
    String prefixBehindNick = getUri(nick);
    if (StringUtils.isBlank(prefixBehindNick)) {
        return null;
    }/* w  w w  .ja  v  a  2  s.c  o  m*/
    String qualifiedName = StringUtils.substring(unqualifiedUri, prefixBehindNick.length());
    return qualifiedName;
}

From source file:com.zhaimi.message.event.DataEventMessageDispatcher.java

/**
 * ?Topic???,  onXXX./*from w w w  .  j av a  2s  .c o  m*/
 * :
 *  com.zhaimi.message.demo.trading.mapper.impl.OrderMapperImpl.insertOrder
 * ????   onInsertOrder
 *
 * @param event topic
 * @return ??
 */
private String getEventName(String event) {
    event = StringUtils.substring(event, event.lastIndexOf('.') + 1);

    event = StringUtils.substring(event, 0, 1).toUpperCase() + StringUtils.substring(event, 1);

    event = "on" + event;
    return event;
}

From source file:hydrograph.ui.perspective.dialog.PreStartActivity.java

private void restartHydrograph() {
    logger.info("Starting New Hydrograph");
    String path = Platform.getInstallLocation().getURL().getPath();
    if ((StringUtils.isNotBlank(path)) && (StringUtils.startsWith(path, "/")) && (OSValidator.isWindows())) {
        path = StringUtils.substring(path, 1);
    }//from   w w w .  j  ava 2 s .c o m
    String command = path + HYDROGRAPH_EXE;
    Runtime runtime = Runtime.getRuntime();
    try {
        if (OSValidator.isWindows()) {
            String[] commandArray = { "cmd.exe", "/c", command };
            runtime.exec(commandArray);
        }
    } catch (IOException ioException) {
        logger.error("Exception occurred while starting hydrograph" + ioException);
    }
    System.exit(0);
}

From source file:com.alibaba.otter.shared.arbitrate.impl.zookeeper.lock.DistributedLock.java

/**
 * lock??watch????lock?/*from   w w w  .  j a  va2 s  .  c  om*/
 */
private Boolean acquireLock(final BooleanMutex mutex) {
    try {
        do {
            if (id == null) {// ?lock
                long sessionId = getSessionId();
                String prefix = "x-" + sessionId + "-";
                // 
                String path = zookeeper.create(root + "/" + prefix, data, CreateMode.EPHEMERAL_SEQUENTIAL);
                int index = path.lastIndexOf("/");
                id = StringUtils.substring(path, index + 1);
                idName = new LockNode(id);
            }

            if (id != null) {
                List<String> names = zookeeper.getChildren(root);
                if (names.isEmpty()) {
                    logger.warn("lock lost with scene:empty list, id[] and node[]", id, idName);
                    unlock();// ??
                } else {
                    // ?
                    SortedSet<LockNode> sortedNames = new TreeSet<LockNode>();
                    for (String name : names) {
                        sortedNames.add(new LockNode(name));
                    }

                    if (sortedNames.contains(idName) == false) {
                        logger.warn("lock lost with scene:not contains ,id[] and node[]", id, idName);
                        unlock();// ??
                        continue;
                    }

                    // ?ownerId
                    ownerId = sortedNames.first().getName();
                    if (mutex != null && isOwner()) {
                        mutex.set(true);// ?
                        return true;
                    } else if (mutex == null) {
                        return isOwner();
                    }

                    SortedSet<LockNode> lessThanMe = sortedNames.headSet(idName);
                    if (!lessThanMe.isEmpty()) {
                        // ?
                        LockNode lastChildName = lessThanMe.last();
                        lastChildId = lastChildName.getName();
                        // watcher?
                        IZkConnection connection = zookeeper.getConnection();
                        // zkclient?zk?lock??watcher?zk?
                        ZooKeeper orginZk = ((ZooKeeperx) connection).getZookeeper();
                        Stat stat = orginZk.exists(root + "/" + lastChildId, new AsyncWatcher() {

                            public void asyncProcess(WatchedEvent event) {
                                if (!mutex.state()) { // ?????lock
                                    acquireLock(mutex);
                                } else {
                                    logger.warn("locked successful.");
                                }
                            }

                        });

                        if (stat == null) {
                            acquireLock(mutex);// ????watcher?
                        }
                    } else {
                        if (isOwner()) {
                            mutex.set(true);
                        } else {
                            logger.warn("lock lost with scene:no less ,id[] and node[]", id, idName);
                            unlock();// ?idownerId??
                        }
                    }
                }
            }
        } while (id == null);
    } catch (KeeperException e) {
        exception = e;
        if (mutex != null) {
            mutex.set(true);
        }
    } catch (InterruptedException e) {
        interrupt = e;
        if (mutex != null) {
            mutex.set(true);
        }
    } catch (Throwable e) {
        other = e;
        if (mutex != null) {
            mutex.set(true);
        }
    }

    if (isOwner() && mutex != null) {
        mutex.set(true);
    }
    return Boolean.FALSE;
}