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

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

Introduction

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

Prototype

public static String substringAfter(final String str, final String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:cgeo.geocaching.connector.ec.ECConnector.java

@Override
@Nullable//from ww  w .j a  v  a2s.  c om
public String getGeocodeFromUrl(@NonNull final String url) {
    final String geocode = "EC" + StringUtils.substringAfter(url, "extremcaching.com/index.php/output-2/");
    if (canHandle(geocode)) {
        return geocode;
    }
    return super.getGeocodeFromUrl(url);
}

From source file:com.yiji.openapi.sdk.util.Servlets.java

/**
 * ?URL/*w ww  . ja va 2s  .c o  m*/
 * 
 * @param request
 * @return
 */
public static String getRequestPath(HttpServletRequest request) {
    return StringUtils.substringAfter(request.getRequestURI(), request.getContextPath());
}

From source file:com.eryansky.common.orm.hibernate.HibernateDao.java

private String prepareCountHql(String orgHql) {
    String fromHql = orgHql;//w  ww  .ja  v  a  2s  .c o m
    // select??order by???count,?.
    fromHql = "from " + StringUtils.substringAfter(fromHql, "from");
    fromHql = StringUtils.substringBefore(fromHql, "order by");

    String countHql = "select count(*) " + fromHql;
    return countHql;
}

From source file:com.project.framework.dao.BaseDao.java

/**
 * count./* w w w . ja  v a 2s . c om*/
 * 
 * ????,???count?.
 */
public long countResult(final String queryString, final Object... values) {
    String fromHql = queryString;
    //select??order by???count,?.
    fromHql = "from " + StringUtils.substringAfter(fromHql, "from");
    fromHql = StringUtils.substringBefore(fromHql, "order by");

    String countHql = "select count(*) " + fromHql;

    try {
        Long count = executeUniqueQuery(countHql, values);
        return count;
    } catch (Exception e) {
        throw new RuntimeException("queryString can't be auto count, queryString is:" + countHql, e);
    }
}

From source file:com.neatresults.mgnltweaks.neatu2b.ui.action.AddU2BMetadataSaveDialogAction.java

public String getVideoId() {
    String fieldName = getDefinition().getIdFieldName();
    Property prop = item.getItemProperty(fieldName);
    if (prop == null) {
        throw new NullPointerException(fieldName
                + " is not set or name of the required field for this dialog is not correctly configured.");
    }//from  ww  w .  j  a va2 s .c  o m
    String maybeId = (String) prop.getValue();
    if (maybeId == null) {
        return null;
    }
    if (maybeId.startsWith("http")) {
        maybeId = StringUtils.substringBefore(StringUtils.substringAfter(maybeId, "?v="), "&");
    }
    return maybeId;
}

From source file:bear.core.BearMain.java

/**
 * -VbearMain.appConfigDir=src/main/groovy/examples -VbearMain.buildDir=.bear/classes -VbearMain.script=dumpSampleGrid -VbearMain.projectClass=SecureSocialDemoProject -VbearMain.propertiesFile=.bear/test.properties
 */// ww w.ja va 2  s.co  m
public static void main(String[] args) throws Exception {
    int i = ArrayUtils.indexOf(args, "--log-level");

    if (i != -1) {
        LoggingBooter.changeLogLevel(LogManager.ROOT_LOGGER_NAME, Level.toLevel(args[i + 1]));
    }

    i = ArrayUtils.indexOf(args, "-q");

    if (i != -1) {
        LoggingBooter.changeLogLevel(LogManager.ROOT_LOGGER_NAME, Level.WARN);
    }

    GlobalContext global = GlobalContext.getInstance();

    BearMain bearMain = null;

    try {
        bearMain = new BearMain(global, getCompilerManager(), args);
    } catch (Exception e) {
        if (e.getClass().getSimpleName().equals("MissingRequiredOptionException")) {
            System.out.println(e.getMessage());
        } else {
            Throwables.getRootCause(e).printStackTrace();
        }

        System.exit(-1);
    }

    if (bearMain.checkHelpAndVersion()) {
        return;
    }

    AppOptions2 options2 = bearMain.options;

    if (options2.has(AppOptions2.UNPACK_DEMOS)) {
        String filesAsText = ProjectGenerator.readResource("/demoFiles.txt");

        int count = 0;

        for (String resource : filesAsText.split("::")) {
            File dest = new File(BEAR_DIR + resource);
            System.out.printf("copying %s to %s...%n", resource, dest);

            writeStringToFile(dest, ProjectGenerator.readResource(resource));

            count++;
        }

        System.out.printf("extracted %d files%n", count);

        return;
    }

    if (options2.has(AppOptions2.CREATE_NEW)) {
        String dashedTitle = options2.get(AppOptions2.CREATE_NEW);

        String user = options2.get(AppOptions2.USER);
        String pass = options2.get(AppOptions2.PASSWORD);

        List<String> hosts = options2.getList(AppOptions2.HOSTS);

        List<String> template;

        if (options2.has(AppOptions2.TEMPLATE)) {
            template = options2.getList(AppOptions2.TEMPLATE);
        } else {
            template = emptyList();
        }

        ProjectGenerator g = new ProjectGenerator(dashedTitle, user, pass, hosts, template);

        if (options2.has(AppOptions2.ORACLE_USER)) {
            g.oracleUser = options2.get(AppOptions2.ORACLE_USER);
        }

        if (options2.has(AppOptions2.ORACLE_PASSWORD)) {
            g.oraclePassword = options2.get(AppOptions2.ORACLE_PASSWORD);
        }

        File projectFile = new File(BEAR_DIR, g.getProjectTitle() + ".groovy");
        File pomFile = new File(BEAR_DIR, "pom.xml");

        writeStringToFile(projectFile, g.processTemplate("TemplateProject.template"));

        writeStringToFile(new File(BEAR_DIR, dashedTitle + ".properties"),
                g.processTemplate("project-properties.template"));
        writeStringToFile(new File(BEAR_DIR, "demos.properties"),
                g.processTemplate("project-properties.template"));
        writeStringToFile(new File(BEAR_DIR, "bear-fx.properties"),
                g.processTemplate("bear-fx.properties.template"));

        writeStringToFile(pomFile, g.generatePom(dashedTitle));

        System.out.printf("Created project file: %s%n", projectFile.getPath());
        System.out.printf("Created maven pom: %s%n", pomFile.getPath());

        System.out.println("\nProject files have been created. You may now: " + "\n a) Run `bear "
                + g.getShortName() + ".ls` to quick-test your minimal setup"
                + "\n b) Import the project to IDE or run smoke tests, find more details at the project wiki: https://github.com/chaschev/bear/wiki/.");

        return;
    }

    Bear bear = global.bear;

    if (options2.has(AppOptions2.QUIET)) {
        global.put(bear.quiet, true);
        LoggingBooter.changeLogLevel(LogManager.ROOT_LOGGER_NAME, Level.WARN);
    }

    if (options2.has(AppOptions2.USE_UI)) {
        global.put(bear.useUI, true);
    }

    if (options2.has(AppOptions2.NO_UI)) {
        global.put(bear.useUI, false);
    }

    List<?> list = options2.getOptionSet().nonOptionArguments();

    if (list.size() > 1) {
        throw new IllegalArgumentException("too many arguments: " + list + ", "
                + "please specify an invoke line, project.method(arg1, arg2)");
    }

    if (list.isEmpty()) {
        throw new UnsupportedOperationException("todo implement running a single project");
    }

    String invokeLine = (String) list.get(0);

    String projectName;
    String method;

    if (invokeLine.contains(".")) {
        projectName = StringUtils.substringBefore(invokeLine, ".");
        method = StringUtils.substringAfter(invokeLine, ".");
    } else {
        projectName = invokeLine;
        method = null;
    }

    if (method == null || method.isEmpty())
        method = "deploy()";
    if (!method.contains("("))
        method += "()";

    Optional<CompiledEntry<? extends BearProject>> optional = bearMain.compileManager.findProject(projectName);

    if (!optional.isPresent()) {
        throw new IllegalArgumentException("project was not found: " + projectName + ", loaded classes: \n"
                + Joiner.on("\n").join(bearMain.compileManager.findProjects()) + ", searched in: "
                + bearMain.compileManager.getSourceDirs() + ", ");
    }

    BearProject project = OpenBean.newInstance(optional.get().aClass).injectMain(bearMain);

    GroovyShell shell = new GroovyShell();

    shell.setVariable("project", project);
    shell.evaluate("project." + method);
}

From source file:io.wcm.handler.url.suffix.impl.UrlSuffixUtil.java

/**
 * @param resource the resource being addressed by the relative path
 * @param baseResource the resource used as base to resolve the relative path
 * @return the relative path (without leading slash)
 *///from www. j a  v  a2  s .  c o m
public static String getRelativePath(Resource resource, Resource baseResource) {
    if (baseResource == null) {
        throw new IllegalArgumentException("the base resource for constructing relative path must not be null");
    }
    if (resource == null) {
        throw new IllegalArgumentException("the resource for constructing relative path must not be null");
    }
    String absolutePath = resource.getPath();
    String basePath = baseResource.getPath();

    if (absolutePath.equals(basePath)) {
        // relative path for the root resource is "."
        return ".";
    }

    // be picky about resources not located beneath the base resource
    if (!absolutePath.startsWith(basePath + "/")) {
        throw new IllegalArgumentException(
                "the resource " + resource + " is not a descendent of the base resource " + baseResource);
    }

    // return relative path
    return StringUtils.substringAfter(absolutePath, basePath + "/");
}

From source file:io.wcm.maven.plugins.i18n.TransformMojo.java

/**
 * Get the JSON file for source file./*  w  w  w  . j av  a 2s .  co  m*/
 * @param sourceFile the source file
 * @param selectedOutputFormat Output format
 * @return File with name and path based on file parameter
 * @throws IOException
 */
private File getTargetFile(File sourceFile, OutputFormat selectedOutputFormat) throws IOException {

    File sourceDirectory = getSourceDirectory();
    String relativePath = StringUtils.substringAfter(sourceFile.getAbsolutePath(),
            sourceDirectory.getAbsolutePath());
    String relativeTargetPath = FileUtils.removeExtension(relativePath) + "."
            + selectedOutputFormat.getFileExtension();

    File jsonFile = new File(getGeneratedResourcesFolder().getPath() + relativeTargetPath);

    jsonFile = jsonFile.getCanonicalFile();

    File parentDirectory = jsonFile.getParentFile();
    if (!parentDirectory.exists()) {
        parentDirectory.mkdirs();
    }

    return jsonFile;
}

From source file:com.shallop.codedrill.common.persistence.hibernate.HibernateDao.java

private String prepareCountHql(String orgHql) {
    String fromHql = orgHql;/*from  ww  w .j a v a 2 s .c o m*/
    //select??order by???count,?.
    fromHql = "from " + StringUtils.substringAfter(fromHql, "from");
    fromHql = StringUtils.substringBefore(fromHql, "order by");

    String countHql = "select count(*) " + fromHql;
    return countHql;
}

From source file:eu.openanalytics.rsb.Util.java

/**
 * Extracts an UriBuilder for the current request, taking into account the possibility of
 * header-based URI override.//from  ww w  . j  a v  a2 s .  co  m
 * 
 * @param uriInfo
 * @param httpHeaders
 * @return
 * @throws URISyntaxException
 */
public static UriBuilder getUriBuilder(final UriInfo uriInfo, final HttpHeaders httpHeaders)
        throws URISyntaxException {
    final UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();

    final List<String> hosts = httpHeaders.getRequestHeader(HttpHeaders.HOST);
    if ((hosts != null) && (!hosts.isEmpty())) {
        final String host = hosts.get(0);
        uriBuilder.host(StringUtils.substringBefore(host, ":"));

        final String port = StringUtils.substringAfter(host, ":");
        if (StringUtils.isNotBlank(port)) {
            uriBuilder.port(Integer.valueOf(port));
        }
    }

    final String protocol = getSingleHeader(httpHeaders, Constants.FORWARDED_PROTOCOL_HTTP_HEADER);
    if (StringUtils.isNotBlank(protocol)) {
        uriBuilder.scheme(protocol);
    }

    return uriBuilder;
}