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

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

Introduction

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

Prototype

public static boolean startsWith(String str, String prefix) 

Source Link

Document

Check if a String starts with a specified prefix.

Usage

From source file:org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryStorage.java

@Override
public String getFilePathWithVersion(final String requestPath,
        ManagedRepositoryContent managedRepositoryContent) throws XMLException, RelocationException {

    if (StringUtils.endsWith(requestPath, METADATA_FILENAME)) {
        return getFilePath(requestPath, managedRepositoryContent.getRepository());
    }//from  ww  w  .j  av a 2s .com

    String filePath = getFilePath(requestPath, managedRepositoryContent.getRepository());

    ArtifactReference artifactReference = null;
    try {
        artifactReference = pathParser.toArtifactReference(filePath);
    } catch (LayoutException e) {
        return filePath;
    }

    if (StringUtils.endsWith(artifactReference.getVersion(), VersionUtil.SNAPSHOT)) {
        // read maven metadata to get last timestamp
        File metadataDir = new File(managedRepositoryContent.getRepoRoot(), filePath).getParentFile();
        if (!metadataDir.exists()) {
            return filePath;
        }
        File metadataFile = new File(metadataDir, METADATA_FILENAME);
        if (!metadataFile.exists()) {
            return filePath;
        }
        ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read(metadataFile);
        int buildNumber = archivaRepositoryMetadata.getSnapshotVersion().getBuildNumber();
        String timestamp = archivaRepositoryMetadata.getSnapshotVersion().getTimestamp();

        // MRM-1846
        if (buildNumber < 1 && timestamp == null) {
            return filePath;
        }

        // org/apache/archiva/archiva-checksum/1.4-M4-SNAPSHOT/archiva-checksum-1.4-M4-SNAPSHOT.jar
        // ->  archiva-checksum-1.4-M4-20130425.081822-1.jar

        filePath = StringUtils.replace(filePath, //
                artifactReference.getArtifactId() //
                        + "-" + artifactReference.getVersion(), //
                artifactReference.getArtifactId() //
                        + "-" + StringUtils.remove(artifactReference.getVersion(), "-" + VersionUtil.SNAPSHOT) //
                        + "-" + timestamp //
                        + "-" + buildNumber);

        throw new RelocationException(
                "/repository/" + managedRepositoryContent.getRepository().getId()
                        + (StringUtils.startsWith(filePath, "/") ? "" : "/") + filePath,
                RelocationException.RelocationType.TEMPORARY);

    }

    return filePath;
}

From source file:org.apache.archiva.proxy.common.DefaultWagonFactory.java

@Override
public Wagon getWagon(WagonFactoryRequest wagonFactoryRequest) throws WagonFactoryException {
    try {// w  ww  . j a  v  a2 s . com
        String protocol = StringUtils.startsWith(wagonFactoryRequest.getProtocol(), "wagon#")
                ? wagonFactoryRequest.getProtocol()
                : "wagon#" + wagonFactoryRequest.getProtocol();

        // if it's a ntlm proxy we have to lookup the wagon light which support thats
        // wagon http client doesn't support that
        if (wagonFactoryRequest.getNetworkProxy() != null
                && wagonFactoryRequest.getNetworkProxy().isUseNtlm()) {
            protocol = protocol + "-ntlm";
        }

        Wagon wagon = applicationContext.getBean(protocol, Wagon.class);
        wagon.addTransferListener(debugTransferListener);
        configureUserAgent(wagon, wagonFactoryRequest);
        return wagon;
    } catch (BeansException e) {
        throw new WagonFactoryException(e.getMessage(), e);
    }
}

From source file:org.apache.archiva.redback.rest.services.DefaultRoleManagementService.java

private Collection<org.apache.archiva.redback.rbac.Role> filterApplicationRoles(ModelApplication application,
        List<org.apache.archiva.redback.rbac.Role> allRoles, List<ModelTemplate> applicationTemplates) {
    Set<org.apache.archiva.redback.rbac.Role> applicationRoles = new HashSet<org.apache.archiva.redback.rbac.Role>();
    List<ModelRole> roles = application.getRoles();

    for (ModelRole modelRole : roles) {
        org.apache.archiva.redback.rbac.Role r = isInList(modelRole.getName(), allRoles);
        if (r != null) {
            applicationRoles.add(r);//from w w  w  . j  a  v a  2 s.  c  o m
        }
    }

    List<String> roleNames = toRoleNames(allRoles);

    for (ModelTemplate modelTemplate : applicationTemplates) {
        for (org.apache.archiva.redback.rbac.Role r : allRoles) {
            if (StringUtils.startsWith(r.getName(),
                    modelTemplate.getNamePrefix() + modelTemplate.getDelimiter())) {
                applicationRoles.add(r);
            }
        }
    }

    return applicationRoles;
}

From source file:org.apache.archiva.redback.rest.services.DefaultRoleManagementService.java

private boolean roleFromTemplate(String roleName, List<ModelTemplate> applicationTemplates) {

    for (ModelTemplate modelTemplate : applicationTemplates) {
        if (StringUtils.startsWith(roleName, modelTemplate.getNamePrefix() + modelTemplate.getDelimiter())) {
            return true;
        }//ww  w  .  ja v  a  2s  . c  o  m

    }
    return false;
}

From source file:org.apache.archiva.redback.rest.services.DefaultUserService.java

public int removeFromCache(String userName) throws RedbackServiceException {
    if (userAssignmentsCache != null) {
        userAssignmentsCache.remove(userName);
    }//from   w  w w. j a v a 2s. c o  m
    if (userPermissionsCache != null) {
        userPermissionsCache.remove(userName);
    }
    if (usersCache != null) {
        usersCache.remove(userName);
    }

    CacheManager cacheManager = CacheManager.getInstance();
    String[] caches = cacheManager.getCacheNames();
    for (String cacheName : caches) {
        if (StringUtils.startsWith(cacheName, "org.apache.archiva.redback.rbac.jdo")) {
            cacheManager.getCache(cacheName).removeAll();
        }
    }

    return 0;
}

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

protected List<ArtifactContentEntry> readFileEntries(File file, String filterPath, String repoId)
        throws IOException {
    Map<String, ArtifactContentEntry> artifactContentEntryMap = new HashMap<>();
    int filterDepth = StringUtils.countMatches(filterPath, "/");
    /*if ( filterDepth == 0 )
    {/*from w w w.  ja va  2s  .  com*/
    filterDepth = 1;
    }*/
    JarFile jarFile = new JarFile(file);
    try {
        Enumeration<JarEntry> jarEntryEnumeration = jarFile.entries();
        while (jarEntryEnumeration.hasMoreElements()) {
            JarEntry currentEntry = jarEntryEnumeration.nextElement();
            String cleanedEntryName = StringUtils.endsWith(currentEntry.getName(), "/") ? //
                    StringUtils.substringBeforeLast(currentEntry.getName(), "/") : currentEntry.getName();
            String entryRootPath = getRootPath(cleanedEntryName);
            int depth = StringUtils.countMatches(cleanedEntryName, "/");
            if (StringUtils.isEmpty(filterPath) //
                    && !artifactContentEntryMap.containsKey(entryRootPath) //
                    && depth == filterDepth) {

                artifactContentEntryMap.put(entryRootPath,
                        new ArtifactContentEntry(entryRootPath, !currentEntry.isDirectory(), depth, repoId));
            } else {
                if (StringUtils.startsWith(cleanedEntryName, filterPath) //
                        && (depth == filterDepth || (!currentEntry.isDirectory() && depth == filterDepth))) {
                    artifactContentEntryMap.put(cleanedEntryName, new ArtifactContentEntry(cleanedEntryName,
                            !currentEntry.isDirectory(), depth, repoId));
                }
            }
        }

        if (StringUtils.isNotEmpty(filterPath)) {
            Map<String, ArtifactContentEntry> filteredArtifactContentEntryMap = new HashMap<>();

            for (Map.Entry<String, ArtifactContentEntry> entry : artifactContentEntryMap.entrySet()) {
                filteredArtifactContentEntryMap.put(entry.getKey(), entry.getValue());
            }

            List<ArtifactContentEntry> sorted = getSmallerDepthEntries(filteredArtifactContentEntryMap);
            if (sorted == null) {
                return Collections.emptyList();
            }
            Collections.sort(sorted, ArtifactContentEntryComparator.INSTANCE);
            return sorted;
        }
    } finally {
        if (jarFile != null) {
            jarFile.close();
        }
    }
    List<ArtifactContentEntry> sorted = new ArrayList<>(artifactContentEntryMap.values());
    Collections.sort(sorted, ArtifactContentEntryComparator.INSTANCE);
    return sorted;
}

From source file:org.apache.archiva.webdav.ArchivaDavResourceFactory.java

private String addHrefPrefix(String contextPath, String path) {
    String prefix = archivaConfiguration.getConfiguration().getWebapp().getUi().getApplicationUrl();
    if (prefix == null || prefix.isEmpty()) {
        prefix = contextPath;/*from   ww w.ja va  2  s  . c o  m*/
    }
    return prefix + (StringUtils.startsWith(path, "/") ? "" : (StringUtils.endsWith(prefix, "/") ? "" : "/"))
            + path;
}

From source file:org.apache.atlas.type.AtlasTypeUtil.java

public static boolean isArrayType(String typeName) {
    return StringUtils.startsWith(typeName, ATLAS_TYPE_ARRAY_PREFIX)
            && StringUtils.endsWith(typeName, ATLAS_TYPE_ARRAY_SUFFIX);
}

From source file:org.apache.atlas.type.AtlasTypeUtil.java

public static boolean isMapType(String typeName) {
    return StringUtils.startsWith(typeName, ATLAS_TYPE_MAP_PREFIX)
            && StringUtils.endsWith(typeName, ATLAS_TYPE_MAP_SUFFIX);
}

From source file:org.apache.ctakes.jdl.data.xml.DomUtilTest.java

@Theory
public void nodeToStr(String xml) {
    xml = FileUtil.getFile(xml).toString();
    Document document = DomUtil.srcToDocument(xml);
    Element element = document.getDocumentElement();
    assertThat(StringUtils.startsWith(DomUtil.nodeToStr(element), "<" + Resources.ROOT_LOAD), is(true));
    assertThat(StringUtils.endsWith(DomUtil.nodeToStr(element).trim(), "</" + Resources.ROOT_LOAD + ">"),
            is(true));/*from w w  w  .ja  v  a 2 s  .c  o  m*/
}