List of usage examples for java.net URI toURL
public URL toURL() throws MalformedURLException
From source file:org.lenskit.config.LenskitConfigDSL.java
@Override public void include(URI uri) throws IOException, RecommenderConfigurationException { URI realURI = uri; if (!realURI.isAbsolute()) { realURI = getBaseURI().resolve(realURI); }/*from w ww .j ava2s .co m*/ LenskitConfigScript script = getConfigLoader().loadScript(realURI.toURL()); script.configure(getConfig()); }
From source file:org.jrb.docasm.service.document.DocumentServiceImpl.java
private Document loadDocument(final NamedKey key) throws IOException { final Document document = (key.hasId()) ? documentRepository.findOne(key.getId()) : documentRepository.findByName(key.getName()); if (document != null) { final URI templateUri = document.getTemplateUri(); try (final InputStream is = templateUri.toURL().openStream()) { document.setTemplate(IOUtils.toString(is)); }//from w ww. j ava2 s .c o m } return document; }
From source file:com.penguineering.cleanuri.sites.reichelt.ReicheltExtractor.java
@Override public Map<Metakey, String> extractMetadata(URI uri) throws ExtractorException { if (uri == null) throw new NullPointerException("URI argument must not be null!"); URL url;/* w w w . j av a 2s . c o m*/ try { url = uri.toURL(); } catch (MalformedURLException e) { throw new IllegalArgumentException("The provided URI is not a URL!"); } Map<Metakey, String> meta = new HashMap<Metakey, String>(); try { final URLConnection con = url.openConnection(); LineNumberReader reader = null; try { reader = new LineNumberReader(new InputStreamReader(con.getInputStream())); String line; while ((line = reader.readLine()) != null) { if (!line.contains("<h2>")) continue; // h2 int h2_idx = line.indexOf("h2"); // Doppelpunkte int col_idx = line.indexOf("<span> :: <span"); final String art_id = line.substring(h2_idx + 3, col_idx); meta.put(Metakey.ID, html2oUTF8(art_id).trim()); int span_idx = line.indexOf("</span>"); final String art_name = line.substring(col_idx + 32, span_idx); meta.put(Metakey.NAME, html2oUTF8(art_name).trim()); break; } return meta; } finally { if (reader != null) reader.close(); } } catch (IOException e) { throw new ExtractorException("I/O exception during extraction: " + e.getMessage(), e, uri); } }
From source file:es.gva.cit.gazetteer.idec.drivers.IDECGazetteerServiceDriver.java
public Feature[] getFeature(URI uri, GazetteerQuery query) { Collection nodes = new java.util.ArrayList(); URL url = null;//from w w w . j a v a 2 s . c om try { url = uri.toURL(); } catch (MalformedURLException e) { setServerAnswerReady("errorServerNotFound"); return null; } setQuery(query); System.out.println(getPOSTGetFeature(query)); nodes = new HTTPPostProtocol().doQuery(url, getPOSTGetFeature(query), 0); if ((nodes != null) && (nodes.size() == 1)) { return IdecFeatureParser.parse((XMLNode) nodes.toArray()[0]); } else { return null; } }
From source file:com.mgmtp.jfunk.data.generator.Generator.java
public void parseXml(final IndexedFields theIndexedFields) throws IOException, JDOMException { this.indexedFields = theIndexedFields; final String generatorFile = configuration.get(GeneratorConstants.GENERATOR_CONFIG_FILE); if (StringUtils.isBlank(generatorFile)) { LOGGER.info("No generator configuration file found"); return;//from w ww . j ava 2 s. co m } SAXBuilder builder = new SAXBuilder(); builder.setValidation(true); builder.setIgnoringElementContentWhitespace(false); builder.setFeature("http://apache.org/xml/features/validation/schema/normalized-value", false); builder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(final String publicId, final String systemId) throws IOException { String resolvedSystemId = configuration.processPropertyValue(systemId); URI uri = URI.create(resolvedSystemId); File file = uri.isAbsolute() ? toFile(uri.toURL()) : new File(uri.toString()); return new InputSource(ResourceLoader.getBufferedReader(file, Charsets.UTF_8.name())); } }); InputStream in = ResourceLoader.getConfigInputStream(generatorFile); Document doc = null; try { String systemId = ResourceLoader.getConfigDir() + '/' + removeExtension(generatorFile) + ".dtd"; doc = builder.build(in, systemId); Element root = doc.getRootElement(); Element charsetsElement = root.getChild(XMLTags.CHARSETS); @SuppressWarnings("unchecked") List<Element> charsetElements = charsetsElement.getChildren(XMLTags.CHARSET); for (Element element : charsetElements) { CharacterSet.initCharacterSet(element); } @SuppressWarnings("unchecked") List<Element> constraintElements = root.getChild(XMLTags.CONSTRAINTS).getChildren(XMLTags.CONSTRAINT); constraints = Lists.newArrayListWithExpectedSize(constraintElements.size()); for (Element element : constraintElements) { constraints.add(constraintFactory.createModel(random, element)); } } finally { closeQuietly(in); } LOGGER.info("Generator was successfully initialized"); }
From source file:org.cytoscape.biopax.internal.BioPaxFilter.java
@Override public boolean accepts(URI uri, DataCategory category) { String ext = FilenameUtils.getExtension(uri.toString()); try {/*ww w .ja va2s .c o m*/ return (category == this.category) && extensions.contains(ext) && accepts(streamUtil.getInputStream(uri.toURL()), category); } catch (IOException e) { return false; } }
From source file:org.obm.service.solr.SolrClientFactoryImpl.java
public CommonsHttpSolrServer create(SolrService service, ObmDomain domain) { try {// w ww. j a va 2s.c o m URI uri = new URIBuilder().setScheme("http") .setHost(locatorService.getServiceLocation(service.getName(), domain.getName())).setPort(8080) .setPath('/' + service.getName()).build(); return new CommonsHttpSolrServer(uri.toURL(), httpClient); } catch (MalformedURLException e) { throw new LocatorClientException(e); } catch (URISyntaxException e) { throw new LocatorClientException(e); } }
From source file:com.example.appengine.analytics.AnalyticsServlet.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String trackingId = System.getenv("GA_TRACKING_ID"); URIBuilder builder = new URIBuilder(); builder.setScheme("http").setHost("www.google-analytics.com").setPath("/collect").addParameter("v", "1") // API Version. .addParameter("tid", trackingId) // Tracking ID / Property ID. // Anonymous Client Identifier. Ideally, this should be a UUID that // is associated with particular user, device, or browser instance. .addParameter("cid", "555").addParameter("t", "event") // Event hit type. .addParameter("ec", "example") // Event category. .addParameter("ea", "test action"); // Event action. URI uri = null; try {/*from w ww. j a v a2 s.c om*/ uri = builder.build(); } catch (URISyntaxException e) { throw new ServletException("Problem building URI", e); } URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService(); URL url = uri.toURL(); fetcher.fetch(url); resp.getWriter().println("Event tracked."); }
From source file:org.opencastproject.episode.filesystem.FileSystemElementStore.java
/** Return the extension of a URI, i.e. the extentension of its path. */ private Option<String> extension(URI uri) { try {/*from ww w . ja v a 2 s. c om*/ return trimToNone(getExtension(uri.toURL().getPath())); } catch (MalformedURLException e) { throw new Error(e); } }
From source file:com.nbzs.ningbobus.ui.loaders.BusRunInfoReaderLoader.java
private BusLineRunInfoItem downloadOneFeedItem(Integer busLine) { try {/*from w w w . j av a 2 s . c o m*/ URI newUri = URI.create(mFeedUri.toString() + "/" + Integer.toString(busLine) + "/?format=json"); HttpURLConnection conn = (HttpURLConnection) newUri.toURL().openConnection(); InputStream in; int status; conn.setDoInput(true); conn.setInstanceFollowRedirects(true); conn.setRequestProperty("User-Agent", getContext().getString(R.string.user_agent_string)); in = conn.getInputStream(); status = conn.getResponseCode(); if (status < 400) { String result = IOUtils.readStream(in); BusLineRunInfoItem item = new BusLineRunInfoItem(); //result = "{\"RunInfo\" : " + result + "}"; JSONObject jo = new JSONObject(result); //item.setBusLineName(jo.getString("Name")); item.setBusLineCurrentInfo(jo.getString("RunInfo")); //result = URLDecoder.decode(result, "UTF-8"); //item.setBusLineCurrentInfo(result); item.setBusLineName(FeedService.getBusLineFromId(getContext(), busLine)); return item; } conn.disconnect(); } catch (UnknownHostException e) { mActivity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(mActivity, "No network connection.", Toast.LENGTH_SHORT).show(); } }); } catch (IOException e) { Log.d(TAG, "error reading feed"); Log.d(TAG, Log.getStackTraceString(e)); } catch (IllegalStateException e) { Log.d(TAG, "this should not happen"); Log.d(TAG, Log.getStackTraceString(e)); } catch (JSONException e) { Log.d(TAG, "this should not happen"); Log.d(TAG, Log.getStackTraceString(e)); } return null; }