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

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

Introduction

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

Prototype

public static String substring(String str, int start, int end) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

Usage

From source file:org.cesecore.certificates.ca.X509CA.java

/**
 * Constructs the SubjectAlternativeName extension that will end up on the generated certificate.
 * /*from   w  ww  . j av a2 s  . co m*/
 * If the DNS values in the subjectAlternativeName extension contain parentheses to specify labels that should be redacted, the parentheses are removed and another extension 
 * containing the number of redacted labels is added.
 * 
 * @param subAltNameExt
 * @param publishToCT
 * @return An extension generator containing the SubjectAlternativeName extension and an extension holding the number of redacted labels if the certificate is to be published 
 * to a CTLog
 * @throws IOException
 */
private ExtensionsGenerator getSubjectAltNameExtensionForCert(Extension subAltNameExt, boolean publishToCT)
        throws IOException {
    String subAltName = CertTools.getAltNameStringFromExtension(subAltNameExt);
    List<String> dnsValues = CertTools.getPartsFromDN(subAltName, CertTools.DNS);
    int[] nrOfRecactedLables = new int[dnsValues.size()];
    boolean sanEdited = false;
    int i = 0;
    for (String dns : dnsValues) {
        if (StringUtils.contains(dns, "(") && StringUtils.contains(dns, ")")) { // if it contains parts that should be redacted
            // Remove the parentheses from the SubjectAltName that will end up on the certificate
            String certBuilderDNSValue = StringUtils.remove(dns, '(');
            certBuilderDNSValue = StringUtils.remove(certBuilderDNSValue, ')');
            subAltName = StringUtils.replace(subAltName, dns, certBuilderDNSValue);
            sanEdited = true;
            if (publishToCT) {
                String redactedLable = StringUtils.substring(dns, StringUtils.indexOf(dns, "("),
                        StringUtils.lastIndexOf(dns, ")") + 1); // tex. (top.secret).domain.se => redactedLable = (top.secret) aka. including the parentheses 
                nrOfRecactedLables[i] = StringUtils.countMatches(redactedLable, ".") + 1;
            }
        }
        i++;
    }
    ExtensionsGenerator gen = new ExtensionsGenerator();
    gen.addExtension(Extension.subjectAlternativeName, subAltNameExt.isCritical(),
            CertTools.getGeneralNamesFromAltName(subAltName));
    // If there actually are redacted parts, add the extension containing the number of redacted lables to the certificate 
    if (publishToCT && sanEdited) {
        ASN1EncodableVector v = new ASN1EncodableVector();
        for (int val : nrOfRecactedLables) {
            v.add(new ASN1Integer(val));
        }
        ASN1Encodable seq = new DERSequence(v);
        gen.addExtension(new ASN1ObjectIdentifier("1.3.6.1.4.1.11129.2.4.6"), false, seq);
    }

    return gen;
}

From source file:org.cesecore.certificates.ca.X509CA.java

/**
 * Constructs the SubjectAlternativeName extension that will end up on the certificate published to a CTLog
 * /*from  w w  w.j  av a2 s .c o  m*/
 * If the DNS values in the subjectAlternativeName extension contain parentheses to specify labels that should be redacted, these labels will be replaced by the string "PRIVATE" 
 * 
 * @param subAltNameExt
 * @returnAn extension generator containing the SubjectAlternativeName extension
 * @throws IOException
 */
private ExtensionsGenerator getSubjectAltNameExtensionForCTCert(Extension subAltNameExt) throws IOException {
    String subAltName = CertTools.getAltNameStringFromExtension(subAltNameExt);

    List<String> dnsValues = CertTools.getPartsFromDN(subAltName, CertTools.DNS);
    for (String dns : dnsValues) {
        if (StringUtils.contains(dns, "(") && StringUtils.contains(dns, ")")) { // if it contains parts that should be redacted
            String redactedLable = StringUtils.substring(dns, StringUtils.indexOf(dns, "("),
                    StringUtils.lastIndexOf(dns, ")") + 1); // tex. (top.secret).domain.se => redactedLable = (top.secret) aka. including the parentheses 
            subAltName = StringUtils.replace(subAltName, redactedLable, "(PRIVATE)");
        }
    }

    ExtensionsGenerator gen = new ExtensionsGenerator();
    gen.addExtension(Extension.subjectAlternativeName, subAltNameExt.isCritical(),
            CertTools.getGeneralNamesFromAltName(subAltName).getEncoded());
    return gen;
}

From source file:org.cleverbus.api.asynch.msg.ChildMessage.java

@Override
public String toString() {
    return new ToStringBuilder(this).append("parentMessage", parentMessage).append("bindingType", bindingType)
            .append("service", service != null ? service.getServiceName() : null)
            .append("operationName", operationName).append("objectId", objectId)
            .append("entityType", entityType != null ? entityType.getEntityType() : null)
            .append("funnelValues", funnelValues).append("body", StringUtils.substring(body, 0, 500))
            .toString();//from w w  w. ja va2 s .  c  om
}

From source file:org.cloudbyexample.dc.agent.command.ImageIdMatcher.java

public String findId(String line) {
    String id = null;//from   w  w w .  j a v a 2  s . c  o m

    int matchIndex = StringUtils.indexOf(line, pattern);

    if (matchIndex > -1) {
        int start = matchIndex + pattern.length();
        int end = line.length() - 4;

        id = StringUtils.substring(line, start, end);
    }

    return id;
}

From source file:org.cloudbyexample.dc.shell.command.DockerContainerCommand.java

@CliCommand(value = CONTAINER_LIST_CMD, help = CONTAINER_LIST_HELP)
public String find() {
    DockerContainerFindResponse response = client.find();
    List<DockerContainer> results = response.getResults();

    StringBuilder sb = new StringBuilder();

    for (DockerContainer container : results) {
        sb.append(StringUtils.substring(container.getId(), 0, 10));
        sb.append(" ");
        sb.append(container.getImage());
        sb.append(" ");

        for (PortBindings port : container.getPorts()) {
            sb.append("  ");
            sb.append(port.getPublicPort());
            sb.append("->");
            sb.append(port.getPrivatePort());
            sb.append("/tcp");
        }//from   ww w  .j ava 2  s.c  o m

        sb.append("\n");
    }

    return sb.toString();
}

From source file:org.cloudbyexample.dc.shell.command.DockerImageCommand.java

@CliCommand(value = IMAGE_LIST_CMD, help = IMAGE_LIST_HELP)
public String find() {
    DockerImageFindResponse response = client.find();
    List<DockerImage> results = response.getResults();

    StringBuilder sb = new StringBuilder();

    for (DockerImage image : results) {
        // FIXME: move length of id substring to parent or util
        sb.append(StringUtils.substring(image.getId(), 0, 10));
        sb.append(" ");
        sb.append(Arrays.toString(image.getRepoTags().toArray(new String[] {})));
        sb.append("\n");
    }//w w  w  . j a v  a 2  s.  c  o m

    return sb.toString();
}

From source file:org.codice.proxy.http.HttpProxyCamelHttpTransportServlet.java

private String getEndpointNameFromPath(String path) {
    // path is like: "/example1/something/0/thing.html"
    // or is like: "/example1"
    // endpointName is: "example1"
    String endpointName = (StringUtils.indexOf(path, "/", 1) != StringUtils.INDEX_NOT_FOUND)
            ? StringUtils.substring(path, 0, StringUtils.indexOf(path, "/", 1))
            : path;//  w  w w . j av  a2 s  .com
    endpointName = StringUtils.remove(endpointName, "/");
    return endpointName;
}

From source file:org.commonjava.indy.httprox.util.ProxyResponseHelper.java

public TrackingKey getTrackingKey(UserPass proxyUserPass) throws IndyWorkflowException {
    TrackingKey tk = null;//from   ww  w  . j  a  v  a2s .c om
    switch (config.getTrackingType()) {
    case ALWAYS: {
        if (proxyUserPass == null) {
            throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(),
                    "Tracking is always-on, but no username was provided! Cannot initialize tracking key.");
        }

        tk = new TrackingKey(proxyUserPass.getUser());

        break;
    }
    case SUFFIX: {
        if (proxyUserPass != null) {
            final String user = proxyUserPass.getUser();

            if (user != null && user.endsWith(TRACKED_USER_SUFFIX)
                    && user.length() > TRACKED_USER_SUFFIX.length()) {
                tk = new TrackingKey(StringUtils.substring(user, 0, -TRACKED_USER_SUFFIX.length()));
            }
        }

        break;
    }
    default: {
    }
    }
    return tk;
}

From source file:org.commonjava.maven.galley.transport.htcli.ContentsFilteringTransferDecorator.java

/**
 * Checks if the given element is an artifact. Artifacts always starts with
 * &lt;artifactId&gt;-&lt;version&gt;.
 *///from ww  w  .  j a  v  a 2 s  .c o  m
private boolean isArtifact(final String element, final String artifactId, final String version) {
    if (element.endsWith("/")) {
        return false;
    }

    boolean isRemoteSnapshot = false;
    if (SnapshotUtils.isSnapshotVersion(version) && element.startsWith(artifactId + '-')
            && !element.startsWith(artifactId + '-' + version)) {
        final SnapshotPart snapshotPart = SnapshotUtils.extractSnapshotVersionPart(version);
        final int artIdLenght = artifactId.length() + 1 + version.length() - snapshotPart.getLiteral().length()
                + 1;
        isRemoteSnapshot = SnapshotUtils
                .isRemoteSnapshotVersionPart(StringUtils.substring(element, artIdLenght, artIdLenght + 17));
    }

    return element.startsWith(artifactId + '-' + version + '-')
            || element.startsWith(artifactId + '-' + version + '.') || isRemoteSnapshot;
}

From source file:org.craftercms.cstudio.alfresco.service.impl.CStudioNodeServiceImpl.java

@Override
public NodeRef createNewFolder(String fullPath, Map<QName, Serializable> nodeProperties) {
    int idx = StringUtils.lastIndexOf(fullPath, '/');
    String parentPath = StringUtils.substring(fullPath, 0, idx - 1);
    String folderName = StringUtils.substring(fullPath, idx + 1);
    if (!nodeProperties.containsKey(ContentModel.PROP_NAME)) {
        nodeProperties.put(ContentModel.PROP_NAME, folderName);
    }/*w  ww . ja  v a2 s.co m*/
    return createNewFolder(parentPath, folderName, nodeProperties);
}