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

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

Introduction

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

Prototype

public static String removeStart(final String str, final String remove) 

Source Link

Document

Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.

A null source string will return null .

Usage

From source file:blue.lapis.pore.converter.type.TypeConverterTest.java

@Parameterized.Parameters(name = "{0}")
public static Set<String> getConverters() throws Exception {
    ImmutableSet.Builder<String> converters = ImmutableSet.builder();
    for (ClassPath.ClassInfo converter : PoreTests.getClassPath()
            .getTopLevelClassesRecursive(CONVERTER_PACKAGE)) {
        converters.add(StringUtils.removeStart(converter.getName(), CONVERTER_PREFIX));
    }//from ww  w  .j av  a  2s. c om
    return converters.build();
}

From source file:com.cognifide.qa.bb.provider.selenium.DesiredCapabilitiesProvider.java

/**
 * Returns new default DesiredCapabilities object.
 *//*  w  ww. java 2s. c om*/
@Override
public Capabilities get() {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    Map<String, String> mapProperties = new HashMap<>();

    for (String name : properties.stringPropertyNames()) {
        if (name.startsWith(CAPABILITIES_PREFIX)) {
            String capName = StringUtils.removeStart(name, CAPABILITIES_PREFIX);
            capabilities.setCapability(capName, properties.getProperty(name));
        } else if (name.startsWith(CAPABILITIES_MAP_PREFIX)) {
            mapProperties.put(StringUtils.removeStart(name, CAPABILITIES_MAP_PREFIX),
                    properties.getProperty(name));
        }
    }
    processMapProperties(capabilities, mapProperties);
    return capabilities;
}

From source file:io.ecarf.core.term.TermRoot.java

/**
 * Break down and add a term to this TermRoot
 * <http://dblp.uni-trier.de/rec/bibtex/books/mk/WidomC96>
 * @param term//w w w  .jav  a2  s  . c om
 */
public void addTerm(String term) {

    if (!SchemaURIType.RDF_OWL_TERMS.contains(term)) {

        String url = term.substring(1, term.length() - 1);
        String path = StringUtils.removeStart(url, TermUtils.HTTP);

        if (path.length() == url.length()) {
            path = StringUtils.removeStart(path, TermUtils.HTTPS);
        }

        //String [] parts = StringUtils.split(path, URI_SEP);
        // this is alot faster than String.split or StringUtils.split
        List<String> parts = Utils.split(path, TermUtils.URI_SEP);

        // invalid URIs, e.g. <http:///www.taotraveller.com> is parsed by NxParser as http:///
        if (!parts.isEmpty()) {

            String domain = parts.remove(0);

            if (!(TermUtils.equals(domain, SchemaURIType.W3_DOMAIN)
                    && term.contains(SchemaURIType.LIST_EXPANSION_URI))) {
                TermPart termPart = this.terms.get(domain);

                if (termPart == null) {
                    termPart = new TermPart(domain);
                    this.terms.put(domain, termPart);
                }

                // do we have children
                if (parts.size() > 1) {
                    termPart.addChildren(parts);
                }
            } // else RDF list expansion e.g. <http://www.w3.org/1999/02/22-rdf-syntax-ns#_15>
        }

    } // else a schema URI
}

From source file:com.xpn.xwiki.test.TestApplicationContext.java

@Override
public InputStream getResourceAsStream(String resourceName) {
    return getClass().getResourceAsStream(StringUtils.removeStart(resourceName, "/"));
}

From source file:it.f2informatica.webapp.security.BasicAuthorityService.java

private boolean matchRoles(String authorization, String roleAuthority) {
    final String authorizationName = StringUtils.removeStart(roleAuthority, PREFIX_ROLE);
    return StringUtils.containsIgnoreCase(authorization, authorizationName);
}

From source file:blue.lapis.pore.impl.event.PoreEventImplTest.java

@Parameterized.Parameters(name = "{0}")
public static Set<String> getEvents() throws Exception {
    ImmutableSet.Builder<String> events = ImmutableSet.builder();
    for (ClassPath.ClassInfo event : PoreTests.getClassPath().getTopLevelClassesRecursive(PORE_PACKAGE)) {
        String name = event.getName();
        if (!name.endsWith("Test")) {
            events.add(StringUtils.removeStart(event.getName(), PORE_PREFIX));
        }//from w ww  .j ava  2  s  . c  o m
    }
    return events.build();
}

From source file:blue.lapis.pore.converter.wrapper.WrapperConverterTest.java

@Parameterized.Parameters(name = "{0}")
public static Set<Object[]> getObjects() throws Exception {
    ImmutableSet.Builder<Object[]> objects = ImmutableSet.builder();
    ListMultimap<Class<?>, Class<?>> registry = createRegistry();
    for (Class<?> type : registry.keySet()) {
        objects.add(new Object[] { StringUtils.removeStart(type.getName(), IMPL_PREFIX), type,
                registry.get(type) });/*from   w  w  w  . j a  va2  s  .  c  o  m*/
    }
    return objects.build();
}

From source file:com.embedler.moon.jtxt2img.CoreHelper.java

public static Color hex2Rgb(String colorStr) {
    Validate.notBlank(colorStr, "Color string must not be null");
    String _color = StringUtils.rightPad(StringUtils.removeStart(colorStr, "#"), 6,
            colorStr.charAt(colorStr.length() - 1));
    return new Color(Integer.valueOf(_color.substring(0, 2), 16), Integer.valueOf(_color.substring(2, 4), 16),
            Integer.valueOf(_color.substring(4, 6), 16));
}

From source file:com.ctrip.infosec.rule.converter.Ip2ProvinceCityConverter.java

@Override
public void convert(PreActionEnums preAction, Map fieldMapping, RiskFact fact, String resultWrapper,
        boolean isAsync) throws Exception {
    PreActionParam[] fields = preAction.getFields();
    String ipFieldName = (String) fieldMapping.get(fields[0].getParamName());
    String ipFieldValue = valueAsString(fact.eventBody, ipFieldName);

    // prefix default value
    if (Strings.isNullOrEmpty(resultWrapper)) {
        resultWrapper = ipFieldName + "_IpArea";
    }/*from w w  w  .j ava 2s.  com*/
    // 
    if (fact.eventBody.containsKey(resultWrapper)) {
        return;
    }

    // "8.8.8.8:80"
    ipFieldValue = StringUtils.trimToEmpty(ipFieldValue);
    ipFieldValue = StringUtils.removeStart(ipFieldValue, "\"");
    ipFieldValue = StringUtils.removeEnd(ipFieldValue, "\"");
    ipFieldValue = StringUtils.substringBefore(ipFieldValue, ":");

    if (StringUtils.isNotBlank(ipFieldValue) && !"127.0.0.1".equals(ipFieldValue)) {

        // 
        PropertyUtils.setNestedProperty(fact.eventBody, ipFieldName, ipFieldValue);

        Map params = ImmutableMap.of("ip", ipFieldValue);
        Map result = DataProxy.queryForMap(serviceName, operationName, params);
        if (result != null && !result.isEmpty()) {
            fact.eventBody.put(resultWrapper, result);
        } else {
            TraceLogger.traceLog("?. ip=" + ipFieldValue);
        }
    }
}

From source file:controllers.SvnApp.java

@With(BasicAuthAction.class)
@BodyParser.Of(value = BodyParser.Raw.class, maxLength = Integer.MAX_VALUE)
public static Result service() throws ServletException, IOException, InterruptedException {
    String path;//from  w  w  w. j av  a2 s  .c  o m
    try {
        path = new java.net.URI(request().uri()).getPath();
    } catch (URISyntaxException e) {
        return badRequest();
    }

    // Remove contextPath
    path = StringUtils.removeStart(path, play.Configuration.root().getString("application.context"));

    // If the url starts with slash, remove the slash.
    if (path.startsWith("/")) {
        path = path.substring(1);
    }

    // Split the url into three segments: "svn", userName, pathInfo
    String[] segments = path.split("/", 3);
    if (segments.length < 3) {
        return forbidden();
    }

    // Get userName and pathInfo from path segments.
    final String userName = segments[1];
    String pathInfo = segments[2];

    // Get projectName from the pathInfo.
    String projectName = pathInfo.split("/", 2)[0];

    // if user is anon, currentUser is null
    User currentUser = UserApp.currentUser();
    // Check the user has a permission to access this repository.
    Project project = Project.findByOwnerAndProjectName(userName, projectName);

    if (project == null) {
        return notFound();
    }

    if (!project.vcs.equals(RepositoryService.VCS_SUBVERSION)) {
        return notFound();
    }

    PlayRepository repository = RepositoryService.getRepository(project);
    if (!AccessControl.isAllowed(currentUser, repository.asResource(),
            getRequestedOperation(request().method()))) {
        if (currentUser.isAnonymous()) {
            return BasicAuthAction.unauthorized(response());
        } else {
            return forbidden("You have no permission to access this repository.");
        }
    }

    // Start DAV Service
    PlayServletResponse response = startDavService(userName, pathInfo);

    // Wait until the status code is decided by the DAV service.
    // After that, get the status code.
    int status = response.waitAndGetStatus();

    // Send the response.
    UserApp.currentUser().visits(project);
    return sendResponse(request().method(), status, response.getInputStream());
}