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:org.thelq.stackexchange.dbimport.Utils.java

public static String genTablePrefix(String containerName) {
    String name = containerName.trim().toLowerCase();
    if (StringUtils.isBlank(name))
        return "";
    //Hardcoded conversions
    name = StringUtils.removeEnd(name, ".7z");
    name = StringUtils.removeEnd(name, ".stackexchange.com");
    if (StringUtils.contains(name, "stackoverflow"))
        name = StringUtils.replace(name, "stackoverflow", "so");
    else if (StringUtils.contains(name, "serverfault"))
        name = StringUtils.replace(name, "serverfault", "sf");
    else if (StringUtils.containsIgnoreCase(name, "superuser"))
        name = StringUtils.replace(name, "superuser", "su");

    //Remove unnessesary extensions
    name = StringUtils.removeEnd(name, ".com");

    //Meta handling
    if (StringUtils.startsWith(name, "meta"))
        name = StringUtils.removeStart(name, "meta") + "_m";
    else if (StringUtils.startsWith(name, "meta."))
        name = StringUtils.removeStart(name, "meta.") + "_m";

    //Basic make valid for SQL
    //TODO: more validation?
    name = StringUtils.remove(name, " ");
    name = StringUtils.remove(name, ".");
    return name + "_";
}

From source file:org.wrml.runtime.schema.DefaultSchemaLoader.java

@Override
public SortedSet<UniqueName> getSchemaNames(final UniqueName namespace) {

    final SortedSet<UniqueName> allSubschemaNames = getAllSubschemaNames(namespace);

    if (allSubschemaNames == null || allSubschemaNames.isEmpty()) {
        return allSubschemaNames;
    }//w  w w. j  a v a 2s .c o m

    final String namespaceString = (namespace != null) ? namespace.toString() : "";
    final SortedSet<UniqueName> schemaNames = new TreeSet<>();
    for (final UniqueName subschemaName : allSubschemaNames) {
        final String subschemaNameString = subschemaName.toString();
        final String remainderNameString = StringUtils.removeStart(subschemaNameString,
                namespaceString + UniqueName.NAME_SEPARATOR);
        if (!remainderNameString.contains(UniqueName.NAME_SEPARATOR)) {
            schemaNames.add(subschemaName);
        }
    }

    return schemaNames;
}

From source file:org.wrml.runtime.schema.DefaultSchemaLoader.java

@Override
public SortedSet<UniqueName> getSchemaSubnamespaces(final UniqueName namespace) {

    final SortedSet<UniqueName> allSubschemaNames = getAllSubschemaNames(namespace);

    if (allSubschemaNames == null || allSubschemaNames.isEmpty()) {
        return allSubschemaNames;
    }//from  ww  w.  j a v a 2  s.co m

    String namespaceString = (namespace != null) ? namespace.toString() : "";
    if (!namespaceString.endsWith(UniqueName.NAME_SEPARATOR)) {
        namespaceString = namespaceString + UniqueName.NAME_SEPARATOR;
    }
    final SortedSet<UniqueName> subnamespaces = new TreeSet<>();
    for (final UniqueName subschemaName : allSubschemaNames) {
        final String subschemaNameString = subschemaName.toString();
        final String remainderNameString = StringUtils.removeStart(subschemaNameString, namespaceString);

        final int endIndex = remainderNameString.indexOf(UniqueName.NAME_SEPARATOR);
        if (endIndex > 0) {
            final String localName = remainderNameString.substring(0, endIndex);
            subnamespaces.add(new UniqueName(namespace, localName));
        }

    }

    return subnamespaces;
}

From source file:org.xlrnet.metadict.core.storage.StorageServiceFactory.java

private void initializeDefaultConfiguration() {
    Map<String, String> properties = CommonUtils.getProperties(STORAGE_CONFIG_FILE);

    for (String key : properties.keySet()) {
        if (StringUtils.startsWith(key, "storage." + this.defaultStorageServiceName + ".")) {
            String configKey = StringUtils.removeStart(key, "storage." + this.defaultStorageServiceName + ".");
            String configValue = properties.get(key);
            this.defaultStorageConfigMap.put(configKey, configValue);
            LOGGER.debug("Detected configuration key '{}' with value '{}'", configKey, configValue);
        }/*from  w  w w . ja v  a  2  s.  c o m*/
    }
}

From source file:org.xlrnet.metadict.engines.woxikon.WoxikonEngine.java

private void extractDescription(@NotNull Element element, String queryString,
        DictionaryObjectBuilder objectBuilder) {
    Element descriptionNode = element.getElementsByClass(CLASS_DESCRIPTION).first();
    if (descriptionNode == null) {
        // Try to detect the description node with an alternative class (necessary for synonyms)
        descriptionNode = element.getElementsByClass(CLASS_EXTRA_INFO).first();
    }/*  w  ww.  jav  a2  s .  co  m*/
    if (descriptionNode != null) {
        String description = descriptionNode.text();

        description = StringUtils.removeStart(description, DESCRIPTION_BEGIN);
        description = StringUtils.removeEnd(description, DESCRIPTION_END);

        if (!StringUtils.equalsIgnoreCase(description, queryString)) // Set description only if it is different from request string
            objectBuilder.setDescription(StringUtils.strip(description));
    }
}

From source file:org.xwiki.contrib.authentication.internal.DefaultTrustedAuthenticationConfiguration.java

private String stripContextPathFromURL(URL url) {
    XWikiContext context = contextProvider.get();
    return StringUtils.removeStart(url.toExternalForm(),
            url.getProtocol() + "://" + url.getAuthority() + context.getWiki().getWebAppPath(context));
}

From source file:org.xwiki.filter.instance.internal.input.AbstractInstanceInputFilterStreamTest.java

protected void assertXML(String resource, InstanceInputProperties instanceProperties)
        throws FilterException, IOException {
    if (instanceProperties == null) {
        instanceProperties = new InstanceInputProperties();
        instanceProperties.setVerbose(false);
    }// w w w.  j  av a 2 s . c  o m

    URL url = getClass().getResource("/" + resource + ".xml");

    String expected = IOUtils.toString(url, "UTF-8");

    expected = StringUtils.removeStart(expected, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n");

    InputFilterStream inputFilterStream = this.inputFilterStreamFactory
            .createInputFilterStream(instanceProperties);

    StringWriterOutputTarget writer = new StringWriterOutputTarget();

    FilterXMLOutputProperties properties = new FilterXMLOutputProperties();
    properties.setTarget(writer);

    OutputFilterStream outputFilterStream = this.xmlOutputFilterStreamFactory
            .createOutputFilterStream(properties);

    inputFilterStream.read(outputFilterStream.getFilter());

    inputFilterStream.close();
    outputFilterStream.close();

    Assert.assertEquals(expected, writer.getBuffer().toString());
}

From source file:org.xwiki.filter.xar.XARInputFilterStreamTest.java

private void assertXML(String resource, XARInputProperties xarProperties)
        throws FilterException, IOException, ComponentLookupException {
    URL url = getClass().getResource("/xar/" + resource + ".output.xml");

    String expected = IOUtils.toString(url, "UTF-8");

    expected = StringUtils.removeStart(expected, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n");

    BeanInputFilterStreamFactory<XARInputProperties> inputFilterStreamFactory = this.mocker
            .getInstance(InputFilterStreamFactory.class, FilterStreamType.XWIKI_XAR_CURRENT.serialize());
    InputFilterStream inputFilterStream = inputFilterStreamFactory.createInputFilterStream(xarProperties);

    StringWriterOutputTarget writer = new StringWriterOutputTarget();

    FilterXMLOutputProperties properties = new FilterXMLOutputProperties();
    properties.setTarget(writer);// w  w  w .  j a  v a 2  s .c  om

    BeanOutputFilterStreamFactory<FilterXMLOutputProperties> xmlOutputFilterStreamFactory = this.mocker
            .getInstance(OutputFilterStreamFactory.class, FilterStreamType.FILTER_XML.serialize());
    OutputFilterStream outputFilterStream = xmlOutputFilterStreamFactory.createOutputFilterStream(properties);

    inputFilterStream.read(outputFilterStream.getFilter());

    inputFilterStream.close();
    outputFilterStream.close();

    Assert.assertEquals(expected, writer.getBuffer().toString());
}

From source file:org.xwiki.refactoring.script.RefactoringScriptService.java

/**
 * @param type the type of refactoring/*from   www  .ja  va  2 s .c o m*/
 * @param suffix uniquely identifies the job among those of the specified type
 * @return an id for a job to perform the specified type of refactoring
 */
private List<String> getJobId(String type, String suffix) {
    return Arrays.asList(RefactoringJobs.GROUP, StringUtils.removeStart(type, RefactoringJobs.GROUP_PREFIX),
            suffix);
}

From source file:org.xwiki.test.escaping.TemplateTest.java

/**
 * Create a target URL from given parameters, adding the template name.
 * /*from  w ww .j ava2 s.co  m*/
 * @param space space name to use, "Main" is used if null
 * @param page page name to use, "WebHome" is used if null
 * @param parameter parameter name to add, omitted if null or empty string
 * @param value parameter value, empty string is used if null
 * @return the resulting absolute URL
 * @see #createUrl(String, String, String, java.util.Map)
 */
protected String createUrl(String space, String page, String parameter, String value) {
    String skin = "default";
    if (this.name.startsWith("skins")) {
        skin = this.name.replaceFirst("^\\w+/", "").replaceAll("/.+$", "");
    }

    final String TEMPLATES_DIR = "templates" + File.separator;
    final String SKINS_DIR = "skins" + File.separator;
    String template;
    if (this.name.startsWith(TEMPLATES_DIR)) {
        template = StringUtils.removeStart(this.name, TEMPLATES_DIR);
    } else if (this.name.startsWith(SKINS_DIR)) {
        template = StringUtils.removeStart(this.name, SKINS_DIR + skin + File.separator);
    } else {
        template = this.name.replaceAll("^(.+)/", "");
    }

    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("skin", skin);
    if ("xpart".equals(parameter)) {
        // xpart=something must be tested differently
        parameters.put("xpage", template).replaceAll("\\.\\w+$", "");
    } else {
        // this variant initializes some commonly used variables
        parameters.put("xpage", "xpart");
        parameters.put("vm", template);
    }
    if (parameter != null) {
        parameters.put(parameter, value);
    }
    return createUrl(null, space, page, parameters);
}