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

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

Introduction

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

Prototype

public static String substringAfter(String str, String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:com.alibaba.otter.manager.deployer.OtterManagerLauncher.java

public static void main(String[] args) throws Throwable {
    try {//w  ww . j a  v  a2 s  .c om
        String conf = System.getProperty("otter.conf", "classpath:otter.properties");
        Properties properties = new Properties();
        if (conf.startsWith(CLASSPATH_URL_PREFIX)) {
            conf = StringUtils.substringAfter(conf, CLASSPATH_URL_PREFIX);
            properties.load(OtterManagerLauncher.class.getClassLoader().getResourceAsStream(conf));
        } else {
            properties.load(new FileInputStream(conf));
        }

        // ??system?
        mergeProps(properties);

        logger.info("## start the manager server.");
        final JettyEmbedServer server = new JettyEmbedServer(
                properties.getProperty("otter.jetty", "jetty.xml"));
        server.start();
        logger.info("## the manager server is running now ......");
        Runtime.getRuntime().addShutdownHook(new Thread() {

            public void run() {
                try {
                    logger.info("## stop the manager server");
                    server.join();
                } catch (Throwable e) {
                    logger.warn("##something goes wrong when stopping manager Server:\n{}",
                            ExceptionUtils.getFullStackTrace(e));
                } finally {
                    logger.info("## manager server is down.");
                }
            }

        });
    } catch (Throwable e) {
        logger.error("## Something goes wrong when starting up the manager Server:\n{}",
                ExceptionUtils.getFullStackTrace(e));
        System.exit(0);
    }
}

From source file:eu.annocultor.analyzers.SolrPropertyHitsAnalyzer.java

/**
 * @param args/*from  w  w w .  j a  v a 2 s.  c  om*/
 */
public static void main(String[] args) throws Exception {

    String solrUrl = args[0];
    SolrServer solr = new CommonsHttpSolrServer(solrUrl);

    String prefixOne = args[1];
    String prefixTwo = args[2];

    long prefixOneCount = 0;
    long prefixTwoCount = 0;

    long totalPassedCount = 0;

    for (File logLocation : FileUtils.listFiles(new File(args[3]), null, true)) {
        System.out.println("Parsing " + logLocation);

        for (String line : FileUtils.readLines(logLocation)) {
            if (StringUtils.contains(line, "FULL_RESULT_HMTL")) {
                line = StringUtils.substringAfter(line, "europeana_uri=");
                String solrDocumentId = StringUtils.substringBefore(line, ",");
                String query = extractQuery(line);
                if (StringUtils.startsWith(solrDocumentId, "http://") && isLongEnoughToCount(query)) {

                    SolrQuery solrQuery = new SolrQuery("europeana_uri:\"" + solrDocumentId + "\"");
                    QueryResponse response = solr.query(solrQuery);
                    SolrDocumentList sourceDocs = response.getResults();
                    if (sourceDocs.isEmpty()) {
                        System.out.println("Could not find object " + solrDocumentId);
                    } else {
                        SolrDocument document = sourceDocs.get(0);

                        if (hasWord(document, prefixOne, query)) {
                            prefixOneCount++;
                        } else {
                            if (hasWord(document, prefixTwo, query)) {
                                prefixTwoCount++;
                            }
                        }
                    }
                }
                totalPassedCount++;
            }
        }
        System.out.println(prefixOne + " : " + prefixOneCount + " " + prefixTwo + " : " + prefixTwoCount
                + " of total passed entries " + totalPassedCount);
    }
}

From source file:ReplayTest.java

public static void main(String[] args) throws IOException {

    int cnt = 0;//from   ww  w  .  j  a  v  a 2 s.  c o  m
    String operateTime = "";
    String operateType = "";
    String uuid = "";
    String programId = "";
    List<String> lines = Files.readLines(new File("e:\\test\\sample4.txt"), Charsets.UTF_8);
    System.out.println(lines.size());
    for (String value1 : lines) {
        String[] values = value1.split(SPLIT_T);
        //logArr16?operateDate=2014-04-25 17:59:59 621, operateType=STARTUP, deviceCode=010333501065233, versionId=, mac=10:48:b1:06:4d:23, platformId=00000032AmlogicMDZ-05-201302261821793, ipAddress=60.10.133.10
        if (values.length != 16) {
            continue;
        }
        String logContent = values[15];

        if (logContent == null || logContent.trim().length() <= 0) {
            System.out.println("logContent");
            return;
        }
        String[] contentArr = logContent.split(COMMA_SIGN);//content

        if (contentArr == null || contentArr.length != 3) {
            System.out.println("logContentArr:" + contentArr.length);
            return;
        }

        StringBuffer stringBuffer = new StringBuffer();

        //1.CNTVID??
        stringBuffer.append(StringsUtils.getEncodeingStr(values[3])).append(SPLIT);

        //2.IP?
        if (null == values[7] || EMPTY.equals(values[7])) {
            stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT);
        } else {
            stringBuffer.append(StringsUtils.getEncodeingStr(values[7].trim())).append(SPLIT);
        }

        //3.OperateTtype   ? 1: 2:?
        operateType = StringUtils.substringAfter(contentArr[0].trim(), EQUAL_SIGN);
        if (null == operateType || EMPTY.equals(operateType)) {
            stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT);
        } else if ("on".equals(operateType)) {
            stringBuffer.append(StringsUtils.getEncodeingStr("1")).append(SPLIT);
        } else if ("out".equals(operateType)) {
            stringBuffer.append(StringsUtils.getEncodeingStr("2")).append(SPLIT);
        }

        // 4.operateTime  ?
        operateTime = DateUtil.convertDateToString("yyyyMMdd HHmmss",
                DateUtil.convertStringToDate("yyyy-MM-dd HH:mm:ss SSS", values[10].trim()));
        if (operateTime == null || EMPTY.equals(operateTime)) {
            stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT);
        } else {
            stringBuffer.append(StringsUtils.getEncodeingStr(operateTime)).append(SPLIT);
        }
        //5.url_addr ?
        stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT);

        //6.channel?
        uuid = StringUtils.substringAfter(contentArr[1].trim(), EQUAL_SIGN);
        if (uuid == null || EMPTY.equals(uuid)) {
            stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT);
        } else {
            stringBuffer.append(StringsUtils.getEncodeingStr(uuid)).append(SPLIT);
        }

        //7.programId id
        programId = StringUtils.substringAfter(contentArr[2].trim(), EQUAL_SIGN);
        if (!programId.matches("\\d+")) { //id????
            return;
        } else {
            stringBuffer.append(StringsUtils.getEncodeingStr(programId)).append(SPLIT);
        }

        //8.EPGCode EPG?,?EPGCode?
        stringBuffer.append(StringsUtils.getEncodeingStr("06")).append(SPLIT);

        //9.DataSource??12
        stringBuffer.append(DATA_SOURCE).append(SPLIT);

        //10.Fsource???????
        stringBuffer.append(F_SOURCE).append(SPLIT);

        //11.resolution ?,?
        stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY));

        System.out.println(stringBuffer.toString());
        cnt++;
    }
    System.out.println(":" + cnt);
}

From source file:com.github.fritaly.svngraph.SvnGraph.java

public static void main(String[] args) throws Exception {
    if (args.length != 2) {
        System.out.println(String.format("%s <input-file> <output-file>", SvnGraph.class.getSimpleName()));
        System.exit(1);//from w  w  w  .j ava2 s.co  m
    }

    final File input = new File(args[0]);

    if (!input.exists()) {
        throw new IllegalArgumentException(
                String.format("The given file '%s' doesn't exist", input.getAbsolutePath()));
    }

    final File output = new File(args[1]);

    final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(input);

    final History history = new History(document);

    final Set<String> rootPaths = history.getRootPaths();

    System.out.println(rootPaths);

    for (String path : rootPaths) {
        System.out.println(path);
        System.out.println(history.getHistory(path).getRevisions());
        System.out.println();
    }

    int count = 0;

    FileWriter fileWriter = null;
    GraphMLWriter graphWriter = null;

    try {
        fileWriter = new FileWriter(output);

        graphWriter = new GraphMLWriter(fileWriter);

        final NodeStyle tagStyle = graphWriter.getNodeStyle();
        tagStyle.setFillColor(Color.WHITE);

        graphWriter.graph();

        // map associating node labels to their corresponding node id in the graph
        final Map<String, String> nodeIdsPerLabel = new TreeMap<>();

        // the node style associated to each branch
        final Map<String, NodeStyle> nodeStyles = new TreeMap<>();

        for (Revision revision : history.getSignificantRevisions()) {
            System.out.println(revision.getNumber() + " - " + revision.getMessage());

            // TODO Render also the deletion of branches
            // there should be only 1 significant update per revision (the one with action ADD)
            for (Update update : revision.getSignificantUpdates()) {
                if (update.isCopy()) {
                    // a merge is also considered a copy
                    final RevisionPath source = update.getCopySource();

                    System.out.println(String.format("  > %s %s from %s@%d", update.getAction(),
                            update.getPath(), source.getPath(), source.getRevision()));

                    final String sourceRoot = Utils.getRootName(source.getPath());

                    if (sourceRoot == null) {
                        // skip the revisions whose associated root is
                        // null (happens whether a branch was created
                        // outside the 'branches' directory for
                        // instance)
                        System.err.println(String.format("Skipped revision %d because of a null root",
                                source.getRevision()));
                        continue;
                    }

                    final String sourceLabel = computeNodeLabel(sourceRoot, source.getRevision());

                    // create a node for the source (path, revision)
                    final String sourceId;

                    if (nodeIdsPerLabel.containsKey(sourceLabel)) {
                        // retrieve the id of the existing node
                        sourceId = nodeIdsPerLabel.get(sourceLabel);
                    } else {
                        // create the new node
                        if (Utils.isTagPath(source.getPath())) {
                            graphWriter.setNodeStyle(tagStyle);
                        } else {
                            if (!nodeStyles.containsKey(sourceRoot)) {
                                final NodeStyle style = new NodeStyle();
                                style.setFillColor(randomColor());

                                nodeStyles.put(sourceRoot, style);
                            }

                            graphWriter.setNodeStyle(nodeStyles.get(sourceRoot));
                        }

                        sourceId = graphWriter.node(sourceLabel);

                        nodeIdsPerLabel.put(sourceLabel, sourceId);
                    }

                    // and another for the newly created directory
                    final String targetRoot = Utils.getRootName(update.getPath());

                    if (targetRoot == null) {
                        System.err.println(String.format("Skipped revision %d because of a null root",
                                revision.getNumber()));
                        continue;
                    }

                    final String targetLabel = computeNodeLabel(targetRoot, revision.getNumber());

                    if (Utils.isTagPath(update.getPath())) {
                        graphWriter.setNodeStyle(tagStyle);
                    } else {
                        if (!nodeStyles.containsKey(targetRoot)) {
                            final NodeStyle style = new NodeStyle();
                            style.setFillColor(randomColor());

                            nodeStyles.put(targetRoot, style);
                        }

                        graphWriter.setNodeStyle(nodeStyles.get(targetRoot));
                    }

                    final String targetId;

                    if (nodeIdsPerLabel.containsKey(targetLabel)) {
                        // retrieve the id of the existing node
                        targetId = nodeIdsPerLabel.get(targetLabel);
                    } else {
                        // create the new node
                        if (Utils.isTagPath(update.getPath())) {
                            graphWriter.setNodeStyle(tagStyle);
                        } else {
                            if (!nodeStyles.containsKey(targetRoot)) {
                                final NodeStyle style = new NodeStyle();
                                style.setFillColor(randomColor());

                                nodeStyles.put(targetRoot, style);
                            }

                            graphWriter.setNodeStyle(nodeStyles.get(targetRoot));
                        }

                        targetId = graphWriter.node(targetLabel);

                        nodeIdsPerLabel.put(targetLabel, targetId);
                    }

                    // create an edge between the 2 nodes
                    graphWriter.edge(sourceId, targetId);
                } else {
                    System.out.println(String.format("  > %s %s", update.getAction(), update.getPath()));
                }
            }

            System.out.println();

            count++;
        }

        // Dispatch the revisions per corresponding branch
        final Map<String, Set<Long>> revisionsPerBranch = new TreeMap<>();

        for (String nodeLabel : nodeIdsPerLabel.keySet()) {
            if (nodeLabel.contains("@")) {
                final String branchName = StringUtils.substringBefore(nodeLabel, "@");
                final long revision = Long.parseLong(StringUtils.substringAfter(nodeLabel, "@"));

                if (!revisionsPerBranch.containsKey(branchName)) {
                    revisionsPerBranch.put(branchName, new TreeSet<Long>());
                }

                revisionsPerBranch.get(branchName).add(revision);
            } else {
                throw new IllegalStateException(nodeLabel);
            }
        }

        // Recreate the missing edges between revisions from a same branch
        for (String branchName : revisionsPerBranch.keySet()) {
            final List<Long> branchRevisions = new ArrayList<>(revisionsPerBranch.get(branchName));

            for (int i = 0; i < branchRevisions.size() - 1; i++) {
                final String nodeLabel1 = String.format("%s@%d", branchName, branchRevisions.get(i));
                final String nodeLabel2 = String.format("%s@%d", branchName, branchRevisions.get(i + 1));

                graphWriter.edge(nodeIdsPerLabel.get(nodeLabel1), nodeIdsPerLabel.get(nodeLabel2));
            }
        }

        graphWriter.closeGraph();

        System.out.println(String.format("Found %d significant revisions", count));
    } finally {
        if (graphWriter != null) {
            graphWriter.close();
        }
        if (fileWriter != null) {
            fileWriter.close();
        }
    }

    System.out.println("Done");
}

From source file:eu.annocultor.data.destinations.RdfGraphSwapNames.java

private static String generateIdAffix(String datasetId) {
    return StringUtils.substringAfter(datasetId, "_");
}

From source file:com.jsqlboxdemo.dispatcher.Dispatcher.java

public static void dispach(PageContext pageContext) throws Exception {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    String uri = StringUtils.substringBefore(request.getRequestURI(), ".");
    String contextPath = request.getContextPath();

    if (!StringUtils.isEmpty(contextPath))
        uri = StringUtils.substringAfter(uri, contextPath);
    if (StringUtils.isEmpty(uri) || "/".equals(uri))
        uri = "/home";

    String[] paths = StringUtils.split(uri, "/");
    String[] pathParams;/*www.j a  v  a 2  s .  c  o m*/
    String resource = null;
    String operation = null;

    if (paths.length >= 2) {// /team/add/100...
        resource = paths[0];
        operation = paths[1];
        pathParams = new String[paths.length - 2];
        for (int i = 2; i < paths.length; i++)
            pathParams[i - 2] = paths[i];
    } else { // /home_default
        resource = paths[0];
        pathParams = new String[0];
    }

    if (operation == null)
        operation = "default";
    StringBuilder controller = new StringBuilder("com.jsqlboxdemo.controller.").append(resource).append("$")
            .append(resource).append("_").append(operation);
    if ("POST".equals(request.getMethod()))
        controller.append("_post");

    WebBox box;
    try {
        Class boxClass = Class.forName(controller.toString());
        box = BeanBox.getPrototypeBean(boxClass);
    } catch (Exception e) {
        throw new ClassNotFoundException("There is no WebBox classs '" + controller + "' found.");
    }
    request.setAttribute("pathParams", pathParams);
    box.show(pageContext);
}

From source file:adalid.util.velocity.Matchmaker.java

private static void match(String path1, String path2) {
    MetaFolderSql meta1 = new MetaFolderSql(path1);
    MetaFolderSql meta2 = new MetaFolderSql(path2);
    boolean read1 = meta1.read();
    boolean read2 = meta2.read();
    if (read1 && read2) {
        String key1;/*from   w  w  w .jav a  2 s. c o  m*/
        String sep1 = meta1.getMetaFolderPath().toString() + separator;
        logger.info("folder = " + sep1);
        for (Path path : meta1.getFiles().keySet()) {
            key1 = StringUtils.substringAfter(path.toString(), sep1);
            keys1.add(key1);
        }
        String key2;
        String sep2 = meta2.getMetaFolderPath().toString() + separator;
        logger.info("folder = " + sep2);
        for (Path path : meta2.getFiles().keySet()) {
            key2 = StringUtils.substringAfter(path.toString(), sep2);
            if (keys1.contains(key2)) {
                logger.info("file = " + key2);
            }
        }
    }
}

From source file:doc.action.SelectedDocsUtils.java

public static Collection saveSelectedDocsIDs(HttpServletRequest request) {
    //System.out.println("start");
    Collection documents = (Collection) request.getSession().getAttribute(Constant.SELECTED_PRESIDENTS);
    //System.out.println(documents);
    if (documents == null) {
        documents = new ArrayList();
        request.getSession().setAttribute(Constant.SELECTED_PRESIDENTS, documents);
    }//from w  w  w  . j a  va 2 s .c  o m

    Enumeration parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String parameterName = (String) parameterNames.nextElement();
        if (parameterName.startsWith("chkbx_")) {
            String docId = StringUtils.substringAfter(parameterName, "chkbx_");
            String parameterValue = request.getParameter(parameterName);
            if (parameterValue.equals(Constant.SELECTED)) {
                if (!documents.contains(docId)) {
                    documents.add(docId);
                }
            } else {
                documents.remove(docId);
            }
        }
    }

    return documents;
}

From source file:com.edm.app.auth.Auth.java

public static void robot(String robotPath) {
    BufferedReader reader = null;
    try {//  www. j a  v  a  2  s . c o m
        reader = new BufferedReader(new InputStreamReader(new FileInputStream(robotPath), "UTF-8"));
        String line = null;

        while ((line = reader.readLine()) != null) {
            if (StringUtils.isBlank(line)) {
                continue;
            }
            String key = StringUtils.substringBefore(line, "=");
            String val = StringUtils.substringAfter(line, "=");
            boolean r = StringUtils.equals(md5.encode(StringUtils.upperCase(key)),
                    "cebb21b542877339c40e7e8ecc96796e");
            if (StringUtils.isNotBlank(key) && r) {
                if (StringUtils.isNotBlank(val)) {
                    ROBOT = StringUtils.lowerCase(val);
                    break;
                }
            }
        }
    } catch (Exception e) {
        logger.error("(Auth:robot) error: ", e);
    } finally {
        try {
            if (reader != null) {
                reader.close();
            }
        } catch (IOException e) {
        }
    }
}

From source file:com.enonic.cms.core.search.AbstractElasticsearchSettingsBuilder.java

String subtractPrefixFromProperty(final String property, final String propertyPrefix) {
    return StringUtils.substringAfter(property, propertyPrefix + ".");
}