List of usage examples for org.springframework.util ResourceUtils getURL
public static URL getURL(String resourceLocation) throws FileNotFoundException
From source file:org.alfresco.util.xml.SchemaHelper.java
public static void main(String... args) { if (args.length < 2 || !args[0].startsWith("--compile-xsd=") && !args[1].startsWith("--output-dir=")) { System.out.println("Usage: SchemaHelper --compile-xsd=<URL> --output-dir=<directory>"); System.exit(1);/*from w ww . j a v a 2 s .c om*/ } final String urlStr = args[0].substring(14); if (urlStr.length() == 0) { System.out.println("Usage: SchemaHelper --compile-xsd=<URL> --output-dir=<directory>"); System.exit(1); } final String dirStr = args[1].substring(13); if (dirStr.length() == 0) { System.out.println("Usage: SchemaHelper --compile-xsd=<URL> --output-dir=<directory>"); System.exit(1); } try { URL url = ResourceUtils.getURL(urlStr); File dir = new File(dirStr); if (!dir.exists() || !dir.isDirectory()) { System.out.println("Output directory not found: " + dirStr); System.exit(1); } ErrorListener errorListener = new ErrorListener() { public void warning(SAXParseException e) { System.out.println("WARNING: " + e.getMessage()); } public void info(SAXParseException e) { System.out.println("INFO: " + e.getMessage()); } public void fatalError(SAXParseException e) { handleException(urlStr, e); } public void error(SAXParseException e) { handleException(urlStr, e); } }; SchemaCompiler compiler = XJC.createSchemaCompiler(); compiler.setErrorListener(errorListener); compiler.parseSchema(new InputSource(url.toExternalForm())); S2JJAXBModel model = compiler.bind(); if (model == null) { System.out.println("Failed to produce binding model for URL " + urlStr); System.exit(1); } JCodeModel codeModel = model.generateCode(null, errorListener); codeModel.build(dir); } catch (Throwable e) { handleException(urlStr, e); System.exit(1); } }
From source file:at.pagu.soldockr.AbstractITestWithEmbeddedSolrServer.java
@BeforeClass public static void initSolrServer() throws IOException, ParserConfigurationException, SAXException { System.setProperty("solr.solr.home", StringUtils.remove(ResourceUtils.getURL("classpath:at/pagu/soldockr").toString(), "file:/")); CoreContainer.Initializer initializer = new CoreContainer.Initializer(); CoreContainer coreContainer = initializer.initialize(); solrServer = new EmbeddedSolrServer(coreContainer, ""); }
From source file:com.shengpay.commons.bp.logback.LogbackConfigurer.java
/** * Initialize logback from the given file location, with no config file refreshing. Assumes an XML file in case of a ".xml" file extension, and a properties file otherwise. * //from ww w . jav a 2s. c o m * @param location * the location of the config file: either a "classpath:" location (e.g. "classpath:mylogback.properties"), an absolute file URL (e.g. "file:C:/logback.properties), or a plain absolute path in the file system (e.g. "C:/logback.properties") * @throws FileNotFoundException * if the location specifies an invalid file path */ public static void initLogging(String location) throws FileNotFoundException { String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location); URL url = ResourceUtils.getURL(resolvedLocation); if (resolvedLocation.toLowerCase().endsWith(XML_FILE_EXTENSION)) { // DOMConfigurator.configure(url); configurator.setContext(lc); lc.reset(); try { configurator.doConfigure(url); } catch (JoranException ex) { throw new FileNotFoundException(url.getPath()); } lc.start(); } // else { // PropertyConfigurator.configure(url); // } }
From source file:at.pagu.soldockr.repository.cdi.SolrTemplateProducer.java
private SolrServer getSolrServerInstance() throws IOException, ParserConfigurationException, SAXException { System.setProperty("solr.solr.home", StringUtils.remove(ResourceUtils.getURL("classpath:at/pagu/soldockr").toString(), "file:/")); CoreContainer.Initializer initializer = new CoreContainer.Initializer(); CoreContainer coreContainer = initializer.initialize(); return new EmbeddedSolrServer(coreContainer, ""); }
From source file:ch.qos.logback.ext.spring.LogbackConfigurer.java
/** * Initialize logback from the given file. * * @param location the location of the config file: either a "classpath:" location * (e.g. "classpath:logback.xml"), an absolute file URL * (e.g. "file:C:/logback.xml), or a plain absolute path in the file system * (e.g. "C:/logback.xml") * @throws java.io.FileNotFoundException if the location specifies an invalid file path * @throws ch.qos.logback.core.joran.spi.JoranException * Thrown *//*from www . ja v a 2s.c o m*/ public static void initLogging(String location) throws FileNotFoundException, JoranException { String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location); URL url = ResourceUtils.getURL(resolvedLocation); LoggerContext loggerContext = (LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory(); // in the current version logback automatically configures at startup the context, so we have to reset it loggerContext.reset(); // reinitialize the logger context. calling this method allows configuration through groovy or xml new ContextInitializer(loggerContext).configureByResource(url); }
From source file:com.yxw.framework.common.spring.ext.LogbackConfigurer.java
/** * Initialize logback from the given file. * /*from w w w .j a v a 2 s .co m*/ * @param location * the location of the config file: either a "classpath:" location (e.g. "classpath:logback.xml"), an * absolute file URL (e.g. "file:C:/logback.xml), or a plain absolute path in the file system (e.g. * "C:/logback.xml") * @throws java.io.FileNotFoundException * if the location specifies an invalid file path * @throws ch.qos.logback.core.joran.spi.JoranException * Thrown */ public static void initLogging(String location) throws FileNotFoundException, JoranException { String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location); URL url = ResourceUtils.getURL(resolvedLocation); LoggerContext loggerContext = (LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory(); // in the current version logback automatically configures at startup // the context, so we have to reset it loggerContext.reset(); // reinitialize the logger context. calling this method allows // configuration through groovy or xml new ContextInitializer(loggerContext).configureByResource(url); }
From source file:io.spring.initializr.generator.ProjectResourceLocator.java
private InputStream getInputStream(String location) throws IOException { URL url = ResourceUtils.getURL(location); return url.openStream(); }
From source file:com.excilys.ebi.utils.spring.log.logback.LogbackConfigurer.java
/** * Initialize logback from the given file. JUL is correctly handled and * redirected on SLF4J (@see//from w ww .j a va2 s . co m * http://logback.qos.ch/manual/configuration.html#LevelChangePropagator). * * @param location * the location of the config file: either a "classpath:" * location (e.g. "classpath:logback.xml"), an absolute file URL * (e.g. "file:C:/logback.xml), or a plain absolute path in the * file system (e.g. "C:/logback.xml") * @throws java.io.FileNotFoundException * if the location specifies an invalid file path * @throws FileNotFoundException * the file not found exception * @throws JoranException * the joran exception */ public static void initLogging(String location) throws FileNotFoundException, JoranException { String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location); URL url = ResourceUtils.getURL(resolvedLocation); ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector(); LoggerContext loggerContext = selector.getLoggerContext(); // in the current version logback automatically configures at startup // the context, so we have to reset it loggerContext.reset(); ContextInitializer contextInitializer = new ContextInitializer(loggerContext); contextInitializer.configureByResource(url); // reset JUL // don't forget to configure the LevelChangePropagator contextListener // in the config file!!! SLF4JBridgeHandler.install(); }
From source file:at.pagu.soldockr.core.EmbeddedSolrServerFactory.java
/** * @param path Any Path expression valid for use with {@link ResourceUtils} * @return new instance of {@link EmbeddedSolrServer} * @throws ParserConfigurationException/*from ww w. j ava 2 s .co m*/ * @throws IOException * @throws SAXException */ public final EmbeddedSolrServer createPathConfiguredSolrServer(String path) throws ParserConfigurationException, IOException, SAXException { String solrHome = System.getProperty(SOLR_HOME_SYSTEM_PROPERTY); if (StringUtils.isBlank(solrHome)) { solrHome = StringUtils.remove(ResourceUtils.getURL(path).toString(), "file:/"); } return new EmbeddedSolrServer(new CoreContainer(solrHome, new File(solrHome + "/solr.xml")), null); }
From source file:edu.amc.sakai.user.JLDAPDirectoryProviderIntegrationTestSupport.java
ConfigurableApplicationContext newTestApplicationContext(ApplicationContext parent) { List existingFiles = new ArrayList(); for (String fileName : TEST_CONTEXT_CONFIG_FILE_NAMES) { try {//from ww w . j a v a 2s . com ResourceUtils.getFile(ResourceUtils.getURL(ResourceUtils.CLASSPATH_URL_PREFIX + fileName)); existingFiles.add(fileName); } catch (FileNotFoundException e) { // } } String[] existingFilesArray = new String[existingFiles.size()]; return new ClassPathXmlApplicationContext((String[]) existingFiles.toArray(existingFilesArray), parent); }