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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations