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

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

Introduction

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

Prototype

public static boolean endsWith(String str, String suffix) 

Source Link

Document

Check if a String ends with a specified suffix.

Usage

From source file:org.rapidcontext.app.web.StorageWebService.java

/**
 * Attempts to correct or normalize the specified path if no data
 * can be found at the specified location. This is necessary in
 * order to provide "*.properties" file access to data objects
 * and to adjust for some WebDAV client bugs.
 *
 * @param path           the path to normalize
 *
 * @return the normalized path/* w w w . j av  a 2  s.c  o  m*/
 */
private Path normalizePath(Path path) {
    Storage storage = ApplicationContext.getInstance().getStorage();
    String pathName = path.name();
    Path lookupPath = path;
    Metadata meta = storage.lookup(lookupPath);
    if (meta == null) {
        String str = pathName;
        if (StringUtils.endsWith(str, EXT_HTML)) {
            str = StringUtils.removeEnd(str, EXT_HTML);
        } else if (StringUtils.endsWith(str, EXT_JSON)) {
            str = StringUtils.removeEnd(str, EXT_JSON);
        } else if (StringUtils.endsWith(str, EXT_PROPERTIES)) {
            str = StringUtils.removeEnd(str, EXT_PROPERTIES);
        } else if (StringUtils.endsWith(str, EXT_XML)) {
            str = StringUtils.removeEnd(str, EXT_XML);
        }
        if (!StringUtils.equals(pathName, str)) {
            lookupPath = path.parent().child(str, false);
            meta = storage.lookup(lookupPath);
            if (meta == null && "index".equals(str)) {
                lookupPath = path.parent();
                meta = storage.lookup(lookupPath);
            }
        }
    }
    // Fix for Windows WebDAV (omitting trailing /)
    if (meta == null && !path.isIndex()) {
        lookupPath = path.parent().child(pathName, true);
        meta = storage.lookup(lookupPath);
    }
    return (meta == null) ? null : lookupPath;
}

From source file:org.roche.antibody.tests.DomainServiceTest.java

@Test
public void testAddDomainLast() throws Exception {
    String sequenceToTest = "APRILCLARSCSTEFANC";
    String newSequence = "STEFANC";
    Peptide pep = TestSuite.getTestPeptide();
    Domain dom = ds.addAsLastDomain(newSequence, pep);
    assertTrue(StringUtils.endsWith(dom.getPeptide().getSequence(), newSequence));
    assertEquals("Wrong Sequence in Peptide", sequenceToTest, pep.getSequence());
    assertEquals("Wrong startPosition in Domain", 12, dom.getStartPosition());
    assertEquals("Wrong endPosition in Domain", 7, dom.getEndPosition());
    assertEquals("Wrong Peptide", pep, dom.getPeptide());
    assertEquals("Two domains expected!", 2, pep.getDomains().size());
    assertEquals("Domain is not on last position", dom, pep.getDomains().get(pep.getDomains().size() - 1));
    assertEquals("DomainName should be " + "NN (7AAs)", "NN (7AAs)", dom.getName());
    // we check the index offset of the second domain
    assertEquals(1, pep.getDomains().get(FIRST).getStartPosition());
    assertEquals(11, pep.getDomains().get(FIRST).getEndPosition());
    // we check the connection if indexes were updated
    assertEquals(6, pep.getConnections().get(FIRST).getSourcePosition());
    assertEquals(11, pep.getConnections().get(FIRST).getTargetPosition());
}

From source file:org.sakaiproject.archive.impl.ArchiveService2Impl.java

/*******************************************************************************
* Init and Destroy/*from w w  w  .  j a  va2 s  .  c  o m*/
*******************************************************************************/
public void init() {

    m_storagePath = m_serverConfigurationService.getString("archive.storage.path", m_storagePath);
    if (!StringUtils.endsWith(m_storagePath, "/")) {
        m_storagePath = m_storagePath + "/";
    }

    m_unzipPath = m_serverConfigurationService.getString("archive.unzip.path", m_unzipPath);
    if (!StringUtils.endsWith(m_unzipPath, "/")) {
        m_unzipPath = m_unzipPath + "/";
    }

    m_filterSakaiServices = m_serverConfigurationService.getBoolean("archive.merge.filter.services",
            m_filterSakaiServices);
    m_filterSakaiRoles = m_serverConfigurationService.getBoolean("archive.merge.filter.roles",
            m_filterSakaiRoles);
    String[] filteredServices = m_serverConfigurationService.getStrings("archive.merge.filtered.services");
    if (filteredServices != null) {
        m_filteredSakaiServices = filteredServices;
    }
    String[] filteredRoles = m_serverConfigurationService.getStrings("archive.merge.filtered.roles");
    if (filteredRoles != null) {
        m_filteredSakaiRoles = filteredRoles;
    }

    M_log.info("init(): storage path: " + m_storagePath + ", unzip path: " + m_unzipPath
            + ", merge filter{services=" + m_filterSakaiServices + ", roles=" + m_filterSakaiRoles + "}");
}

From source file:org.sakaiproject.calendaring.api.ExternalCalendaringServiceImpl.java

/**
 * Helper to create the name of the ICS file we are to write
 * @param filename//  w w  w.  j a  v  a 2  s  .c  o m
 * @return
 */
private String generateFilePath(String filename) {
    StringBuilder sb = new StringBuilder();

    String base = sakaiProxy.getCalendarFilePath();
    sb.append(base);

    //add slash if reqd
    if (!StringUtils.endsWith(base, File.separator)) {
        sb.append(File.separator);
    }

    sb.append(filename);
    sb.append(".ics");
    return sb.toString();
}

From source file:org.sakaiproject.calendaring.logic.SakaiProxyImpl.java

/**
 * {@inheritDoc}/* ww w .j a v a 2 s. c  om*/
 */
public String getCalendarFilePath() {
    String path = serverConfigurationService.getString("calendar.ics.generation.path",
            System.getProperty("java.io.tmpdir"));
    //ensure trailing slash
    if (!StringUtils.endsWith(path, File.separator)) {
        path = path + File.separator;
    }
    return path;
}

From source file:org.sakaiproject.component.app.scheduler.jobs.cm.processor.BaseProcessor.java

public String getReport(ProcessorState state) {
    StringBuilder reportTxt = new StringBuilder();
    reportTxt.append("\n").append(getProcessorTitle()).append("\n");

    if (state == null) {
        reportTxt.append(//from   w  ww  . j  a v a  2  s.  c  o m
                "\n\nProcessor state appears not to have created successfully. No reporting data is available.\n");

        return reportTxt.toString();
    }

    Map<String, Object> config = state.getConfiguration();
    reportTxt.append("\nConfiguration:\n");

    for (String key : config.keySet()) {
        // filter out the large temporary maps
        if (StringUtils.equals(key, "path.base") || StringUtils.endsWith(key, ".filename")) {
            reportTxt.append(String.format("%1$-105s => %2$s%n", key, config.get(key).toString()));
        }
    }

    reportTxt.append("\nResults:\n");
    reportTxt.append(String.format("%1$-20s%2$d%n", "Records", state.getRecordCnt()));
    reportTxt.append(String.format("%1$-20s%2$d%n", "Processed", state.getProcessedCnt()));
    reportTxt.append(String.format("%1$-20s%2$d%n", "Errors", state.getErrorCnt()));
    reportTxt.append(String.format("%1$-20s%2$d%n", "Inserts", state.getInsertCnt()));
    reportTxt.append(String.format("%1$-20s%2$d%n", "Updates", state.getUpdateCnt()));
    reportTxt.append(String.format("%1$-20s%2$d%n", "Unchanged", state.getIgnoreCnt()));
    reportTxt.append(String.format("%1$-20s%2$d%n", "Deletes", state.getDeleteCnt()));
    reportTxt.append(String.format("%1$-20s%2$tc%n", "Start", state.getStartDate()));
    reportTxt.append(String.format("%1$-20s%2$tc%n", "End", state.getEndDate()));

    reportTxt.append("\nMessages:\n");
    for (String error : state.getErrorList()) {
        reportTxt.append("\n* " + error);
    }

    return reportTxt.toString();
}

From source file:org.sakaiproject.lap.util.FileUtils.java

/**
 * Add a trailing slash to the end of the path, if none exists
 * //  ww w  .j  ava 2 s  . com
 * @param path the path string
 * @return the path with a trailing slash
 */
public static String addTrailingSlash(String path) {
    if (!StringUtils.endsWith(path, System.getProperty("file.separator"))) {
        path += System.getProperty("file.separator");
    }

    return path;
}

From source file:org.sakaiproject.oaai.service.FileService.java

private String addTrailingSlash(String path) {
    if (!StringUtils.endsWith(path, "/")) {
        path += "/";
    }//from   ww  w . j  a v  a  2s.  c  o m

    return path;
}

From source file:org.sakaiproject.site.tool.SiteAction.java

/**
 * Handles uploading an archive file as part of the site creation workflow
 * @param data// www . j  a v a2s .c  om
 */
public void doUploadArchive(RunData data) {
    ParameterParser params = data.getParameters();
    SessionState state = ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());

    //get params
    FileItem fi = data.getParameters().getFileItem("importFile");

    //get uploaded file into a location we can process
    String archiveUnzipBase = ServerConfigurationService.getString("archive.storage.path",
            FileUtils.getTempDirectoryPath());

    //convert inputstream into actual file so we can unzip it
    String zipFilePath = archiveUnzipBase + File.separator + fi.getFileName();

    //rudimentary check that the file is a zip file
    if (!StringUtils.endsWith(fi.getFileName(), ".zip")) {
        addAlert(state, rb.getString("archive.createsite.failedupload"));
        return;
    }

    File tempZipFile = new File(zipFilePath);
    if (tempZipFile.exists()) {
        tempZipFile.delete();
    }

    FileOutputStream fileOutputStream = null;
    try {
        fileOutputStream = new FileOutputStream(tempZipFile);
        //copy contents into this file
        IOUtils.copyLarge(fi.getInputStream(), fileOutputStream);

        //set path into state so we can process it later
        state.setAttribute(STATE_UPLOADED_ARCHIVE_PATH, tempZipFile.getAbsolutePath());
        state.setAttribute(STATE_UPLOADED_ARCHIVE_NAME, tempZipFile.getName());

    } catch (Exception e) {
        M_log.error(e.getMessage(), e); //general catch all for the various exceptions that occur above. all are failures.
        addAlert(state, rb.getString("archive.createsite.failedupload"));
    } finally {
        IOUtils.closeQuietly(fileOutputStream);
    }

    //go to confirm screen
    state.setAttribute(STATE_TEMPLATE_INDEX, "10");
}

From source file:org.seedstack.seed.security.internal.authorization.ConfigurationRoleMapping.java

/**
 * Finds the scope in a string that corresponds to a role with {wildcard}.<br>
 * For example, if wildcardAuth is toto.{SCOPE} and auth is toto.foo then
 * scope is foo./*from   w ww .  j  a v  a 2  s. c  o  m*/
 *
 * @param wildcard     the wildcard to search for
 * @param wildcardAuth auth with {wildcard}
 * @param auth         auth that corresponds
 * @return the scope.
 */
private String findScope(String wildcard, String wildcardAuth, String auth) {
    String scope;
    String before = StringUtils.substringBefore(wildcardAuth, wildcard);
    String after = StringUtils.substringAfter(wildcardAuth, wildcard);
    if (StringUtils.startsWith(wildcardAuth, wildcard)) {
        scope = StringUtils.substringBefore(auth, after);
    } else if (StringUtils.endsWith(wildcardAuth, wildcard)) {
        scope = StringUtils.substringAfter(auth, before);
    } else {
        scope = StringUtils.substringBetween(auth, before, after);
    }
    return scope;
}