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:de.jcup.egradle.core.util.LinkToTypeConverter.java

private void cleanupSlashes(LinkData data) {
    if (data == null) {
        return;//from ww w  .  j  a  va 2s.  co  m
    }
    String typeName = data.mainName;
    if (typeName == null) {
        return;
    }
    while (typeName.endsWith("/")) {
        typeName = StringUtils.chop(typeName);
    }
    while (typeName.startsWith("/")) {
        typeName = StringUtils.removeStart(typeName, "/");
    }
    data.mainName = typeName;
}

From source file:de.vandermeer.skb.commons.utils.CLIApache.java

@Override
public String parse(String[] args, boolean stopAtNonOption) {
    String ret = "";
    CommandLineParser parser = new PosixParser();
    try {/* w  ww . j a v a  2s .  co  m*/
        this.cmdLine = parser.parse(this.options, args, stopAtNonOption);
    } catch (ParseException exp) {
        ret = StringUtils.removeStart(exp.toString(), "org.apache.commons.cli.UnrecognizedOptionException: ");
    }
    return ret;
}

From source file:com.mirth.connect.server.servlets.WebStartServlet.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // MIRTH-1745
    response.setCharacterEncoding("UTF-8");

    try {/*  ww w  .  j av  a2 s. com*/
        response.setContentType("application/x-java-jnlp-file");
        response.setHeader("Pragma", "no-cache");
        PrintWriter out = response.getWriter();
        Document jnlpDocument = null;

        if (request.getServletPath().equals("/webstart.jnlp") || request.getServletPath().equals("/webstart")) {
            jnlpDocument = getAdministratorJnlp(request);
        } else if (request.getServletPath().equals("/webstart/extensions")) {
            String extensionPath = StringUtils.removeEnd(StringUtils.removeStart(request.getPathInfo(), "/"),
                    ".jnlp");
            jnlpDocument = getExtensionJnlp(extensionPath);
        }

        DocumentSerializer docSerializer = new DocumentSerializer(true);
        docSerializer.toXML(jnlpDocument, out);
    } catch (RuntimeIOException rio) {
        logger.debug(rio);
    } catch (Throwable t) {
        logger.error(ExceptionUtils.getStackTrace(t));
        throw new ServletException(t);
    }
}

From source file:ch.cyberduck.core.b2.B2AttributesFinderFeature.java

protected PathAttributes toAttributes(final B2FileResponse response) {
    final PathAttributes attributes = new PathAttributes();
    attributes.setSize(response.getContentLength());
    if (response.getFileInfo().containsKey(X_BZ_INFO_LARGE_FILE_SHA1)) {
        attributes.setChecksum(Checksum.parse(response.getFileInfo().get(X_BZ_INFO_LARGE_FILE_SHA1)));
    } else {//from  w w w  . j av  a  2  s .com
        attributes.setChecksum(Checksum.parse(StringUtils
                .removeStart(StringUtils.lowerCase(response.getContentSha1(), Locale.ROOT), "unverified:")));
    }
    final Map<String, String> metadata = new HashMap<>();
    for (Map.Entry<String, String> entry : response.getFileInfo().entrySet()) {
        metadata.put(entry.getKey(), entry.getValue());
    }
    attributes.setMetadata(metadata);
    attributes.setVersionId(response.getFileId());
    if (response.getFileInfo().containsKey(X_BZ_INFO_SRC_LAST_MODIFIED_MILLIS)) {
        attributes.setModificationDate(
                Long.valueOf(response.getFileInfo().get(X_BZ_INFO_SRC_LAST_MODIFIED_MILLIS)));
    }
    return attributes;
}

From source file:net.sf.dynamicreports.googlecharts.jasper.geomap.GeoMapElementHtmlHandler.java

@Override
public String getHtmlFragment(JRHtmlExporterContext context, JRGenericPrintElement element) {
    Boolean showLegend = (Boolean) element.getParameterValue(GeoMapPrintElement.PARAMETER_SHOW_LEGEND);
    GeoMapDataMode dataMode = (GeoMapDataMode) element
            .getParameterValue(GeoMapPrintElement.PARAMETER_DATA_MODE);
    String region = (String) element.getParameterValue(GeoMapPrintElement.PARAMETER_REGION);
    String valueLabel = (String) element.getParameterValue(GeoMapPrintElement.PARAMETER_VALUE_LABEL);
    if (valueLabel == null) {
        valueLabel = "";
    }/*from   w w w  . j  av a2 s . co  m*/
    @SuppressWarnings("unchecked")
    List<Color> colors = (List<Color>) element.getParameterValue(GeoMapPrintElement.PARAMETER_COLORS);
    String stringColors = null;
    if (colors != null && !colors.isEmpty()) {
        stringColors = "";
        for (Color color : colors) {
            stringColors += "," + getColorString(color);
        }
        stringColors = StringUtils.removeStart(stringColors, ",");
    }
    @SuppressWarnings("unchecked")
    Set<GeoMapData> dataset = (Set<GeoMapData>) element.getParameterValue(GeoMapPrintElement.PARAMETER_DATASET);

    VelocityContext velocityContext = new VelocityContext();
    velocityContext.put("showLegend", showLegend);
    if (dataMode != null) {
        switch (dataMode) {
        case REGIONS:
            velocityContext.put("dataMode", "regions");
            break;
        case MARKERS:
            velocityContext.put("dataMode", "markers");
            break;
        default:
            break;
        }
    }
    velocityContext.put("id", "map_" + element.hashCode());
    velocityContext.put("region", region);
    velocityContext.put("valueLabel", valueLabel);
    velocityContext.put("colors", stringColors);
    velocityContext.put("dataset", dataset);
    if (context.getExporter() instanceof JRXhtmlExporter) {
        velocityContext.put("xhtml", "xhtml");
        velocityContext.put("elementX", ((JRXhtmlExporter) context.getExporter()).toSizeUnit(element.getX()));
        velocityContext.put("elementY", ((JRXhtmlExporter) context.getExporter()).toSizeUnit(element.getY()));
    } else {
        velocityContext.put("elementX", ((JRHtmlExporter) context.getExporter()).toSizeUnit(element.getX()));
        velocityContext.put("elementY", ((JRHtmlExporter) context.getExporter()).toSizeUnit(element.getY()));
    }
    velocityContext.put("elementWidth", element.getWidth());
    velocityContext.put("elementHeight", element.getHeight());

    if (element.getModeValue() == ModeEnum.OPAQUE) {
        velocityContext.put("backgroundColor", JRColorUtil.getColorHexa(element.getBackcolor()));
    }
    return VelocityUtil.processTemplate(GEOMAP_ELEMENT_HTML_TEMPLATE, velocityContext);
}

From source file:jobhunter.models.SubscriptionItem.java

public String getWorkingLink() {
    if (StringUtils.startsWith(this.link, "http"))
        return this.link;

    if (StringUtils.startsWith(this.link, "//"))
        return this.host + StringUtils.removeStart(this.link, "//");

    if (StringUtils.startsWith(this.link, "/"))
        return this.host + StringUtils.removeStart(this.link, "/");

    return this.link;

}

From source file:com.joyent.manta.client.MantaObjectConversionFunction.java

@Override
public MantaObject apply(final Map<String, Object> item) {
    String name = Validate.notNull(item.get(NAME_FIELD_KEY), "Filename is null").toString();
    String mtime = Validate.notNull(item.get(MTIME_FIELD_KEY), "Modification time is null").toString();
    String type = Validate.notNull(item.get(TYPE_FIELD_KEY), "File type is null").toString();

    String objPath = String.format("%s%s%s",
            StringUtils.removeEnd(item.get(PATH_FIELD_KEY).toString(), SEPARATOR), SEPARATOR,
            StringUtils.removeStart(name, SEPARATOR));
    MantaHttpHeaders headers = new MantaHttpHeaders();
    headers.setLastModified(mtime);/*from w  w  w . ja va 2 s.c om*/

    /* We look for contentType explicitly because it is being added to Manta
     * in a future version and this property may not be available on all
     * Manta installs for quite some time. */
    if (item.containsKey(CONTENT_TYPE_FIELD_KEY)) {
        String contentType = Objects.toString(item.get(CONTENT_TYPE_FIELD_KEY), null);
        headers.setContentType(contentType);
    } else if (type.equals(MantaObject.MANTA_OBJECT_TYPE_DIRECTORY)) {
        headers.setContentType(MantaObjectResponse.DIRECTORY_RESPONSE_CONTENT_TYPE);
    }

    if (item.containsKey(ETAG_FIELD_KEY)) {
        headers.setETag(Objects.toString(item.get(ETAG_FIELD_KEY)));
    }

    if (item.containsKey(SIZE_FIELD_KEY)) {
        long size = Long.parseLong(Objects.toString(item.get(SIZE_FIELD_KEY)));
        headers.setContentLength(size);
    }

    if (item.containsKey(DURABILITY_FIELD_KEY)) {
        String durabilityString = Objects.toString(item.get(DURABILITY_FIELD_KEY));
        if (durabilityString != null) {
            int durability = Integer.parseInt(durabilityString);
            headers.setDurabilityLevel(durability);
        }
    }

    // This property may not be available on all Manta installs for quite some time
    if (item.containsKey(CONTENT_MD5_FIELD_KEY)) {
        String contentMD5 = Objects.toString(item.get(CONTENT_MD5_FIELD_KEY), null);
        headers.setContentMD5(contentMD5);
    }

    return new MantaObjectResponse(formatPath(objPath), headers);
}

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

@Test
public void findUnimplementedEvents() throws IOException {
    Set<Class<?>> events = Sets.newLinkedHashSet();

    for (ClassPath.ClassInfo info : PoreTests.getClassPath().getTopLevelClassesRecursive(BUKKIT_PACKAGE)) {
        try {// w w w  . ja  v  a  2  s . c o  m
            Class<?> event = info.load();
            if (Event.class.isAssignableFrom(event) && !Modifier.isAbstract(event.getModifiers())) {
                events.add(event);
            }
        } catch (Throwable e) {
            PoreTests.getLogger().warn("Failed to load {}", info, e);
        }
    }

    for (ClassPath.ClassInfo info : PoreTests.getClassPath().getTopLevelClassesRecursive(PORE_PACKAGE)) {
        Class<?> type;
        try {
            type = info.load();
            if (!Event.class.isAssignableFrom(type)) {
                continue;
            }
        } catch (Throwable e) {
            PoreTests.getLogger().warn("Failed to load {}", info, e);
            continue;
        }

        events.remove(type.getSuperclass());
    }

    if (!events.isEmpty()) {
        for (Class<?> event : events) {
            String bukkitPackage = StringUtils.removeStart(event.getPackage().getName(), BUKKIT_PACKAGE + '.');
            PoreTests.getLogger().warn("{}: Pore{} is missing", bukkitPackage, event.getSimpleName());
        }
    }
}

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

License:asdf

/**
 * Split a term into parts//from   w  w  w.  java  2 s  .com
 * @param term
 * @return
 */
public static List<String> split(String term) {
    String url = term.substring(1, term.length() - 1);
    String path = StringUtils.removeStart(url, HTTP);

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

    //String [] parts = StringUtils.split(path, URI_SEP);
    // this is alot faster than String.split or StringUtils.split
    return Utils.split(path, URI_SEP);
}

From source file:net.minecrell.quartz.launch.mappings.MappingsLoader.java

public static Mappings load(Logger logger) throws IOException {
    URI source;/*from   ww  w  .j  a v  a 2 s . co m*/
    try {
        source = requireNonNull(Mapping.class.getProtectionDomain().getCodeSource(),
                "Unable to find class source").getLocation().toURI();
    } catch (URISyntaxException e) {
        throw new IOException("Failed to find class source", e);
    }

    Path location = Paths.get(source);
    logger.debug("Mappings location: {}", location);

    List<ClassNode> mappingClasses = new ArrayList<>();

    // Load the classes from the source
    if (Files.isDirectory(location)) {
        // We're probably in development environment or something similar
        // Search for the class files
        Files.walkFileTree(location.resolve(PACKAGE), new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                if (file.getFileName().toString().endsWith(".class")) {
                    try (InputStream in = Files.newInputStream(file)) {
                        ClassNode classNode = MappingsParser.loadClassStructure(in);
                        mappingClasses.add(classNode);
                    }
                }

                return FileVisitResult.CONTINUE;
            }
        });
    } else {
        // Go through the JAR file
        try (ZipFile zip = new ZipFile(location.toFile())) {
            Enumeration<? extends ZipEntry> entries = zip.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                String name = StringUtils.removeStart(entry.getName(), MAPPINGS_DIR);
                if (entry.isDirectory() || !name.endsWith(".class") || !name.startsWith(PACKAGE_PREFIX)) {
                    continue;
                }

                // Ok, we found something
                try (InputStream in = zip.getInputStream(entry)) {
                    ClassNode classNode = MappingsParser.loadClassStructure(in);
                    mappingClasses.add(classNode);
                }
            }
        }
    }

    return new Mappings(mappingClasses);
}