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

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

Introduction

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

Prototype

public static String chop(String str) 

Source Link

Document

Remove the last character from a String.

Usage

From source file:org.kuali.rice.ksb.api.bus.support.AbstractServiceDefinition.java

@Override
public void validate() {

    if (this.serviceName == null && this.localServiceName == null) {
        throw new ConfigurationException("Must give a serviceName or localServiceName");
    }/*from  w  w w.  ja  v a2  s  . c  o m*/

    if (this.applicationId == null) {
        String applicationId = CoreConfigHelper.getApplicationId();
        if (applicationId == null) {
            throw new ConfigurationException("Must have an applicationId");
        }
        this.applicationId = applicationId;
    }

    if (this.instanceId == null) {
        String instanceId = CoreConfigHelper.getInstanceId();
        if (instanceId == null) {
            throw new ConfigurationException("Must have an instanceId");
        }
        this.instanceId = instanceId;
    }

    if (this.serviceName != null && this.localServiceName == null) {
        this.localServiceName = this.getServiceName().getLocalPart();
    }

    if (this.servicePath != null) {
        if (this.servicePath.endsWith("/")) {
            this.servicePath = StringUtils.chop(servicePath);
        }
        if (!this.servicePath.startsWith("/")) {
            this.servicePath = "/" + this.servicePath;
        }
    } else {
        // default the serivce path to namespace
        this.servicePath = "/";
    }

    // default to 'unspecified' service version
    if (StringUtils.isBlank(serviceVersion)) {
        setServiceVersion(CoreConstants.Versions.UNSPECIFIED);
    }

    LOG.debug("Validating service " + this.serviceName);

    if (this.endpointUrl == null) {
        String endPointURL = ConfigContext.getCurrentContextConfig().getEndPointUrl();
        if (endPointURL == null) {
            throw new ConfigurationException("Must provide a serviceEndPoint or serviceServletURL");
        }
        if (!endPointURL.endsWith("/")) {
            endPointURL += servicePath;
        } else {
            endPointURL = StringUtils.chop(endPointURL) + servicePath;
        }
        try {
            if (servicePath.equals("/")) {
                this.endpointUrl = new URL(endPointURL + this.getServiceName().getLocalPart());
            } else {
                this.endpointUrl = new URL(endPointURL + "/" + this.getServiceName().getLocalPart());
            }
        } catch (Exception e) {
            throw new ConfigurationException("Service Endpoint URL creation failed.", e);
        }

    }

    if (this.priority == null) {
        setPriority(5);
    }

    if (this.retryAttempts == null) {
        setRetryAttempts(0);
    }

    if (this.millisToLive == null) {
        setMillisToLive(new Long(-1));
    }

}

From source file:org.opennms.features.namecutter.NameCutter.java

public String trimByCamelCase(String name, Integer maxLength) {
    String result = "";
    String[] nameParts = StringUtils.splitByCharacterTypeCamelCase(name);
    Integer charsOver = name.length() - maxLength;
    for (int i = 0; i < charsOver; i++) {
        Integer largest = 0;//  w w w. j a v a  2s.  com
        Integer index = 0;
        for (int j = 0; j < nameParts.length; j++) {
            if (nameParts[j].length() > largest) {
                largest = nameParts[j].length();
                index = j;
            }
        }
        nameParts[index] = StringUtils.chop(nameParts[index]);
    }
    for (String namePart : nameParts) {
        result = result + namePart;
    }
    return result;
}

From source file:org.pentaho.di.job.entries.build.JobEntryBuildModel.java

public BiServerConnection environmentSubstitute(BiServerConnection conn) {
    if (conn == null) {
        return null;
    }/*  w w  w . ja  va  2s .c om*/
    BiServerConnection substituted = new BiServerConnection();
    // BiServerConnection always adds a trailing '/' if not there.. including vars
    String url = environmentSubstitute(conn.getUrl());
    if (StringUtils.endsWith(url, "//")) {
        url = StringUtils.chop(url);
    }
    substituted.setUrl(url);
    substituted.setUserId(environmentSubstitute(conn.getUserId()));
    substituted.setPassword(environmentSubstitute(conn.getPassword()));
    return substituted;
}

From source file:org.pentaho.di.ui.job.entries.common.ServerConnectionGroupWrapper.java

public BiServerConnection getBiServerConnection(boolean resolveVariables) {

    BiServerConnection biServerModel = new BiServerConnection();

    if (resolveVariables) {
        String url = this.jobMeta.environmentSubstitute(wPublishUrl.getText());
        if (StringUtils.endsWith(url, "//")) {
            url = StringUtils.chop(url);
        }//from w  ww .j  a v a 2s.c o m
        biServerModel.setUrl(url);
        biServerModel.setUserId(this.jobMeta.environmentSubstitute(wPublishUser.getText()));
        biServerModel.setPassword(this.jobMeta.environmentSubstitute(wPublishPassword.getText()));
    } else {
        biServerModel.setUrl(wPublishUrl.getText());
        biServerModel.setUserId(wPublishUser.getText());
        biServerModel.setPassword(wPublishPassword.getText());
    }

    return biServerModel;
}

From source file:org.sipfoundry.sipxconfig.site.ListWebTestCase.java

protected String buildEditId(String id) {
    return StringUtils.chop(m_idPrefix) + ":" + id;
}

From source file:org.sipfoundry.sipxconfig.test.SqlFileReader.java

public List<String> parse() throws IOException {
    List<String> sql = new ArrayList<String>();
    StringBuilder sqlLine = new StringBuilder();
    boolean eof = false;
    do {//  w ww  .  jav  a  2  s  .  c o m
        boolean eol = false;
        String line = m_in.readLine();
        if (line == null) {
            eol = true;
            eof = true;
        } else {
            line = line.trim();
            if (line.startsWith("--")) {
                continue;
            }
            if (line.endsWith(";")) {
                eol = true;
                line = StringUtils.chop(line);
            }
            if (sqlLine.length() > 0) {
                sqlLine.append(' ');
            }
            sqlLine.append(line);
        }
        if (eol && StringUtils.isNotBlank(line)) {
            sql.add(sqlLine.toString());
            sqlLine.setLength(0);
        }
    } while (!eof);
    return sql;
}

From source file:org.sonar.batch.RemoteServerMetadata.java

public RemoteServerMetadata(Server server) {
    serverUrl = server.getURL();
    if (serverUrl.endsWith("/")) {
        serverUrl = StringUtils.chop(serverUrl);
    }
}

From source file:org.sonar.dotnet.tools.commons.visualstudio.ModelFactory.java

/**
 * Gets all the projects in a solution.//w  w w.  jav  a2  s. co m
 * 
 * @param solutionFile
 *          the solution file
 * @param solutionContent
 *          the text content of the solution file
 * @return a list of projects
 * @throws IOException
 * @throws DotNetToolsException
 */
private static List<VisualStudioProject> getProjects(File solutionFile, String solutionContent,
        List<String> buildConfigurations) throws IOException, DotNetToolsException {

    File baseDirectory = solutionFile.getParentFile();

    // A pattern to extract the projects from a visual studion solution
    String projectExtractExp = "(Project.*?^EndProject$)";
    Pattern projectExtractPattern = Pattern.compile(projectExtractExp, Pattern.MULTILINE + Pattern.DOTALL);
    List<String> projectDefinitions = new ArrayList<String>();
    // Extracts all the projects from the solution
    Matcher globalMatcher = projectExtractPattern.matcher(solutionContent);
    while (globalMatcher.find()) {
        String projectDefinition = globalMatcher.group(1);
        projectDefinitions.add(projectDefinition);
    }

    // This pattern extracts the projects from a Visual Studio solution
    String normalProjectExp = "\\s*Project\\([^\\)]*\\)\\s*=\\s*\"([^\"]*)\"\\s*,\\s*\"([^\"]*?\\.csproj)\"";
    String webProjectExp = "\\s*Project\\([^\\)]*\\)\\s*=\\s*\"([^\"]*).*?ProjectSection\\(WebsiteProperties\\).*?"
            + "Debug\\.AspNetCompiler\\.PhysicalPath\\s*=\\s*\"([^\"]*)";
    Pattern projectPattern = Pattern.compile(normalProjectExp);
    Pattern webPattern = Pattern.compile(webProjectExp, Pattern.MULTILINE + Pattern.DOTALL);

    List<VisualStudioProject> result = new ArrayList<VisualStudioProject>();
    for (String projectDefinition : projectDefinitions) {
        // Looks for project files
        Matcher matcher = projectPattern.matcher(projectDefinition);
        if (matcher.find()) {
            String projectName = matcher.group(1);
            String projectPath = StringUtils.replace(matcher.group(2), "\\", File.separatorChar + "");

            File projectFile = new File(baseDirectory, projectPath);
            if (!projectFile.exists()) {
                throw new FileNotFoundException("Could not find the project file: " + projectFile);
            }
            VisualStudioProject project = getProject(projectFile, projectName, buildConfigurations);
            result.add(project);
        } else {
            // Searches the web project
            Matcher webMatcher = webPattern.matcher(projectDefinition);

            if (webMatcher.find()) {
                String projectName = webMatcher.group(1);
                String projectPath = webMatcher.group(2);
                if (projectPath.endsWith("\\")) {
                    projectPath = StringUtils.chop(projectPath);
                }
                File projectRoot = new File(baseDirectory, projectPath);
                VisualStudioProject project = getWebProject(baseDirectory, projectRoot, projectName,
                        projectDefinition);
                result.add(project);
            }
        }
    }
    return result;
}

From source file:org.sonar.flex.checks.asdoc.ASDocMemberCheck.java

/**
 * Verifies that for every method's parameter a "@param" tag followed by the parameter's name
 * is present in the ASDoc./*from  ww  w.j  a v a2s  . c o  m*/
 */
private void checkForParametersASDoc(ASDocCheck check, MethodASDoc methodASDoc, AstNode functionDef) {
    StringBuilder builder = new StringBuilder();

    for (AstNode parameter : Function.getParametersIdentifiers(functionDef)) {
        String paramValue = parameter.getTokenValue();

        if (!methodASDoc.isParameterDocumented(paramValue)) {
            builder.append(paramValue).append(", ");
        }
    }

    if (builder.length() > 0) {
        check.getContext().createLineViolation(check, "Add the missing \"@param\" ASDoc for: {0}.", functionDef,
                StringUtils.chop(builder.toString().trim()));
    }
}

From source file:org.sonar.plugins.cxx.coverage.BullseyeParser.java

private void recTreeWalk(String refPath, SMInputCursor folder, List<String> path,
        final Map<String, CoverageMeasuresBuilder> coverageData) throws XMLStreamException {
    SMInputCursor child = folder.childElementCursor();
    while (child.getNext() != null) {
        String folderChildName = child.getLocalName();
        String name = child.getAttrValue("name");
        path.add(name);//from  www.ja v a 2s .  com
        if (folderChildName.equalsIgnoreCase("src")) {
            String fileName = "";
            Iterator<String> iterator = path.iterator();
            while (iterator.hasNext()) {
                fileName += iterator.next() + "/";
            }

            fileName = StringUtils.chop(fileName);

            if ((new File(fileName)).isAbsolute()) {
                refPath = "";
            }
            CoverageMeasuresBuilder fileMeasuresBuilderIn = CoverageMeasuresBuilder.create();
            fileWalk(child, fileMeasuresBuilderIn);
            String normalPath = CxxUtils.normalizePath(refPath + fileName);
            if (normalPath != null) {
                coverageData.put(normalPath, fileMeasuresBuilderIn);
            }

        } else {
            recTreeWalk(refPath, child, path, coverageData);
        }
        path.remove(path.size() - 1);
    }
}