List of usage examples for org.springframework.core.io Resource getURL
URL getURL() throws IOException;
From source file:com.freebox.engeneering.application.web.common.ApplicationContextListener.java
/** * Initializes the application context by web flow xml configs. * @param servletContextEvent the servlet context event. *//*from w ww . j a v a2 s . c o m*/ public void contextInitialized(ServletContextEvent servletContextEvent) { final ServletContext servletContext = servletContextEvent.getServletContext(); final WebApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(servletContext); String initParameter = servletContext.getInitParameter(CONFIG_LOCATION_PARAM); final String[] configLocations = getConfigLocations(context, initParameter); final Set<URL> xmlConfigs = new HashSet<URL>(); for (String configLocation : configLocations) { try { final Resource[] locationResources = context.getResources(configLocation); for (Resource locationResource : locationResources) { xmlConfigs.add(locationResource.getURL()); } } catch (IOException e) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Could not find state chart configuration", e); } } } Assert.notEmpty(xmlConfigs, "Cannot find state chart configuration."); ApplicationContextLocator.setWebFlowConfiguration(xmlConfigs); ApplicationContextLocator.setApplicationContext(context); final FlowConfigurationLoader flowConfigurationLoader = (FlowConfigurationLoader) context .getBean("flowConfigurationLoader"); flowConfigurationLoader.init(xmlConfigs); }
From source file:org.osiam.OsiamHome.java
private void copyToHome(Resource resource, Path osiamHomeDir) throws IOException { String pathUnderHome = resource.getURL().toString().replaceFirst(".*home/", ""); Path target = osiamHomeDir.resolve(pathUnderHome); Files.createDirectories(target.getParent()); Files.copy(resource.getInputStream(), target, StandardCopyOption.REPLACE_EXISTING); }
From source file:com.agileapes.couteau.maven.resource.ClassPathScanningClassProvider.java
public Set<Class> findCandidateClasses(String basePackage) { Set<Class> candidates = new TreeSet<Class>(new Comparator<Class>() { @Override/*w w w . ja v a2s .c o m*/ public int compare(Class dis, Class dat) { if (dis == null && dat == null) { return 0; } else if (dis == null) { return -1; } else if (dat == null) { return 1; } else { return dis.getName().compareTo(dat.getName()); } } }); try { final String packageSearchPath = classpathUrlPrefix + resolveBasePackage(basePackage) + "/" + DEFAULT_RESOURCE_PATTERN; final Resource[] resources = ((ResourcePatternResolver) this.getResourceLoader()) .getResources(packageSearchPath); if (resources == null) { return Collections.emptySet(); } for (Resource resource : resources) { if (resource.isReadable() && resource.getURL().getPath() != null) { if (isCandidateComponent(this.metadataReaderFactory.getMetadataReader(resource))) { candidates.add(resolveClass(resource, basePackage)); } } } } catch (IOException ex) { throw new RuntimeException("I/O failure during classpath scanning", ex); } catch (ClassNotFoundException e) { throw new RuntimeException("System failure during classpath scanning. No class were found.", e); } return candidates; }
From source file:de.alpharogroup.mystic.crypt.spring.SpringApplicationContext.java
/** * Instantiates a new spring application context. *///from w w w. j av a 2s .com private SpringApplicationContext() { final String rootContextDirectoryClassPath = "/ctx"; final String applicationContextPath = rootContextDirectoryClassPath + "/application-context.xml"; final ApplicationContext ac = new ClassPathXmlApplicationContext(applicationContextPath); final Resource resource = ac.getResource("classpath:conf/log4j/log4jconfig.xml"); try { DOMConfigurator.configure(resource.getURL()); } catch (final FactoryConfigurationError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } applicationContext = ac; }
From source file:com.quartzdesk.executor.common.spring.db.DataSourceScriptExecutorFactoryBean.java
/** * Applies the specified SQL init script to the database. * * @param con a JDBC connection.//from w w w . j a v a 2 s .com * @param initScript the SQL init script to apply. */ private void applyInitScript(Connection con, Resource initScript) { URL initScriptUrl; try { initScriptUrl = initScript.getURL(); } catch (IOException e) { throw new RuntimeException("Error obtaining URL of SQL script resource: " + initScript); } boolean autoCommit = true; try { autoCommit = con.getAutoCommit(); DatabaseScriptExecutor scriptExecutor = new DatabaseScriptExecutor(); scriptExecutor.addScriptUrl(initScriptUrl); scriptExecutor.executeScripts(con); // if auto-commit disabled, we need to commit the changes if (!autoCommit) con.commit(); log.info("Successfully applied SQL script: {} to database.", initScriptUrl); } catch (SQLException e) { try { if (!autoCommit) con.rollback(); } catch (SQLException se) { log.warn("Error rolling-back connection: " + con, se); } throw new RuntimeException("Error applying SQL script: " + initScriptUrl, e); } }
From source file:com.haulmont.cuba.core.sys.dbupdate.ScriptResource.java
public ScriptResource(Resource resource) { try {//from w w w . j ava 2 s . co m this.resource = resource; this.name = resource.getFilename(); this.path = URLEncodeUtils.decodeUtf8(resource.getURL().getPath()); this.dir = StringUtils.substringBeforeLast(this.path, "/"); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.javaetmoi.core.spring.vfs.Vfs2PathMatchingResourcePatternResolver.java
/** * The fix https://jira.spring.io/browse/SPR-11676 for the 4.0.4 Spring release breaks VFS * support. By waiting the 4.0.6 release and its patch https://jira.spring.io/browse/SPR-11887, * we override this method in ordrer to remove the the URL_PROTOCOL_VFSZIP check. * /*from ww w. j av a 2 s . com*/ */ @Override protected boolean isJarResource(Resource resource) throws IOException { String protocol = resource.getURL().getProtocol(); return (URL_PROTOCOL_JAR.equals(protocol) || URL_PROTOCOL_ZIP.equals(protocol) || URL_PROTOCOL_WSJAR.equals(protocol)); }
From source file:scriptella.driver.spring.EtlExecutorBean.java
/** * Sets configuration location.// ww w . ja va 2 s. co m * * @param resource configuration resource. */ public void setConfigLocation(Resource resource) throws IOException { configLocation = resource.getURL(); }
From source file:org.beangle.ems.dev.hibernate.web.action.EvolutionAction.java
public String display() throws IOException { String sql = get("sqlfile"); Resource resource = resolver.getResource(sql); InputStream is = null;/* ww w . ja v a 2 s . c o m*/ try { is = resource.getURL().openStream(); put("sqllines", IOs.readLines(new InputStreamReader(is))); } catch (IOException e) { e.printStackTrace(); } finally { if (null != is) is.close(); } put("databaseName", databaseName); put("resource", resource); return forward(); }
From source file:org.dms.sys.repo.logging.Log4JHierarchyInit.java
/** * Import log settings.// www . jav a2s . co m * * @param method the method * @param springUrl the spring url */ private void importLogSettings(Method method, String springUrl) { Resource[] resources = null; try { resources = resolver.getResources(springUrl); } catch (Exception e) { logger.warn("Failed to find additional Logger configuration: " + springUrl); } // Read each resource for (Resource resource : resources) { try { URL url = resource.getURL(); method.invoke(null, url); } catch (Throwable e) { if (logger.isDebugEnabled()) { logger.debug("Failed to add extra Logger configuration: \n" + " URL: " + springUrl + "\n" + " Error: " + e.getMessage(), e); } } } }