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:org.sonar.server.platform.ServerIdChecksum.java

/**
 * Deal with this strange URL format://w  w  w  . j  a v a 2 s . c  om
 * https://docs.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url
 * https://docs.microsoft.com/en-us/sql/connect/jdbc/setting-the-connection-properties
 */
private static String sanitizeSqlServerUrl(String jdbcUrl) {
    StringBuilder result = new StringBuilder();
    result.append(SQLSERVER_PREFIX);

    String host;
    if (jdbcUrl.contains(";")) {
        host = StringUtils.substringBetween(jdbcUrl, SQLSERVER_PREFIX, ";");
    } else {
        host = StringUtils.substringAfter(jdbcUrl, SQLSERVER_PREFIX);
    }

    String queryString = StringUtils.substringAfter(jdbcUrl, ";");
    Map<String, String> parameters = KeyValueFormat.parse(queryString);
    Optional<String> server = firstValue(parameters, "serverName", "servername", "server");
    if (server.isPresent()) {
        result.append(server.get());
    } else {
        result.append(StringUtils.substringBefore(host, ":"));
    }

    Optional<String> port = firstValue(parameters, "portNumber", "port");
    if (port.isPresent()) {
        result.append(':').append(port.get());
    } else if (host.contains(":")) {
        result.append(':').append(StringUtils.substringAfter(host, ":"));
    }

    Optional<String> database = firstValue(parameters, "databaseName", "database");
    database.ifPresent(s -> result.append('/').append(s));
    return result.toString();
}

From source file:org.sonar.server.startup.GwtPublisher.java

protected void publish() throws IOException, URISyntaxException {
    for (final GwtExtension module : extensions) {
        URL sourceDir = module.getClass().getResource("/" + module.getGwtId() + "/");
        if (sourceDir == null) {
            throw new SonarException("Can not find the directory " + module.getGwtId()
                    + " defined by the GWT module " + module.getClass().getName());
        }//from   w ww . j a  v a 2 s .  c  om
        Logs.INFO.info("Deploy {} to {}", module.getGwtId(), outputDir);
        if (sourceDir.toString().startsWith("jar:file")) {
            // unzip the JAR
            String path = StringUtils.substringBetween(sourceDir.toString(), "jar:file:", "!");
            File gwtJar = new File(getCleanPath(path));
            ZipUtils.unzip(gwtJar, outputDir, new ZipUtils.ZipEntryFilter() {
                public boolean accept(ZipEntry entry) {
                    return entry.getName().startsWith(module.getGwtId());
                }
            });
        } else {
            // just copy the files
            File source = new File(sourceDir.toURI());
            FileUtils.copyDirectory(source, new File(outputDir, module.getGwtId()));
        }
    }
}

From source file:org.sonarqube.cppcheck.CppcheckRuleRepositoryTest.java

private static List<String> listVersions() {
    Collection<File> files = FileUtils.listFiles(new File("src/main/files"), new String[] { "xml" }, false);
    List<String> names = Lists.newArrayList();
    for (File file : files) {
        names.add(StringUtils.substringBetween(file.getName(), "cppcheck-", ".xml"));
    }//from w  ww  .j  av a2  s  .c  o  m
    Collections.sort(names);
    return names;
}

From source file:org.sonarsource.scanner.maven.bootstrap.MavenPlugin.java

private static int getIndex(String key) {
    // parsing index-syntax (e.g. item[1])
    if (key.matches(".*?\\[\\d+\\]")) {
        return Integer.parseInt(StringUtils.substringBetween(key, "[", "]"));
    }/*  w w w.j  a  va2 s.c o  m*/
    // for down-compatibility of api we fallback to default 0
    return 0;
}

From source file:org.sonarsource.sonarqube.upgrade.MssqlConfig.java

/**
 * Versions prior to 5.2 support only jTDS driver. Versions greater than or equal to 5.2
 * support only MS driver. The problem is that the test is configured with only
 * the MS URL, so it must be changed at runtime for versions < 5.2.
 *//*from   w  w  w .j  a v  a2  s  .com*/
public static String fixUrl(Configuration conf, Version sqVersion) {
    String jdbcUrl = requireNonNull(conf.getString("sonar.jdbc.url"), "No JDBC url configured");
    if (jdbcUrl.startsWith("jdbc:sqlserver:") && !sqVersion.isGreaterThanOrEquals("5.2")) {
        // Job is configured with the new Microsoft driver, which is not supported by old versions of SQ
        String host = StringUtils.substringBetween(jdbcUrl, "jdbc:sqlserver://", ";databaseName=");
        String db = StringUtils.substringAfter(jdbcUrl, "databaseName=");
        jdbcUrl = "jdbc:jtds:sqlserver://" + host + "/" + db;
        System.out.println("Replaced JDBC url to: " + jdbcUrl);
        return jdbcUrl;
    }
    return jdbcUrl;
}

From source file:org.tsm.concharto.web.eventsearch.SearchHelper.java

/**
 * TODO - There is a wierd bug with Get string character encoding that results in improper
 * decoding of the query string - when you call request.getCharacterEncoding() it returns UTF-8,
 * but the parameter is not decoded as UTF-8.  So we have to do it by hand here.
 *  //from  w w w.  jav a2s.com
 * @param request
 * @param paramName
 */
private String getUtf8QueryStringParameter(HttpServletRequest request, String paramName) {
    String queryString = request.getQueryString();
    String before = paramName + "=";
    String tag = StringUtils.substringBetween(queryString, before, "&");
    if (tag == null) {
        tag = StringUtils.substringAfter(queryString, before);
    }
    try {
        tag = URLDecoder.decode(tag, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        log.error("Couldn't decode query paramter " + tag, e);
    }
    return tag;
}

From source file:org.tsm.concharto.web.filter.LoginFilter.java

/**
 * Returns the first part of the URL path: "/member/settings.htm?id=1234" returns "member"
 * @param httpRequest/*from   w  w  w  . j a  v  a 2  s . c  om*/
 * @return first part of the URL path
 */
private String[] getUrlParts(HttpServletRequest httpRequest) {
    String uri = httpRequest.getRequestURI();
    //should like like '/admin/canDelete' or '/admin/findUsers'
    String path = StringUtils.substringBetween(uri, httpRequest.getContextPath(), ".htm");
    String[] parts = StringUtils.split(path, '/');
    return parts;
}

From source file:org.tsm.concharto.web.filter.ResponseHeaderFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    // set the provided HTTP response parameters
    for (Enumeration<?> e = fc.getInitParameterNames(); e.hasMoreElements();) {
        String headerName = (String) e.nextElement();
        String value = fc.getInitParameter(headerName);
        response.addHeader(headerName, value);
        //special case for Cache-Control
        if (HEADER_CACHE_CONTROL.equals(headerName)) {
            String maxAgeStr = StringUtils.substringBetween(value, "=", ",");
            addExpiresHeader(response, maxAgeStr);
        }/*w  w w .ja  va 2  s  .  co  m*/
    }
    // pass the request/response on
    chain.doFilter(req, response);
}

From source file:org.viafirma.nucleo.validacion.OcspValidatorHandler.java

/**
 * Retorna el CN de un certificado.//from  ww  w  . ja  v  a  2 s  .c o  m
 * 
 * @param certificadoResponseOCSP
 * @return
 */
private String getCN(X509Certificate certificadoResponseOCSP) {
    // ej: C=ES,O=DIRECCION GENERAL DE LA POLICIA,OU=DNIE,OU=FNMT,CN=AV DNIE
    // FNMT
    // cn:AV DNIE FNMT
    String cn = StringUtils.substringBetween(certificadoResponseOCSP.getSubjectDN().getName(), "CN=", ",");
    if (cn == null) {
        // Puede que este al final de Subcjet
        cn = StringUtils.substringAfterLast(certificadoResponseOCSP.getSubjectDN().getName(), "CN=");
    }
    return cn;
}

From source file:org.webguitoolkit.ui.util.export.ExcelTableExport.java

protected void writeStringCell(HSSFCell cell, IConverter converter, Object obj, IDataBag dbag) {
    // most are string catch them first to save instance checks
    // remove html linebreaks from tabledate
    String tableData = obj.toString();
    if (converter != null) {
        tableData = (String) converter.convert(String.class, obj);
    }//from  w w  w.  ja  v  a  2 s.c o  m

    // replace html-line-breaks
    if (tableData.contains("<br/>") || tableData.contains("<br>")) {
        tableData = tableData.replaceAll("<br\\/>", " ");
        tableData = tableData.replaceAll("<br>", " ");
    }

    // replace html-blanks
    tableData = StringUtils.replace(tableData, "&nbsp;", " ");

    // image filter - image tags will be deleted
    String imgOpenTag = "<img";
    String imgCloseTag = ">";
    while (StringUtils.contains(tableData, imgOpenTag) && StringUtils.contains(tableData, imgCloseTag)) {
        tableData = StringUtils.remove(tableData,
                imgOpenTag + StringUtils.substringBetween(tableData, imgOpenTag, imgCloseTag) + imgCloseTag);

    }

    cell.setCellValue(new HSSFRichTextString(tableData));
    if (getExcelContentstyle() != null) {
        cell.setCellStyle(getExcelContentstyle());
    }
}