use of org.springframework.core.io.ClassPathResource in project uPortal by Jasig.
the class IdentityImportExportTest method testSubscribedFragment40ImportExport.
@Test
public void testSubscribedFragment40ImportExport() throws Exception {
runSql("INSERT INTO UP_USER (USER_ID, USER_NAME, USER_DFLT_USR_ID, USER_DFLT_LAY_ID, NEXT_STRUCT_ID, LST_CHAN_UPDT_DT) " + "VALUES (1, 'admin', 0, 0, 0, null)");
runSql("INSERT INTO UP_USER (USER_ID, USER_NAME, USER_DFLT_USR_ID, USER_DFLT_LAY_ID, NEXT_STRUCT_ID, LST_CHAN_UPDT_DT) " + "VALUES (2, 'mum-lo-campus-apps', 0, 0, 0, null)");
runSql("INSERT INTO UP_USER (USER_ID, USER_NAME, USER_DFLT_USR_ID, USER_DFLT_LAY_ID, NEXT_STRUCT_ID, LST_CHAN_UPDT_DT) " + "VALUES (3, 'mum-lo-cg', 0, 0, 0, null)");
final ClassPathResource permissionOwnerResource = new ClassPathResource("/org/apereo/portal/io/xml/subscribed-fragment/test_4-0.subscribed-fragment.xml");
IdentityImportExportTestUtilities.testIdentityImportExport(this.transactionOperations, this.subscribedFragmentImporter, this.subscribedFragmentExporter, permissionOwnerResource, new Function<ExternalSubscribedFragments, String>() {
@Override
public String apply(ExternalSubscribedFragments input) {
return input.getUsername();
}
});
}
use of org.springframework.core.io.ClassPathResource in project uPortal by Jasig.
the class SitemapTest method testStylesheetCompilation.
@Test
public void testStylesheetCompilation() throws IOException {
final MockHttpServletRequest request = new MockHttpServletRequest();
Resource resource = new ClassPathResource(STYLESHEET_LOCATION);
Source source = new StreamSource(resource.getInputStream(), resource.getURI().toASCIIString());
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer(source);
transformer.setParameter(SitemapPortletController.USE_TAB_GROUPS, useTabGroups);
transformer.setParameter(SitemapPortletController.USER_LANG, "en_US");
transformer.setParameter(XsltPortalUrlProvider.CURRENT_REQUEST, request);
transformer.setParameter(XsltPortalUrlProvider.XSLT_PORTAL_URL_PROVIDER, this.xsltPortalUrlProvider);
Source xmlSource = new StreamSource(new ClassPathResource(XML_LOCATION).getFile());
CharArrayWriter buffer = new CharArrayWriter();
TransformerUtils.enableIndenting(transformer);
transformer.transform(xmlSource, new StreamResult(buffer));
if (logger.isTraceEnabled()) {
logger.trace("XML: " + new String(buffer.toCharArray()));
}
} catch (TransformerConfigurationException e) {
logger.error(e.getMessage(), e);
throw new RuntimeException(e);
} catch (TransformerException e) {
logger.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.springframework.core.io.ClassPathResource in project spring-boot by spring-projects.
the class InitializrServiceMetadataTests method readJson.
private static JSONObject readJson(String version) throws IOException, JSONException {
Resource resource = new ClassPathResource("metadata/service-metadata-" + version + ".json");
InputStream stream = resource.getInputStream();
try {
return new JSONObject(StreamUtils.copyToString(stream, Charset.forName("UTF-8")));
} finally {
stream.close();
}
}
use of org.springframework.core.io.ClassPathResource in project spring-boot by spring-projects.
the class SpringConfiguration method init.
@PostConstruct
public void init() throws IOException {
Properties props = new Properties();
props.load(new ClassPathResource("application.properties").getInputStream());
String value = props.getProperty("message");
if (value != null) {
this.message = value;
}
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class Jaxb2CollectionHttpMessageConverterTests method readXmlRootElementExternalEntityDisabled.
@Test
@SuppressWarnings("unchecked")
public void readXmlRootElementExternalEntityDisabled() throws Exception {
Resource external = new ClassPathResource("external.txt", getClass());
String content = "<!DOCTYPE root [" + " <!ELEMENT external ANY >\n" + " <!ENTITY ext SYSTEM \"" + external.getURI() + "\" >]>" + " <list><rootElement><type s=\"1\"/><external>&ext;</external></rootElement></list>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
converter = new Jaxb2CollectionHttpMessageConverter<Collection<Object>>() {
@Override
protected XMLInputFactory createXmlInputFactory() {
XMLInputFactory inputFactory = super.createXmlInputFactory();
inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, true);
return inputFactory;
}
};
try {
Collection<RootElement> result = converter.read(rootElementListType, null, inputMessage);
assertEquals(1, result.size());
assertEquals("", result.iterator().next().external);
} catch (HttpMessageNotReadableException ex) {
// Some parsers raise an exception
}
}
Aggregations