List of usage examples for java.net URI getFragment
public String getFragment()
From source file:org.asqatasun.ruleimplementation.link.AbstractDownloadableLinkRuleImplementation.java
@Override protected void select(SSPHandler sspHandler) { super.select(sspHandler); Iterator<Element> iter = getElements().get().iterator(); Element el;// w w w .j ava 2s.c om while (iter.hasNext()) { el = iter.next(); try { URI uri = new URI(el.absUrl(HREF_ATTR)); if (isLinkWithProperExtension(uri)) { if (StringUtils.isNotBlank(uri.getFragment())) { iter.remove(); } else { linkWithSimpleExtension.add(el); } } } catch (Exception ex) { } } }
From source file:org.apache.hadoop.filecache.DistributedCache.java
private static Path localizeCache(Configuration conf, URI cache, long confFileStamp, CacheStatus cacheStatus, FileStatus fileStatus, boolean isArchive, Path currentWorkDir, boolean honorSymLinkConf) throws IOException { boolean doSymlink = honorSymLinkConf && getSymlink(conf); if (cache.getFragment() == null) { doSymlink = false;//from w ww .j a va2 s. com } FileSystem fs = getFileSystem(cache, conf); String link = currentWorkDir.toString() + Path.SEPARATOR + cache.getFragment(); File flink = new File(link); if (ifExistsAndFresh(conf, fs, cache, confFileStamp, cacheStatus, fileStatus)) { if (isArchive) { if (doSymlink) { if (!flink.exists()) FileUtil.symLink(cacheStatus.localLoadPath.toString(), link); } return cacheStatus.localLoadPath; } else { if (doSymlink) { if (!flink.exists()) FileUtil.symLink(cacheFilePath(cacheStatus.localLoadPath).toString(), link); } return cacheFilePath(cacheStatus.localLoadPath); } } else { // remove the old archive // if the old archive cannot be removed since it is being used by // another // job // return null if (cacheStatus.refcount > 1 && (cacheStatus.currentStatus == true)) throw new IOException( "Cache " + cacheStatus.localLoadPath.toString() + " is in use and cannot be refreshed"); FileSystem localFs = FileSystem.getLocal(conf); localFs.delete(cacheStatus.localLoadPath, true); synchronized (baseDirSize) { Long dirSize = baseDirSize.get(cacheStatus.baseDir); if (dirSize != null) { dirSize -= cacheStatus.size; baseDirSize.put(cacheStatus.baseDir, dirSize); } } Path parchive = new Path(cacheStatus.localLoadPath, new Path(cacheStatus.localLoadPath.getName())); if (!localFs.mkdirs(cacheStatus.localLoadPath)) { throw new IOException("Mkdirs failed to create directory " + cacheStatus.localLoadPath.toString()); } String cacheId = cache.getPath(); fs.copyToLocalFile(new Path(cacheId), parchive); if (isArchive) { String tmpArchive = parchive.toString().toLowerCase(); File srcFile = new File(parchive.toString()); File destDir = new File(parchive.getParent().toString()); if (tmpArchive.endsWith(".jar")) { RunJar.unJar(srcFile, destDir); } else if (tmpArchive.endsWith(".zip")) { FileUtil.unZip(srcFile, destDir); } else if (isTarFile(tmpArchive)) { FileUtil.unTar(srcFile, destDir); } // else will not do anyhting // and copy the file into the dir as it is } long cacheSize = FileUtil.getDU(new File(parchive.getParent().toString())); cacheStatus.size = cacheSize; synchronized (baseDirSize) { Long dirSize = baseDirSize.get(cacheStatus.baseDir); if (dirSize == null) { dirSize = Long.valueOf(cacheSize); } else { dirSize += cacheSize; } baseDirSize.put(cacheStatus.baseDir, dirSize); } // do chmod here try { FileUtil.chmod(parchive.toString(), "+x"); } catch (InterruptedException e) { LOG.warn("Exception in chmod" + e.toString()); } // update cacheStatus to reflect the newly cached file cacheStatus.currentStatus = true; cacheStatus.mtime = getTimestamp(conf, cache); } if (isArchive) { if (doSymlink) { if (!flink.exists()) FileUtil.symLink(cacheStatus.localLoadPath.toString(), link); } return cacheStatus.localLoadPath; } else { if (doSymlink) { if (!flink.exists()) FileUtil.symLink(cacheFilePath(cacheStatus.localLoadPath).toString(), link); } return cacheFilePath(cacheStatus.localLoadPath); } }
From source file:org.codice.ddf.catalog.async.data.impl.LazyProcessResourceImpl.java
public void setUri(URI uri) { this.uri = uri; if (uri != null && StringUtils.isNotBlank(uri.getFragment())) { this.qualifier = uri.getFragment(); }// w w w . j av a2s .co m }
From source file:net.oneandone.sushi.fs.webdav.WebdavFilesystem.java
public WebdavRoot root(URI uri) { WebdavRoot result;/*from ww w.j a v a 2 s .c o m*/ String info; int port; NetRc.NetRcAuthenticator authenticator; if (uri.getFragment() != null) { throw new IllegalArgumentException(uri.toString()); } // ignores url.getPath() port = uri.getPort(); if (port == -1) { port = "https".equals(uri.getScheme()) ? 443 : 80; } result = new WebdavRoot(this, internalScheme, uri.getHost(), port); info = uri.getUserInfo(); if (info != null) { result.setUserInfo(info); } else { authenticator = getWorld().getNetRc().getAuthenticators(uri.getHost()); if (authenticator != null) { result.setCredentials(authenticator.getUser(), authenticator.getPass()); } } return result; }
From source file:org.jenkinsci.plugins.workflow.steps.scm.SubversionStepTest.java
@Test public void multipleSCMs() throws Exception { File sampleRepo = tmp.newFolder(); URI u = sampleRepo.toURI(); String sampleRepoU = new URI(u.getScheme(), "", u.getPath(), u.getFragment()).toString(); // TODO SVN rejects File.toUri syntax (requires blank authority field) run(sampleRepo, "svnadmin", "create", "--compatible-version=1.5", sampleRepo.getAbsolutePath()); File sampleWc = tmp.newFolder(); run(sampleWc, "svn", "co", sampleRepoU, "."); FileUtils.touch(new File(sampleWc, "file")); run(sampleWc, "svn", "add", "file"); run(sampleWc, "svn", "commit", "--message=init"); File otherRepo = tmp.newFolder(); u = otherRepo.toURI();/* w w w . j a va 2 s . c o m*/ String otherRepoU = new URI(u.getScheme(), "", u.getPath(), u.getFragment()).toString(); run(otherRepo, "svnadmin", "create", "--compatible-version=1.5", otherRepo.getAbsolutePath()); File otherWc = tmp.newFolder(); run(otherWc, "svn", "co", otherRepoU, "."); FileUtils.touch(new File(otherWc, "otherfile")); run(otherWc, "svn", "add", "otherfile"); run(otherWc, "svn", "commit", "--message=init"); WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "demo"); p.addTrigger(new SCMTrigger("")); p.setQuietPeriod(3); // so it only does one build p.setDefinition(new CpsFlowDefinition( "node {\n" + " ws {\n" + " dir('main') {\n" + " svn(url: '" + sampleRepoU + "')\n" + " }\n" + " dir('other') {\n" + " svn(url: '" + otherRepoU + "')\n" + " }\n" + " archive '**'\n" + " }\n" + "}")); WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); VirtualFile artifacts = b.getArtifactManager().root(); assertTrue(artifacts.child("main/file").isFile()); assertTrue(artifacts.child("other/otherfile").isFile()); FileUtils.touch(new File(sampleWc, "file2")); run(sampleWc, "svn", "add", "file2"); run(sampleWc, "svn", "commit", "--message=+file2"); FileUtils.touch(new File(otherWc, "otherfile2")); run(otherWc, "svn", "add", "otherfile2"); run(otherWc, "svn", "commit", "--message=+otherfile2"); notifyCommit(uuid(sampleRepoU), "file2"); notifyCommit(uuid(otherRepoU), "otherfile2"); r.waitUntilNoActivity(); b = p.getLastBuild(); assertEquals(2, b.number); artifacts = b.getArtifactManager().root(); assertTrue(artifacts.child("main/file2").isFile()); assertTrue(artifacts.child("other/otherfile2").isFile()); Iterator<? extends SCM> scms = p.getSCMs().iterator(); assertTrue(scms.hasNext()); assertEquals(sampleRepoU.replaceFirst("/$", ""), ((SubversionSCM) scms.next()).getLocations()[0].getURL()); assertTrue(scms.hasNext()); assertEquals(otherRepoU.replaceFirst("/$", ""), ((SubversionSCM) scms.next()).getLocations()[0].getURL()); assertFalse(scms.hasNext()); List<ChangeLogSet<? extends ChangeLogSet.Entry>> changeSets = b.getChangeSets(); assertEquals(2, changeSets.size()); ChangeLogSet<? extends ChangeLogSet.Entry> changeSet = changeSets.get(0); assertEquals(b, changeSet.getRun()); assertEquals("svn", changeSet.getKind()); Iterator<? extends ChangeLogSet.Entry> iterator = changeSet.iterator(); assertTrue(iterator.hasNext()); ChangeLogSet.Entry entry = iterator.next(); assertEquals("[/file2]", entry.getAffectedPaths().toString()); assertFalse(iterator.hasNext()); changeSet = changeSets.get(1); iterator = changeSet.iterator(); assertTrue(iterator.hasNext()); entry = iterator.next(); assertEquals("[/otherfile2]", entry.getAffectedPaths().toString()); assertFalse(iterator.hasNext()); }
From source file:com.collective.celos.ci.deploy.WorkflowFilesDeployer.java
URI getTargetJsFileUri(URI uri) throws URISyntaxException { String path = uri.getPath() + File.separator + config.getWorkflowName() + ".js"; return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery(), uri.getFragment()); }
From source file:org.jvoicexml.interpreter.grammar.GrammarLoader.java
/** * Take the route of processing an external grammar. * * @param context//from w ww . j a v a 2 s .c o m * The current context * @param attributes * attributes governing the fetch. * @param grammar * The grammar to be processed. * * @return Is just the string representation of the grammar as well as the * type. * * @throws UnsupportedFormatError * If an unsupported grammar has to be processed. * @throws BadFetchError * If the document could not be fetched successfully. * @throws SemanticError * if the srcexpr attribute could not be evaluated * @exception URISyntaxException * if the URI of the external grammar could not be resolved */ private GrammarDocument loadExternalGrammar(final VoiceXmlInterpreterContext context, final FetchAttributes attributes, final Grammar grammar) throws BadFetchError, UnsupportedFormatError, SemanticError, URISyntaxException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("loading external grammar"); } // First of all, we need to check, if user has provided any // grammar type. URI src = getExternalUriSrc(grammar, context); if (src.getFragment() != null) { // TODO add support for URI fragments LOGGER.warn("URI fragments are currently not supported: " + "ignoring fragment"); src = new URI(src.getScheme(), src.getUserInfo(), src.getHost(), src.getPort(), src.getPath(), src.getQuery(), null); } // Now load the grammar LOGGER.info("loading grammar from source: '" + src + "'"); final FetchAttributes adaptedAttributes = adaptFetchAttributes(attributes, grammar); final GrammarDocument document = context.acquireExternalGrammar(src, adaptedAttributes); if (document == null) { throw new BadFetchError("Unable to load grammar '" + src + "'!"); } return document; }
From source file:org.eclipse.orion.server.servlets.JsonURIUnqualificationStrategy.java
private void rewrite(JSONObject json, String scheme, String hostname, int port, String contextPath) { String[] names = JSONObject.getNames(json); if (names == null) return;/* w w w. j a va 2 s .c o m*/ for (String name : names) { Object o = json.opt(name); if (o instanceof URI) { try { URI uri = (URI) o; if ("orion".equals(uri.getScheme())) { uri = new URI(null, null, contextPath + uri.getPath(), uri.getQuery(), uri.getFragment()); } json.put(name, unqualifyObjectProperty(name, uri, scheme, hostname, port)); } catch (JSONException e) { } catch (URISyntaxException e) { } } else if (o instanceof String) { String string = (String) o; if (string.startsWith(scheme) || string.startsWith("orion:/")) { try { URI uri = new URI(string); if ("orion".equals(uri.getScheme())) { uri = new URI(null, null, contextPath + uri.getPath(), uri.getQuery(), uri.getFragment()); } json.put(name, unqualifyObjectProperty(name, uri, scheme, hostname, port)); } catch (JSONException e) { } catch (URISyntaxException e) { } } } else { rewrite(o, scheme, hostname, port, contextPath); } } }
From source file:com.collaborne.jsonschema.validator.plugin.ValidateMojo.java
@VisibleForTesting protected URITranslatorConfigurationBuilder addSchemaMappings(URITranslatorConfigurationBuilder builder) throws MojoExecutionException { for (DirectoryURIMapping schemaMapping : schemaMappings) { URI uri = schemaMapping.uri; if (uri.getFragment() != null) { throw new MojoExecutionException("URI " + uri + " must not contain a fragment"); }//from w w w .j a v a2s . co m if (!uri.isAbsolute()) { throw new MojoExecutionException("URI " + uri + " must be absolute"); } // Check the path (and fix it up for the obvious issues) String path = uri.getPath(); if (path == null) { path = "/"; } if (!path.endsWith("/")) { getLog().warn("URI " + uri + " does not end with '/'"); path += "/"; try { uri = new URI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { // Basically impossible: it was (syntactically) valid before that. throw new MojoExecutionException("Cannot construct fixed URI", e); } } getLog().debug("Mapping " + schemaMapping.directory + " to " + uri); builder.addPathRedirect(uri, schemaMapping.directory.toURI()); } return builder; }
From source file:org.exist.xquery.functions.fn.FunUnparsedText.java
private Source getSource(final String uriParam) throws XPathException { try {//w ww .j av a 2s . c om URI uri = new URI(uriParam); if (uri.getScheme() == null) { uri = new URI(XmldbURI.EMBEDDED_SERVER_URI_PREFIX + uriParam); } if (uri.getFragment() != null) { throw new XPathException(this, ErrorCodes.FOUT1170, "href argument may not contain fragment identifier"); } final Source source = SourceFactory.getSource(context.getBroker(), "", uri.toASCIIString(), false); if (!context.getBroker().getCurrentSubject().hasDbaRole()) { throw new XPathException(this, ErrorCodes.FOUT1170, "non-dba user not allowed to read from file system"); } return source; } catch (IOException | PermissionDeniedException | URISyntaxException e) { throw new XPathException(this, ErrorCodes.FOUT1170, e.getMessage()); } }