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:cc.recommenders.utils.Zips.java

public static String path(ICoReTypeName type, @Nullable String suffix) {
    String name = StringUtils.removeStart(type.getIdentifier(), "L");
    return suffix == null ? name : name + suffix;
}

From source file:com.neatresults.mgnltweaks.ui.field.TemplateIdConverter.java

@Override
public String convertToModel(String path, Class<? extends String> targetType, Locale locale)
        throws ConversionException {
    // Null is required for the property to be removed if path is empty
    String res = null;//from www  .j a v a  2s .c om
    if (StringUtils.isBlank(path)) {
        return res;
    }
    String id = StringUtils.substringBefore(StringUtils.removeStart(path, "/modules/"), "/");
    String template = StringUtils.substringAfter(path, "/templates/");
    res = id + ":" + template;
    return res;
}

From source file:com.roche.iceboar.demo.JnlpServlet.java

/**
 * This method handle all HTTP requests for *.jnlp files (defined in web.xml). Method check, is name correct
 * (allowed), read file from disk, replace #{codebase} (it's necessary to be generated based on where application
 * is deployed), #{host} () and write to the response.
 * <p>//from  w w  w . ja  v a2 s  . c  o  m
 * You can use this class in your code for downloading JNLP files.
 * Return a content of requested jnlp file in response.
 *
 * @throws IOException when can't close some stream
 */
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String contextPath = request.getContextPath();
    String requestURI = request.getRequestURI();
    String host = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
    String codebase = host + contextPath;
    String filename = StringUtils.removeStart(requestURI, contextPath);
    response.setContentType("application/x-java-jnlp-file");
    response.addHeader("Pragma", "no-cache");
    response.addHeader("Expires", "-1");

    OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream());

    InputStream in = JnlpServlet.class.getResourceAsStream(filename);
    if (in == null) {
        error(response, "Can't open: " + filename);
        return;
    }
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    String line = reader.readLine();
    while (line != null) {
        line = line.replace("#{codebase}", codebase);
        line = line.replace("#{host}", host);
        out.write(line);
        out.write("\n");
        line = reader.readLine();
    }

    out.flush();
    out.close();
    reader.close();
}

From source file:glluch.com.ontotaxoseeker.Path.java

/**
 * Creates a friendly representation of the path.
 * @return An string showing the path like a unix file path. For example,
 * /electronic_design_automation_and_methodology/design_methodology/prototypes
 *//*from   ww w . j  a  v  a2  s .  co m*/
public String prettyPrint() {
    String sp = "";
    ArrayList<String> nodes = new ArrayList<>();
    Iterator<Statement> states = this.iterator();
    while (states.hasNext()) {
        Statement st = states.next();
        String uri = st.getSubject().getURI();
        //String node=uri.substring(15);
        String node = StringUtils.removeStart(uri, Config.NS);
        nodes.add(node);
    }

    for (int i = nodes.size() - 1; i > -1; i--) {
        sp += "/" + nodes.get(i);
    }
    return sp;
}

From source file:com.kixeye.chassis.transport.swagger.SwaggerServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    // figure out the real path
    String pathInfo = StringUtils.trimToEmpty(req.getPathInfo());

    while (pathInfo.endsWith("/")) {
        pathInfo = StringUtils.removeEnd(pathInfo, "/");
    }//from w  w w.j a va 2 s  . co  m

    while (pathInfo.startsWith("/")) {
        pathInfo = StringUtils.removeStart(pathInfo, "/");
    }

    if (StringUtils.isBlank(pathInfo)) {
        resp.sendRedirect(rootContextPath + "/" + WELCOME_PAGE);
    } else {
        // get the resource
        AbstractFileResolvingResource resource = (AbstractFileResolvingResource) resourceLoader
                .getResource(SWAGGER_DIRECTORY + "/" + pathInfo);

        // send it to the response
        if (resource.exists()) {
            StreamUtils.copy(resource.getInputStream(), resp.getOutputStream());
            resp.setStatus(HttpServletResponse.SC_OK);
            resp.flushBuffer();
        } else {
            resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    }
}

From source file:jodtemplate.pptx.Slide.java

public String getNextId() {
    int id = 1;/*from w w w . j ava 2s. c  om*/
    for (final Relationship rel : otherRelationships) {
        final String numStr = StringUtils.removeStart(rel.getId(), Relationship.ID_PREFIX);
        if (NumberUtils.isDigits(numStr)) {
            final int num = Integer.parseInt(numStr);
            if (num >= id) {
                id = num + 1;
            }
        }
    }
    return Relationship.ID_PREFIX + id;
}

From source file:com.ibm.watson.developer_cloud.retrieve_and_rank.v1.util.ZipUtils.java

private static void writeZipEntry(ZipOutputStream out, String name, byte[] data) throws IOException {
    final ZipEntry entry = new ZipEntry(StringUtils.removeStart(name, "/"));
    out.putNextEntry(entry);//from ww w. j  a  va2 s  . c  om
    out.write(data, 0, data.length);
    out.closeEntry();
}

From source file:it.cnr.ilc.latmorphwebapp.ProxyHandler.java

private String addContextPath(FacesContext context, String url) {
    final HttpServletRequest request = ((HttpServletRequest) context.getExternalContext().getRequest());
    String result = url;/*from ww  w. java 2s.c  o m*/
    if (url.startsWith("/")) {
        int subpath = StringUtils.countMatches(getPath(request), "/") - 1;
        String pathPrefix = "";
        if (subpath > 0) {
            while (subpath > 0) {
                pathPrefix += "/..";
                subpath--;
            }
            pathPrefix = StringUtils.removeStart(pathPrefix, "/");
        }
        result = pathPrefix + result;
    }
    log.debug("addContextPath: = " + result);
    return result;
}

From source file:cop.raml.processor.RestApi.java

@NotNull
private static Resource add(@NotNull Map<String, Resource> resources, @NotNull String path) {
    path = path.startsWith("/") ? path : '/' + path;

    for (Resource resource : resources.values()) {
        String basePath = resource.getPath();

        if (basePath.equals(path))
            return resource;
        if (path.startsWith(basePath + '/'))
            return add(resource.children, StringUtils.removeStart(path, basePath));

        String commonPath = findLongestPrefix(basePath, path);

        if (commonPath.isEmpty())
            continue;

        Resource parent = new Resource(commonPath, resource);
        resources.remove(basePath);//from  w  w  w  .j  a  v  a 2  s .  c  o  m
        resources.put(parent.getPath(), parent);
        resource.removePathPrefix(commonPath);
        resource.removeUriParameters(
                parent.getUriParameters().stream().map(Parameter::getName).collect(Collectors.toList()));
        parent.children.put(resource.getPath(), resource);

        String suffix = StringUtils.removeStart(path, commonPath);

        if (StringUtils.isBlank(suffix))
            return parent;
        return add(parent.children, StringUtils.removeStart(path, commonPath));
    }

    Resource resource = new Resource(path);
    resources.put(resource.getPath(), resource);

    return resource;
}

From source file:ch.cyberduck.cli.TerminalHelpFormatter.java

protected StringBuffer renderWrappedText(final StringBuffer sb, final int width, int nextLineTabStop,
        String text) {/*from   w ww  . ja v  a2 s. c o  m*/
    int pos = findWrapPos(text, width, 0);
    if (pos == -1) {
        sb.append(rtrim(text));

        return sb;
    }
    sb.append(rtrim(text.substring(0, pos))).append(getNewLine());
    if (nextLineTabStop >= width) {
        // stops infinite loop happening
        nextLineTabStop = 1;
    }
    // all following lines must be padded with nextLineTabStop space characters
    final String padding = createPadding(nextLineTabStop);
    while (true) {
        text = padding + StringUtils.removeStart(text.substring(pos), StringUtils.SPACE);
        pos = findWrapPos(text, width, 0);
        if (pos == -1) {
            sb.append(text);
            return sb;
        }
        if ((text.length() > width) && (pos == nextLineTabStop - 1)) {
            pos = width;
        }
        sb.append(rtrim(text.substring(0, pos))).append(getNewLine());
    }
}