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

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

Introduction

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

Prototype

public static int lastIndexOf(String str, String searchStr) 

Source Link

Document

Finds the last index within a String, handling null.

Usage

From source file:org.artifactory.api.module.ModuleInfoUtils.java

/**
 * Constructs the module version pattern, starting from [baseRev] to [fileItegRev]
 *
 * @param itemPathPattern the item path containing all the tokens of a given repo layout
 * @return the tokens path representing the file name, empty string ("") in case of unsupported layout,
 *         Unsupported layout is one which [fileItegRev] is before [baseRev]
 *///from  www. j  a v a 2  s .  c o m
private static String getModuleVersionPattern(String itemPathPattern) {
    String wrappedBaseRevisionToken = RepoLayoutUtils.wrapKeywordAsToken(RepoLayoutUtils.BASE_REVISION);
    String wrappedFileItegRevToken = RepoLayoutUtils
            .wrapKeywordAsToken(RepoLayoutUtils.FILE_INTEGRATION_REVISION);
    int baseRevStartPos = StringUtils.lastIndexOf(itemPathPattern, wrappedBaseRevisionToken);
    int fileItegRevEndPos = StringUtils.lastIndexOf(itemPathPattern, wrappedFileItegRevToken);
    int indexOfClosingOptionalBracket = StringUtils.indexOf(itemPathPattern, ")", fileItegRevEndPos);
    if (indexOfClosingOptionalBracket > 0) {
        fileItegRevEndPos = indexOfClosingOptionalBracket + 1;
    }
    if (fileItegRevEndPos >= baseRevStartPos) {
        return StringUtils.substring(itemPathPattern, baseRevStartPos, fileItegRevEndPos);
    }

    return "";
}

From source file:org.beanfuse.struts2.route.Action.java

public String getNamespace() {
    String namespace = null;/*from w  w  w .  j a  va  2 s.  co m*/
    if (null != name) {
        namespace = name.substring(0, StringUtils.lastIndexOf(name, '/') + 1);
    }
    return namespace;
}

From source file:org.beangle.struts2.view.template.AbstractTemplateEngine.java

public String getParentTemplate(String template) {
    int start = StringUtils.indexOf(template, '/', 1) + 1;
    int end = StringUtils.lastIndexOf(template, '/');

    String parentTheme = (String) getThemeProps(template.substring(start, end)).get("parent");
    if (null == parentTheme)
        return null;
    return StrUtils.concat(template.substring(0, start), parentTheme, template.substring(end));
}

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

/**
 * Constructs the SubjectAlternativeName extension that will end up on the generated certificate.
 * //w  ww. j a va2  s .c  o  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 www  . ja v a 2s.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.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  va  2 s  .c  o  m
    return createNewFolder(parentPath, folderName, nodeProperties);
}

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

@Override
public NodeRef createNewFile(String fullPath, InputStream content, Map<QName, Serializable> nodeProperties) {
    int idx = StringUtils.lastIndexOf(fullPath, '/');
    String parentPath = StringUtils.substring(fullPath, 0, idx - 1);
    String fileName = StringUtils.substring(fullPath, idx + 1);
    if (!nodeProperties.containsKey(ContentModel.PROP_NAME)) {
        nodeProperties.put(ContentModel.PROP_NAME, fileName);
    }/*from  w  ww  . j  a v  a2  s.  c  o  m*/
    return createNewFile(parentPath, fileName, content, nodeProperties);
}

From source file:org.ebayopensource.turmeric.eclipse.resources.util.SOAClientConfigUtil.java

private static String getServiceNameFromClientConfigServiceName(String serviceName) {
    // this has bracket {namespace}serviceName
    if (StringUtils.lastIndexOf(serviceName, "}") != -1) {
        return StringUtils.substringAfterLast(serviceName, "}");
    }//from  w  w  w .j a v a  2s  .  co m
    return serviceName;
}

From source file:org.eclipse.skalli.testutil.HttpServerMock.java

@Override
public void run() {
    BufferedReader request = null;
    DataOutputStream response = null;
    try {/*from   ww  w. j  a va  2s.  c o  m*/
        server = new ServerSocket(port);
        while (true) {
            Socket connection = server.accept();

            request = new BufferedReader(new InputStreamReader(connection.getInputStream(), "ISO8859_1"));
            response = new DataOutputStream(connection.getOutputStream());

            String httpCode;
            String contentId = "";
            String requestLine = request.readLine();

            if (!StringUtils.startsWithIgnoreCase(requestLine, "GET")) {
                httpCode = "405";
            } else {
                String path = StringUtils.split(requestLine, " ")[1];
                int n = StringUtils.lastIndexOf(path, "/");
                contentId = StringUtils.substring(path, 1, n);
                httpCode = StringUtils.substring(path, n + 1);
            }

            String content = bodies.get(contentId);
            StringBuffer sb = new StringBuffer();
            sb.append("HTTP/1.1 ").append(httpCode).append(" CustomStatus\r\n");
            sb.append("Server: MiniMockUnitServer\r\n");
            sb.append("Content-Type: text/plain\r\n");
            if (content != null) {
                sb.append("Content-Length: ").append(content.length()).append("\r\n");
            }
            sb.append("Connection: close\r\n");
            sb.append("\r\n");
            if (content != null) {
                sb.append(content);
            }

            response.writeBytes(sb.toString());
            IOUtils.closeQuietly(response);
        }
    } catch (IOException e) {
        IOUtils.closeQuietly(request);
        IOUtils.closeQuietly(response);
    } finally {
        try {
            server.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.eclipse.wb.internal.rcp.model.jface.FieldEditorLabelsConstantsPropertyEditor.java

/**
 * @return the error message or <code>null</code>.
 *///from  w ww  .  jav a 2 s .  c o  m
private static String prepareLabelsFields(List<String> resultLabels, List<IField> resultFields,
        GenericProperty property, String text) throws Exception {
    IJavaProject javaProject;
    String topTypeName;
    {
        JavaInfo javaInfo = property.getJavaInfo();
        javaProject = javaInfo.getEditor().getJavaProject();
        TypeDeclaration typeDeclaration = JavaInfoUtils.getTypeDeclaration(javaInfo);
        topTypeName = AstNodeUtils.getFullyQualifiedName(typeDeclaration, false);
    }
    // prepare containers
    List<String> tmpLabels = Lists.newArrayList();
    List<IField> tmpFields = Lists.newArrayList();
    resultLabels.clear();
    resultFields.clear();
    // analyze each line
    String[] lines = StringUtils.split(text, Text.DELIMITER);
    for (String line : lines) {
        line = line.trim();
        String[] words = StringUtils.split(line);
        if (words.length < 2) {
            return MessageFormat.format(ModelMessages.FieldEditorLabelsConstantsPropertyEditor_errLabelField,
                    line);
        }
        // prepare "label" and "field" code
        int lastSpaceIndex = StringUtils.lastIndexOf(line, " ");
        String label = line.substring(0, lastSpaceIndex).trim();
        String fieldCode = line.substring(lastSpaceIndex).trim();
        // convert "fieldCode" into IField
        IField field;
        if (fieldCode.contains(".")) {
            String typeName = StringUtils.substringBeforeLast(fieldCode, ".");
            String fieldName = StringUtils.substringAfterLast(fieldCode, ".");
            field = CodeUtils.findField(javaProject, typeName, fieldName);
        } else {
            field = CodeUtils.findField(javaProject, topTypeName, fieldCode);
        }
        // we should have IField
        if (field == null) {
            return MessageFormat
                    .format(ModelMessages.FieldEditorLabelsConstantsPropertyEditor_errInvalidFieldName, line);
        }
        // add label/field
        tmpLabels.add(label);
        tmpFields.add(field);
    }
    // OK
    resultLabels.addAll(tmpLabels);
    resultFields.addAll(tmpFields);
    return null;
}