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

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

Introduction

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

Prototype

public static String substringAfterLast(String str, String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:org.apache.archiva.cli.ArchivaCli.java

@SuppressWarnings("unchecked")
private Map<String, KnownRepositoryContentConsumer> getConsumers() {
    Map<String, KnownRepositoryContentConsumer> beans = applicationContext
            .getBeansOfType(KnownRepositoryContentConsumer.class);
    // we use a naming conventions knownRepositoryContentConsumer#hint
    // with plexus we used only hint so remove before#

    Map<String, KnownRepositoryContentConsumer> smallNames = new HashMap<>(beans.size());

    for (Map.Entry<String, KnownRepositoryContentConsumer> entry : beans.entrySet()) {
        smallNames.put(StringUtils.substringAfterLast(entry.getKey(), "#"), entry.getValue());
    }/*from w  w  w.  j a  v  a 2  s  .c  o m*/

    return smallNames;
}

From source file:org.apache.archiva.consumers.core.AbstractArtifactConsumerTest.java

public String getName() {
    return StringUtils.substringAfterLast(getClass().getName(), ".");
}

From source file:org.apache.archiva.metadata.repository.cassandra.CassandraRepositorySessionFactory.java

@PostConstruct
public void initialize() {
    Map<String, MetadataFacetFactory> tmpMetadataFacetFactories = applicationContext
            .getBeansOfType(MetadataFacetFactory.class);
    // olamy with spring the ID.toString() is now "metadataFacetFactory#hint"
    // whereas was only hint with plexus so let remove  metadataFacetFactory#
    metadataFacetFactories = new HashMap<>(tmpMetadataFacetFactories.size());

    for (Map.Entry<String, MetadataFacetFactory> entry : tmpMetadataFacetFactories.entrySet()) {
        metadataFacetFactories.put(StringUtils.substringAfterLast(entry.getKey(), "#"), entry.getValue());
    }//from   w ww .ja  v a 2 s .  c o  m
}

From source file:org.apache.archiva.metadata.repository.file.FileRepositorySessionFactory.java

@PostConstruct
public void initialize() {
    Map<String, MetadataFacetFactory> tmpMetadataFacetFactories = applicationContext
            .getBeansOfType(MetadataFacetFactory.class);
    // olamy with spring the "id" is now "metadataFacetFactory#hint"
    // whereas was only hint with plexus so let remove  metadataFacetFactory#
    metadataFacetFactories = new HashMap<>(tmpMetadataFacetFactories.size());

    for (Map.Entry<String, MetadataFacetFactory> entry : tmpMetadataFacetFactories.entrySet()) {
        metadataFacetFactories.put(StringUtils.substringAfterLast(entry.getKey(), "#"), entry.getValue());
    }//from  w  w w .j  a  v a2  s . c  o m

}

From source file:org.apache.archiva.metadata.repository.jcr.JcrRepositorySessionFactory.java

@PostConstruct
public void initialize() throws Exception {

    // skip initialisation if not cassandra
    if (!StringUtils.equals(repositorySessionFactoryBean.getId(), "jcr")) {
        return;/*  w w w.  ja v  a 2 s .  c  o  m*/
    }

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    metadataFacetFactories = applicationContext.getBeansOfType(MetadataFacetFactory.class);
    // olamy with spring the "id" is now "metadataFacetFactory#hint"
    // whereas was only hint with plexus so let remove  metadataFacetFactory#
    Map<String, MetadataFacetFactory> cleanedMetadataFacetFactories = new HashMap<>(
            metadataFacetFactories.size());

    for (Map.Entry<String, MetadataFacetFactory> entry : metadataFacetFactories.entrySet()) {
        cleanedMetadataFacetFactories.put(StringUtils.substringAfterLast(entry.getKey(), "#"),
                entry.getValue());
    }

    metadataFacetFactories = cleanedMetadataFacetFactories;

    JcrMetadataRepository metadataRepository = null;
    try {
        metadataRepository = new JcrMetadataRepository(metadataFacetFactories, repository);
        JcrMetadataRepository.initialize(metadataRepository.getJcrSession());
    } catch (RepositoryException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        if (metadataRepository != null) {
            metadataRepository.close();
        }
    }

    stopWatch.stop();
    logger.info("time to initialize JcrRepositorySessionFactory: {}", stopWatch.getTime());
}

From source file:org.apache.archiva.proxy.DefaultRepositoryProxyConnectors.java

/**
 * Apply the policies.// w ww . j a  v a  2 s.co  m
 *
 * @param policies  the map of policies to execute. (Map of String policy keys, to {@link DownloadPolicy} objects)
 * @param settings  the map of settings for the policies to execute. (Map of String policy keys, to String policy
 *                  setting)
 * @param request   the request properties (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, File)}
 *                  )
 * @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, File)})
 * @throws PolicyViolationException
 */
private void validatePolicies(Map<String, ? extends DownloadPolicy> policies, Map<String, String> settings,
        Properties request, File localFile) throws PolicyViolationException {
    for (Entry<String, ? extends DownloadPolicy> entry : policies.entrySet()) {
        // olamy with spring rolehint is now downloadPolicy#hint
        // so substring after last # to get the hint as with plexus
        String key = StringUtils.substringAfterLast(entry.getKey(), "#");
        DownloadPolicy policy = entry.getValue();
        String defaultSetting = policy.getDefaultOption();

        String setting = StringUtils.defaultString(settings.get(key), defaultSetting);

        log.debug("Applying [{}] policy with [{}]", key, setting);
        try {
            policy.applyPolicy(setting, request, localFile);
        } catch (PolicyConfigurationException e) {
            log.error(e.getMessage(), e);
        }
    }
}

From source file:org.apache.archiva.proxy.DefaultRepositoryProxyConnectors.java

private void validatePolicies(Map<String, DownloadErrorPolicy> policies, Map<String, String> settings,
        Properties request, ArtifactReference artifact, RemoteRepositoryContent content, File localFile,
        Exception exception, Map<String, Exception> previousExceptions) throws ProxyDownloadException {
    boolean process = true;
    for (Entry<String, ? extends DownloadErrorPolicy> entry : policies.entrySet()) {

        // olamy with spring rolehint is now downloadPolicy#hint
        // so substring after last # to get the hint as with plexus
        String key = StringUtils.substringAfterLast(entry.getKey(), "#");
        DownloadErrorPolicy policy = entry.getValue();
        String defaultSetting = policy.getDefaultOption();
        String setting = StringUtils.defaultString(settings.get(key), defaultSetting);

        log.debug("Applying [{}] policy with [{}]", key, setting);
        try {// w  w w . j  a  va 2 s  .  co m
            // all policies must approve the exception, any can cancel
            process = policy.applyPolicy(setting, request, localFile, exception, previousExceptions);
            if (!process) {
                break;
            }
        } catch (PolicyConfigurationException e) {
            log.error(e.getMessage(), e);
        }
    }

    if (process) {
        // if the exception was queued, don't throw it
        if (!previousExceptions.containsKey(content.getId())) {
            throw new ProxyDownloadException(
                    "An error occurred in downloading from the remote repository, and the policy is to fail immediately",
                    content.getId(), exception);
        }
    } else {
        // if the exception was queued, but cancelled, remove it
        previousExceptions.remove(content.getId());
    }

    log.warn(
            "Transfer error from repository {} for artifact {} , continuing to next repository. Error message: {}",
            content.getRepository().getId(), Keys.toKey(artifact), exception.getMessage());
    log.debug("Full stack trace", exception);
}

From source file:org.apache.archiva.rest.services.AbstractRestService.java

protected <T> Map<String, T> getBeansOfType(ApplicationContext applicationContext, Class<T> clazz) {
    //TODO do some caching here !!!
    // olamy : with plexus we get only roleHint
    // as per convention we named spring bean role#hint remove role# if exists
    Map<String, T> springBeans = applicationContext.getBeansOfType(clazz);

    Map<String, T> beans = new HashMap<>(springBeans.size());

    for (Map.Entry<String, T> entry : springBeans.entrySet()) {
        String key = StringUtils.contains(entry.getKey(), '#')
                ? StringUtils.substringAfterLast(entry.getKey(), "#")
                : entry.getKey();/*  w ww. j av  a 2 s. c om*/
        beans.put(key, entry.getValue());
    }
    return beans;
}

From source file:org.apache.archiva.web.rss.RssFeedServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

    String repoId = null;//  ww  w.  j a v  a 2s  .co m
    String groupId = null;
    String artifactId = null;

    String url = StringUtils.removeEnd(req.getRequestURL().toString(), "/");

    if (StringUtils.countMatches(StringUtils.substringAfter(url, "feeds/"), "/") > 0) {
        artifactId = StringUtils.substringAfterLast(url, "/");
        groupId = StringUtils.substringBeforeLast(StringUtils.substringAfter(url, "feeds/"), "/");
        groupId = StringUtils.replaceChars(groupId, '/', '.');
    } else if (StringUtils.countMatches(StringUtils.substringAfter(url, "feeds/"), "/") == 0) {
        // we receive feeds?babla=ded which is not correct
        if (StringUtils.countMatches(url, "feeds?") > 0) {
            res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request url.");
            return;
        }
        repoId = StringUtils.substringAfterLast(url, "/");
    } else {
        res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request url.");
        return;
    }

    RssFeedProcessor processor = null;

    try {
        Map<String, String> map = new HashMap<>();
        SyndFeed feed = null;

        if (isAllowed(req, repoId, groupId, artifactId)) {
            if (repoId != null) {
                // new artifacts in repo feed request
                processor = newArtifactsprocessor;
                map.put(RssFeedProcessor.KEY_REPO_ID, repoId);
            } else if ((groupId != null) && (artifactId != null)) {
                // TODO: this only works for guest - we could pass in the list of repos
                // new versions of artifact feed request
                processor = newVersionsprocessor;
                map.put(RssFeedProcessor.KEY_GROUP_ID, groupId);
                map.put(RssFeedProcessor.KEY_ARTIFACT_ID, artifactId);
            }
        } else {
            res.sendError(HttpServletResponse.SC_UNAUTHORIZED, USER_NOT_AUTHORIZED);
            return;
        }

        RepositorySession repositorySession = repositorySessionFactory.createSession();
        try {
            feed = processor.process(map, repositorySession.getRepository());
        } finally {
            repositorySession.close();
        }
        if (feed == null) {
            res.sendError(HttpServletResponse.SC_NO_CONTENT, "No information available.");
            return;
        }

        res.setContentType(MIME_TYPE);

        if (repoId != null) {
            feed.setLink(req.getRequestURL().toString());
        } else if ((groupId != null) && (artifactId != null)) {
            feed.setLink(req.getRequestURL().toString());
        }

        SyndFeedOutput output = new SyndFeedOutput();
        output.output(feed, res.getWriter());
    } catch (UserNotFoundException unfe) {
        log.debug(COULD_NOT_AUTHENTICATE_USER, unfe);
        res.sendError(HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER);
    } catch (AccountLockedException acce) {
        res.sendError(HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER);
    } catch (AuthenticationException authe) {
        log.debug(COULD_NOT_AUTHENTICATE_USER, authe);
        res.sendError(HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER);
    } catch (FeedException ex) {
        log.debug(COULD_NOT_GENERATE_FEED_ERROR, ex);
        res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, COULD_NOT_GENERATE_FEED_ERROR);
    } catch (MustChangePasswordException e) {
        res.sendError(HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER);
    } catch (UnauthorizedException e) {
        log.debug(e.getMessage());
        if (repoId != null) {
            res.setHeader("WWW-Authenticate",
                    "Basic realm=\"Repository Archiva Managed " + repoId + " Repository");
        } else {
            res.setHeader("WWW-Authenticate", "Basic realm=\"Artifact " + groupId + ":" + artifactId);
        }

        res.sendError(HttpServletResponse.SC_UNAUTHORIZED, USER_NOT_AUTHORIZED);
    }
}

From source file:org.apache.archiva.web.startup.SecuritySynchronization.java

protected <T> Map<String, T> getBeansOfType(Class<T> clazz) {
    //TODO do some caching here !!!
    // olamy : with plexus we get only roleHint
    // as per convention we named spring bean role#hint remove role# if exists
    Map<String, T> springBeans = applicationContext.getBeansOfType(clazz);

    Map<String, T> beans = new HashMap<>(springBeans.size());

    for (Entry<String, T> entry : springBeans.entrySet()) {
        String key = StringUtils.substringAfterLast(entry.getKey(), "#");
        beans.put(key, entry.getValue());
    }/*from w  w  w  .j  av  a2 s.  c  o m*/
    return beans;
}