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:fathom.test.XmlRpcIntegrationTest.java

protected <X> X call(String username, String password, String path, String methodName, Object... args) {
    try {//from   w w w .  j  av a 2 s .c om
        URL url = new URL(getTestBoot().getSettings().getFathomUrl() + StringUtils.removeStart(path, "/"));
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setBasicUserName(username);
        config.setBasicPassword(password);
        config.setServerURL(url);
        XmlRpcClient xmlrpc = new XmlRpcClient();
        xmlrpc.setConfig(config);
        Object x = xmlrpc.execute(methodName, args);
        return (X) x;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.u2apple.rt.util.AndroidDeviceUtils.java

public static String getProductName(String brand, String model) {
    if (StringUtils.isNotBlank(brand) && StringUtils.isNotBlank(model)) {
        String productName;//w  w w  .j av  a 2  s.  c  om
        if (StringUtils.containsIgnoreCase(model, brand)) {
            int index = model.toLowerCase().indexOf(brand.toLowerCase());
            productName = model.substring(index + brand.length());
        } else {
            productName = model;
        }
        //Remove prefix -.
        productName = StringUtils.removeStart(productName, "-");
        productName = StringUtils.removeStart(productName, "_");
        return productName.replace("_", "-").trim();
    } else {
        return null;
    }
}

From source file:de.micromata.tpsb.doc.parser.japa.handler.AddCommentMethodCallHandler.java

@Override
public void handle(MethodCallExpr node, ParserContext ctx) {
    List<Expression> methodArgs = node.getArgs();
    if (methodArgs == null || methodArgs.size() != 1) {
        return;//w ww  .j  av a2 s.  co  m
    }
    String comment = methodArgs.iterator().next().toString();
    if (StringUtils.isBlank(comment) == true) {
        return;
    }

    if (comment.startsWith(QUOTE) == true) {
        comment = StringUtils.removeStart(comment, QUOTE);
    }

    if (comment.endsWith(QUOTE) == true) {
        comment = StringUtils.removeEnd(comment, QUOTE);
    }

    ctx.setCurrentInlineComment(comment);
}

From source file:hoot.services.utils.PostgresUtils.java

static Map<String, String> parseTags(String tagsStr) {
    Map<String, String> tagsMap = new HashMap<>();

    if ((tagsStr != null) && (!tagsStr.isEmpty())) {
        Pattern regex = Pattern.compile("(\"[^\"]*\")=>(\"(?:\\\\.|[^\"\\\\]+)*\"|[^,\"]*)");
        Matcher regexMatcher = regex.matcher(tagsStr);
        while (regexMatcher.find()) {
            String key = regexMatcher.group(1);
            key = StringUtils.removeStart(key, "\"");
            key = StringUtils.removeEnd(key, "\"");
            String val = regexMatcher.group(2);
            val = StringUtils.removeStart(val, "\"");
            val = StringUtils.removeEnd(val, "\"");
            tagsMap.put(key, val);
        }//from   w  w  w  . j a  v a 2 s . c  o m
    }

    return tagsMap;
}

From source file:annis.gui.requesthandler.ResourceRequestHandler.java

@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
        throws IOException {
    if (request.getPathInfo() != null && request.getPathInfo().startsWith("/vis-iframe-res/")) {
        String uuidString = StringUtils.removeStart(request.getPathInfo(), "/vis-iframe-res/");
        UUID uuid = UUID.fromString(uuidString);
        IFrameResourceMap map = VaadinSession.getCurrent().getAttribute(IFrameResourceMap.class);
        if (map == null) {
            response.setStatus(404);//from  www.  ja  v  a 2  s .  co  m
        } else {
            IFrameResource res = map.get(uuid);
            if (res != null) {
                response.setStatus(200);
                response.setContentType(res.getMimeType());
                response.getOutputStream().write(res.getData());
            }
        }
        return true;
    }
    return false;
}

From source file:ch.cyberduck.core.ftp.LoggingProtocolCommandListener.java

@Override
public void protocolCommandSent(final ProtocolCommandEvent event) {
    final String message = StringUtils.chomp(event.getMessage());
    if (message.startsWith(FTPCmd.PASS.name())) {
        this.log(Type.request, String.format("%s %s", FTPCmd.PASS.name(), StringUtils.repeat("*",
                StringUtils.length(StringUtils.removeStart(message, FTPCmd.PASS.name())))));
    } else {//  www.  j  av a 2  s  .c o m
        this.log(Type.request, message);
    }
}

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

@Override
public URL getResource(String resourceName) throws MalformedURLException {
    return getClass().getClassLoader().getResource(StringUtils.removeStart(resourceName, "/"));
}

From source file:hoot.services.db.postgres.PostgresUtils.java

/**
 * Converts an hstore Postgres object to a string map
 * /*ww w. ja  v  a  2s  .c  om*/
 * @param postgresObj a Postgres object containing an hstore
 * @return a string map with the hstore's data
 * @throws Exception
 */
public static Map<String, String> postgresObjToHStore(final PGobject postgresObj) throws Exception {
    //type = hstore
    //value = "key 1"=>"val 1", "key 2"=>"val 2"

    //TODO: don't understand why this string doesn't match up
    //System.out.println(postgresObj.getType());
    //if (postgresObj.getType().equals("hstore"))
    //{
    //throw new Exception("Invalid PGobject type.  Expected: hstore");
    //}

    Map<String, String> hstore = new HashMap<String, String>();
    if (postgresObj != null && postgresObj.getValue() != null
            && StringUtils.trimToNull(postgresObj.getValue()) != null) {
        String[] vals = postgresObj.getValue().split(",");
        for (int i = 0; i < vals.length; i++) {
            String[] pair = vals[i].split("=>");
            if (pair.length == 2) {
                //remove the quotes at the very beginning and end of the string
                String key = pair[0].trim();
                key = StringUtils.removeStart(key, "\"");
                key = StringUtils.removeEnd(key, "\"");
                String val = pair[1].trim();
                val = StringUtils.removeStart(val, "\"");
                val = StringUtils.removeEnd(val, "\"");
                hstore.put(key, val);
            }
        }
    }
    return hstore;
}

From source file:io.apiman.gateway.vertx.http.HttpServiceFactory.java

public static ServiceRequest build(HttpServerRequest req, String stripFromStart) {
    ServiceRequest apimanRequest = new ServiceRequest();
    apimanRequest.setApiKey(parseApiKey(req));
    parseHeaders(apimanRequest.getHeaders(), req.headers(), Collections.<String>emptySet());

    // Remove the gateway's URI from the start of the path if it's there.
    apimanRequest.setDestination(StringUtils.removeStart(req.path(), "/" + stripFromStart)); //$NON-NLS-1$
    apimanRequest.setRemoteAddr(req.remoteAddress().getAddress().getHostAddress());
    apimanRequest.setType(req.method());

    return apimanRequest;
}

From source file:com.thinkbiganalytics.security.core.encrypt.EncryptionService.java

public String decrypt(String str) {
    if (StringUtils.isNotBlank(str)) {
        if (StringUtils.startsWith(str, CIPHER_PREFIX)) {
            str = StringUtils.removeStart(str, CIPHER_PREFIX);
        }//  w w  w .ja va 2s  . c  o m
        return encryptor.decrypt(str);
    } else {
        return str;
    }
}