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

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

Introduction

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

Prototype

public static String removeEnd(String str, String remove) 

Source Link

Document

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

Usage

From source file:com.cloudbees.plugins.credentials.ContextMenuIconUtils.java

/**
 * Combine segments of an URL in the style expected by {@link ModelObjectWithContextMenu.MenuItem}.
 *
 * @param segments the segments.//from  w w  w.  ja  v a  2s.  c o m
 * @return the combined URL.
 */
@NonNull
public static String buildUrl(String... segments) {
    StringBuilder result = new StringBuilder();
    boolean first = true;
    for (String segment : segments) {
        if (segment == null) {
            continue;
        }
        String str = StringUtils.removeEnd(StringUtils.removeStart(segment, "/"), "/");
        if (str.isEmpty()) {
            continue;
        }
        if (first) {
            first = false;
        } else {
            result.append('/');
        }
        result.append(str);
    }
    return result.toString();
}

From source file:com.adobe.acs.commons.users.impl.AbstractAuthorizable.java

public AbstractAuthorizable(Map<String, Object> config) throws EnsureAuthorizableException {
    String tmp = PropertiesUtil.toString(config.get(EnsureServiceUser.PROP_PRINCIPAL_NAME), null);

    if (StringUtils.contains(tmp, "/")) {
        tmp = StringUtils.removeStart(tmp, getDefaultPath());
        tmp = StringUtils.removeStart(tmp, "/");
        this.principalName = StringUtils.substringAfterLast(tmp, "/");
        this.intermediatePath = PathUtil.makePath(getDefaultPath(),
                StringUtils.removeEnd(tmp, this.principalName));
    } else {//ww w. j  a  v  a2 s. c  o  m
        this.principalName = tmp;
        this.intermediatePath = getDefaultPath();
    }

    // Check the principal name for validity
    if (StringUtils.isBlank(this.principalName)) {
        throw new EnsureAuthorizableException("No Principal Name provided to Ensure Service User");
    } else if (ProtectedAuthorizables.isProtected(this.principalName)) {
        throw new EnsureAuthorizableException(String.format(
                "[ %s ] is an System User provided by AEM or ACS AEM Commons. You cannot ensure this user.",
                this.principalName));
    }

    final String[] acesProperty = PropertiesUtil.toStringArray(config.get(EnsureServiceUser.PROP_ACES),
            new String[0]);
    for (String entry : acesProperty) {
        if (StringUtils.isNotBlank(entry)) {
            try {
                aces.add(new Ace(entry));
            } catch (EnsureAuthorizableException e) {
                log.warn("Malformed ACE config [ " + entry + " ] for Service User [ "
                        + StringUtils.defaultIfEmpty(this.principalName, "NOT PROVIDED") + " ]", e);
            }
        }
    }
}

From source file:com.aqnote.shared.cryptology.cert.tool.PrivateKeyTool.java

private static byte[] getKeyEncoded(String base64KeyFile) {
    if (StringUtils.isEmpty(base64KeyFile)) {
        return null;
    }/*  w  w w. j  a  v  a  2 s . c  o  m*/

    String tmpBase64KeyFile = base64KeyFile;
    String headLine = BEGIN_KEY + lineSeparator;
    if (base64KeyFile.startsWith(headLine)) {
        tmpBase64KeyFile = StringUtils.removeStart(base64KeyFile, headLine);
    }
    headLine = BEGIN_KEY + "\r\n";
    if (base64KeyFile.startsWith(headLine)) {
        tmpBase64KeyFile = StringUtils.removeStart(base64KeyFile, headLine);
    }

    if (tmpBase64KeyFile.endsWith(END_KEY)) {
        tmpBase64KeyFile = StringUtils.removeEnd(base64KeyFile, END_KEY);
    }

    return Base64.decodeBase64(tmpBase64KeyFile);
}

From source file:com.cloudbees.maven.release.policy.impl.CloudBeesVersionPolicy.java

/**
 * {@inheritDoc}//from  w w  w .j a  va 2 s  .co m
 */
public VersionPolicyResult getReleaseVersion(VersionPolicyRequest versionPolicyRequest)
        throws PolicyException, VersionParseException {
    // this one is easy, just always throw away the -SNAPSHOT
    return new VersionPolicyResult()
            .setVersion(StringUtils.removeEnd(versionPolicyRequest.getVersion(), "-SNAPSHOT"));
}

From source file:com.adobe.acs.commons.users.impl.ServiceUser.java

public ServiceUser(Map<String, Object> config) throws EnsureServiceUserException {
    String tmp = PropertiesUtil.toString(config.get(EnsureServiceUser.PROP_PRINCIPAL_NAME), null);

    if (StringUtils.contains(tmp, "/")) {
        tmp = StringUtils.removeStart(tmp, PATH_SYSTEM_USERS);
        tmp = StringUtils.removeStart(tmp, "/");
        this.principalName = StringUtils.substringAfterLast(tmp, "/");
        this.intermediatePath = PathUtil.makePath(PATH_SYSTEM_USERS,
                StringUtils.removeEnd(tmp, this.principalName));
    } else {//from   ww  w. ja va  2s  . c om
        this.principalName = tmp;
        this.intermediatePath = "/home/users/system";
    }

    // Check the principal name for validity
    if (StringUtils.isBlank(this.principalName)) {
        throw new EnsureServiceUserException("No Principal Name provided to Ensure Service User");
    } else if (ProtectedSystemUsers.isProtected(this.principalName)) {
        throw new EnsureServiceUserException(String.format(
                "[ %s ] is an System User provided by AEM or ACS AEM Commons. You cannot ensure this user.",
                this.principalName));
    }

    final String[] acesProperty = PropertiesUtil.toStringArray(config.get(EnsureServiceUser.PROP_ACES),
            new String[0]);
    for (String entry : acesProperty) {
        try {
            aces.add(new Ace(entry));
        } catch (EnsureServiceUserException e) {
            log.warn("Malformed ACE config [ " + entry + " ] for Service User [ "
                    + StringUtils.defaultIfEmpty(this.principalName, "NOT PROVIDED") + " ]", e);
        }
    }
}

From source file:com.abiquo.api.handlers.CheckLinksPermissionsHandler.java

@Override
public void handleResponse(final MessageContext msgContext) throws Throwable {
    if (msgContext.getResponseEntity() != null
            && msgContext.getResponseEntity() instanceof SingleResourceTransportDto) {
        SingleResourceTransportDto srtDto = (SingleResourceTransportDto) msgContext.getResponseEntity();
        if (srtDto != null) {
            String baseUri = StringUtils.removeEnd(msgContext.getUriInfo().getBaseUri().toString(), SLASH);
            if (srtDto instanceof WrapperDto<?>) {
                for (Object obj : ((WrapperDto<?>) srtDto).getCollection()) {
                    if (obj instanceof SingleResourceTransportDto) {
                        SingleResourceTransportDto srt = (SingleResourceTransportDto) obj;
                        srt.setLinks(checkLinks(srt.getLinks(), baseUri));
                    }/*  w ww  . j a  v a2  s .co m*/
                }
            } else if (srtDto.getLinks() != null) {
                srtDto.setLinks(checkLinks(srtDto.getLinks(), baseUri));
            }
        }
    }
    super.handleResponse(msgContext);
}

From source file:com.intel.cosbench.driver.iterator.NumericNameIterator.java

@Override
public String next(String curr, int idx, int all) {
    int value;/*from  ww w  .j  a v  a 2s. c  o  m*/
    if (StringUtils.isEmpty(curr)) {
        if ((value = iterator.next(0, idx, all)) <= 0)
            return null;
        return StringUtils.join(new Object[] { prefix, value, suffix });
    }
    curr = StringUtils.removeStart(curr, prefix);
    curr = StringUtils.removeEnd(curr, suffix);
    if ((value = iterator.next(Integer.parseInt(curr), idx, all)) <= 0)
        return null;
    return StringUtils.join(new Object[] { prefix, value, suffix });
}

From source file:com.hangum.tadpole.rdb.core.actions.object.rdb.object.TableColumnSelectionAction.java

@Override
public void run(IStructuredSelection selection, UserDBDAO userDB, OBJECT_TYPE actionType) {
    if (selection.isEmpty())
        return;//from   w  w w . java 2s.c o m

    String strColumnName = "";
    Object[] arryObj = selection.toArray();
    for (int i = 0; i < arryObj.length; i++) {
        Object obj = arryObj[arryObj.length - i - 1];

        TableColumnDAO tcDAO = (TableColumnDAO) obj;
        strColumnName += tcDAO.getField() + ", "; //$NON-NLS-1$
    }
    strColumnName = StringUtils.removeEnd(strColumnName, ", "); //$NON-NLS-1$

    FindEditorAndWriteQueryUtil.runAtPosition(strColumnName);
}

From source file:com.aqnote.shared.encrypt.cert.bc.loader.CaCertLoader.java

public synchronized static String getB64CaCrt() throws IOException {
    if (StringUtils.isBlank(b64CaCrt)) {
        ClassLoader classLoader = ClassLoaderUtil.getClassLoader();
        InputStream is = classLoader.getResourceAsStream(CA_CRT_FILE);
        b64CaCrt = StreamUtil.stream2Bytes(is, StandardCharsets.UTF_8);
        b64CaCrt = StringUtils.removeStart(b64CaCrt, BEGIN_CERT);
        b64CaCrt = StringUtils.removeEnd(b64CaCrt, END_CERT);
    }//from  w w w  .ja va 2s.  c  om
    return b64CaCrt;
}

From source file:com.hangum.tadpole.rdb.core.actions.object.rdb.object.ObjectExplorerSelectionToEditorAction.java

@Override
public void run(IStructuredSelection selection, UserDBDAO userDB, OBJECT_TYPE actionType) {
    if (selection.isEmpty())
        return;/*from  w w w  . ja  v  a  2  s .c o  m*/

    String strObjectName = "";
    Object[] arryObj = selection.toArray();

    if (arryObj[0] instanceof StructObjectDAO) {
        for (int i = 0; i < arryObj.length; i++) {
            StructObjectDAO tcDAO = (StructObjectDAO) arryObj[i];
            strObjectName += tcDAO.getFullName() + ", "; //$NON-NLS-1$
        }
    }

    strObjectName = StringUtils.removeEnd(strObjectName, ", "); //$NON-NLS-1$
    FindEditorAndWriteQueryUtil.runAtPosition(strObjectName);
}