List of usage examples for java.net URI toURL
public URL toURL() throws MalformedURLException
From source file:biz.gabrys.lesscss.extended.compiler.source.FtpSourceFactory.java
public FtpSource createAbsoluteSource(final LessSource source, final String importAbsolutePath) { try {//from ww w . j a v a 2 s .co m final URI importUri = new URI(importAbsolutePath).normalize(); return new FtpSource(importUri.toURL(), source.getEncoding()); } catch (final URISyntaxException e) { throw new SourceFactoryException("Cannot normalize URL", e); } catch (final MalformedURLException e) { throw new SourceFactoryException("Cannot create relative URL", e); } }
From source file:org.colombbus.tangara.update.UpdateRequester.java
public void setUpdateSite(String site) throws MalformedURLException { Validate.notNull(site, "site argument is null");//$NON-NLS-1$ URI updateSiteURI = URI.create(site + "/update.properties");//$NON-NLS-1$ this.updateSite = updateSiteURI.toURL(); }
From source file:biz.gabrys.lesscss.extended.compiler.source.HttpSourceFactory.java
public HttpSource createAbsoluteSource(final LessSource source, final String importAbsolutePath) { try {// w ww. j a v a2s . com final URI importUri = new URI(importAbsolutePath).normalize(); return new HttpSource(importUri.toURL()); } catch (final URISyntaxException e) { throw new SourceFactoryException("Cannot normalize URL", e); } catch (final MalformedURLException e) { throw new SourceFactoryException("Cannot create relative URL", e); } }
From source file:fr.eolya.utils.http.HttpUtils.java
public static String urlNormalize(String url, String preferedHost) { String ret_url = url.trim();// w ww. ja v a 2 s . c o m // Perform some url nomalizations described here : http://en.wikipedia.org/wiki/URL_normalization try { // Remove last "/" - NO !!! //if (ret_url.lastIndexOf("/") == ret_url.length()-1) // ret_url = ret_url.substring(0, ret_url.length()-1); // Remove final "?" if unique in url - http://www.example.com/display? -> http://www.example.com/display if (ret_url.lastIndexOf("?") == ret_url.length() - 1) ret_url = ret_url.substring(0, ret_url.length() - 1); // Fix "?&" int index = ret_url.indexOf("?&"); //int l = ret_url.length()-2; if (index != -1) { if (index != ret_url.length() - 2) { ret_url = ret_url.substring(0, index + 1) + ret_url.substring(index + 2); } else { ret_url = ret_url.substring(0, ret_url.length() - 2); } } // Replace "&" by "&" ret_url = StringEscapeUtils.unescapeHtml4(ret_url); // Replace " " by "%20" ret_url = ret_url.replace(" ", "%20"); // Replace "'" by "%27" ret_url = ret_url.replace("'", "%27"); // Replace "%5F" by "_" ret_url = ret_url.replace("%5f", "_"); ret_url = ret_url.replace("%5F", "_"); // Remove dot-segments. // http://www.example.com/../a/b/../c/./d.html => http://www.example.com/a/c/d.html URI uri = new URI(ret_url); uri = uri.normalize(); ret_url = uri.toURL().toExternalForm(); // Remove dot-segments at the beginning of the path // http://www.example.com/../a/d.html => http://www.example.com/a/d.html URL tempUrl = new URL(ret_url); String path = tempUrl.getFile(); String pattern = ""; while (path.startsWith("/../")) { path = path.substring(3); pattern += "/.."; } if (!pattern.equals("")) { index = ret_url.indexOf(pattern); ret_url = ret_url.substring(0, index) + ret_url.substring(index + pattern.length()); } // Remove default port if (ret_url.indexOf("http://" + uri.getHost() + ":80") != -1) { ret_url = ret_url.replace("//" + uri.getHost() + ":80", "//" + uri.getHost()); } if (ret_url.indexOf("https://" + uri.getHost() + ":443") != -1) { ret_url = ret_url.replace("//" + uri.getHost() + ":443", "//" + uri.getHost()); } // translate to prefered host (www.site.com vs site.com) if (preferedHost != null && !"".equals(preferedHost)) { if (uri.getHost().equals("www." + preferedHost) || ("www." + uri.getHost()).equals(preferedHost)) { ret_url = ret_url.replace("//" + uri.getHost(), "//" + preferedHost); } } // Remove the fragment. // http://www.example.com/bar.html#section1 => http://www.example.com/bar.html if (ret_url.indexOf("#") != -1) ret_url = ret_url.substring(0, ret_url.indexOf("#")); // Reorder parameters in query string //ret_url = urlReorderParameters (ret_url); return ret_url; } catch (Exception e) { } return ret_url; }
From source file:io.druid.segment.realtime.firehose.HttpFirehoseFactory.java
@Override protected InputStream openObjectStream(URI object) throws IOException { return object.toURL().openConnection().getInputStream(); }
From source file:net.akehurst.build.resolver.p2.osgi.SimpleTransport.java
@Override public IStatus download(URI toDownload, OutputStream target, long startPos, IProgressMonitor monitor) { try {/*from w ww.j a va2 s. c om*/ IOUtils.copy(toDownload.toURL().openStream(), target); return Status.OK_STATUS; } catch (Exception ex) { return Status.OK_STATUS; } }
From source file:de.fuberlin.agcsw.heraclitus.graph.GraphAnalyse.java
public static Graph<JungVertex, JungEdge> mapOntologyToGraphModel(URI physicalURI, URI namespace) { System.out.println("Starting mapping full Ontology to full Graph Model"); Graph<JungVertex, JungEdge> g = new DirectedSparseMultigraph<JungVertex, JungEdge>(); try {/* w ww .j ava 2 s . c o m*/ rep = new SailRepository(new MemoryStore()); rep.initialize(); RepositoryConnection con = rep.getConnection(); ValueFactory f = rep.getValueFactory(); con.add(physicalURI.toURL(), namespace.toString(), RDFFormat.RDFXML, f.createURI("http://graph.com")); // con.getStatements(arg0, arg1, arg2, arg3, arg4) RepositoryResult<Statement> statements = con.getStatements(null, null, null, true); // System.out.println("There are "+statements.asList().size()+" statements in the graph"); while (statements.hasNext()) { Statement st = statements.next(); Resource sub = st.getSubject(); org.openrdf.model.URI pred = st.getPredicate(); Value obj = st.getObject(); System.out.println( "S: " + sub.stringValue() + " P: " + pred.stringValue() + " O: " + obj.stringValue()); // if (pred.stringValue().equals("http://www.w3.org/2000/01/rdf-schema#subClassOf")) { String strSub = sub.stringValue().substring(sub.stringValue().indexOf("#") + 1); String strPred = pred.stringValue().substring(pred.stringValue().indexOf("#") + 1); String strObj = obj.stringValue().substring(obj.stringValue().indexOf("#") + 1); // if (strPred.equals("subClassOf")) { //test of obj is blank node -- continue then // if (strObj.startsWith("node")) continue; //test id Sub Vertex is in graph JungVertex subV = null; JungVertex objV = null; boolean subExists = false; boolean objExists = false; for (JungVertex v : g.getVertices()) { if (v.toString().equals(strSub)) { subExists = true; subV = v; } if (v.toString().equals(strObj)) { objExists = true; objV = v; } } if (!subExists) { subV = new JungVertex(strSub, URI.create(sub.stringValue())); g.addVertex(subV); } if (!objExists) { //findout if obj is literal if (obj instanceof Literal) { objV = new JungVertex(strObj, null); } else objV = new JungVertex(strObj, URI.create(obj.stringValue())); g.addVertex(objV); } // g.getV // // boolean end = false; // Collection<String> edges = g.findEdgeSet(strSub, strObj); // for (String se : edges) { // if (se.equals(strPred)) { // System.out.println("Edge still exists -- dont add it again"); // end = true; // } // } // if (end) continue; JungEdge predV = new JungEdge(strPred); g.addEdge(predV, subV, objV); } // } // Node e1 = m.createNode(strSub,false); // // Node e2 = m.createNode(strObj,(obj instanceof Literal)); // // m.addEdge(new Edge(e1,e2,strPred)); return g; } catch (RepositoryException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RDFParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return g; }
From source file:de.catma.document.source.contenthandler.DefaultProtocolHandler.java
private void handle(URI sourceDocURI) throws IOException { final String sourceDocURL = sourceDocURI.toURL().toString(); final String sourceURIPath = sourceDocURI.getPath(); SourceDocumentHandler sourceDocumentHandler = new SourceDocumentHandler(); URLConnection urlConnection = new URL(sourceDocURL).openConnection(); InputStream is = urlConnection.getInputStream(); try {/*from w w w. j av a 2s .c o m*/ this.byteContent = IOUtils.toByteArray(is); if (this.mimeType == null) { this.mimeType = sourceDocumentHandler.getMimeType(sourceURIPath, urlConnection, FileType.TEXT.getMimeType()); } this.encoding = Charset.defaultCharset().name(); if (this.mimeType.equals(FileType.TEXT.getMimeType()) || (this.mimeType.equals(FileType.HTML.getMimeType()))) { this.encoding = sourceDocumentHandler.getEncoding(urlConnection, byteContent, Charset.defaultCharset().name()); } } finally { is.close(); } }
From source file:org.gradle.api.internal.resource.UriResource.java
private InputStream getInputStream(URI url) throws IOException { final URLConnection urlConnection = url.toURL().openConnection(); urlConnection.setRequestProperty("User-Agent", getUserAgentString()); return urlConnection.getInputStream(); }
From source file:biz.gabrys.lesscss.extended.compiler.source.FtpSourceFactory.java
public FtpSource createRelativeSource(final LessSource source, final String importRelativePath) { try {//from www . j a va 2s . c o m final String sourcePath = source.getPath(); final String parentPath = sourcePath.substring(0, sourcePath.lastIndexOf('/')); final URI importUri = new URI(parentPath + '/' + importRelativePath).normalize(); return new FtpSource(importUri.toURL(), source.getEncoding()); } catch (final URISyntaxException e) { throw new SourceFactoryException("Cannot normalize URL", e); } catch (final MalformedURLException e) { throw new SourceFactoryException("Cannot create relative URL", e); } }