List of usage examples for org.springframework.core.io FileSystemResourceLoader FileSystemResourceLoader
FileSystemResourceLoader
From source file:fr.letitzen.demo.web.GenericWebXmlContextLoader.java
public GenericWebXmlContextLoader(String warRootDir, boolean isClasspathRelative) { ResourceLoader resourceLoader = isClasspathRelative ? new DefaultResourceLoader() : new FileSystemResourceLoader(); this.servletContext = initServletContext(warRootDir, resourceLoader); }
From source file:gda.data.metadata.icat.XMLIcat.java
@Override protected String getValue(String visitIDFilter, String userNameFilter, String accessName) throws Exception { String filepath = "file:" + LocalProperties.get(URL_PROP); Resource xmlfile = new FileSystemResourceLoader().getResource(filepath); XmlBeanFactory bf = new XmlBeanFactory(xmlfile); long tolerance = LocalProperties.getAsInt(SHIFT_TOL_PROP, 1440); // if not filtering on visit ID if (visitIDFilter == null || visitIDFilter.isEmpty()) { //loop over all the beans String values = ""; Map<String, XMLIcatEntry> beans = bf.getBeansOfType(XMLIcatEntry.class); for (XMLIcatEntry bean : beans.values()) { // filter on username String names[] = bean.getUsernames().split(","); if (ArrayUtils.contains(names, userNameFilter)) { // filter on date Date now;//from w ww. j av a 2 s . c om if (operatingDate != null) { now = operatingDate; } else { now = new Date(); } Date start = formatter.parse(bean.getExperimentStart()); Date end = formatter.parse(bean.getExperimentStart()); start.setTime(start.getTime() - tolerance * 60000);// tolerance is in minutes but getTime returns in // ms end.setTime(end.getTime() + tolerance * 60000); // tolerance is in minutes but getTime returns in ms if (now.after(start) && now.before(end)) { // add to return string try { if (values.isEmpty()) { values = BeanUtils.getProperty(bean, accessName); } else { values += "," + BeanUtils.getProperty(bean, accessName); } } catch (Exception e) { logger.warn("Exception trying to get property " + accessName + " from bean.", e); } } } } // return the values string if (values.isEmpty()) { return null; } return values; } // else find the experiment for that visit and get its property XMLIcatEntry visit = bf.getBean(visitIDFilter, XMLIcatEntry.class); String names[] = visit.getUsernames().split(","); if (ArrayUtils.contains(names, userNameFilter)) { try { return BeanUtils.getProperty(visit, accessName); } catch (Exception e) { logger.warn("Exception trying to get property " + accessName + " from bean.", e); } } // else return null; }
From source file:org.bonitasoft.web.designer.workspace.WorkspaceInitializerTest.java
@Before public void initializeWorkspaceInitializer() { workspaceInitializer/*from ww w . ja v a 2 s . c o m*/ .setServletContext(new MockServletContext(WAR_BASE_PATH, new FileSystemResourceLoader())); workspaceInitializer.setMigrations(Arrays.<LiveMigration>asList(pageLiveMigration, widgetLiveMigration)); }
From source file:org.gwtwidgets.server.spring.test.HandlerTest.java
@Override @Before/*from w ww .j a v a2s. co m*/ public void setUp() throws Exception { super.setUp(); ServletContext servletContext = new MockServletContext(new FileSystemResourceLoader()); requestService = new MockHttpServletRequest("PUT", "/service"); applicationContext = new XmlWebApplicationContext(); applicationContext.setServletContext(servletContext); applicationContext.setConfigLocations(new String[] { "src/main/webapp/WEB-INF/handler-servlet.xml", "src/main/webapp/WEB-INF/applicationContext.xml" }); try { applicationContext.refresh(); } catch (Throwable e) { e.printStackTrace(); } handler = (GWTHandler) applicationContext.getBean("urlMapping", GWTHandler.class); }
From source file:org.parancoe.web.test.PluginTest.java
@Override protected ConfigurableApplicationContext createApplicationContext(String[] locations) { FileSystemResourceLoader rl = new FileSystemResourceLoader(); ServletContext servletContext = new MockServletContext(rl); XmlWebApplicationContext context = new XmlWebApplicationContext(); context.setServletContext(servletContext); context.setConfigLocations(locations); context.refresh();/* www . j av a 2s . c om*/ return context; }
From source file:com.ables.pix.utility.PictureOps.java
private void rotatePicture(Picture pic, double rotation) { ResourceLoader loader = new FileSystemResourceLoader(); Resource resource = loader.getResource(repositoryRoot + pic.getLocation()); BufferedImage image;//from w w w. ja v a 2s . c o m try { image = ImageIO.read(resource.getFile()); BufferedImage result = tilt(image, rotation); String fileName = pic.getFileName(); ImageIO.write(result, fileName.substring(fileName.indexOf('.' + 1)), new File(resource.getFile().toURI())); } catch (IOException io) { throw new RuntimeException("Failed to rotate image", io); } }
From source file:com.example.springsecurity.web.controllers.GenericWebContextLoader.java
public GenericWebContextLoader(String warRootDir, boolean isClasspathRelative) { ResourceLoader resourceLoader = isClasspathRelative ? new DefaultResourceLoader() : new FileSystemResourceLoader(); this.servletContext = initServletContext(warRootDir, resourceLoader); }
From source file:org.parancoe.web.test.BaseTest.java
@Override protected ConfigurableApplicationContext createApplicationContext(String[] locations) { FileSystemResourceLoader rl = new FileSystemResourceLoader(); MockServletContext servletContext = new MockServletContext(rl); servletContext.setMinorVersion(4);/*from w w w . java2 s.co m*/ servletContext.registerContext("/test", servletContext); servletContext.setServletContextName("/test"); servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, arrayToString(locations)); ContextLoader loader = new ContextLoader(); WebApplicationContext context = loader.initWebApplicationContext(servletContext); return (ConfigurableApplicationContext) context; }
From source file:org.jasig.portlet.calendar.util.MockWebApplicationContextLoader.java
public ApplicationContext loadContext(String... locations) throws Exception { // Establish the portlet context and config based on the test class's MockWebApplication annotation. MockServletContext mockServletContext = new MockServletContext(configuration.webapp(), new FileSystemResourceLoader()); final ServletWrappingPortletContext portletContext = new ServletWrappingPortletContext(mockServletContext); final MockPortletConfig portletConfig = new MockPortletConfig(portletContext, configuration.name()); // Create a WebApplicationContext and initialize it with the xml and portlet configuration. final XmlPortletApplicationContext portletApplicationContext = new XmlPortletApplicationContext(); portletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, portletApplicationContext);// w w w.j ava 2s . c om portletApplicationContext.setPortletConfig(portletConfig); portletApplicationContext.setConfigLocations(locations); // Create a DispatcherPortlet that uses the previously established WebApplicationContext. final DispatcherPortlet dispatcherPortlet = new DispatcherPortlet() { @Override protected WebApplicationContext createPortletApplicationContext(ApplicationContext parent) { return portletApplicationContext; } }; final ViewResolver viewResolver = new MockViewResolver(); // Add the DispatcherPortlet (and anything else you want) to the context. // Note: this doesn't happen until refresh is called below. portletApplicationContext.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() { public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { beanFactory.registerResolvableDependency(DispatcherPortlet.class, dispatcherPortlet); // Register any other beans here, including a ViewResolver if you are using JSPs. beanFactory.registerResolvableDependency(ViewResolver.class, viewResolver); } }); // Have the context notify the portlet every time it is refreshed. portletApplicationContext.addApplicationListener(new SourceFilteringListener(portletApplicationContext, new ApplicationListener<ContextRefreshedEvent>() { public void onApplicationEvent(ContextRefreshedEvent event) { dispatcherPortlet.onApplicationEvent(event); } })); // Prepare the context. portletApplicationContext.refresh(); portletApplicationContext.registerShutdownHook(); // Initialize the portlet. dispatcherPortlet.setContextConfigLocation(""); dispatcherPortlet.init(portletConfig); return portletApplicationContext; }
From source file:org.agatom.springatom.data.vin.decoder.resolver.DefaultWMIManufacturedInResolver.java
@PostConstruct private void initializeWMICodes() { try {// w w w.java2 s .c om final InputStream stream = new FileSystemResourceLoader().getResource(WMI_PATH).getInputStream(); final WMIBeanList wmiBeans = this.objectMapper.readValue(stream, WMIBeanList.class); Assert.notNull(wmiBeans, "Failed to read WMI codes, returned WMIBeanList is null"); this.postProcessWMIBeans(wmiBeans); } catch (Exception exp) { LOGGER.error("initializeWMICodes failed", exp); } }