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

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

Introduction

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

Prototype

public static String removeEnd(String str, String remove) 

Source Link

Document

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

Usage

From source file:net.ymate.platform.core.util.RuntimeUtils.java

/**
 * @param safe WEB??WEB-INF/*  w  w  w  .  ja  v a 2  s.  com*/
 * @return 
 */
public static String getRootPath(boolean safe) {
    //
    String _rootPath = null;
    //
    URL _rootURL = RuntimeUtils.class.getClassLoader().getResource("/");
    if (_rootURL == null) {
        _rootURL = RuntimeUtils.class.getClassLoader().getResource("");
        if (_rootURL != null) {
            _rootPath = _rootURL.getPath();
        }
    } else {
        _rootPath = StringUtils.removeEnd(
                StringUtils.substringBefore(_rootURL.getPath(), safe ? "classes/" : "WEB-INF/"), "/");
    }
    //
    if (_rootPath != null) {
        _rootPath = StringUtils.replace(_rootPath, "%20", " ");
        if (isWindows()) {
            _rootPath = StringUtils.removeStart(_rootPath, "/");
        }
    }
    return StringUtils.trimToEmpty(_rootPath);
}

From source file:nl.strohalm.cyclos.utils.LinkGeneratorImpl.java

private String getBaseUrl(SystemGroup group) {
    // As there is no FetchServiceLocal here, load the group again with the correct relationships
    group = (SystemGroup) loadGroup(group.getId());

    // Attempt by group
    String url = group.getRootUrl();

    if (StringUtils.isEmpty(url)) {
        // Not found on group. Attempt on group filters
        final Collection<GroupFilter> groupFilters = group.getGroupFilters();
        for (final GroupFilter groupFilter : groupFilters) {
            if (StringUtils.isNotEmpty(groupFilter.getRootUrl())) {
                url = groupFilter.getRootUrl();
                break;
            }//ww w.j a  v a  2s  .co  m
        }
    }

    if (StringUtils.isEmpty(url)) {
        // Get the system default
        url = settingsService.getLocalSettings().getRootUrl();
    }

    if (StringUtils.isEmpty(url)) {
        // None found?!? Should be required on settings!!!
        LOG.error("No root url was found when generating a link");
        return "";
    }

    // Make sure the trailing / is removed
    return StringUtils.removeEnd(url, "/");
}

From source file:nl.tricode.magnolia.blogs.setup.task.ModuleDependencyBootstrapTask.java

public ModuleDependencyBootstrapTask(final String bootstrapResourcePath, final String dependencyName) {
    super("Bootstrap " + dependencyName, "Bootstraps " + dependencyName + " content if installed.",
            dependencyName, new BootstrapResourcesTask(StringUtils.EMPTY, StringUtils.EMPTY,
                    ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING) {
                @Override//  w  ww . ja v a2  s  .  c o  m
                protected boolean acceptResource(InstallContext ctx, String name) {
                    final String path = StringUtils.removeEnd(bootstrapResourcePath, "/") + "/" + dependencyName
                            + "/";
                    return name.startsWith(path) && name.endsWith(".xml");
                }
            });
}

From source file:orca.ip_assignment.ndl.RequestSaver.java

/**
 * Do a reverse lookip on domain (NDL -> short name)
 * @param dom/* w  w  w  . j  a v  a2 s.c o  m*/
 * @return
 */
public static String reverseLookupDomain(Resource dom) {
    if (dom == null)
        return null;
    // strip off name space and "/Domain"
    String domainName = StringUtils.removeStart(dom.getURI(), NdlCommons.ORCA_NS);
    domainName = StringUtils.removeEnd(domainName, "/Domain");
    for (Iterator<Map.Entry<String, String>> domName = domainMap.entrySet().iterator(); domName.hasNext();) {
        Map.Entry<String, String> e = domName.next();
        if (domainName.equals(e.getValue()))
            return e.getKey();
    }
    return null;
}

From source file:orca.ndllib.ndl.RequestLoader.java

public void ndlReservation(Resource i, final OntModel m) {

    request.logger().debug("Reservation: " + i + ", sliceState(Request:ndlReservation) = "
            + NdlCommons.getGeniSliceStateName(i));
    // try to extract the guid out of the URL
    String u = i.getURI();/* w w  w  .  j  a  va 2 s. c  om*/
    String guid = StringUtils.removeEnd(StringUtils.removeStart(u, NdlCommons.ORCA_NS), "#");

    this.request.setNsGuid(guid);

    this.slice.setState(NdlCommons.getGeniSliceStateName(i));

    /*if (i != null) {
       reservationDomain = RequestSaver.reverseLookupDomain(NdlCommons.getDomain(i));
       this.request.setOFVersion(NdlCommons.getOpenFlowVersion(i));
    }*/
}

From source file:orca.ndllib.ndl.RequestSaver.java

/**************************************  Helper Function ***************************************/

// use different maps to try to do a reverse lookup
private static String reverseLookupDomain_(Resource domain, Map<String, String> m, String suffix) {
    String domainName = StringUtils.removeStart(domain.getURI(), NdlCommons.ORCA_NS);
    if (domainName == null)
        return null;

    // remove one or the other
    domainName = StringUtils.removeEnd(domainName, suffix);
    for (Iterator<Map.Entry<String, String>> domName = m.entrySet().iterator(); domName.hasNext();) {
        Map.Entry<String, String> e = domName.next();
        if (domainName.equals(e.getValue()))
            return e.getKey();
    }//from  w w w.j  av a2  s.c  om
    return null;
}

From source file:orca.ndllib.ndl.RequestSaver.java

private static String reverseLookupDomain_(String dom, Map<String, String> m, String suffix) {
    String domainName = StringUtils.removeStart(dom, NdlCommons.ORCA_NS);
    if (domainName == null)
        return null;

    // remove one or the other
    domainName = StringUtils.removeEnd(domainName, suffix);
    for (Iterator<Map.Entry<String, String>> domName = m.entrySet().iterator(); domName.hasNext();) {
        Map.Entry<String, String> e = domName.next();
        if (domainName.equals(e.getValue()))
            return e.getKey();
    }//from www.j  a  v a2 s .com
    return null;
}

From source file:org.apache.apex.malhar.lib.fs.s3.S3InitiateFileUploadOperator.java

@Override
public void setup(Context.OperatorContext context) {
    outputDirectoryPath = StringUtils.removeEnd(outputDirectoryPath, Path.SEPARATOR);
    currentWindowRecoveryState = new ArrayList<>();
    windowDataManager.setup(context);//  w w w  . j  av  a2 s  .  c  o  m
    s3Client = createClient();
}

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

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

    String repoId = null;// w  ww. j  a  v a  2 s.com
    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.webdav.ArchivaDavResourceFactory.java

private DavResource processRepositoryGroup(final DavServletRequest request,
        ArchivaDavResourceLocator archivaLocator, List<String> repositories, String activePrincipal,
        List<String> resourcesInAbsolutePath, RepositoryGroupConfiguration repoGroupConfig)
        throws DavException {
    DavResource resource = null;//  ww w. j  a  va 2 s.  c o m
    List<DavException> storedExceptions = new ArrayList<>();

    String pathInfo = StringUtils.removeEnd(request.getPathInfo(), "/");

    String rootPath = StringUtils.substringBeforeLast(pathInfo, "/");

    if (StringUtils.endsWith(rootPath, repoGroupConfig.getMergedIndexPath())) {
        // we are in the case of index file request
        String requestedFileName = StringUtils.substringAfterLast(pathInfo, "/");
        File temporaryIndexDirectory = buildMergedIndexDirectory(repositories, activePrincipal, request,
                repoGroupConfig);

        File resourceFile = new File(temporaryIndexDirectory, requestedFileName);
        resource = new ArchivaDavResource(resourceFile.getAbsolutePath(), requestedFileName, null,
                request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this,
                mimeTypes, auditListeners, scheduler, fileLockManager);

    } else {
        for (String repositoryId : repositories) {
            ManagedRepositoryContent managedRepositoryContent;
            try {
                managedRepositoryContent = repositoryFactory.getManagedRepositoryContent(repositoryId);
            } catch (RepositoryNotFoundException e) {
                throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
            } catch (RepositoryException e) {
                throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
            }

            try {
                ManagedRepository managedRepository = managedRepositoryAdmin.getManagedRepository(repositoryId);
                DavResource updatedResource = processRepository(request, archivaLocator, activePrincipal,
                        managedRepositoryContent, managedRepository);
                if (resource == null) {
                    resource = updatedResource;
                }

                String logicalResource = getLogicalResource(archivaLocator, null, false);
                if (logicalResource.endsWith("/")) {
                    logicalResource = logicalResource.substring(1);
                }
                resourcesInAbsolutePath.add(
                        new File(managedRepositoryContent.getRepoRoot(), logicalResource).getAbsolutePath());
            } catch (DavException e) {
                storedExceptions.add(e);
            } catch (RepositoryAdminException e) {
                storedExceptions.add(new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e));
            }
        }
    }
    if (resource == null) {
        if (!storedExceptions.isEmpty()) {
            // MRM-1232
            for (DavException e : storedExceptions) {
                if (401 == e.getErrorCode()) {
                    throw e;
                }
            }

            throw new DavException(HttpServletResponse.SC_NOT_FOUND);
        } else {
            throw new DavException(HttpServletResponse.SC_NOT_FOUND);
        }
    }
    return resource;
}