Search in sources :

Example 96 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project web3sdk by FISCO-BCOS.

the class P12Manager method load.

public void load() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, NoSuchProviderException {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    keyStore = KeyStore.getInstance("PKCS12", "BC");
    Resource keyStoreResource = resolver.getResource(p12File);
    keyStore.load(keyStoreResource.getInputStream(), password.toCharArray());
// logger.debug(" p12 load, keyStore: {}", keyStore);
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 97 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project jaffa-framework by jaffa-projects.

the class JaffaI18nFactorySet method parseXmlFile.

/**
 * Parse specified xml file and find definitions from with in classpath by searching all jars
 * and add definition to specified definitions set.
 * This method is used to load several description files in one instances list.
 * If filename exists and definition set is <code>null</code>, create a new set. Otherwise, return
 * passed definition set (can be <code>null</code>).
 * @param servletContext Current servlet context. Used to open file.
 * @param xmlDefinitions Definitions set to which definitions will be added. If null, a definitions
 * set is created on request.
 * @return XmlDefinitionsSet The definitions set created or passed as parameter.
 * @throws DefinitionsFactoryException On errors parsing file.
 */
protected XmlDefinitionsSet parseXmlFile(ServletContext servletContext, XmlDefinitionsSet xmlDefinitions) throws DefinitionsFactoryException {
    if (log.isDebugEnabled()) {
        log.debug("Parsing tiles definition files from classpath");
    }
    try {
        List<Resource> resourceList = new ArrayList<>();
        for (String filename : filenames) {
            PathMatchingResourcePatternResolver resolver = OrderedPathMatchingResourcePatternResolver.getInstance();
            resourceList.addAll(Arrays.asList(resolver.getResources(filename)));
        }
        // if( xmlParser == null )
        if (true) {
            xmlParser = new XmlParser();
            xmlParser.setValidating(isValidatingParser);
        }
        // Check if definition set already exist.
        if (xmlDefinitions == null) {
            xmlDefinitions = new XmlDefinitionsSet();
        }
        if (resourceList != null && resourceList.size() > 0) {
            for (Resource resource : resourceList) {
                if (log.isDebugEnabled()) {
                    log.debug("Parsing tiles definition: " + resource.getFilename());
                }
                xmlParser.parse(resource.getInputStream(), xmlDefinitions);
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Can't open files '" + filenames + "'");
            }
            return xmlDefinitions;
        }
    } catch (SAXException | IOException ex) {
        if (log.isDebugEnabled()) {
            log.debug("Error while parsing files '" + filenames + "'.");
            ex.printStackTrace();
        }
        throw new DefinitionsFactoryException("Error while parsing files '" + filenames + "'. " + ex.getMessage(), ex);
    }
    return xmlDefinitions;
}
Also used : XmlParser(org.apache.struts.tiles.xmlDefinition.XmlParser) DefinitionsFactoryException(org.apache.struts.tiles.DefinitionsFactoryException) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) OrderedPathMatchingResourcePatternResolver(org.jaffa.util.OrderedPathMatchingResourcePatternResolver) XmlDefinitionsSet(org.apache.struts.tiles.xmlDefinition.XmlDefinitionsSet) SAXException(org.xml.sax.SAXException)

Example 98 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project jaffa-framework by jaffa-projects.

the class DwrServletTest method getResourceAsStream.

/**
 * Overriden to reset the default path from "/WEB-INF/dwr.xml" to
 * "/dwr.xml".
 */
public InputStream getResourceAsStream(String path) {
    InputStream inputStream = null;
    try {
        PathMatchingResourcePatternResolver resolver = OrderedPathMatchingResourcePatternResolver.getInstance();
        inputStream = resolver.getResource(path).getInputStream();
        System.out.println("path:" + path);
        System.out.println("inputStream:" + inputStream);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return inputStream;
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) OrderedPathMatchingResourcePatternResolver(org.jaffa.util.OrderedPathMatchingResourcePatternResolver)

Example 99 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project jaffa-framework by jaffa-projects.

the class FakeServletContext method getResourceAsStream.

/**
 * Overriden to reset the default path from "/WEB-INF/dwr.xml" to
 * "/dwr.xml".
 */
public InputStream getResourceAsStream(String path) {
    InputStream inputStream = null;
    try {
        PathMatchingResourcePatternResolver resolver = OrderedPathMatchingResourcePatternResolver.getInstance();
        inputStream = resolver.getResource("/dwr.xml").getInputStream();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return inputStream;
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) OrderedPathMatchingResourcePatternResolver(org.jaffa.util.OrderedPathMatchingResourcePatternResolver)

Example 100 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project jaffa-framework by jaffa-projects.

the class ConfigApiCore method getMetaInfResource.

/**
 * getMetaInfResource - Retrieves resource files from the META-INF directory within a configuration archive
 * @param file    The configuration archive file
 * @param manager The current manager containing the repository to inject resources into
 * @return    The resource file retrieved from META-INF
 */
private static Resource getMetaInfResource(File file, IManager manager) {
    ClassLoader loader = ConfigApiCore.class.getClassLoader();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(loader);
    String absolutePath = file.getAbsolutePath();
    String resourceFileName = manager.getResourceFileName();
    String filePath = "file:" + absolutePath + "/META-INF/" + resourceFileName;
    Resource resource = resolver.getResource(filePath);
    // TODO get the pattern matching to work correctly
    if (!resource.exists() && filePath.contains("*")) {
        filePath = filePath.replace("*", "");
        Resource resource2 = resolver.getResource(filePath);
        if (resource2.exists()) {
            resource = resource2;
        }
    }
    return resource;
}
Also used : Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Aggregations

PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)135 Resource (org.springframework.core.io.Resource)86 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)53 IOException (java.io.IOException)37 Bean (org.springframework.context.annotation.Bean)30 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)29 ArrayList (java.util.ArrayList)16 Properties (java.util.Properties)14 ClassPathResource (org.springframework.core.io.ClassPathResource)14 File (java.io.File)13 InputStream (java.io.InputStream)12 Test (org.junit.jupiter.api.Test)12 JndiDataSourceLookup (org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup)11 PageHelper (com.github.pagehelper.PageHelper)10 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)10 Primary (org.springframework.context.annotation.Primary)9 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)9 MetadataReader (org.springframework.core.type.classreading.MetadataReader)9 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)7 URL (java.net.URL)6