List of usage examples for java.net URI resolve
public URI resolve(String str)
From source file:stargate.client.hdfs.StargateFileSystem.java
private StargateFileStatus makeStargateFileStatus(DataObjectMetadata metadata, URI resourceURI) throws IOException { if (!metadata.isDirectory() && isLocalClusterPath(metadata.getPath())) { try {// w ww . j a v a 2 s. c o m URI metaURI = urify(metadata.getPath()); URI absURI = resourceURI.resolve(metaURI); return new StargateFileStatus(metadata, DEFAULT_BLOCK_SIZE, absURI, this.userInterfaceClient.getLocalResourcePath(metadata.getPath())); } catch (URISyntaxException ex) { throw new IOException(ex); } } else { try { URI metaURI = urify(metadata.getPath()); URI absURI = resourceURI.resolve(metaURI); return new StargateFileStatus(metadata, DEFAULT_BLOCK_SIZE, absURI); } catch (URISyntaxException ex) { throw new IOException(ex); } } }
From source file:com.collaborne.jsonschema.generator.pojo.PojoGeneratorSmokeTest.java
private SchemaLoader loadSchema(URI rootUri, String path) throws IOException { LoadingConfigurationBuilder loadingConfigurationBuilder = LoadingConfiguration.newBuilder(); JsonNode schemaNode = new JsonNodeReader().fromInputStream(getClass().getResourceAsStream(path)); loadingConfigurationBuilder.preloadSchema(rootUri.resolve(path).toASCIIString(), schemaNode); return new SchemaLoader(loadingConfigurationBuilder.freeze()); }
From source file:org.callimachusproject.client.HttpClientFactoryTest.java
@Test public void test302CachedRedirectTarget() throws Exception { do {// w w w . java2 s . co m HttpGet get = new HttpGet("http://example.com/302"); get.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true); BasicHttpResponse redirect = new BasicHttpResponse(_302); redirect.setHeader("Location", "http://example.com/200"); redirect.setHeader("Cache-Control", "public,max-age=3600"); responses.add(redirect); BasicHttpResponse doc = new BasicHttpResponse(_200); doc.setHeader("Cache-Control", "public,max-age=3600"); responses.add(doc); client.execute(get, new ResponseHandler<Void>() { public Void handleResponse(HttpResponse response) throws ClientProtocolException, IOException { assertEquals(_200.getStatusCode(), response.getStatusLine().getStatusCode()); return null; } }); } while (false); do { HttpContext localContext = new BasicHttpContext(); HttpGet get = new HttpGet("http://example.com/302"); get.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); BasicHttpResponse redirect = new BasicHttpResponse(_302); redirect.setHeader("Location", "http://example.com/200"); redirect.setHeader("Cache-Control", "public,max-age=3600"); responses.add(redirect); client.execute(get, new ResponseHandler<Void>() { public Void handleResponse(HttpResponse response) throws ClientProtocolException, IOException { assertEquals(_302.getStatusCode(), response.getStatusLine().getStatusCode()); return null; } }, localContext); HttpHost host = (HttpHost) localContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST); HttpUriRequest req = (HttpUriRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST); URI root = new URI(host.getSchemeName(), null, host.getHostName(), -1, "/", null, null); assertEquals("http://example.com/302", root.resolve(req.getURI()).toASCIIString()); } while (false); }
From source file:net.ripe.rpki.validator.commands.TopDownWalker.java
void processManifestFiles(CertificateRepositoryObjectValidationContext context, ManifestCms manifestCms) { URI repositoryURI = context.getRepositoryURI(); for (String fileName : manifestCms.getFileNames()) { try {//from w ww . j a va 2s.c om processManifestEntry(manifestCms, context, repositoryURI, fileName); } catch (RuntimeException e) { validationResult.error(ValidationString.VALIDATOR_OBJECT_PROCESSING_EXCEPTION, repositoryURI.resolve(fileName).toString()); } } }
From source file:org.structr.schema.export.StructrMethodDefinition.java
@Override public URI getId() { final URI parentId = parent.getId(); if (parentId != null) { try {//from w w w . ja va2 s . co m final URI containerURI = new URI(parentId.toString() + "/"); return containerURI.resolve("properties/" + getName()); } catch (URISyntaxException urex) { logger.warn("", urex); } } return null; }
From source file:ru.histone.resourceloaders.DefaultResourceLoader.java
public URI makeFullLocation(String location, String baseLocation) { if (location == null) { throw new ResourceLoadException("Resource location is undefined!"); }//w w w .ja v a 2s. c om URI locationURI = URI.create(location); if (baseLocation == null && !locationURI.isAbsolute()) { throw new ResourceLoadException("Base HREF is empty and resource location is not absolute!"); } if (baseLocation != null) { baseLocation = baseLocation.replace("\\", "/"); baseLocation = baseLocation.replace("file://", "file:/"); } URI baseLocationURI = (baseLocation != null) ? URI.create(baseLocation) : null; if (!locationURI.isAbsolute() && baseLocation != null) { locationURI = baseLocationURI.resolve(locationURI.normalize()); } if (!locationURI.isAbsolute()) { throw new ResourceLoadException("Resource location is not absolute!"); } return locationURI; }
From source file:uk.ac.cam.caret.sakai.rwiki.component.service.impl.BaseFOPSerializer.java
/** * {@inheritDoc}/*ww w .ja v a 2s . c o m*/ */ public ContentHandler asContentHandler() throws IOException { if (fop == null) { InputStream stream = null; try { DefaultConfigurationBuilder cfgBuild = new DefaultConfigurationBuilder(); stream = getClass().getResourceAsStream(configfile); Configuration cfg = cfgBuild.build(stream); final FopFactory ff = FopFactory.newInstance(); ff.setUserConfig(cfg); FOUserAgent userAgent = ff.newFOUserAgent(); userAgent.setURIResolver(new URIResolver() { public Source resolve(String href, String base) throws TransformerException { Source source = null; try { logger.info("Resolving " + href + " from " + base); HttpServletRequest request = XSLTEntityHandler.getCurrentRequest(); if (request != null && href.startsWith("/access")) { // going direct into the ContentHandler Service try { String path = href.substring("/access".length()); Reference ref = EntityManager.newReference(path); ContentResource resource = ContentHostingService.getResource(ref.getId()); return new StreamSource(resource.streamContent()); } catch (Exception ex) { URI uri = new URI(base); String content = uri.resolve(href).toString(); source = new StreamSource(content); } } else { // use default resolver to resolve font if (base == null) { return ff.resolveURI(href, base); } URI uri = new URI(base); String content = uri.resolve(href).toString(); source = new StreamSource(content); } } catch (Exception ex) { throw new TransformerException("Failed to get " + href, ex); } return source; } }); userAgent.setBaseURL(ServerConfigurationService.getString("serverUrl")); fop = ff.newFop(mimeType, userAgent, outputStream); } catch (Exception e) { logger.error("Failed to create Handler ", e); throw new IOException("Failed to create " + mimeType + " Serializer: " + e.getMessage()); } finally { if (stream != null) { stream.close(); } } } DefaultHandler dh; try { dh = fop.getDefaultHandler(); } catch (FOPException e) { logger.error("Failed to get FOP Handler ", e); throw new RuntimeException("Failed to get FOP Handler ", e); } return dh; }
From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategy.java
@Override public String checkStatus(final InstanceConfig config, final URI triggerUrl) throws ResponseStatusException { Preconditions.checkArgument(config != null); Preconditions.checkArgument(triggerUrl != null); final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(), config.getUsername(), config.getPassword()); final URI url = triggerUrl.resolve(triggerUrl.getPath() + STATUS_PATH); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); final HttpEntity<String> httpEntity = new HttpEntity<>(headers); final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class); final HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.OK)) { return response.getBody(); } else {//from w w w .j av a 2 s . c o m throw new ResponseStatusException( "HttpStatus " + status.toString() + " response received. Load trigger monitoring failed."); } }
From source file:com.xmlcalabash.io.ReadableDocument.java
private void readDoc(StepContext stepContext) { runtime.getTracer().debug(null, stepContext, -1, this, null, " DOCU > LOADING..."); c_init.close(stepContext.curChannel); if (uri == null) { documents.addChannel(stepContext.curChannel); runtime.getTracer().debug(null, stepContext, -1, this, null, " DOCU > NOTHING"); } else {//from w ww . j a v a2 s.co m if (doc == null) { try { // What if this is a directory? String fn = uri; if (fn.startsWith("file:")) { fn = fn.substring(5); if (fn.startsWith("///")) { fn = fn.substring(2); } } File f = new File(fn); if (f.isDirectory()) { if (pattern == null) { pattern = Pattern.compile("^.*\\.xml$"); } for (File file : f.listFiles(new RegexFileFilter(pattern))) { doc = runtime.parse(file.getCanonicalPath(), base); documents.newPipedDocument(stepContext.curChannel, doc); } } else { doc = null; boolean json = false; try { doc = runtime.parse(uri, base); } catch (XProcException xe) { if (runtime.transparentJSON()) { try { URI baseURI = new URI(base); URL url = baseURI.resolve(uri).toURL(); URLConnection conn = url.openConnection(); InputStreamReader reader = new InputStreamReader(conn.getInputStream()); JSONTokener jt = new JSONTokener(reader); doc = JSONtoXML.convert(runtime.getProcessor(), jt, runtime.jsonFlavor()); documents.newPipedDocument(stepContext.curChannel, doc); json = true; } catch (Exception e) { throw xe; } } else { throw xe; } } if (!json) { if (fn.contains("#")) { int pos = fn.indexOf("#"); String ptr = fn.substring(pos + 1); if (ptr.matches("^[\\w]+$")) { ptr = "element(" + ptr + ")"; } XPointer xptr = new XPointer(ptr); Vector<XdmNode> nodes = xptr.selectNodes(runtime, doc); if (nodes.size() == 1) { doc = nodes.get(0); } else if (nodes.size() != 0) { throw new XProcException(node, "XPointer matches more than one node!?"); } } } } } catch (Exception except) { throw XProcException.dynamicError(11, node, except, "Could not read: " + uri); } } documents.newPipedDocument(stepContext.curChannel, doc); runtime.getTracer().debug(null, stepContext, -1, this, null, " DOCU > LOADED"); } // close documents documents.close(stepContext.curChannel); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceImpl.java
private OwncloudRestResourceExtension createOwncloudResourceFrom(DavResource davResource, OwncloudResourceConversionProperties conversionProperties) { log.debug("Create OwncloudResource based on DavResource {}", davResource.getHref()); MediaType mediaType = MediaType.valueOf(davResource.getContentType()); URI rootPath = conversionProperties.getRootPath(); URI href = rootPath.resolve(davResource.getHref()); String name = davResource.getName(); if (davResource.isDirectory() && href.equals(rootPath)) { name = SLASH;/* w w w . j a v a2 s. co m*/ } LocalDateTime lastModifiedAt = LocalDateTime.ofInstant(davResource.getModified().toInstant(), ZoneId.systemDefault()); href = rootPath.relativize(href); href = URI.create(SLASH).resolve(href).normalize(); // prepend "/" to the href OwncloudRestResourceExtension owncloudResource = OwncloudRestResourceImpl.builder().href(href).name(name) .lastModifiedAt(lastModifiedAt).mediaType(mediaType) .eTag(StringUtils.strip(davResource.getEtag(), QUOTE)).build(); if (davResource.isDirectory()) { return owncloudResource; } return OwncloudRestFileResourceImpl.fileBuilder().owncloudResource(owncloudResource) .contentLength(davResource.getContentLength()).build(); }