Example usage for org.apache.commons.lang StringUtils substringBeforeLast

List of usage examples for org.apache.commons.lang StringUtils substringBeforeLast

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substringBeforeLast.

Prototype

public static String substringBeforeLast(String str, String separator) 

Source Link

Document

Gets the substring before the last occurrence of a separator.

Usage

From source file:hydrograph.ui.propertywindow.validators.ComponentValidator.java

/**
 * Validates given component state//  w  w  w.j av a2s  . c o  m
 * 
 * @param {@link Component}
 * @return true - if component has valid state
 */
public boolean validate(Component component) {
    PropertyToolTipInformation propertyToolTipInformation = new PropertyToolTipInformation(ISSUE_PROPERTY_NAME,
            HIDE_TOOLTIP, TOOLTIP_DATATYPE);
    boolean validationStatus = true;
    String errorMessages = "";
    if (componentValidators != null && componentValidators.containsKey(component.getType().toUpperCase())) {
        for (IComponentValidator componentValidator : componentValidators
                .get(component.getType().toUpperCase())) {

            String errorMessage = componentValidator.validateComponent(component);
            if (errorMessage != null) {
                errorMessages = errorMessages + errorMessage + "\n";
            }
        }

        errorMessages = StringUtils.substringBeforeLast(errorMessages, "\n");

        if (!StringUtils.isEmpty(errorMessages)) {
            propertyToolTipInformation = new PropertyToolTipInformation(ISSUE_PROPERTY_NAME, SHOW_TOOLTIP,
                    TOOLTIP_DATATYPE);
            propertyToolTipInformation.setPropertyValue(errorMessages);
            validationStatus = false;
        }

        component.getTooltipInformation().put(ISSUE_PROPERTY_NAME, propertyToolTipInformation);
    }

    return validationStatus;
}

From source file:adalid.util.i18n.Mapper.java

private String base(File bundle) {
    String name = bundle.getName();
    String base = _project + FILE_SEPARATOR;
    base += StringUtils.substringAfterLast(bundle.getParent(), join(_project));
    if (name.contains("_")) {
        base = base + FILE_SEPARATOR + StringUtils.substringBefore(name, "_");
    } else {//from   ww w  .java 2  s  .  c  o m
        base = base + FILE_SEPARATOR + StringUtils.substringBeforeLast(name, ".");
    }
    return base;
}

From source file:info.magnolia.cms.beans.config.URI2RepositoryMapping.java

/**
 * Create a node handle based on an uri.
 *//*from   w  ww. j a  v a 2 s .c o  m*/
public String getHandle(String uri) {
    String handle;
    handle = StringUtils.removeStart(uri, this.URIPrefix);
    if (StringUtils.isNotEmpty(this.handlePrefix)) {
        StringUtils.removeStart(handle, "/");
        handle = this.handlePrefix + "/" + handle;
    }
    //remove extension (ignore . anywhere else in the uri)
    String fileName = StringUtils.substringAfterLast(handle, "/");
    String extension = StringUtils.substringAfterLast(fileName, ".");
    handle = StringUtils.removeEnd(handle, "." + extension);
    handle = cleanHandle(handle);

    try {
        final Session session = MgnlContext.getJCRSession(this.repository);
        if (!session.itemExists(handle)) {
            String maybeHandle = (this.handlePrefix.endsWith("/") ? "/" : "")
                    + StringUtils.removeStart(handle, this.handlePrefix);
            // prefix might have been prepended incorrectly. Second part of the condition is there to match links to binary nodes
            if (session.itemExists(maybeHandle) || (maybeHandle.lastIndexOf("/") > 0
                    && session.itemExists(StringUtils.substringBeforeLast(maybeHandle, "/")))) {
                return maybeHandle;
            }
        }
    } catch (RepositoryException e) {
        //Log the exception and return handle
        log.debug(e.getMessage(), e);
    }
    return handle;
}

From source file:ips1ap101.lib.base.BaseBundle.java

public static String getOpcionOrdenFuncionSelect(String key) {
    String string = getString(key, OPCION_ORDEN_FUNCION_SELECT);
    if (string == null) {
        String dominio = StringUtils.substringBeforeLast(key, ".");
        if (key.equals(dominio)) {
        } else {/*ww w.  jav  a  2s .c o  m*/
            string = getString(dominio, OPCION_ORDEN_FUNCION_SELECT);
        }
    }
    if (string == null) {
        string = getString(DEFAULT, OPCION_ORDEN_FUNCION_SELECT);
    }
    return string;
}

From source file:adalid.util.i18n.Mapper.java

private String locale(String name) {
    String substringBeforeLast = StringUtils.substringBeforeLast(name, ".");
    String substringAfter = StringUtils.substringAfter(substringBeforeLast, "_");
    return StringUtils.trimToNull(substringAfter);
}

From source file:info.magnolia.cms.module.ModuleUtil.java

public static void registerProperties(HierarchyManager hm, Map map)
        throws AccessDeniedException, PathNotFoundException, RepositoryException {
    for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
        String key = (String) iter.next();
        String value = (String) map.get(key);

        String name = StringUtils.substringAfterLast(key, "."); //$NON-NLS-1$
        String path = StringUtils.substringBeforeLast(key, ".").replace('.', '/'); //$NON-NLS-1$
        Content node = ContentUtil.createPath(hm, path);
        node.createNodeData(name).setValue(value);
    }//from  ww w.jav a 2 s  .  c  o  m
}

From source file:com.adobe.acs.commons.mcp.impl.processes.renovator.MovingPage.java

private void movePageChildren(ResourceResolver rr, ResourceResolver res) throws MovingException {
    Resource source;/*from   w  ww .  jav a2  s .  c  o m*/
    source = rr.getResource(getSourcePath());
    try {
        if (source != null && source.hasChildren()) {
            for (Resource child : source.getChildren()) {
                if (!hasChild(child.getPath())) {
                    String childDestination = child.getPath().replaceAll(getSourcePath(), getDestinationPath());
                    String childDestinationParent = StringUtils.substringBeforeLast(childDestination, "/");
                    if (!resourceExists(res, childDestination)) {
                        waitUntilResourceFound(res, childDestinationParent);
                        res.move(child.getPath(), childDestination);
                    }
                }
            }
            res.commit();
        }
    } catch (PersistenceException e) {
        throw new MovingException(getSourcePath(), e);
    }
}

From source file:com.qualitesys.sonarqcr4pblplugin.pbl.PblFile.java

public boolean matchFilePattern(String antPattern) {
    String patternWithoutFileSuffix = StringUtils.substringBeforeLast(antPattern, ".");
    WildcardPattern matcher = WildcardPattern.create(patternWithoutFileSuffix, ".");
    return matcher.match(getKey());
}

From source file:gobblin.aws.AWSJobConfigurationManagerTest.java

@Test(enabled = false)
private String getJobConfigZipUri(File source) throws IOException {
    final File destination = new File(
            StringUtils.substringBeforeLast(source.toString(), File.separator) + File.separator + URI_ZIP_NAME);
    if (destination.exists()) {
        if (!destination.delete()) {
            throw new IOException("Cannot clean destination job conf zip file: " + destination);
        }//from w  w  w.  j a v a 2s. co m
    }
    FileUtils.copyFile(source, destination);

    return destination.toURI().toString();
}

From source file:com.qualitesys.sonarqcr4pblplugin.pbl.PblFile.java

/**
 * Creates a {@link PblFile} from a file in the source directories.
 *
 * @param unitTest whether it is a unit test file or a source file
 * @return the {@link PblFile} created if exists, null otherwise
 *//*from w  ww .  ja v a 2 s  .  c  o  m*/
public static PblFile fromIOFile(File file, List<File> sourceDirs, boolean unitTest) {
    if (file == null) {
        return null;
    }
    //System.out.println("PblFile fromIOFile file "+file+" sourceDirs "+sourceDirs.toString());
    String relativePath = DefaultProjectFileSystem.getRelativePath(file, sourceDirs);
    if (relativePath != null) {
        String pacname = null;
        String classname = relativePath;

        if (relativePath.indexOf('/') >= 0) {
            pacname = StringUtils.substringBeforeLast(relativePath, "/");
            pacname = StringUtils.replace(pacname, "/", ".");
            classname = StringUtils.substringAfterLast(relativePath, "/");
        }
        // Modif D.C. 01 11 2010 en Pb deux fichiers peuvent avoir le meme nom
        // et des extensions differentes. On garde l'extension
        //classname = StringUtils.substringBeforeLast(classname, ".");
        return new PblFile(pacname, classname, unitTest);
    }
    return null;
}