List of usage examples for java.lang ClassLoader getSystemResource
public static URL getSystemResource(String name)
From source file:org.n52.sir.IT.InsertSensorStatusIT.java
@Test public void insertSensorStatus() throws XmlException, IOException, OwsExceptionReport, HttpException { File sensor_status = new File(ClassLoader.getSystemResource("Requests/InsertSensorStatus.xml").getFile()); InsertSensorStatusRequestDocument request = InsertSensorStatusRequestDocument.Factory.parse(sensor_status); XmlObject res = client.xSendPostRequest(request); InsertSensorStatusResponseDocument response = InsertSensorStatusResponseDocument.Factory .parse(res.getDomNode());/* www .jav a2 s. c om*/ String expected = request.getInsertSensorStatusRequest().getStatusDescription().getSensorIDInSIR(); String actual = response.getInsertSensorStatusResponse().getSensorIDInSIR(); assertThat("sensor IDs equal", actual, is(equalTo(expected))); }
From source file:org.openmrs.module.metadatasharing.converter.ConceptMapConverterTest.java
@Before public void before() throws Exception { File file = new File(ClassLoader.getSystemResource(TEXT_CONCEPT_MAP_XML_FILE).getPath()); originalXml = FileUtils.readFileToString(file, "UTF-8"); document = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(ClassLoader.getSystemResourceAsStream(TEXT_CONCEPT_MAP_XML_FILE)); }
From source file:org.kontalk.util.Tr.java
public static void init() { // get language String lang = Locale.getDefault().getLanguage(); if (lang.equals(DEFAULT_LANG)) { return;/* w w w . j a v a2 s . c o m*/ } LOGGER.info("Setting language: " + lang); // load string keys file String path = Kontalk.RES_PATH + I18N_DIR + STRING_FILE + PROP_EXT; PropertiesConfiguration stringKeys; try { stringKeys = new PropertiesConfiguration(ClassLoader.getSystemResource(path)); } catch (ConfigurationException ex) { LOGGER.log(Level.WARNING, "can't load string key file", ex); return; } // load translation file path = Kontalk.RES_PATH + I18N_DIR + STRING_FILE + "_" + lang + PROP_EXT; URL url = ClassLoader.getSystemResource(path); if (url == null) { LOGGER.info("can't find translation file: " + path); return; } PropertiesConfiguration tr = new PropertiesConfiguration(); tr.setEncoding("UTF-8"); try { tr.load(url); } catch (ConfigurationException ex) { LOGGER.log(Level.WARNING, "can't load translation file", ex); return; } TR_MAP = new HashMap<>(); Iterator<String> it = tr.getKeys(); while (it.hasNext()) { String k = it.next(); if (!stringKeys.containsKey(k)) { LOGGER.warning("key in translation but not in key file: " + k); continue; } TR_MAP.put(stringKeys.getString(k), tr.getString(k)); } }
From source file:org.ballerinalang.test.task.AppointmentTest.java
@BeforeClass public void setup() { System.setProperty("java.util.logging.config.file", ClassLoader.getSystemResource("logging.properties").getPath()); System.setProperty("java.util.logging.manager", "org.ballerinalang.logging.BLogManager"); }
From source file:Resources.java
/** * Returns the URL of the resource on the classpath * * @param loader The classloader used to load the resource * @param resource The resource to find//from ww w . j a v a 2 s . com * @return The resource * @throws IOException If the resource cannot be found or read */ public static URL getResourceURL(ClassLoader loader, String resource) throws IOException { URL url = null; if (loader != null) url = loader.getResource(resource); if (url == null) url = ClassLoader.getSystemResource(resource); if (url == null) throw new IOException("Could not find resource " + resource); return url; }
From source file:org.jboss.pressgang.ccms.contentspec.client.ClientTest.java
@Before public void setUp() { File file = FileUtils.toFile(ClassLoader.getSystemResource("")); System.setProperty("user.home", file.getAbsolutePath()); }
From source file:com.github.dozermapper.core.util.ResourceLoader.java
public URL getResource(String resource) { resource = resource.trim();/* w ww . j a v a2s . c om*/ URL result = Thread.currentThread().getContextClassLoader().getResource(resource); // Could not find resource. Try with the classloader that loaded this class. if (result == null) { ClassLoader classLoader = ResourceLoader.class.getClassLoader(); if (classLoader != null) { result = classLoader.getResource(resource); } } // Last ditch attempt searching classpath if (result == null) { result = ClassLoader.getSystemResource(resource); } // one more time if (result == null && StringUtils.contains(resource, ":")) { try { result = new URL(resource); } catch (MalformedURLException e) { MappingUtils.throwMappingException(e); } } return result; }
From source file:org.wte4j.impl.service.LocalFileStoreTest.java
@Test public void storeFile() throws IOException { LocalFileStore fileStore = new LocalFileStore(); fileStore.setTemplateDirectory(tempDir); URL url = ClassLoader.getSystemResource("org/wte4j/impl/test.txt"); File testFile = FileUtils.toFile(url); OutputStream out = null;/*from www. j a va 2 s . co m*/ InputStream in = null; try { final String fileName = "fileStoreTest.txt"; out = fileStore.getOutStream(fileName); in = FileUtils.openInputStream(testFile); IOUtils.copy(in, out); File[] filesInDir = tempDir.listFiles(); assertEquals(1, filesInDir.length); assertEquals(fileName, filesInDir[0].getName()); assertTrue(FileUtils.contentEquals(testFile, filesInDir[0])); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } }
From source file:dk.cubing.liveresults.uploader.configuration.Configuration.java
/** * @param engine/*from ww w .j a v a 2 s .c om*/ */ public Configuration(ResultsEngine engine) { this.engine = engine; try { File configFile = new File(new File(".").getAbsolutePath() + "/conf/config.properties"); if (!configFile.getCanonicalFile().exists()) { configFile = new File(ClassLoader.getSystemResource("config.properties").getFile()); } log.debug("Config file: {}", configFile.getCanonicalFile()); config = new PropertiesConfiguration(configFile.getCanonicalFile()); config.setReloadingStrategy(new ResultsConfigReloadingStrategy(engine)); } catch (Exception e) { log.error("Could not load configuration file", e); engine.shutdown(); } }
From source file:de.tbuchloh.kiskis.persistence.exporter.XHTMLExporterTest.java
/** * Test fr Export// w w w. j av a 2 s . c om * * @throws Exception * wenn unvorhergesehene Fehler auftreten. */ @Test public void testExportHtml() throws Exception { final File file = new File("target/test.html"); new XSLExporter(ClassLoader.getSystemResource("export/kiskis-html.xsl")) .export(CSVExporterTest.initDocument(), file); final String content = FileProcessor.readFile(file); LOG.debug(content); final String[] contents = { "e-mail related stuff here", // Group comment "ebay", // Label "144434365tfhgcfghcv", // password "googlemailer", // user name "Comment with multiple lines", // account comment "2010-11-16T15:19:45", // created on, "2010-11-16T15:17:43", // last changed "2010-11-16T15:17:35", // last viewed "<td>7</td>", // view count "2011-11-16", // expires on "2009-11-12T15:15:43", // archived On "foobar@gmx.eu", // email "http://www.amazon.com", // url }; for (final String s : contents) { assertTrue(s, content.contains(s)); } // expiresNever = true assertFalse(content.contains("2028-11-16")); }