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

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

Introduction

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

Prototype

public static String strip(String str, final String stripChars) 

Source Link

Document

Strips any of a set of characters from the start and end of a String.

Usage

From source file:io.github.swagger2markup.utils.IOUtils.java

/**
 * Create a normalized name from an arbitrary string.<br>
 * Paths separators are replaced, so this function can't be applied on a whole path, but must be called on each path sections.
 *
 * @param name current name of the file/*  w w w  .ja  v  a  2s.  co  m*/
 * @return a normalized filename
 */
public static String normalizeName(String name) {
    String fileName = NAME_FORBIDDEN_PATTERN.matcher(name).replaceAll("_");
    fileName = fileName.replaceAll(String.format("([%1$s])([%1$s]+)", "-_"), "$1");
    fileName = StringUtils.strip(fileName, "_-");
    fileName = fileName.trim();
    return fileName;
}

From source file:com.vaadin.tests.components.combobox.ComboBoxPopupPositionEmbeddedInDivTest.java

@Test
public void popupBelow() {
    driver.get(StringUtils.strip(getBaseURL(), "/") + "/statictestfiles/ComboBoxEmbeddingHtmlPage.html");

    // Chrome requires document.scrollTop (<body>)
    // Firefox + IE wants document.documentElement.scrollTop (<html>)
    executeScript(/*from  w  w  w  .ja  v a  2 s  . c om*/
            "document.body.scrollTop=200;document.documentElement.scrollTop=200;document.body.scrollLeft=50;document.documentElement.scrollLeft=50;");

    ComboBoxElement combobox = $(ComboBoxElement.class).first();
    combobox.openPopup();
    WebElement popup = $(ComboBoxElement.class).first().getSuggestionPopup();

    Point comboboxLocation = combobox.getLocation();
    Point popupLocation = popup.getLocation();
    Assert.assertTrue("Popup should be below combobox", popupLocation.getY() > comboboxLocation.getY());

    Assert.assertTrue("Popup should be left aligned with the combobox",
            popupLocation.getX() == comboboxLocation.getX());
}

From source file:com.twosigma.beaker.mimetype.MIMEContainer.java

public static MIMEContainer Math(String code) {
    code = StringUtils.strip(code, "$");
    return addMimeType(TEXT_LATEX, "$$" + code + "$$");
}

From source file:eu.europeana.querylog.clean.TrimCleaner.java

public String clean(String query) {
    return StringUtils.strip(query, stripChars);
}

From source file:com.nhncorp.lucy.security.xss.listener.SecurityUtils.java

/**
 * @param element/*from  w ww .  j  a va  2 s. c  om*/
 * @param srcUrl
 * @param isWhiteUrl
 * @return
 */
public static boolean checkVulnerable(Element element, String srcUrl, boolean isWhiteUrl) {
    boolean isVulnerable = false;

    // embed/object   ? (XSSFILTERSUS-109)
    if (isWhiteUrl) {

    } else {
        String type = element.getAttributeValue("type").trim();
        type = StringUtils.strip(type, "'\"");

        if (type != null && type.length() != 0) {

            //? type ??
            if (!(isAllowedType(type) || props.values().contains(type))) {
                isVulnerable = true;
            }
        } else {
            //? ?
            String url = StringUtils.strip(srcUrl, "'\"");
            String extension = getExtension(url);

            if (StringUtils.containsAny(extension, specialCharArray)) {
                int pos = StringUtils.indexOfAny(extension, specialCharArray);
                if (pos != -1) {
                    extension = StringUtils.substring(extension, 0, pos);
                }
            }

            if (StringUtils.isEmpty(extension)) {
                // ?  MIME TYPE ? ?  ,  . ? hole ? ? ? ? .
            } else {
                type = getTypeFromExtension(extension);

                if (StringUtils.isEmpty(type)) {
                    type = props.getProperty(extension);

                    if (type != null) {
                        type = type.trim();
                    }
                }

                //? type ??
                if (StringUtils.isEmpty(type)) {
                    isVulnerable = true;
                } else {
                    element.putAttribute("type", "\"" + type + "\"");
                }
            }

        }
    }
    return isVulnerable;
}

From source file:it.cnr.isti.hpc.dexter.spot.cleanpipe.cleaner.StripCleaner.java

private String trim(String str) {
    // return str.trim();
    return StringUtils.strip(str, trimChars);
}

From source file:com.bellman.bible.android.control.link.UriAnalyzer.java

public boolean analyze(String uri) {
    // check for urls like gdef:01234

    String protocol;/*www .ja  v  a2s .  c o m*/
    String ref;

    // split the prefix from the book
    if (!uri.contains(":")) {
        protocol = Constants.BIBLE_PROTOCOL;
        ref = uri;
    } else {
        String[] uriTokens = uri.split(":");
        protocol = uriTokens[0];
        ref = uriTokens[1];
    }

    // Doc type
    if (Constants.SWORD_PROTOCOL.equals(protocol)) {
        docType = DocType.SPECIFIC_DOC;
    } else if (Constants.BIBLE_PROTOCOL.equals(protocol)) {
        docType = DocType.BIBLE;
    } else if (Constants.GREEK_DEF_PROTOCOL.equals(protocol)) {
        docType = DocType.GREEK_DIC;
    } else if (Constants.HEBREW_DEF_PROTOCOL.equals(protocol)) {
        docType = DocType.HEBREW_DIC;
    } else if (Constants.ROBINSON_GREEK_MORPH_PROTOCOL.equals(protocol)) {
        docType = DocType.ROBINSON;
    } else if (Constants.ALL_GREEK_OCCURRENCES_PROTOCOL.equals(protocol)) {
        docType = DocType.ALL_GREEK;
    } else if (Constants.ALL_HEBREW_OCCURRENCES_PROTOCOL.equals(protocol)) {
        docType = DocType.ALL_HEBREW;
    } else {
        // not a valid Strongs Uri
        return false;
    }

    // Document
    if (StringUtils.isEmpty(ref)) {
        return false;
    }

    // remove the first 2 slashes from the url e.g. //module/key
    ref = StringUtils.strip(ref, "/");
    if (!ref.contains("/")) {
        key = ref;
    } else {
        int firstSlash = ref.indexOf("/");
        book = ref.substring(0, firstSlash);

        // handle uri like sword://Bible/John.17.11 found in Calvin's commentary avoiding any attempt to find a book named Bible that will fail
        if (Constants.BIBLE_PROTOCOL.equalsIgnoreCase(book)) {
            docType = DocType.BIBLE;
        }

        // safe to grab after slash because slash can't be on end due to above strip("/")
        key = ref.substring(firstSlash + 1);
    }

    // handled this url (or at least attempted to)
    return true;
}

From source file:com.sangupta.clitools.file.Trim.java

@Override
protected boolean processFile(File file) throws IOException {
    // read entire file in memory
    List<String> contents = FileUtils.readLines(file);
    final long initial = file.length();

    // now for each string - trim from end
    for (int index = 0; index < contents.size(); index++) {
        String line = contents.get(index);
        line = StringUtils.strip(line, null);
        contents.set(index, line);/*from w  w  w .  ja  va2 s.  c o  m*/
    }

    // write back contents of file
    FileUtils.writeLines(file, contents);
    long current = file.length();

    this.bytesSaved.addAndGet(initial - current);
    System.out.println("File " + file.getAbsoluteFile().getAbsolutePath() + " trimmed and saved "
            + (initial - current) + " bytes.");
    return true;
}

From source file:com.microsoft.rest.serializer.JacksonHelper.java

/**
 * Serializes an object into a raw string using the current {@link ObjectMapper}.
 * The leading and trailing quotes will be trimmed.
 *
 * @param object the object to serialize.
 * @return the serialized string. Null if the object to serialize is null.
 *///from ww  w . j a  v  a2 s . c  o  m
public static String serializeRaw(Object object) {
    if (object == null)
        return null;
    return StringUtils.strip(serialize(object), "\"");
}

From source file:com.vaadin.tests.performance.MemoryIT.java

private void openUI(String path, int itemsNumber) {
    getDriver().get(StringUtils.strip(getBaseURL(), "/") + path + "?items=" + itemsNumber);
    Assert.assertTrue(isElementPresent(By.className("v-grid")));
}