List of usage examples for java.net URI getScheme
public String getScheme()
From source file:de.fhg.igd.mapviewer.cache.FileTileCache.java
/** * Determines if for a given URI the local file cache shall be used * //w w w . j a v a 2 s . co m * @param uri the URI * * @return if the file cache shall be used */ protected boolean useFileCacheFor(URI uri) { String scheme = uri.getScheme(); return scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https"); //$NON-NLS-1$ //$NON-NLS-2$ }
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 w ww.jav a 2 s . co m*/ }
From source file:net.netheos.pcsapi.oauth.PasswordSessionManager.java
@Override public CResponse execute(HttpUriRequest request) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("{}: {}", request.getMethod(), PcsUtils.shortenUrl(request.getURI())); }/* w ww. ja v a2 s . co m*/ try { URI uri = request.getURI(); HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); HttpContext context = getHttpContext(host); HttpResponse httpResponse = httpClient.execute(host, request, context); return new CResponse(request, httpResponse); } catch (IOException ex) { // a low level error should be retried : throw new CRetriableException(ex); } }
From source file:com.cliqset.salmon.keyfinder.OpenXRDKeyFinder.java
private MagicKey fetchKey(URI uri) throws MagicSigException { if (SCHEME_DATA.equals(uri.getScheme())) { String data = uri.getSchemeSpecificPart(); if (data.contains(",")) { String[] split = data.split(","); byte[] dataBytes = null; try { dataBytes = split[1].getBytes("ASCII"); } catch (UnsupportedEncodingException e) { }//from ww w .ja v a2s. c o m return new MagicKey(dataBytes); //work around for status.net } else { String[] split = data.split(";"); byte[] dataBytes = null; try { dataBytes = split[1].getBytes("ASCII"); } catch (UnsupportedEncodingException e) { } return new MagicKey(dataBytes); } } else if (SCHEME_HTTP.equals(uri.getScheme()) || SCHEME_HTTPS.equals(uri.getScheme())) { HttpGet get = new HttpGet(uri); try { HttpResponse response = httpClient.execute(get); ByteArrayOutputStream baos = new ByteArrayOutputStream(); response.getEntity().writeTo(baos); return new MagicKey(baos.toByteArray()); } catch (ClientProtocolException cpe) { throw new MagicSigException(cpe); } catch (IOException ioe) { throw new MagicSigException(ioe); } } else { throw new MagicSigException( "URI Scheme " + uri.getScheme() + " is not supported when resolving magic key."); } }
From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java
/** * Retrieve all accessible {@link IVariableFragment} instances starting from * the given {@link IFileFragment} and traversing the ancestor tree in * breadth-first order, adding all immediate {@link IVariableFragment} * instances to the list first, before exploring the next ancestor as given * by <em>source_files</em>. * * @param fragment/*from w w w . j a v a 2s .co m*/ * @return */ public static List<IVariableFragment> getAggregatedVariables(IFileFragment fragment) { HashMap<String, IVariableFragment> names = new HashMap<>(); List<IVariableFragment> allVars = new ArrayList<>(); List<IFileFragment> parentsToExplore = new LinkedList<>(); // System.out.println("Parent files " + parentsToExplore); parentsToExplore.add(fragment); while (!parentsToExplore.isEmpty()) { IFileFragment parent = parentsToExplore.remove(0); try { IVariableFragment sf = parent.getChild("source_files", true); try { Collection<String> c = ArrayTools.getStringsFromArray(sf.getArray()); for (String s : c) { // log.debug("Processing file {}", s); URI path = URI.create(FileTools.escapeUri(s)); if (path.getScheme() == null || !path.getPath().startsWith("/")) { URI resolved = FileTools.resolveRelativeUri(fragment.getUri(), path); // log.debug("Adding resolved relative path: {} to {}", path, resolved); parentsToExplore.add(new FileFragment(resolved)); } else { // log.debug("Adding absolute path: {}", path); parentsToExplore.add(new FileFragment(path)); } // File file = new File(s); // if (file.isAbsolute()) { // parentsToExplore.add(new FileFragment(file)); // } else { // try { // file = new File( // cross.datastructures.tools.FileTools.resolveRelativeFile(new File( // fragment.getAbsolutePath()).getParentFile(), new File( // s))); // parentsToExplore.add(new FileFragment(file.getCanonicalFile())); // } catch (IOException ex) { // log.error("{}", ex); // } // } } } catch (ConstraintViolationException cve) { } } catch (ResourceNotAvailableException rnae) { } // System.out.println("Parent files " + parentsToExplore); try { for (IVariableFragment ivf : getVariablesFor(parent)) { if (!ivf.getName().equals("source_files")) { if (!names.containsKey(ivf.getName())) { names.put(ivf.getName(), ivf); allVars.add(ivf); } } } } catch (IOException ex) { // log.warn("{}", ex); } } return allVars; }
From source file:com.nesscomputing.config.ConfigFactory.java
private ConfigStrategy selectConfigStrategy(final URI configLocation) { final ConfigStrategyProvider configStrategyProvider = STRATEGY_PROVIDERS.get(configLocation.getScheme()); if (configStrategyProvider == null) { throw new IllegalStateException("No strategy for " + configLocation + " available!"); }/*from w w w. j a va2 s .c om*/ return configStrategyProvider.getStrategy(configLocation); }
From source file:net.ripe.rpki.validator.util.UriToFileMapper.java
public File map(URI uri, ValidationResult result) { Validate.notNull(result);//from ww w. java 2 s .com Validate.notNull(uri); result.rejectIfFalse(RSYNC_SCHEME.equalsIgnoreCase(uri.getScheme()), VALIDATOR_URI_RSYNC_SCHEME, uri.toString()); result.rejectIfNull(uri.getHost(), VALIDATOR_URI_HOST, uri.toString()); result.rejectIfNull(uri.getRawPath(), VALIDATOR_URI_PATH, uri.toString()); String s = uri.toString(); result.rejectIfTrue(s.contains("/../") || s.endsWith("/.."), VALIDATOR_URI_SAFETY, uri.toString()); if (result.hasFailureForCurrentLocation()) { return null; } return new File(new File(targetDirectory, getHostPortAsString(uri)), uri.getRawPath()); }
From source file:org.apache.storm.elasticsearch.common.EsConfig.java
/** * EsConfig Constructor to be used in EsIndexBolt, EsPercolateBolt and EsStateFactory * * @param urls Elasticsearch addresses in scheme://host:port pattern string array * @throws IllegalArgumentException if urls are empty * @throws NullPointerException on any of the fields being null *///from ww w .j a va 2s . c o m public EsConfig(String... urls) { if (urls.length == 0) { throw new IllegalArgumentException("urls is required"); } this.httpHosts = new HttpHost[urls.length]; for (int i = 0; i < urls.length; i++) { URI uri = toURI(urls[i]); this.httpHosts[i] = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); } }
From source file:com.subgraph.vega.internal.model.web.WebModel.java
private HttpHost uriToHost(URI uri) { return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); }
From source file:com.recomdata.transmart.data.export.util.ExportImageProcessor.java
private String getFilename(URI imageURI) { String filename = null;/*ww w . j ava 2s. co m*/ if (StringUtils.equalsIgnoreCase("file", imageURI.getScheme())) { filename = (new File(imageURI.toString())).getName(); } else { if (null != imageURI) { String imageURIStr = imageURI.toString(); if (StringUtils.isNotEmpty(imageURIStr)) { int loc = imageURIStr.lastIndexOf("/"); if (loc == imageURIStr.length() - 1) { loc = (imageURIStr.substring(0, loc - 1)).lastIndexOf("/"); } filename = imageURIStr.substring(loc + 1, imageURIStr.length()); } } } return filename; }