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

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

Introduction

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

Prototype

public static String removeStart(String str, String remove) 

Source Link

Document

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

Usage

From source file:com.github.sakserv.minicluster.impl.KnoxLocalCluster.java

public static boolean copyJarResourcesRecursively(final File destDir, final JarURLConnection jarConnection)
        throws IOException {

    final JarFile jarFile = jarConnection.getJarFile();

    for (final Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements();) {
        final JarEntry entry = e.nextElement();
        if (entry.getName().startsWith(jarConnection.getEntryName())) {
            final String filename = StringUtils.removeStart(entry.getName(), //
                    jarConnection.getEntryName());

            final File f = new File(destDir, filename);
            if (!entry.isDirectory()) {
                final InputStream entryInputStream = jarFile.getInputStream(entry);
                if (!copyStream(entryInputStream, f)) {
                    return false;
                }//  w w w. j  a v a  2  s  .  c  o  m
                entryInputStream.close();
            } else {
                if (!ensureDirectoryExists(f)) {
                    throw new IOException("Could not create directory: " + f.getAbsolutePath());
                }
            }
        }
    }
    return true;
}

From source file:com.fiveamsolutions.nci.commons.mojo.copywebfiles.CopyWebFilesMojo.java

/**
 * @param latestDeployDirectory/*from  ww w .j ava2 s  .  c om*/
 * @param fileFilter
 * @throws MojoExecutionException
 */
@SuppressWarnings("rawtypes")
private void copyFiles(File latestDeployDirectory, IOFileFilter fileFilter) throws MojoExecutionException {
    try {
        for (File srcDir : srcDirectories) {
            Collection filesToCopy = FileUtils.listFiles(srcDir, fileFilter, TrueFileFilter.INSTANCE);
            int count = 0;
            for (Object o : filesToCopy) {
                File src = (File) o;
                String relativePath = StringUtils.removeStart(src.getAbsolutePath(), srcDir.getAbsolutePath());
                File dest = new File(latestDeployDirectory.getAbsoluteFile() + relativePath);
                if (src.lastModified() > dest.lastModified()) {
                    getLog().debug("Copying " + src.getAbsolutePath() + " to " + dest.getAbsolutePath());
                    FileUtils.copyFile(src, dest);
                    count++;
                }
            }
            getLog().info("Copied " + count + " files from " + srcDir.getAbsolutePath() + " to "
                    + latestDeployDirectory.getAbsolutePath());
            FileUtils.copyDirectory(srcDir, latestDeployDirectory, fileFilter);
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to copy web files", e);
    }
}

From source file:energy.usef.core.service.business.ParticipantDiscoveryService.java

/**
 * Checks whether a participant is found in the list of real participants.
 *
 * @param domain - {@link String} containing the participants's domain.
 * @param participantRole - {@link USEFRole} indicating the participant's role.
 * @throws BusinessException if no participant is matching the sender.
 *///from  w w w  .  j  av  a  2 s .  c  om
protected static Participant findParticipantInDns(String domain, USEFRole participantRole)
        throws BusinessException {

    Participant participant = new Participant();
    participant.setDomainName(domain);
    participant.setUsefRole(participantRole);
    participant.setSpecVersion(getUsefVersion(domain));
    participant.setUrl(getUsefEndpoint(domain));
    ParticipantRole role = new ParticipantRole(participantRole);
    role.setUrl(getUsefEndpoint(domain));

    String[] keys = getPublicUnsealingKey(domain, participantRole).split(" ");
    for (String singleKey : keys) {
        role.setPublicKeys(Collections.singletonList(StringUtils.removeStart(singleKey, PUBLIC_KEY_PREFIX)));
        participant.setPublicKeys(
                Collections.singletonList(StringUtils.removeStart(singleKey, PUBLIC_KEY_PREFIX)));
    }

    participant.setRoles(Collections.singletonList(role));
    return participant;
}

From source file:ips1ap101.lib.core.util.EA.java

private static void clipConfigurationProperties() {
    Bitacora.trace(EA.class, "clipConfigurationProperties");
    String key;/* ww  w  .j a  v a 2 s . c om*/
    String sep = System.getProperties().getProperty("file.separator");
    String osname1 = System.getProperties().getProperty("os.name");
    String osname2 = StringUtils.containsIgnoreCase(osname1, "windows") ? "windows" : "linux";
    String glassRoot = System.getProperties().getProperty("com.sun.aas.instanceRoot");
    String jbossHome = System.getProperties().getProperty("jboss.home.dir");
    String jbossBase = System.getProperties().getProperty("jboss.server.base.dir");
    String somedir;
    boolean glassfish = StringUtils.isNotBlank(glassRoot);
    boolean jboss = StringUtils.isNotBlank(jbossHome);
    if (StringUtils.isBlank(content_root_dir)) {
        key = StringUtils.removeStart(SEV.ENT_APP_CONTENT_ROOT_DIR, SEV.ENT_APP_VAR_PREFFIX);
        somedir = coalesceToUserDir(glassRoot, jbossHome);
        if (glassfish) {
            content_root_dir = somedir + sep + "docroot";
        } else if (jboss) {
            content_root_dir = somedir + sep + "welcome-content";
        } else {
            content_root_dir = somedir + sep + "ROOT";
        }
        show(key, content_root_dir);
        isDirectory(content_root_dir);
    }
    if (StringUtils.isBlank(home_dir)) {
        key = StringUtils.removeStart(SEV.ENT_APP_HOME_DIR, SEV.ENT_APP_VAR_PREFFIX);
        somedir = coalesceToUserDir(glassRoot, jbossBase);
        home_dir = somedir + sep + lower_case_code;
        show(key, home_dir);
        isDirectory(home_dir);
    }
    if (StringUtils.isBlank(configuration_properties_file)) {
        key = StringUtils.removeStart(SEV.ENT_APP_CONFIGURATION_PROPERTIES_FILE, SEV.ENT_APP_VAR_PREFFIX);
        configuration_properties_file = home_dir + sep + "resources" + sep + "config" + sep + osname2 + sep
                + lower_case_code + ".properties";
        show(key, configuration_properties_file);
        isFile(configuration_properties_file);
    }
    if (StringUtils.isBlank(jdbc_driver)) {
        key = StringUtils.removeStart(SEV.ENT_APP_JDBC_DRIVER, SEV.ENT_APP_VAR_PREFFIX);
        jdbc_driver = "org.postgresql.Driver";
        show(key, jdbc_driver);
    }
    if (StringUtils.isBlank(jdbc_url)) {
        key = StringUtils.removeStart(SEV.ENT_APP_JDBC_URL, SEV.ENT_APP_VAR_PREFFIX);
        jdbc_url = "jdbc:postgresql://localhost:5432/" + upper_case_code;
        show(key, jdbc_url);
    }
    if (StringUtils.isBlank(jdbc_user)) {
        key = StringUtils.removeStart(SEV.ENT_APP_JDBC_USER, SEV.ENT_APP_VAR_PREFFIX);
        jdbc_user = lower_case_code;
        show(key, jdbc_user);
    }
    if (StringUtils.isBlank(jdbc_password)) {
        key = StringUtils.removeStart(SEV.ENT_APP_JDBC_PASSWORD, SEV.ENT_APP_VAR_PREFFIX);
        jdbc_password = lower_case_code;
        show(key, jdbc_password);
    }
    if (StringUtils.isBlank(jndi_ejb_lookup_pattern)) {
        key = StringUtils.removeStart(SEV.ENT_APP_JNDI_EJB_LOOKUP_PATTERN, SEV.ENT_APP_VAR_PREFFIX);
        jndi_ejb_lookup_pattern = "java:global/" + lower_case_code + "/" + lower_case_code + "-ejb/{0}!{1}";
        jndi_ejb_lookup_pattern = "java:global/" + lower_case_code + "/" + lower_case_code + "-ejb/{0}"; // GlassFish 4.0 & JBoss 7.1
        show(key, jndi_ejb_lookup_pattern);
    }
    if (StringUtils.isBlank(project_stage)) {
        key = StringUtils.removeStart(SEV.ENT_APP_PROJECT_STAGE, SEV.ENT_APP_VAR_PREFFIX);
        project_stage = "Production"; // Production, Development, UnitTest, SystemTest, Extension
        show(key, project_stage);
    }
    if (StringUtils.isBlank(project_mailing)) {
        key = StringUtils.removeStart(SEV.ENT_APP_PROJECT_MAILING, SEV.ENT_APP_VAR_PREFFIX);
        project_mailing = "disabled"; // disabled, enabled
        show(key, project_mailing);
    }
    if (StringUtils.isBlank(velocity_properties_file)) {
        key = StringUtils.removeStart(SEV.ENT_APP_VELOCITY_PROPERTIES_FILE, SEV.ENT_APP_VAR_PREFFIX);
        velocity_properties_file = home_dir + sep + "resources" + sep + "velocity" + sep
                + "velocity.properties";
        show(key, velocity_properties_file);
        isFile(velocity_properties_file);
    }
    if (StringUtils.isBlank(velocity_file_resource_loader_path)) {
        key = StringUtils.removeStart(SEV.ENT_APP_VELOCITY_FILE_RESOURCE_LOADER_PATH, SEV.ENT_APP_VAR_PREFFIX);
        velocity_file_resource_loader_path = home_dir + sep + "resources" + sep + "velocity" + sep
                + "templates";
        show(key, velocity_file_resource_loader_path);
        isDirectory(velocity_file_resource_loader_path);
    }
}

From source file:info.magnolia.cms.core.AggregationState.java

/**
 * WARNING: If passing URI without context path but it starts with same text as the context path it will be stripped off as well!!!
 * @param uri with contextPath (maybe)/* w  w  w  .j  a  va  2s.  com*/
 * @return uri stripped of the prefix matching the contextPath
 */
protected String stripContextPathIfExists(String uri) {
    // MAGNOLIA-2064 & others ... remove context path only when it is actually present not when page name starts with context path
    String contextPath = MgnlContext.getContextPath();
    if (uri != null && uri.startsWith(contextPath + "/")) {
        return StringUtils.removeStart(uri, contextPath);
    }
    return uri;
}

From source file:com.egt.core.aplicacion.FiltroBusqueda.java

public String toString(String dominio) {
    String where = StringUtils.EMPTY;
    String token;//from   w  ww  .j  av a 2  s . c  om
    for (CriterioBusqueda criterio : criterios) {
        token = criterio.toString(dominio);
        where += StringUtils.isBlank(token) ? "" : conjuncion.palabra() + token;
    }
    for (FiltroBusqueda filtro : filtros) {
        token = filtro.toString(dominio);
        where += StringUtils.isBlank(token) ? "" : conjuncion.palabra() + token;
    }
    where = StringUtils.removeStart(where, conjuncion.palabra());
    return StringUtils.isBlank(where) ? null : "(" + where.trim() + ")";
}

From source file:edu.mayo.cts2.framework.plugin.service.bprdf.dao.id.DefaultIdService.java

@Override
public String getAcronymForUri(String uri) {
    // try adding a '/' if we don't find it
    for (String addition : Arrays.asList("", "/")) {
        String acronym = this.getFromCache(this.uriToAcronym, uri + addition);
        if (acronym != null) {
            return acronym;
        }/*  w w  w.  ja  va  2  s.  c  om*/
    }

    if (uri.startsWith(BIOPORTAL_PURL_URI)) {
        uri = StringUtils.removeStart(uri, BIOPORTAL_PURL_URI);
        uri = StringUtils.removeEnd(uri, "/");
        uri = StringUtils.substringBefore(uri, "/");

        uri = StringUtils.removeEnd(uri, ":");
        uri = StringUtils.removeEnd(uri, "#");

        return uri;
    }
    if (uri.startsWith(PURL_OBO_OWL_URI)) {
        uri = StringUtils.removeStart(uri, PURL_OBO_OWL_URI);
        uri = StringUtils.removeEnd(uri, "/");
        uri = StringUtils.substringBefore(uri, "/");

        uri = StringUtils.removeEnd(uri, ":");
        uri = StringUtils.removeEnd(uri, "#");

        return uri;
    } else {
        return null;
    }
}

From source file:hydrograph.ui.graph.handler.ExternalSchemaUpdaterHandler.java

private boolean closeEditorIfAlreadyOpen(IPath jobFilePath, String fileName) {

    String jobPathRelative = StringUtils.removeStart(jobFilePath.toString(), "..");
    jobPathRelative = StringUtils.removeStart(jobPathRelative, "/");
    String jobPathAbsolute = StringUtils.replace(jobPathRelative, "/", "\\");
    IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (activeWorkbenchWindow != null) {
        IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
        for (IEditorReference editorRefrence : activePage.getEditorReferences()) {
            if (StringUtils.equals(editorRefrence.getTitleToolTip(), jobPathRelative)
                    || StringUtils.equals(editorRefrence.getTitleToolTip(), jobPathAbsolute)
                    || fileName.equals(editorRefrence.getTitleToolTip())) {
                IEditorPart editor = editorRefrence.getEditor(true);
                if (!activePage.closeEditor(editor, true)) {
                    LOGGER.debug("Editor not closed");
                }/*ww  w  . j ava  2 s  . co m*/
                LOGGER.debug("Editor closed");
                return true;
            }
        }
    }
    return false;
}

From source file:net.bible.service.device.speak.TextToSpeechController.java

@Override
public void onUtteranceCompleted(String utteranceId) {
    Log.d(TAG, "onUtteranceCompleted:" + utteranceId);
    // pause/rew/ff can sometimes allow old messages to complete so need to prevent move to next sentence if completed utterance is out of date 
    if ((!isPaused && isSpeaking) && StringUtils.startsWith(utteranceId, UTTERANCE_PREFIX)) {
        long utteranceNo = Long.valueOf(StringUtils.removeStart(utteranceId, UTTERANCE_PREFIX));
        if (utteranceNo == uniqueUtteranceNo - 1) {
            mSpeakTextProvider.finishedUtterance(utteranceId);

            // estimate cps
            mSpeakTiming.finished(utteranceId);

            // ask TTs to say the text
            if (mSpeakTextProvider.isMoreTextToSpeak()) {
                speakNextChunk();//from www  . j  av a 2  s  . c o m
            } else {
                Log.d(TAG, "Shutting down TTS");
                shutdown();
            }
        }
    }
}

From source file:gobblin.compaction.dataset.TimeBasedSubDirDatasetsFinder.java

protected DateTime getFolderTime(Path path, Path basePath) {
    int startPos = path.toString().indexOf(basePath.toString()) + basePath.toString().length();
    return this.timeFormatter.parseDateTime(StringUtils.removeStart(path.toString().substring(startPos), "/"));
}