List of usage examples for java.lang ClassLoader getSystemResource
public static URL getSystemResource(String name)
From source file:org.apache.james.sieverepository.lib.SieveRepositoryManagementTest.java
@Test public void importSieveScriptFileToRepositoryShouldNotImportFileWithWrongPathToRepistory() throws Exception { String userName = "user@domain"; String script = "user_script"; URL sieveResource = ClassLoader.getSystemResource("sieve/my_sieve"); User user = User.fromUsername(userName); ScriptName scriptName = new ScriptName(script); String sieveContent = IOUtils.toString(sieveResource, StandardCharsets.UTF_8); ScriptContent scriptContent = new ScriptContent(sieveContent); sieveRepositoryManagement.addActiveSieveScriptFromFile(userName, script, "wrong_path/" + sieveResource.getFile()); verify(sieveRepository, times(0)).putScript(user, scriptName, scriptContent); verify(sieveRepository, times(0)).setActive(user, scriptName); }
From source file:org.n52.sir.IT.GetCapabilitiesIT.java
private void checkCapabilities(CapabilitiesDocument actual) throws XmlException, IOException, SAXException { assertThat("Document is valid according to XMLBeans.", actual.validate(), is(true)); File f = new File(ClassLoader.getSystemResource("responses/sir/capabilities.xml").getFile()); CapabilitiesDocument expected = CapabilitiesDocument.Factory.parse(f); Diff diff = new Diff(actual.getCapabilities().getOperationsMetadata().toString(), expected.getCapabilities().getOperationsMetadata().toString()); XMLAssert.assertXMLEqual(diff, true); // assertThat("XML is similar.", diff.similar(), is(true)); // assertThat("XML is identical.", diff.identical(), is(true)); }
From source file:org.harmony.server.startup.ResourceLoader.java
/** * This method will search for <code>resource</code> in different places. * The search order is as follows:/*w w w . j av a2s. c o m*/ * * <ol> * * <p> * <li>Search for <code>resource</code> using the thread context class * loader under Java2. If that fails, search for <code>resource</code> using * the class loader that loaded this class (<code>Loader</code>). Under JDK * 1.1, only the the class loader that loaded this class ( * <code>Loader</code>) is used. * * <p> * <li>Try one last time with * <code>ClassLoader.getSystemResource(resource)</code>, that is is using * the system class loader in JDK 1.2 and virtual machine's built-in class * loader in JDK 1.1. * * </ol> */ static public URL getResource(final String resource) { ClassLoader classLoader = null; URL url = null; try { if (!java1) { classLoader = getTCL(); if (classLoader != null) { trace.debug("Trying to find [" + resource + "] using context classloader " + classLoader + "."); url = classLoader.getResource(resource); if (url != null) return url; } } // We could not find resource. Ler us now try with the // classloader that loaded this class. classLoader = ResourceLoader.class.getClassLoader(); if (classLoader != null) { trace.debug("Trying to find [" + resource + "] using " + classLoader + " class loader."); url = classLoader.getResource(resource); if (url != null) return url; } } catch (final Throwable t) { trace.warn(TSTR, t); } // Last ditch attempt: get the resource from the class path. It // may be the case that clazz was loaded by the Extentsion class // loader which the parent of the system class loader. Hence the // code below. trace.debug("Trying to find [" + resource + "] using ClassLoader.getSystemResource()."); return ClassLoader.getSystemResource(resource); }
From source file:org.apache.tajo.storage.http.ExampleHttpServerHandler.java
private static File getRequestedFile(String uri) throws FileNotFoundException, URISyntaxException { String path = URI.create(uri).getPath(); URL url = ClassLoader.getSystemResource("dataset/" + path); if (url == null) { throw new FileNotFoundException(uri); }/*from ww w . j av a 2s . c om*/ return new File(url.toURI()); }
From source file:org.jboss.pressgang.ccms.contentspec.client.commands.PullCommandTest.java
@Before public void setUp() { bindStdOut();//from w w w.j a v a 2s.c om command = new PullCommand(parser, cspConfig, clientConfig); rootTestDirectory = FileUtils.toFile(ClassLoader.getSystemResource("")); when(cspConfig.getRootOutputDirectory()).thenReturn(rootTestDirectory.getAbsolutePath() + File.separator); }
From source file:org.apache.james.jmap.utils.MailboxBasedHtmlTextExtractorTest.java
@Test public void toPlainTextShouldWorkWithMoreComplexHTML() throws Exception { String html = IOUtils.toString(ClassLoader.getSystemResource("example.html")); String expectedPlainText = "\n" + " Why a new Logo?\n" + "\n" + "\n" + "\n" + " We are happy with our current logo, but for the\n" + " upcoming James Server 3.0 release, we would like to\n" + " give our community the opportunity to create a new image for James.\n" + "\n" + "\n" + "\n" + " Don't be shy, take your inkscape and gimp, and send us on\n" + " the James Server User mailing list\n" + " your creations. We will publish them on this page.\n" + "\n" + "\n" + "\n" + " We need an horizontal logo (100p height) to be show displayed on the upper\n" + " left corner of this page, an avatar (48x48p) to be used on a Twitter stream for example.\n" + " The used fonts should be redistributable (or commonly available on Windows and Linux).\n" + " The chosen logo should be delivered in SVG format.\n" + " We also like the Apache feather.\n" + "\n" + "\n" + "\n"; assertThat(textExtractor.toPlainText(html)).isEqualTo(expectedPlainText); }
From source file:de.tudarmstadt.ukp.dkpro.tc.core.util.TaskUtils.java
/** * Loads the JSON file as a system resource, parses it and returnd the JSONObject. * * @param path/*from w w w . j a v a2s .c om*/ * path to the config file * @return the JSONObject containing all config parameters * @throws IOException */ public static JSONObject getConfigFromJSON(String path) throws IOException { String jsonPath = FileUtils.readFileToString(new File(ClassLoader.getSystemResource(path).getFile())); return (JSONObject) JSONSerializer.toJSON(jsonPath); }
From source file:org.apache.james.jmap.json.ParsingWritingObjectsTest.java
@Test public void writingJsonShouldWorkOnMessage() throws Exception { String expected = IOUtils.toString(ClassLoader.getSystemResource("json/message.json")); SimpleFilterProvider filterProvider = new SimpleFilterProvider() .addFilter(JmapResponseWriterImpl.PROPERTIES_FILTER, SimpleBeanPropertyFilter.serializeAll()) .addFilter(GetMessagesMethod.HEADERS_FILTER, SimpleBeanPropertyFilter.serializeAll()); String json = testee.forWriting().setFilterProvider(filterProvider).writeValueAsString(MESSAGE); assertThatJson(json).when(IGNORING_ARRAY_ORDER).isEqualTo(expected); }
From source file:eu.serco.dhus.plugin.slstr.SlstrPlugin.java
private void loadTaskTables() throws ParserConfigurationException, SAXException, IOException { taskTables = new HashMap<String, TaskTable>(); Iterator<Map.Entry<String, String>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> pair = (Map.Entry<String, String>) it.next(); System.out.println(pair.getKey() + " = " + pair.getValue()); URL taskTableName = ClassLoader .getSystemResource("../etc/task_tables/" + pair.getValue() + "_TaskTable.xml"); TaskTable taskTable;//from ww w . j a va 2 s . c om if (taskTableName != null) { taskTable = TaskTableParser.parseTaskTable(taskTableName.getFile()); taskTables.put(pair.getKey() + "", taskTable); logger.info("Task Table parsed successfully for type " + pair.getKey()); } else { logger.warn(" Cannot find task table file for type " + pair.getKey()); } // it.remove(); // avoids a ConcurrentModificationException } }
From source file:org.n52.sir.IT.OpenSearchSpatialTemporalIT.java
@Before public void parseJsonSensorsAndInsert() throws IOException, OwsExceptionReport, XmlException, org.apache.http.HttpException { File sensor_file = new File(ClassLoader.getSystemResource("data/randomSensors.json").getFile()); File sensor_temp = new File(ClassLoader.getSystemResource("AirBase-test.xml").getFile()); SensorMLDocument DOC = SensorMLDocument.Factory.parse(sensor_temp); Gson gson = new Gson(); StringBuilder builder = new StringBuilder(); String s;//from ww w . j a v a2 s . com BufferedReader reader = new BufferedReader((new FileReader(sensor_file))); while ((s = reader.readLine()) != null) builder.append(s); JSONSensorsCollection collection = gson.fromJson(builder.toString(), JSONSensorsCollection.class); Iterator<JSONSensor> sensors = collection.sensors.iterator(); while (sensors.hasNext()) { SirSensor sensor = new SirSensor(); JSONSensor jsensor = sensors.next(); sensor.setKeywords(jsensor.keywords); SirTimePeriod period = new SirTimePeriod(); DateTime begin = DateTime.parse(jsensor.beginPosition); DateTime end = DateTime.parse(jsensor.endPosition); period.setStartTime(begin.toDate()); period.setEndTime(end.toDate()); sensor.setTimePeriod(period); sensor.setIdentificationsList(jsensor.Identifiers); sensor.setLatitude(jsensor.lat); sensor.setLongitude(jsensor.lng); KeywordList klist = KeywordList.Factory.newInstance(); klist.setKeywordArray(jsensor.keywords.toArray(new String[] {})); DOC.getSensorML().getMemberArray(0).getProcess().getKeywordsArray(0).setKeywordList(klist); InsertSensorInfoRequestDocument req = InsertSensorInfoRequestDocument.Factory.newInstance(); req.addNewInsertSensorInfoRequest().addNewInfoToBeInserted() .setSensorDescription(DOC.getSensorML().getMemberArray(0).getProcess()); XmlObject res = client.xSendPostRequest(req); InsertSensorInfoResponseDocument resp = InsertSensorInfoResponseDocument.Factory .parse(res.getDomNode()); } }