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.cleverbus.common.Strings.java

/**
 * Returns true if url address starts with 'http://' or 'https://'.
 *
 * @param url url/*from www . ja va 2s .co  m*/
 * @return boolean
 */
public static boolean isAbsoluteUrl(@Nullable String url) {
    return (StringUtils.startsWith(url, HTTP_PREFIX) || StringUtils.startsWith(url, HTTPS_PREFIX));
}

From source file:org.codehaus.redback.rest.services.DefaultRoleManagementService.java

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

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

    List<String> roleNames = toRoleNames(allRoles);

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

    return applicationRoles;
}

From source file:org.codehaus.redback.rest.services.DefaultUserService.java

public int removeFromCache(String userName) throws RedbackServiceException {
    if (userAssignmentsCache != null) {
        userAssignmentsCache.remove(userName);
    }// w w w .  ja  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.codehaus.plexus.redback.rbac.jdo")) {
            cacheManager.getCache(cacheName).removeAll();
        }
    }

    return 0;
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.GetRecordsResponseConverter.java

private void parseXmlNamespaceDeclarations(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Map<String, String> namespaces = new HashMap<>();
    Iterator<String> attributeNames = reader.getAttributeNames();
    while (attributeNames.hasNext()) {
        String name = attributeNames.next();
        if (StringUtils.startsWith(name, CswConstants.XMLNS)) {
            String attributeValue = reader.getAttribute(name);
            namespaces.put(name, attributeValue);
        }//from w  w w.j a va 2 s.co  m
    }
    if (!namespaces.isEmpty()) {
        context.put(CswConstants.WRITE_NAMESPACES, namespaces);
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.XStreamAttributeCopier.java

/**
 * Copies the namespace declarations on the XML element {@code reader} is currently at into
 * {@code context}. The namespace declarations will be available in {@code context} at the key
 * {@link CswConstants#NAMESPACE_DECLARATIONS}. The new namespace declarations will be added to any
 * existing ones already in {@code context}.
 *
 * @param reader  the reader currently at the XML element with namespace declarations you want
 *                to copy//from w w w  .j a  va 2s.  c o  m
 * @param context the {@link UnmarshallingContext} that the namespace declarations will be
 *                copied to
 */
public static void copyXmlNamespaceDeclarationsIntoContext(HierarchicalStreamReader reader,
        UnmarshallingContext context) {
    @SuppressWarnings("unchecked")
    Map<String, String> namespaces = (Map<String, String>) context.get(CswConstants.NAMESPACE_DECLARATIONS);

    if (namespaces == null) {
        namespaces = new HashMap<>();
    }

    @SuppressWarnings("unchecked")
    Iterator<String> attributeNames = reader.getAttributeNames();
    while (attributeNames.hasNext()) {
        String name = attributeNames.next();
        if (StringUtils.startsWith(name, CswConstants.XMLNS)) {
            String attributeValue = reader.getAttribute(name);
            namespaces.put(name, attributeValue);
        }
    }
    if (!namespaces.isEmpty()) {
        context.put(CswConstants.NAMESPACE_DECLARATIONS, namespaces);
    }
}

From source file:org.codice.solr.factory.SolrClientFactory.java

private static SolrClient getSolrClient(String url, String coreName, String configFile, String coreUrl)
        throws IOException, SolrServerException {
    SolrClient client;//from   ww  w.  ja  v  a2 s.  co  m
    if (StringUtils.startsWith(url, "https")) {
        createSolrCore(url, coreName, configFile, getHttpClient(false));
        client = new HttpSolrClient(coreUrl, getHttpClient(true));
    } else {
        createSolrCore(url, coreName, configFile, null);
        client = new HttpSolrClient(coreUrl);
    }
    return client;
}

From source file:org.codice.solr.factory.SolrServerFactory.java

public static SolrServer getHttpSolrServer(String url, String coreName, String configFile) {
    if (StringUtils.isBlank(url)) {
        url = systemBaseUrl.constructUrl("/solr");
    }//from   w ww .  ja va  2 s .co m

    String coreUrl = url + "/" + coreName;
    SolrServer server;
    try {
        if (StringUtils.startsWith(url, "https")) {
            CloseableHttpClient client = getHttpClient();
            createSolrCore(url, coreName, configFile, client);
            server = new HttpSolrServer(coreUrl, client);
        } else {
            createSolrCore(url, coreName, configFile, null);
            server = new HttpSolrServer(coreUrl);
        }
    } catch (SolrException ex) {
        LOGGER.error("Unable to create HTTP Solr server client ({}): {}", coreUrl, ex.getMessage());
        return null;
    }

    LOGGER.info("Created HTTP Solr server client ({})", coreUrl);
    return server;
}

From source file:org.codice.solr.xpath.XpathQueryParser.java

/**
 * Converts XPath into a Lucene query that will pre-filter based on xpath path and attribute
 * index fields. Further post filtering is needed for XPath functionality that cannot evaluated
 * against xpath index.//from w  ww  . ja  va2 s  . com
 *
 * @param queryText
 *            XPath expression to convert into lucene path and attribute index query
 * @return Lucene query to pre-filter using xpath index
 */
private Query getLuceneQuery(final String queryText) {
    String xpath = queryText;

    // Assume root is context node since evaluation does not have a context item
    if (StringUtils.startsWith(xpath, "./")) {
        xpath = StringUtils.removeStart(xpath, ".");
    } else if (!StringUtils.startsWith(xpath, "/")) {
        xpath = "/" + xpath;
    }

    return null; // TODO DDF-1882 add lucene xpath pre-filtering
}

From source file:org.digidoc4j.impl.bdoc.BDocSignatureOpenerTest.java

@Test
public void openBesSignature() throws Exception {
    DSSDocument xadesDoc = new FileDocument("testFiles/xades/test-bes-signature.xml");
    List<BDocSignature> signatures = signatureOpener.parse(xadesDoc);
    assertEquals(1, signatures.size());/*from   w ww.ja v  a 2s . c  o m*/
    BDocSignature signature = signatures.get(0);
    assertEquals("id-693869a500c60f0dc262f7287f033d5d", signature.getId());
    assertEquals(SignatureProfile.B_BES, signature.getProfile());
    logger.debug("Getting signature id");
    assertEquals("id-693869a500c60f0dc262f7287f033d5d", signature.getId());
    logger.debug("Getting signature method");
    assertEquals("http://www.w3.org/2001/04/xmlenc#sha256", signature.getSignatureMethod());
    logger.debug("Getting signing time");
    assertEquals(new Date(1454928400000L), signature.getSigningTime());
    logger.debug("Getting city");
    assertEquals("Tallinn", signature.getCity());
    logger.debug("Getting state");
    assertEquals("Harjumaa", signature.getStateOrProvince());
    logger.debug("Getting postal code");
    assertEquals("13456", signature.getPostalCode());
    logger.debug("Getting country name");
    assertEquals("Estonia", signature.getCountryName());
    logger.debug("Getting signer roles");
    assertEquals("Manager", signature.getSignerRoles().get(0));
    assertEquals("Suspicious Fisherman", signature.getSignerRoles().get(1));
    logger.debug("Getting signing certificate");
    assertNotNull(signature.getSigningCertificate());
    logger.debug("Getting signing cert subject name");
    assertTrue(StringUtils.startsWith(signature.getSigningCertificate().issuerName(),
            "C=EE,O=AS Sertifitseerimiskeskus"));
    logger.debug("Getting signature as a byte array");
    byte[] signatureInBytes = signature.getAdESSignature();
    SignedDocumentValidator validator = SignedDocumentValidator
            .fromDocument(new InMemoryDocument(signatureInBytes));
    assertEquals("id-693869a500c60f0dc262f7287f033d5d", validator.getSignatures().get(0).getId());
    logger.debug("Asserting null values");
    assertNull(signature.getOCSPCertificate());
    assertNull(signature.getOCSPResponseCreationTime());
    assertNull(signature.getTimeStampTokenCertificate());
    assertNull(signature.getTimeStampCreationTime());
    assertNull(signature.getTrustedSigningTime());
    logger.debug("Finished testing BES signature");
}

From source file:org.digidoc4j.impl.bdoc.BDocSignatureOpenerTest.java

@Test
public void openXadesSignature() throws Exception {
    DSSDocument xadesDoc = new FileDocument("testFiles/xades/test-bdoc-ts.xml");
    List<BDocSignature> signatures = signatureOpener.parse(xadesDoc);
    BDocSignature signature = signatures.get(0);
    assertNotNull(signature);/*from ww  w  .  ja va 2s .c o m*/
    assertEquals("S0", signature.getId());
    assertEquals(SignatureProfile.LT, signature.getProfile());
    assertEquals("http://www.w3.org/2001/04/xmlenc#sha256", signature.getSignatureMethod());
    assertEquals(new Date(1454090315000L), signature.getSigningTime());
    assertTrue(StringUtils.startsWith(signature.getSigningCertificate().issuerName(),
            "C=EE,O=AS Sertifitseerimiskeskus"));
    assertNotNull(signature.getOCSPCertificate());
    assertTrue(StringUtils.contains(signature.getOCSPCertificate().getSubjectName(), "OU=OCSP"));
    assertEquals(new Date(1454090317000L), signature.getOCSPResponseCreationTime());
    assertEquals(new Date(1454090316000L), signature.getTimeStampCreationTime());
    assertNotNull(signature.getTimeStampTokenCertificate());
    assertTrue(StringUtils.contains(signature.getTimeStampTokenCertificate().getSubjectName(), "OU=TSA"));
    assertEquals(signature.getTimeStampCreationTime(), signature.getTrustedSigningTime());
}