List of usage examples for java.net URI getFragment
public String getFragment()
From source file:org.dataconservancy.packaging.tool.impl.GeneralPackageDescriptionCreatorTest.java
@Test public void dataItemPlusDataFileTest() throws URISyntaxException { Map<String, PackageArtifact> parentDataItems = new HashMap<String, PackageArtifact>(); List<PackageArtifact> childDataFiles = new ArrayList<PackageArtifact>(); for (PackageArtifact artifact : desc.getPackageArtifacts()) { if (artifact.getArtifactRef().getRefString().contains("impliedData")) { if (artifact.getType().equals("DataItem")) { parentDataItems.put(artifact.getId(), artifact); URI idUri = new URI(artifact.getId()); assertNotNull(idUri.getFragment()); assertNotNull(artifact.getArtifactRef().getFragment()); assertFalse(artifact.isByteStream()); } else { childDataFiles.add(artifact); assertTrue(artifact.isByteStream()); artifact.setByteStream(false); }/*w w w. j a va2 s . c om*/ } } assertEquals(childDataFiles.size(), 3); for (PackageArtifact child : childDataFiles) { Set<String> targets = child.getRelationshipByName(DcsBoPackageOntology.IS_MEMBER_OF).getTargets(); assertEquals(1, targets.size()); assertTrue(parentDataItems.keySet().contains(targets.iterator().next())); URI idUri = new URI(child.getId()); assertNull(idUri.getFragment()); assertNull(child.getArtifactRef().getFragment()); } }
From source file:de.fuberlin.agcsw.heraclitus.graph.GraphAnalyse.java
public static Graph<JungVertex, JungEdge> createGraphModel(URI start) { try {//from w w w . j av a 2s . c o m Graph<JungVertex, JungEdge> g = new DirectedSparseMultigraph<JungVertex, JungEdge>(); ValueFactory f = rep.getValueFactory(); System.out.println("Start Node Fragment: " + start); if (start == null) { return null; } Resource startRes; if (start.toString().startsWith("node")) { //its a blank Node startRes = f.createBNode(start.toString()); } else { startRes = f.createURI(start.toString()); } //this is the subject direction RepositoryResult<Statement> statements = rep.getConnection().getStatements(startRes, null, null, true); JungVertex subVer = new JungVertex(start.getFragment(), start); 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()); String strPred = pred.stringValue().substring(pred.stringValue().indexOf("#") + 1); String strObj = obj.stringValue().substring(obj.stringValue().indexOf("#") + 1); JungVertex objVer = null; if (obj instanceof Literal) { objVer = new JungVertex(strObj, null); } else { objVer = new JungVertex(strObj, URI.create(obj.stringValue())); } JungEdge predV = new JungEdge(strPred); //test if circle (Schlinge) if (strObj.equals(subVer.toString())) { g.addEdge(predV, subVer, subVer); } else { g.addEdge(predV, subVer, objVer); } } //do the object direction statements = rep.getConnection().getStatements(null, null, startRes, true); JungVertex objVer = subVer; 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()); String strSub = sub.stringValue().substring(sub.stringValue().indexOf("#") + 1); String strPred = pred.stringValue().substring(pred.stringValue().indexOf("#") + 1); subVer = new JungVertex(strSub, URI.create(sub.stringValue())); g.addVertex(subVer); JungEdge predV = new JungEdge(strPred); //test if circle (Schlinge) if (strSub.equals(objVer.toString())) { // g.addEdge(predV,subVer,subVer); } else { g.addEdge(predV, subVer, objVer); } } return g; } catch (RepositoryException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:edu.wisc.ws.client.support.DestinationOverridingWebServiceTemplate.java
@Override public String getDefaultUri() { final DestinationProvider destinationProvider = this.getDestinationProvider(); if (destinationProvider != null) { final URI uri = destinationProvider.getDestination(); if (uri == null) { return null; }// w ww . j a va2s . c om if (portOverride == null) { return uri.toString(); } final URI overridenUri; try { overridenUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), portOverride, uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { this.logger.error("Could not override port on URI " + uri + " to " + portOverride, e); return uri.toString(); } return overridenUri.toString(); } return null; }
From source file:com.jaeksoft.searchlib.crawler.rest.RestCrawlThread.java
private void callback(HttpDownloader downloader, URI uri, String query) throws URISyntaxException, ClientProtocolException, IllegalStateException, IOException, SearchLibException { uri = new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), query, uri.getFragment()); DownloadItem dlItem = downloader.request(uri, restCrawlItem.getCallbackMethod(), restCrawlItem.getCredential(), null, null, null); dlItem.checkNoErrorList(200, 201, 202, 203); }
From source file:com.qwazr.utils.json.client.JsonClientAbstract.java
protected JsonClientAbstract(String url, Integer msTimeOut, Credentials credentials) throws URISyntaxException { this.url = url; URI u = new URI(url); String path = u.getPath();/*w w w. ja v a 2 s . co m*/ if (path != null && path.endsWith("/")) u = new URI(u.getScheme(), null, u.getHost(), u.getPort(), path.substring(0, path.length() - 1), u.getQuery(), u.getFragment()); this.scheme = u.getScheme() == null ? "http" : u.getScheme(); this.host = u.getHost(); this.fragment = u.getFragment(); this.path = u.getPath(); this.port = u.getPort() == -1 ? 80 : u.getPort(); this.timeout = msTimeOut == null ? DEFAULT_TIMEOUT : msTimeOut; this.executor = credentials == null ? Executor.newInstance() : Executor.newInstance().auth(credentials); }
From source file:org.eclipse.orion.internal.server.servlets.workspace.ProjectParentDecorator.java
/** * Adds a parent resource representation to the parent array *///from w ww. j a v a 2 s . co m private void addParent(JSONArray parents, String name, URI location) throws JSONException { JSONObject parent = new JSONObject(); parent.put(ProtocolConstants.KEY_NAME, name); parent.put(ProtocolConstants.KEY_LOCATION, location); URI childLocation; try { childLocation = new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(), location.getPath(), "depth=1", location.getFragment()); //$NON-NLS-1$ } catch (URISyntaxException e) { throw new RuntimeException(e); } parent.put(ProtocolConstants.KEY_CHILDREN_LOCATION, childLocation); parents.put(parent); }
From source file:com.collaborne.jsonschema.generator.pojo.PojoGenerator.java
/** * Get the {@link SchemaTree} for the given {@code uri}. * //from w w w . j a va2 s. c o m * This is similar to {@link SchemaLoader#get(URI)}, but allows {@code uri} to contain a fragment. * * @param uri * @return * @throws ProcessingException */ // XXX: Should this be the default behavior of SchemaLoader#get()? @VisibleForTesting protected SchemaTree getSchema(SchemaLoader schemaLoader, URI uri) throws ProcessingException { String fragment = uri.getFragment(); if (fragment == null) { return schemaLoader.get(uri); } else { try { URI schemaTreeUri = new URI(uri.getScheme(), uri.getSchemeSpecificPart(), null); JsonPointer pointer = new JsonPointer(fragment); SchemaTree schema = schemaLoader.get(schemaTreeUri); return schema.setPointer(pointer); } catch (URISyntaxException | JsonPointerException e) { assert false : "Was a valid before, we split things up!"; throw new RuntimeException(e); } } }
From source file:de.zib.sfs.StatisticsFileSystem.java
static Path setAuthority(Path path, String authority) { if (authority != null) { URI pathUri = path.toUri(); String query = pathUri.getQuery(); String fragment = pathUri.getFragment(); return new Path(URI.create(pathUri.getScheme() + "://" + authority + "/" + pathUri.getPath() + (query != null ? ("?" + query) : "")) + (fragment != null ? ("#" + fragment) : "")); }//w ww . j a v a 2 s . com return path; }
From source file:eu.esdihumboldt.hale.common.core.io.PathUpdate.java
/** * Create an alternative path for the given location if it matches changes * from old to new location. If either old or new location is null, or the * given URI wasn't changed in the same way, this method has no effect. * //from w w w . j a va2 s.c om * @param oldSource path where the file was saved to * @return the new URI */ public URI changePath(URI oldSource) { if (oldRaw == null || oldRaw.isEmpty()) { return oldSource; } else { if (oldSource.toString().startsWith(oldRaw)) { return URI.create(oldSource.toString().replace(oldRaw, newRaw)); } else { // try to fix cases where oldRaw matches '<scheme>:///<rest>' // but oldSource matches '<scheme>:/<rest>' or vice versa try { URI oldRawUri = new URI(oldRaw); // URI.normalize() will not remove the additional slashes URI normalizedOldRaw = new URI(oldRawUri.getScheme(), oldRawUri.getHost(), oldRawUri.getPath(), oldRawUri.getQuery(), oldRawUri.getFragment()); URI normalizedOldSource = new URI(oldSource.getScheme(), oldSource.getHost(), oldSource.getPath(), oldSource.getQuery(), oldSource.getFragment()); return URI.create(normalizedOldSource.toString().replace(normalizedOldRaw.toString(), newRaw)); } catch (URISyntaxException e) { // tough luck return oldSource; } } } }
From source file:com.cloudera.livy.rsc.driver.RSCDriver.java
public File copyFileToLocal(File localCopyDir, String filePath, SparkContext sc) throws Exception { synchronized (jc) { if (!localCopyDir.isDirectory() && !localCopyDir.mkdir()) { throw new IOException("Failed to create directory to add pyFile"); }/*from w w w. ja va2 s. c o m*/ } URI uri = new URI(filePath); String name = uri.getFragment() != null ? uri.getFragment() : uri.getPath(); name = new File(name).getName(); File localCopy = new File(localCopyDir, name); if (localCopy.exists()) { throw new IOException(String.format("A file with name %s has " + "already been uploaded.", name)); } Configuration conf = sc.hadoopConfiguration(); FileSystem fs = FileSystem.get(uri, conf); fs.copyToLocalFile(new Path(uri), new Path(localCopy.toURI())); return localCopy; }