List of usage examples for java.net URL getPath
public String getPath()
From source file:com.mg.jet.birt.report.data.oda.ejbql.HibernateUtil.java
public static synchronized void buildConfig(String hibfile, String mapdir, Configuration cfg) throws HibernateException, IOException, Exception { Bundle hibbundle = Platform.getBundle("com.mg.jet.birt.report.data.oda.ejbql"); //?? ?/*from ww w .j a v a 2 s . c o m*/ File cfgDir = new File(mapdir); if (cfgDir != null) { if (cfgDir.isDirectory()) cfg.addDirectory(cfgDir); else if (cfgDir.length() > 0) cfg.addJar(cfgDir); } URL hibfiles = FileLocator.find(hibbundle, new Path(CommonConstant.HIBERNATE_CLASSES), null); URL hibURL = FileLocator.resolve(hibfiles); File hibDirectory = new File(hibURL.getPath()); // ? ? , ? ?? ? File[] files = hibDirectory.listFiles(); if (files != null) for (int i = 0; i < files.length; i++) { if (!files[i].isDirectory() && files[i].getName().startsWith("mg.") && files[i].getName().endsWith(".hbm.xml")) { cfg.addFile(files[i]); } } // ? MBSA // loadMBSADatawarehouse(cfg); File mbsaData = new File(hibURL.getPath().concat(CommonConstant.DATAWAREHOUSE)); if (mbsaData.isFile()) cfg.addJar(mbsaData); cfg.addDirectory(hibDirectory); File cfgFile = new File(hibfile); if (cfgFile != null && cfgFile.length() > 0) { cfg.configure(cfgFile); } else { File configFile = new File(hibURL.getPath() + CommonConstant.DATAWAREHOUSE_CFG_FILE); cfg.configure(configFile); } return; }
From source file:com.rovemonteux.silvertunnel.netlib.adapter.httpclient.HttpClientUtil.java
public static InputStream simpleAction(final URL url) throws IOException { final int port = url.getPort() < 0 ? 80 : url.getPort(); final TcpipNetAddress httpServerNetAddress = new TcpipNetAddress(url.getHost(), port); final Map<String, Object> localProperties = new HashMap<String, Object>(); final NetSocket lowerLayerNetSocket = lowerNetLayer.createNetSocket(localProperties, /* localAddress */null, httpServerNetAddress);/*from www. j a v a 2s. c o m*/ String pathOnHttpServer = url.getPath(); if (pathOnHttpServer == null || pathOnHttpServer.length() < 1) { pathOnHttpServer = "/"; } final long timeoutInMs = 10L * 1000L; return HttpUtil.getInstance().getReponseBodyInputStream(lowerLayerNetSocket, httpServerNetAddress, pathOnHttpServer, timeoutInMs); }
From source file:com.rovemonteux.silvertunnel.netlib.adapter.httpclient.HttpClientUtil.java
public static byte[] simpleBytesAction(final URL url) throws IOException { final int port = url.getPort() < 0 ? 80 : url.getPort(); final TcpipNetAddress httpServerNetAddress = new TcpipNetAddress(url.getHost(), port); final Map<String, Object> localProperties = new HashMap<String, Object>(); final NetSocket lowerLayerNetSocket = lowerNetLayer.createNetSocket(localProperties, /* localAddress */null, httpServerNetAddress);//w w w .j a va 2s .c o m String pathOnHttpServer = url.getPath(); if (pathOnHttpServer == null || pathOnHttpServer.length() < 1) { pathOnHttpServer = "/"; } final long timeoutInMs = 10L * 1000L; HttpUtil.getInstance(); return HttpUtil.get(lowerLayerNetSocket, httpServerNetAddress, pathOnHttpServer, timeoutInMs); }
From source file:de.ingrid.portal.global.UtilsMapServiceManager.java
/** * Create map and there gml files (per classification) for temporary service * /*www . j a va2 s. c o m*/ * @param title * @param coords * @param coordTypeForMapFile * @return path to map or gml file * @throws ConfigurationException * @throws Exception */ public static String createTemporaryService(String title, List<HashMap<String, String>> coords, String fileType) throws ConfigurationException, Exception { String fileName = ""; countTempServiceNumber(); if (fileType.endsWith(UtilsFileHelper.KML)) { URL url = Thread.currentThread().getContextClassLoader() .getResource("../templates/pattern/temporary_service_kml.vm"); String path = url.getPath(); // Create file fileName = UtilsFileHelper.createNewService(title, UtilsFileHelper.KML, getConfig().getString("temp_service_path", null)); UtilsFileHelper.writeContentIntoFile( getTmpDirectory(getConfig().getString("temp_service_path", null)).concat(fileName), mergeTemplateKML(path, coords, title, fileName)); } return fileName; }
From source file:eu.trentorise.smartcampus.network.RemoteConnector.java
private static String normalizeURL(String uriString) throws RemoteException { try {// ww w .j a va 2s. c o m URL url = new URL(uriString); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); uriString = uri.toURL().toString(); } catch (Exception e) { throw new RemoteException(e.getMessage()); } return uriString; }
From source file:main.java.refinement_class.Useful.java
public static Object unmashal(String schema_file, String xml_file, Class c) { Object obj = null;/* ww w .j a va 2s . c om*/ try { // create a JAXBContext capable of handling classes generated into // JAXBContext jc = JAXBContext.newInstance(ObjectFactory.class ); JAXBContext jc = JAXBContext.newInstance(c); // create an Unmarshaller Unmarshaller u = jc.createUnmarshaller(); SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI); try { // LOG.info("\n\n XX -->> Schema file: " + schema_file); // LOG.info("\n\n XX -->> xml_file file: " + xml_file); //++ javax.xml.validation.Schema schema; if (schema_file.contains("/tmp/")) { schema = sf.newSchema(new File(schema_file)); } else { URL urlSchema = getUrl(H2mserviceImpl.class, schema_file); // LOG.info("\n\n XX -->> urlSchema: " + urlSchema.getPath()); schema = sf.newSchema(urlSchema); } //-- //javax.xml.validation.Schema schema = sf.newSchema(new File(schema_file)); // ++ u.setSchema((javax.xml.validation.Schema) schema); u.setEventHandler(new ValidationEventHandler() { // allow unmarshalling to continue even if there are errors public boolean handleEvent(ValidationEvent ve) { // ignore warnings if (ve.getSeverity() != ValidationEvent.WARNING) { ValidationEventLocator vel = ve.getLocator(); System.out.println("Line:Col[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + "]:" + ve.getMessage()); } return true; } }); } catch (org.xml.sax.SAXException se) { System.out.println("Unable to validate due to following error."); se.printStackTrace(); LOG.error("===>[1]ERROR Unmashaling \n\n" + se.toString()); LOG.error(Useful.getStackTrace(se)); } catch (Exception e) { LOG.error("===>[2]ERROR Unmashaling \n\n" + e.toString()); LOG.error(Useful.getStackTrace(e)); } if (xml_file.contains("/tmp/")) { obj = u.unmarshal(new File(xml_file)); } else { URL url_xml_file = getUrl(H2mserviceImpl.class, xml_file); LOG.info("\n\n XX -->> url_xml_file: " + url_xml_file.getPath()); obj = u.unmarshal(url_xml_file); } //-- //obj = u.unmarshal( new File( xml_file)); //++ // even though document was determined to be invalid unmarshalling, // marshal out result. // System.out.println(""); // System.out.println("Still able to marshal invalid document"); // javax.xml.bind.Marshaller m = jc.createMarshaller(); // m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE ); // m.marshal(poe, System.out); } catch (UnmarshalException ue) { // The JAXB specification does not mandate how the JAXB provider // must behave when attempting to unmarshal invalid XML data. // those cases, the JAXB provider is allowed to terminate the // call to unmarshal with an UnmarshalException. System.out.println("Caught UnmarshalException"); LOG.error("===>[3]ERROR Unmashaling \n\n" + ue.toString()); } catch (JAXBException je) { je.printStackTrace(); LOG.error("===>[4]ERROR Unmashaling \n\n" + je.toString()); LOG.error(Useful.getStackTrace(je)); } catch (Exception e) { LOG.error("===>[5]ERROR Unmashaling \n\n" + e.toString()); LOG.error(Useful.getStackTrace(e)); } if (obj == null) { LOG.error("===>[6]ERROR Unmashaling Object NULL"); } return obj; }
From source file:app.web.Application2ITCase.java
public static URL toLocationPath(String location) { try {//from w ww.java 2 s. co m URL fullUrl = new URL(location); // We just throw the query string if any return new URL(fullUrl.getProtocol(), fullUrl.getHost(), fullUrl.getPort(), fullUrl.getPath()); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:Models.Geographic.Repository.RepositoryGoogle.java
/** * Method that geocoding a address from google api * @param country//from w ww . j av a2 s. co m * @param adm1 * @param adm2 * @param adm3 * @param local_area * @param locality * @param uncertainty * @return */ public static Location georenferencing(String country, String adm1, String adm2, String adm3, String local_area, String locality, double uncertainty) { Location a = null; String key; try { key = FixData.generateKey(new String[] { country, adm1, adm2, adm3, local_area, locality }); if (RepositoryGoogle.db == null) RepositoryGoogle.db = new HashMap(); if (RepositoryGoogle.db.containsKey(key)) return (Location) RepositoryGoogle.db.get(key); String data = (!locality.equals("") ? locality : "") + (!local_area.equals("") ? local_area + "+,+" : "") + (!adm3.equals("") ? adm3 + "+,+" : "") + (!adm2.equals("") ? adm2 + "+,+" : "") + (!adm1.equals("") ? adm1 + "+,+" : "") + (!country.equals("") ? country + "+,+" : ""); URL url = new URL(Configuration.getParameter("geocoding_google_url_send_xml") + "address=" + data.replace(" ", "%20").replace(".", "").replace(";", "")); URL file_url = new URL( url.getProtocol() + "://" + url.getHost() + signRequest(url.getPath(), url.getQuery())); // Get information from URL DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); // Create a proxy to work in CIAT (erase this in another place) //Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy2.ciat.cgiar.org", 8080)); DocumentBuilder db = dbf.newDocumentBuilder(); //Document doc = db.parse(file_url.openConnection(proxy).getInputStream()); Document doc = db.parse(file_url.openConnection().getInputStream()); // Document with data if (doc != null) { NodeList locationList = doc.getElementsByTagName("location"); NodeList locationTypeList = doc.getElementsByTagName("location_type"); NodeList viewPortList = doc.getElementsByTagName("viewport"); Node location = null, lat = null, lng = null; if (locationList.getLength() > 0) { for (int i = 0; i < locationList.getLength(); i++) { location = locationList.item(i); if (location.hasChildNodes()) { lat = location.getChildNodes().item(1); lng = location.getChildNodes().item(3); } } Node locationType = null; if (locationTypeList.getLength() > 0) { for (int i = 0; i < locationTypeList.getLength(); i++) locationType = locationTypeList.item(i); } Node viewPort = null, northeast = null, southwest = null, lat_northeast = null, lng_northeast = null, lat_southwest = null, lng_southwest = null; if (viewPortList.getLength() > 0) { for (int i = 0; i < viewPortList.getLength(); i++) { viewPort = viewPortList.item(i); if (viewPort.hasChildNodes()) { northeast = viewPort.getChildNodes().item(1); southwest = viewPort.getChildNodes().item(3); } /* Extract data from viewport field */ if (northeast.hasChildNodes()) { lat_northeast = northeast.getChildNodes().item(1); lng_northeast = northeast.getChildNodes().item(3); } if (southwest.hasChildNodes()) { lat_southwest = southwest.getChildNodes().item(1); lng_southwest = southwest.getChildNodes().item(3); } } } double[] coordValues = new double[] { Double.parseDouble(lat.getTextContent()), Double.parseDouble(lng.getTextContent()) }; double[] coordValuesNortheast = new double[] { Double.parseDouble(lat_northeast.getTextContent()), Double.parseDouble(lng_northeast.getTextContent()) }; double[] coordValuesSouthwest = new double[] { Double.parseDouble(lat_southwest.getTextContent()), Double.parseDouble(lng_southwest.getTextContent()) }; double distance = FixData.getDistance(coordValuesNortheast, coordValuesSouthwest); // Distance - km between Northeast and Southeast if (distance <= uncertainty) a = new Location(coordValues[0], coordValues[1], distance); else { RepositoryGoogle.db.put(key, a); throw new Exception("Exceede uncertainty. " + "Uncertainty: " + distance + " THRESHOLD: " + Configuration.getParameter("geocoding_threshold")); } } } RepositoryGoogle.db.put(key, a); } catch (NoSuchAlgorithmException | InvalidKeyException | URISyntaxException | IOException | ParserConfigurationException | SAXException ex) { System.out.println(ex); } catch (Exception ex) { System.out.println(ex); } return a; }
From source file:ota.otaupdates.utils.Utils.java
public static void DownloadFromUrl(String download_url, String fileName) { final String TAG = "Downloader"; if (!isMainThread()) { try {//from www . j a v a 2s .com URL url = new URL(download_url); if (!new File(DL_PATH).isDirectory()) { if (!new File(DL_PATH).mkdirs()) { Log.e(TAG, "Creating the directory " + DL_PATH + "failed"); } } File file = new File(DL_PATH + fileName); long startTine = System.currentTimeMillis(); Log.d(TAG, "Beginning download of " + url.getPath() + " to " + DL_PATH + fileName); /* * Open a connection and define Streams */ URLConnection ucon = url.openConnection(); InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); /* * Read bytes until there is nothing left */ ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } /* Convert Bytes to a String */ FileOutputStream fos = new FileOutputStream(file); fos.write(baf.toByteArray()); fos.close(); Log.d(TAG, "Download finished in " + ((System.currentTimeMillis() - startTine) / 1000) + " seconds"); } catch (Exception e) { Log.e(TAG, "Error: " + e); e.printStackTrace(); } } else { Log.e(TAG, "Tried to run in Main Thread. Aborting..."); } }
From source file:com.openteach.diamond.container.Container.java
private static String buildOSGIBundles(String[] args) throws Exception { // ???classloaderpluginsjar?? URL url; if (args == null || args.length == 0) { url = Container.class.getClassLoader().getResource(""); } else {/*from ww w .j av a 2 s. c om*/ url = new File(args[0]).toURI().toURL(); } String path = url.getPath(); System.setProperty("diamond.CONTAINER.PATH", path); String searchPath = path + "/plugins"; File file = new File(searchPath); if (!file.exists()) { throw new RuntimeException("?plugins?" + searchPath); } StringBuilder osgiBundlesBuilder = new StringBuilder(); //build core buildBundlesString(searchPath, "core", osgiBundlesBuilder, true); //build extra buildBundlesString(searchPath, "extra", osgiBundlesBuilder, false); //build option buildBundlesString(searchPath, "option", osgiBundlesBuilder, false); //build custom buildBundlesString(searchPath, "custom", osgiBundlesBuilder, false); return osgiBundlesBuilder.toString(); }