use of org.springframework.core.io.ClassPathResource in project spring-boot-admin by codecentric.
the class ConcatenatingResourceResolverTest method test_concatenation.
@Test
public void test_concatenation() throws IOException {
Resource testResource = new ClassPathResource("/testResource.txt");
List<Resource> resources = asList(testResource, testResource, testResource);
Resource resolvedResource = new ConcatenatingResourceResolver(";".getBytes()).resolveResource(null, "/foo.txt", resources, null);
assertThat(resolvedResource.getFilename(), is("foo.txt"));
assertThat(resolvedResource.lastModified(), is(testResource.lastModified()));
assertThat(resolvedResource.getDescription(), is("Byte array resource [(class path resource [testResource.txt], class path resource [testResource.txt], class path resource [testResource.txt])]"));
assertThat(copyToByteArray(resolvedResource.getInputStream()), is("Foobar;Foobar;Foobar".getBytes()));
}
use of org.springframework.core.io.ClassPathResource in project spring-boot-admin by codecentric.
the class PreferMinifiedFilteringResourceResolverTest method test_resolveResource.
@Test
public void test_resolveResource() {
List<? extends Resource> resources = asList(new ClassPathResource("testResource.txt"), new ClassPathResource("application.properties"));
new PreferMinifiedFilteringResourceResolver(".min").resolveResource(null, null, resources, new ResourceResolverChain() {
@Override
public Resource resolveResource(HttpServletRequest request, String requestPath, List<? extends Resource> locations) {
assertThat(locations.size(), is(2));
assertThat(locations, contains((Resource) new ClassPathResource("testResource.min.txt"), (Resource) new ClassPathResource("application.properties")));
return null;
}
@Override
public String resolveUrlPath(String resourcePath, List<? extends Resource> locations) {
return null;
}
});
}
use of org.springframework.core.io.ClassPathResource in project head by mifos.
the class Text method getNonLocalizedFileLookupDatabase.
private static Properties getNonLocalizedFileLookupDatabase() throws TableTagException {
Properties resource = null;
if (null == nonLocalizedFileLookupDatabase) {
ClassPathResource fileLookupDatabase = new ClassPathResource(FilePaths.TABLE_TAG_PATH_DATABASE);
resource = new Properties();
try {
resource.load(fileLookupDatabase.getInputStream());
} catch (IOException e) {
throw new TableTagException(e);
}
}
return resource;
}
use of org.springframework.core.io.ClassPathResource in project head by mifos.
the class TableTag method getNonLocalizedFileLookupDatabase.
private Properties getNonLocalizedFileLookupDatabase() {
Properties resource = null;
if (null == nonLocalizedFileLookupDatabase) {
ClassPathResource fileLookupDatabase = new ClassPathResource(FilePaths.TABLE_TAG_PATH_DATABASE);
resource = new Properties();
try {
resource.load(fileLookupDatabase.getInputStream());
} catch (IOException e) {
throw new MifosRuntimeException(e);
}
}
return resource;
}
use of org.springframework.core.io.ClassPathResource in project head by mifos.
the class ChartOfAccountsConfig method load.
/**
* Factory method which loads the Chart of Accounts configuration from the
* given filename. Given XML filename will be validated against
* {@link FilePaths#CHART_OF_ACCOUNTS_SCHEMA}.
*
* @param chartOfAccountsXml
* a relative path to the Chart of Accounts configuration file.
*/
public static ChartOfAccountsConfig load(String chartOfAccountsXml) throws ConfigurationException {
ChartOfAccountsConfig instance = null;
Document document = null;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = dbf.newDocumentBuilder();
if (FilePaths.CHART_OF_ACCOUNTS_DEFAULT.equals(chartOfAccountsXml)) {
// default chart of accounts
document = parser.parse(MifosResourceUtil.getClassPathResourceAsStream(chartOfAccountsXml));
} else {
// custom chart of accounts
document = parser.parse(MifosResourceUtil.getFile(chartOfAccountsXml));
}
// create a SchemaFactory capable of understanding XML schemas
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// load an XML schema
ClassPathResource schemaFileResource = new ClassPathResource(FilePaths.CHART_OF_ACCOUNTS_SCHEMA);
Source schemaFile = null;
if (schemaFileResource.exists()) {
InputStream in = ChartOfAccountsConfig.class.getClassLoader().getResourceAsStream(FilePaths.CHART_OF_ACCOUNTS_SCHEMA);
schemaFile = new StreamSource(in);
} else {
schemaFile = new StreamSource(MifosResourceUtil.getFile(FilePaths.CHART_OF_ACCOUNTS_SCHEMA));
}
Schema schema = factory.newSchema(schemaFile);
// create a Validator instance and validate document
Validator validator = schema.newValidator();
validator.validate(new DOMSource(document));
} catch (IOException e) {
throw new ConfigurationException(e);
} catch (SAXException e) {
throw new ConfigurationException(e);
} catch (ParserConfigurationException e) {
throw new ConfigurationException(e);
}
instance = new ChartOfAccountsConfig();
instance.coaDocument = document;
return instance;
}
Aggregations