List of usage examples for java.net URI getFragment
public String getFragment()
From source file:eu.stratosphere.nephele.fs.s3.S3FileSystem.java
static Path extendPath(final Path parent, final String extension) throws IOException { final URI parentUri = parent.toUri(); if (extension.isEmpty()) { return parent; }//from w ww. j av a 2s.c o m final String path = parentUri.getPath(); String extendedPath; if (path.isEmpty()) { if (extension.charAt(0) == Path.SEPARATOR_CHAR) { extendedPath = extension; } else { extendedPath = Path.SEPARATOR + extension; } } else { if (path.charAt(path.length() - 1) == Path.SEPARATOR_CHAR) { if (extension.charAt(0) == Path.SEPARATOR_CHAR) { if (extension.length() > 1) { extendedPath = path + extension.substring(1); } else { extendedPath = path; } } else { extendedPath = path + extension; } } else { if (extension.charAt(0) == Path.SEPARATOR_CHAR) { extendedPath = path + extension; } else { extendedPath = path + Path.SEPARATOR + extension; } } } try { final URI extendedUri = new URI(parentUri.getScheme(), ((parentUri.getAuthority() != null) ? parentUri.getAuthority() : ""), extendedPath, parentUri.getQuery(), parentUri.getFragment()); return new Path(extendedUri); } catch (URISyntaxException e) { throw new IOException(StringUtils.stringifyException(e)); } }
From source file:org.dita.dost.module.GenMapAndTopicListModule.java
/** * Add the given file the wait list if it has not been parsed. * //from w w w . j ava 2 s . c o m * @param ref reference to absolute system path */ private void addToWaitList(final Reference ref) { final URI file = ref.filename; assert file.isAbsolute() && file.getFragment() == null; if (doneList.contains(file) || waitList.contains(ref) || file.equals(currentFile)) { return; } waitList.add(ref); }
From source file:com.microsoft.tfs.client.common.ui.dialogs.connect.ACSCredentialsDialog.java
protected URI getSignInURI(final URI serverSigninURL) { String query = serverSigninURL.getQuery(); if (query.indexOf("protocol=") < 0) //$NON-NLS-1$ {//from w ww . j a v a2s .c o m query += "&protocol=javascriptnotify"; //$NON-NLS-1$ } if (query.indexOf("force=") < 0) //$NON-NLS-1$ { query += "&force=1"; //$NON-NLS-1$ } if (query.indexOf("compact=") < 0) //$NON-NLS-1$ { query += "&compact=1"; //$NON-NLS-1$ } return URIUtils.newURI(serverSigninURL.getScheme(), serverSigninURL.getAuthority(), serverSigninURL.getPath(), query, serverSigninURL.getFragment()); }
From source file:com.googlecode.jdeltasync.DeltaSyncClient.java
/** * Slightly modified version of {@link DefaultRedirectStrategy#getLocationURI(HttpRequest, HttpResponse, HttpContext)} * which also adds the query string from the original request URI to the new URI. *///from ww w . j av a 2 s .c o m private URI getRedirectLocationURI(IDeltaSyncSession session, HttpUriRequest request, HttpResponse response, HttpContext context) throws DeltaSyncException { //get the location header to find out where to redirect to Header locationHeader = response.getFirstHeader("location"); if (locationHeader == null) { // got a redirect response, but no location header throw new DeltaSyncException( "Received redirect response " + response.getStatusLine() + " but no location header"); } String location = locationHeader.getValue(); if (session.getLogger().isDebugEnabled()) { session.getLogger().debug("Redirect requested to location '" + location + "'"); } URI uri = null; try { uri = new URI(location); if (request.getURI().getRawQuery() != null) { String query = request.getURI().getRawQuery(); uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), query, uri.getFragment()); } } catch (URISyntaxException ex) { throw new DeltaSyncException("Invalid redirect URI: " + location, ex); } final HttpClientContext clientContext = HttpClientContext.adapt(context); final RequestConfig config = clientContext.getRequestConfig(); // rfc2616 demands the location value be a complete URI // Location = "Location" ":" absoluteURI try { if (!uri.isAbsolute()) { if (config.isRelativeRedirectsAllowed()) { throw new DeltaSyncException("Relative redirect location '" + uri + "' not allowed"); } // Adjust location URI HttpHost target = clientContext.getTargetHost(); if (target == null) { throw new IllegalStateException("Target host not available " + "in the HTTP context"); } URI requestURI = new URI(request.getRequestLine().getUri()); URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, false); uri = URIUtils.resolve(absoluteRequestURI, uri); } } catch (URISyntaxException ex) { throw new DeltaSyncException(ex.getMessage(), ex); } RedirectLocations redirectLocations = (RedirectLocations) clientContext .getAttribute("http.protocol.redirect-locations"); if (redirectLocations == null) { redirectLocations = new RedirectLocations(); context.setAttribute("http.protocol.redirect-locations", redirectLocations); } if (config.isCircularRedirectsAllowed()) { URI redirectURI; if (uri.getFragment() != null) { try { HttpHost target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); redirectURI = URIUtils.rewriteURI(uri, target, true); } catch (URISyntaxException ex) { throw new DeltaSyncException(ex.getMessage(), ex); } } else { redirectURI = uri; } if (redirectLocations.contains(redirectURI)) { throw new DeltaSyncException("Circular redirect to '" + redirectURI + "'"); } else { redirectLocations.add(redirectURI); } } return uri; }
From source file:com.naryx.tagfusion.cfm.http.cfHttpConnection.java
private void addQueryStringData(Map<String, String> _data, String _charset) throws cfmRunTimeException { if (_data.size() > 0) { // don't need to do anything if there's no url data // to add StringBuilder queryString = new StringBuilder(); // method.getQueryString() // ); Iterator<String> keys = _data.keySet().iterator(); while (keys.hasNext()) { String nextKey = keys.next(); try { queryString.append(urlEncoder.encode(nextKey, _charset)); } catch (UnsupportedEncodingException e1) { queryString.append(urlEncoder.encode(nextKey)); }//from w w w . j av a 2 s.c om queryString.append('='); try { queryString.append(urlEncoder.encode(_data.get(nextKey), _charset)); } catch (UnsupportedEncodingException e) { queryString.append(urlEncoder.encode(_data.get(nextKey))); } queryString.append("&"); } // remove last &. We know there is at least one url param queryString = queryString.deleteCharAt(queryString.length() - 1); String currentQStr = message.getURI().getQuery(); if (currentQStr == null) currentQStr = ""; try { URI uri = message.getURI(); String schemeName = uri.getScheme(); String hostName = uri.getHost(); int port = uri.getPort(); String fragment = uri.getFragment(); String path = uri.getPath(); String queryStr = queryString.toString(); if (currentQStr.length() > 0) { uri = URIUtils.createURI(schemeName, hostName, port, path, currentQStr + '&' + queryStr, fragment); } else { uri = URIUtils.createURI(schemeName, hostName, port, path, queryStr, fragment); } ((HttpRequestBase) message).setURI(uri); } catch (URISyntaxException e) { throw newRunTimeException("Failed due to URI Syntax Error: " + e.getMessage()); } } }
From source file:org.apache.hadoop.mapreduce.filecache.TrackerDistributedCacheManager.java
private void createSymlink(Configuration conf, URI cache, CacheStatus cacheStatus, boolean isArchive, Path currentWorkDir, boolean honorSymLinkConf) throws IOException { boolean doSymlink = honorSymLinkConf && DistributedCache.getSymlink(conf); if (cache.getFragment() == null) { doSymlink = false;//from w w w. j a v a 2s .c om } String link = currentWorkDir.toString() + Path.SEPARATOR + cache.getFragment(); File flink = new File(link); if (doSymlink) { if (!flink.exists()) { FileUtil.symLink(cacheStatus.localizedLoadPath.toString(), link); } } }
From source file:org.apache.hadoop.mapreduce.JobSubmitter.java
private void copyAndConfigureFiles(Job job, Path submitJobDir, short replication) throws IOException { Configuration conf = job.getConfiguration(); if (!(conf.getBoolean(Job.USED_GENERIC_PARSER, false))) { LOG.warn("Hadoop command-line option parsing not performed. " + "Implement the Tool interface and execute your application " + "with ToolRunner to remedy this."); }/* w w w . j a v a 2s. c o m*/ // get all the command line arguments passed in by the user conf String files = conf.get("tmpfiles"); String libjars = conf.get("tmpjars"); String archives = conf.get("tmparchives"); String jobJar = job.getJar(); // // Figure out what fs the JobTracker is using. Copy the // job to it, under a temporary name. This allows DFS to work, // and under the local fs also provides UNIX-like object loading // semantics. (that is, if the job file is deleted right after // submission, we can still run the submission to completion) // // Create a number of filenames in the JobTracker's fs namespace LOG.debug("default FileSystem: " + jtFs.getUri()); if (jtFs.exists(submitJobDir)) { throw new IOException("Not submitting job. Job directory " + submitJobDir + " already exists!! This is unexpected.Please check what's there in" + " that directory"); } submitJobDir = jtFs.makeQualified(submitJobDir); submitJobDir = new Path(submitJobDir.toUri().getPath()); FsPermission mapredSysPerms = new FsPermission(JobSubmissionFiles.JOB_DIR_PERMISSION); FileSystem.mkdirs(jtFs, submitJobDir, mapredSysPerms); Path filesDir = JobSubmissionFiles.getJobDistCacheFiles(submitJobDir); Path archivesDir = JobSubmissionFiles.getJobDistCacheArchives(submitJobDir); Path libjarsDir = JobSubmissionFiles.getJobDistCacheLibjars(submitJobDir); // add all the command line files/ jars and archive // first copy them to jobtrackers filesystem if (files != null) { FileSystem.mkdirs(jtFs, filesDir, mapredSysPerms); String[] fileArr = files.split(","); for (String tmpFile : fileArr) { URI tmpURI = null; try { tmpURI = new URI(tmpFile); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } Path tmp = new Path(tmpURI); Path newPath = copyRemoteFiles(filesDir, tmp, conf, replication); try { URI pathURI = getPathURI(newPath, tmpURI.getFragment()); DistributedCache.addCacheFile(pathURI, conf); } catch (URISyntaxException ue) { //should not throw a uri exception throw new IOException("Failed to create uri for " + tmpFile, ue); } } } if (libjars != null) { FileSystem.mkdirs(jtFs, libjarsDir, mapredSysPerms); String[] libjarsArr = libjars.split(","); for (String tmpjars : libjarsArr) { Path tmp = new Path(tmpjars); Path newPath = copyRemoteFiles(libjarsDir, tmp, conf, replication); DistributedCache.addFileToClassPath(new Path(newPath.toUri().getPath()), conf); } } if (archives != null) { FileSystem.mkdirs(jtFs, archivesDir, mapredSysPerms); String[] archivesArr = archives.split(","); for (String tmpArchives : archivesArr) { URI tmpURI; try { tmpURI = new URI(tmpArchives); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } Path tmp = new Path(tmpURI); Path newPath = copyRemoteFiles(archivesDir, tmp, conf, replication); try { URI pathURI = getPathURI(newPath, tmpURI.getFragment()); DistributedCache.addCacheArchive(pathURI, conf); } catch (URISyntaxException ue) { //should not throw an uri excpetion throw new IOException("Failed to create uri for " + tmpArchives, ue); } } } if (jobJar != null) { // copy jar to JobTracker's fs // use jar name if job is not named. if ("".equals(job.getJobName())) { job.setJobName(new Path(jobJar).getName()); } Path jobJarPath = new Path(jobJar); URI jobJarURI = jobJarPath.toUri(); // If the job jar is already in a global fs, // we don't need to copy it from local fs if (jobJarURI.getScheme() == null || jobJarURI.getScheme().equals("file")) { copyJar(jobJarPath, JobSubmissionFiles.getJobJar(submitJobDir), replication); job.setJar(JobSubmissionFiles.getJobJar(submitJobDir).toString()); } } else { LOG.warn("No job jar file set. User classes may not be found. " + "See Job or Job#setJar(String)."); } addLog4jToDistributedCache(job, submitJobDir); // set the timestamps of the archives and files // set the public/private visibility of the archives and files ClientDistributedCacheManager.determineTimestampsAndCacheVisibilities(conf); // get DelegationToken for cached file ClientDistributedCacheManager.getDelegationTokens(conf, job.getCredentials()); }
From source file:org.eclipse.orion.server.git.servlets.GitCommitHandlerV1.java
private boolean identifyNewCommitResource(HttpServletRequest request, HttpServletResponse response, Repository db, String newCommit) throws ServletException { try {/*from www. j a va 2s . com*/ URI u = getURI(request); IPath p = new Path(u.getPath()); IPath np = new Path("/"); //$NON-NLS-1$ for (int i = 0; i < p.segmentCount(); i++) { String s = p.segment(i); if (i == 2) { s += ".." + newCommit; //$NON-NLS-1$ } np = np.append(s); } if (p.hasTrailingSeparator()) np = np.addTrailingSeparator(); URI nu = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), np.toString(), u.getQuery(), u.getFragment()); JSONObject result = new JSONObject(); result.put(ProtocolConstants.KEY_LOCATION, nu); OrionServlet.writeJSONResponse(request, response, result); response.setHeader(ProtocolConstants.HEADER_LOCATION, resovleOrionURI(request, nu).toString()); return true; } catch (Exception e) { return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when identifying a new Commit resource.", e)); } }
From source file:org.dataconservancy.packaging.tool.impl.GeneralPackageDescriptionCreator.java
private void populate(FileContext cxt, Rule rule, Map<String, PackageArtifact> artifacts) { List<Mapping> mappings = rule.getMappings(cxt); for (Mapping mapping : mappings) { /* We are using file URI as artifact IDs, unless multiple mappings */ URIBuilder urib = new URIBuilder(cxt.getFile().toURI()); //String id = cxt.getFile().toURI().toString(); /*//w ww . j a v a2 s . c o m * If multiple mappings implicated by this file, then make sure * they're differentiated */ if (mappings.size() > 1) { String specifier = mapping.getSpecifier(); if (specifier != null) { urib.setFragment(specifier); } } URI uri = null; try { uri = urib.build(); } catch (URISyntaxException e) { } String id = uri.toString(); PackageArtifact artifact = new PackageArtifact(); artifacts.put(id, artifact); artifact.setId(id); artifact.setIgnored(cxt.isIgnored()); //we need to relativize against the content root if one exists, not the supplied root artifact dir if (cxt.getRoot().getParentFile() != null) { Path rootPath = Paths.get(cxt.getRoot().getParentFile().getPath()); Path filePath = Paths.get(cxt.getFile().getPath()); artifact.setArtifactRef(String.valueOf(rootPath.relativize(filePath))); } else { Path filePath = Paths.get(cxt.getFile().getPath()); artifact.setArtifactRef(String.valueOf(filePath)); } if (uri.getFragment() != null) { artifact.getArtifactRef().setFragment(uri.getFragment()); } /* * if file is a normal file, set the isByteStream flag to true on * PackageArtifact */ if (cxt.getFile().isFile()) { artifact.setByteStream(true); } artifact.setType(mapping.getType().getValue()); if (mapping.getType().isByteStream() != null) { artifact.setByteStream(mapping.getType().isByteStream()); } else { artifact.setByteStream(cxt.getFile().isFile()); } for (Map.Entry<String, List<String>> entry : mapping.getProperties().entrySet()) { Set<String> valueSet = new HashSet<>(entry.getValue()); artifact.setSimplePropertyValues(entry.getKey(), valueSet); } /* * Since we use file URI as artifact IDs (with optional specifier as * URI fragment), we just need to use the relationship's target * file's URI as the relationship target, and we're done!. */ List<PackageRelationship> rels = new ArrayList<>(); for (Map.Entry<String, Set<URI>> rel : mapping.getRelationships().entrySet()) { Set<String> relTargets = new HashSet<>(); for (URI target : rel.getValue()) { relTargets.add(target.toString()); } rels.add(new PackageRelationship(rel.getKey(), true, relTargets)); } artifact.setRelationships(rels); } }