List of usage examples for java.lang ClassLoader getSystemResource
public static URL getSystemResource(String name)
From source file:com.stratio.decision.service.SolrOperationsService.java
public void createSolrSchema(List<ColumnNameTypeValue> columns, String confpath) throws ParserConfigurationException, URISyntaxException, IOException, SAXException, TransformerException {/* www .j av a 2 s. c o m*/ DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setIgnoringComments(true); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse(new File(ClassLoader.getSystemResource("./solr-config/schema.xml").toURI())); NodeList nodes = doc.getElementsByTagName("schema"); for (ColumnNameTypeValue column : columns) { Element field = doc.createElement("field"); field.setAttribute("name", column.getColumn()); field.setAttribute("type", streamingToSolr(column.getType())); field.setAttribute("indexed", "true"); field.setAttribute("stored", "true"); nodes.item(0).appendChild(field); } TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult streamResult = new StreamResult(new File(confpath + "/schema.xml")); transformer.transform(source, streamResult); }
From source file:org.n52.oss.IT.OpenSearchIT.java
private String readResource(String name) throws IOException { File results = new File(ClassLoader.getSystemResource(name).getFile()); StringBuilder builder = new StringBuilder(); String realResults = null;//w ww . j a v a 2s.c o m try (BufferedReader reader = new BufferedReader(new FileReader(results));) { String string = ""; while ((string = reader.readLine()) != null) builder.append(string); realResults = builder.toString(); reader.close(); } return realResults; }
From source file:org.n52.sir.IT.DeleteSensorInfoIT.java
@Test public void deleteSensor() throws Exception { File f = new File(ClassLoader.getSystemResource("Requests/sir/DeleteSensorInfo.xml").getFile()); DeleteSensorInfoRequestDocument req = DeleteSensorInfoRequestDocument.Factory.parse(f); req.getDeleteSensorInfoRequest().getInfoToBeDeletedArray(0).getSensorIdentification() .setSensorIDInSIR(sensorID); XmlObject response = client.xSendPostRequest(req); DeleteSensorInfoResponseDocument responseDoc = DeleteSensorInfoResponseDocument.Factory .parse(response.getDomNode()); assertTrue(responseDoc.validate());//from ww w.j ava2s . com assertThat("one sensor was deleted.", responseDoc.getDeleteSensorInfoResponse().getNumberOfDeletedSensors(), is(equalTo(1))); assertThat("no reference was deleted.", responseDoc.getDeleteSensorInfoResponse().getNumberOfDeletedServiceReferences(), is(equalTo(0))); }
From source file:org.reprap.configuration.store.ConfigurationInitializer.java
private void provideDefaultConfiguration() throws IOException { final URL distributionConfiguration = ClassLoader.getSystemResource(DISTRIBUTION_PROPERTIES_DIR_); switch (distributionConfiguration.getProtocol()) { case "file": FileUtils.copyDirectory(new File(URI.create(distributionConfiguration.toString())), reprapDirectory); break;//from w w w . j a v a 2 s . c o m case "jar": copyJarTree(distributionConfiguration, reprapDirectory); break; default: throw new IllegalArgumentException("Cant copy resource stream from " + distributionConfiguration); } }
From source file:net.lightbody.bmp.proxy.jetty.util.Resource.java
/** Construct a system resource from a string. * The resource is tried as classloader resource before being * treated as a normal resource./*from ww w .j av a 2s . c o m*/ */ public static Resource newSystemResource(String resource) throws IOException { URL url = null; // Try to format as a URL? ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader != null) { url = loader.getResource(resource); if (url == null && resource.startsWith("/")) url = loader.getResource(resource.substring(1)); } if (url == null) { loader = Resource.class.getClassLoader(); if (loader != null) { url = loader.getResource(resource); if (url == null && resource.startsWith("/")) url = loader.getResource(resource.substring(1)); } } if (url == null) { url = ClassLoader.getSystemResource(resource); if (url == null && resource.startsWith("/")) url = loader.getResource(resource.substring(1)); } if (url == null) return null; return newResource(url); }
From source file:edu.duke.cabig.c3pr.utils.DaoTestCase.java
/** * For Oracle typically it is "C3PR_DEV" (note- upper case). For Postgres - "public". Dont * forget to override this depending on your database * //www. ja v a 2 s. c o m * @return */ protected static String getSchema() { URL url = ClassLoader.getSystemResource("context/datasource.properties"); Properties p = new Properties(); try { //p.load(new FileInputStream(new File(url.getFile()))); p.load(url.openStream()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return p.getProperty("datasource.testschema"); }
From source file:org.apache.tajo.LocalTajoTestingUtility.java
public static Path getResourcePath(String path, String suffix) { URL resultBaseURL = ClassLoader.getSystemResource(path); return new Path(resultBaseURL.toString(), suffix); }
From source file:com.documentgenerator.view.MainWindow.java
private void loadJson() { URL path = ClassLoader.getSystemResource("window.json"); //System.out.println(path.getAbsolutePath()); Object obj;/*from w w w.ja va 2 s .c o m*/ try { obj = parser.parse(new FileReader(path.getFile())); jsonObj = (JSONArray) obj; } catch (IOException | ParseException ex) { ex.printStackTrace(); } //System.out.println(jsonObj); }
From source file:org.evosuite.statistics.backend.HTMLStatisticsBackend.java
public static void copyFile(String name) { URL systemResource = ClassLoader.getSystemResource("report/" + name); logger.debug("Copying from resource: " + systemResource); copyFile(systemResource, new File(getReportDir(), "files" + File.separator + name)); copyFile(systemResource, new File(getReportDir().getAbsolutePath() + File.separator + "html" + File.separator + "files" + File.separator + name)); }
From source file:org.richie.codeGen.ui.CodeGenMainUI.java
public void initMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu(""); menuBar.add(fileMenu);/*from w w w. j a v a 2 s.c om*/ openPdmFileItem = new JMenuItem("dpm"); openPdmFileItem.setIcon(new ImageIcon(ClassLoader.getSystemResource("resources/images/pdm.png"))); fileMenu.add(openPdmFileItem); JMenu configMenu = new JMenu("?"); menuBar.add(configMenu); templateConfigItem = new JMenuItem("??"); templateConfigItem.addActionListener(this); configMenu.add(templateConfigItem); consConfigItem = new JMenuItem("??"); consConfigItem.addActionListener(this); configMenu.add(consConfigItem); dataTypeConfigItem = new JMenuItem("??"); dataTypeConfigItem.addActionListener(this); configMenu.add(dataTypeConfigItem); JMenu mnHelp = new JMenu(""); menuBar.add(mnHelp); helpDoc = new JMenuItem(""); helpDoc.setIcon(new ImageIcon(ClassLoader.getSystemResource("resources/images/docs.gif"))); mnHelp.add(helpDoc); helpDoc.addActionListener(this); miAbout = new JMenuItem(""); mnHelp.add(miAbout); miAbout.addActionListener(this); openPdmFileItem.addActionListener(this); this.setJMenuBar(menuBar); }