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

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

Introduction

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

Prototype

public static String removeEnd(final String str, final String remove) 

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

A null source string will return null .

Usage

From source file:org.apache.rya.indexing.smarturi.SmartUriAdapter.java

private static String addTypePrefixToUri(final String uriString, final String typePrefix) {
    final String localName = new URIImpl(uriString).getLocalName();
    final String beginning = StringUtils.removeEnd(uriString, localName);
    final String formattedUriString = beginning + typePrefix + localName;
    return formattedUriString;
}

From source file:org.apache.rya.indexing.smarturi.SmartUriAdapter.java

private static String removeTypePrefixFromUri(final String uriString, final String typePrefix) {
    final String localName = new URIImpl(uriString).getLocalName();
    final String beginning = StringUtils.removeEnd(uriString, localName);
    final String replacement = localName.replaceFirst(typePrefix + ".", "");
    final String formattedUriString = beginning + replacement;
    return formattedUriString;
}

From source file:org.apache.sling.nosql.generic.resource.impl.PathUtil.java

/**
 * Generated a regex pattern that accepts all paths that are direct children of the given parent path.
 * @param parentPath Parent path/*from www.  j av  a 2  s .  co  m*/
 * @return Regex pattern
 */
public static Pattern getChildPathPattern(String parentPath) {
    return Pattern.compile("^" + Pattern.quote(StringUtils.removeEnd(parentPath, "/")) + "/[^/]+$");
}

From source file:org.apache.sling.testing.clients.SlingClient.java

/**
 * Extracts the parent path from the given String
 *
 * @param path string containing the path
 * @return the parent path if exists or empty string otherwise
 *///  www .ja v a  2  s . c om
protected String getParentPath(final String path) {
    // TODO define more precisely what is the parent of a folder and of a file
    final String normalizedPath = StringUtils.removeEnd(path, "/"); // remove trailing slash in case of folders
    return StringUtils.substringBeforeLast(normalizedPath, "/");
}

From source file:org.apache.sling.testing.clients.SlingClient.java

/**
 * Extracts the node from path/*  w  ww .  j a va  2  s.c o  m*/
 *
 * @param path string containing the path
 * @return the node without parent path
 */
protected String getNodeNameFromPath(final String path) {
    // TODO define the output for all the cases (e.g. paths with trailing slash)
    final String normalizedPath = StringUtils.removeEnd(path, "/"); // remove trailing slash in case of folders
    final int pos = normalizedPath.lastIndexOf('/');
    if (pos != -1) {
        return normalizedPath.substring(pos + 1, normalizedPath.length());
    }
    return normalizedPath;
}

From source file:org.auraframework.impl.css.util.Flavors.java

/**
 * Builds the correct CSS class name for a {@link FlavoredStyleDef}, based on the given flavor name.
 * <p>/*w  w w  . jav  a 2  s.c o  m*/
 * Specifically this converts a {@link FlavoredStyleDef}'s descriptor name, such as ui-buttonFlavors (e.g., from
 * flavors/ui-buttonFlavors.css), to the appropriate CSS class name of the flavored component (e.g., uiButton), as
 * it would be built by {@link Styles#buildClassName(DefDescriptor)}. This is necessary for custom flavors because
 * the naming convention separates the namespace from the component name using a dash instead of camel-casing (we
 * cannot infer from camel-casing... take mySpecialThingFlavors.css-- is that mySpecial:thing or my:specialThing?)
 *
 * @param flavoredStyle The flavored style def descriptor.
 * @return The CSS class name.
 */
public static String toComponentClassName(DefDescriptor<FlavoredStyleDef> flavoredStyle) {
    List<String> split = Lists.newArrayList(Splitter.on('-').limit(2).split(flavoredStyle.getName()));
    if (split.size() == 1) { // standard flavor
        return split.get(0);
    } else if (split.size() == 2) { // custom flavor
        return split.get(0) + AuraTextUtil.initCap(StringUtils.removeEnd(split.get(1), SUFFIX));
    }
    throw new AuraRuntimeException(
            "Unable to convert flavored style def to component css class" + flavoredStyle.getName());
}

From source file:org.auraframework.impl.css.util.Flavors.java

/**
 * Returns the {@link ComponentDef} descriptor for the component being flavored by the given
 * {@link FlavoredStyleDef}.//  w  ww  .  j a  v a 2 s.  c o m
 */
public static DefDescriptor<ComponentDef> toComponentDescriptor(DefDescriptor<FlavoredStyleDef> styleDesc) {
    if (styleDesc.getPrefix().equals(DefDescriptor.CUSTOM_FLAVOR_PREFIX)) {
        String[] split = styleDesc.getName().split("-");
        String descriptor = String.format("%s:%s", split[0], StringUtils.removeEnd(split[1], SUFFIX));
        return Aura.getDefinitionService().getDefDescriptor(descriptor, ComponentDef.class);
    } else {
        return Aura.getDefinitionService().getDefDescriptor(styleDesc, DefDescriptor.MARKUP_PREFIX,
                ComponentDef.class);
    }
}

From source file:org.blockartistry.mod.Restructured.assets.ZipProcessor.java

private static void traverseZips(final File path, final Predicate<ZipEntry> test,
        final Predicate<Object[]> process) {

    for (final File file : getZipFiles(path)) {
        try {/*w  w w .j  a  v  a  2 s  .c  om*/
            final ZipFile zip = new ZipFile(file);
            final String prefix = StringUtils.removeEnd(file.getName(), ".zip").toLowerCase().replaceAll("[-.]",
                    "_");
            Enumeration<? extends ZipEntry> entries = zip.entries();
            while (entries.hasMoreElements()) {
                final ZipEntry entry = entries.nextElement();
                if (test.apply(entry)) {
                    final InputStream stream = zip.getInputStream(entry);
                    final String name = StringUtils.removeEnd(entry.getName(), ".schematic");
                    process.apply(new Object[] { prefix, name, stream });
                    stream.close();
                }
            }
            zip.close();
        } catch (final Exception ex) {
            ex.printStackTrace();
        }
    }
}

From source file:org.blockartistry.mod.Restructured.assets.ZipProcessor.java

private static void traverseSchematics(final File path, final Predicate<Object[]> process) {

    for (final File file : getSchematicFiles(path)) {
        try {/*from w  ww .  j a  va2 s  .c om*/
            final InputStream stream = new FileInputStream(file);
            final String entry = StringUtils.removeEnd(file.getName(), ".schematic").toLowerCase()
                    .replaceAll("[-.]", "_");
            process.apply(new Object[] { "", entry, stream });
            stream.close();
        } catch (final Exception ex) {
            ex.printStackTrace();
        }
    }
}

From source file:org.brekka.phalanx.webservices.SoapExceptionResolver.java

private void resolveDetail(final MessageContext messageContext, final Throwable ex, final SoapFault soapFault) {
    SoapMessage request = (SoapMessage) messageContext.getRequest();
    DOMSource payloadSource = (DOMSource) request.getPayloadSource();
    Node node = payloadSource.getNode();
    String localName = node.getLocalName();
    String namespace = node.getNamespaceURI();
    String faultName = StringUtils.removeEnd(localName, "Request") + "Fault";
    QName faultQName = new QName(namespace, faultName);

    SchemaType schemaType = XmlBeans.getContextTypeLoader().findDocumentType(faultQName);
    if (schemaType != null) {
        try {/*from w  ww.  j  a  va 2s.co m*/
            XmlObject faultDocument = prepareFaultDetail(messageContext, faultName, schemaType, ex);
            if (faultDocument != null) {
                // Add detailed
                StringWriter writer = new StringWriter();
                faultDocument.save(writer, SAVE_OPTIONS);
                Transformer transformer = transformerFactory.newTransformer();

                SoapFaultDetail faultDetail = soapFault.addFaultDetail();
                Result result = faultDetail.getResult();
                transformer.transform(new StreamSource(new StringReader(writer.toString())), result);
            }
        } catch (Exception e) {
            if (log.isWarnEnabled()) {
                log.warn(format("Failed to create custom fault message of type '%s'", schemaType), e);
            }
        }
    }
}