List of usage examples for java.net URI isAbsolute
public boolean isAbsolute()
From source file:org.apache.taverna.scufl2.validation.correctness.CorrectnessVisitor.java
@Override public void visitWorkflow(Workflow bean) { Set<DataLink> dataLinks = bean.getDataLinks(); Set<ControlLink> controlLinks = bean.getControlLinks(); // ports are done in Ported NamedSet<Processor> processors = bean.getProcessors(); URI workflowIdentifier = bean.getIdentifier(); if (workflowIdentifier != null) { if (!workflowIdentifier.isAbsolute()) listener.nonAbsoluteURI(bean, "workflowIdentifier", workflowIdentifier); else if (workflowIdentifier.getScheme().equals("file")) listener.nonAbsoluteURI(bean, "workflowIdentifier", workflowIdentifier); }//from w w w . j av a2 s.co m if (checkComplete) { if (dataLinks == null) listener.nullField(bean, "dataLinks"); if (controlLinks == null) listener.nullField(bean, "controlLinks"); if (processors == null) listener.nullField(bean, "processors"); if (workflowIdentifier == null) listener.nullField(bean, "workflowIdentifier"); } }
From source file:org.wso2.carbon.humantask.core.deployment.ArchiveBasedHumanTaskDeploymentUnitBuilder.java
@Override public void buildWSDLs() throws HumanTaskDeploymentException { HashSet<Definition> tmpWsdlDefinitions = new HashSet<>(); URI baseUri = humantaskDir.toURI(); for (File file : FileUtils.directoryEntriesInPath(humantaskDir, wsdlFilter)) { try {//from w ww. j a v a2s.co m URI uri = baseUri.relativize(file.toURI()); if (!uri.isAbsolute()) { File f = new File(baseUri.getPath() + File.separator + uri.getPath()); URI abUri = f.toURI(); if (abUri.isAbsolute()) { uri = abUri; } } WSDLReader reader = WSDLFactory.newInstance().newWSDLReader(); reader.setFeature(HumanTaskConstants.JAVAX_WSDL_VERBOSE_MODE_KEY, false); reader.setFeature("javax.wsdl.importDocuments", true); Definition definition = reader.readWSDL(new HumanTaskWSDLLocator(uri)); if (definition != null) { tmpWsdlDefinitions.add(definition); } } catch (WSDLException e) { log.error("Error processing wsdl " + file.getName()); throw new HumanTaskDeploymentException(" Error processing wsdl ", e); } catch (URISyntaxException e) { log.error("Invalid uri in reading wsdl ", e); throw new HumanTaskDeploymentException(" Invalid uri in reading wsdl ", e); } } // Optimizing WSDLs imports. Using HashSet to avoid duplicate entices. HashSet<Definition> optimizedDefinitions = new HashSet<>(); HTDeploymentConfigDocument htDeploymentConfigDocument = getHTDeploymentConfigDocument(); // Iterating Tasks. THTDeploymentConfig.Task[] taskArray = htDeploymentConfigDocument.getHTDeploymentConfig().getTaskArray(); if (taskArray != null) { for (THTDeploymentConfig.Task task : taskArray) { QName taskService = task.getPublish().getService().getName(); Definition taskServiceDefinition = getDefinition(taskService, tmpWsdlDefinitions); if (log.isDebugEnabled()) { log.debug("Optimizing WSDL import for Task : " + task.getName()); } if (taskServiceDefinition != null) { optimizedDefinitions.add(taskServiceDefinition); if (log.isDebugEnabled()) { log.debug("Added WSDL for Task : " + task.getName() + ", Service : " + taskService + ", Imported/Total definition : " + optimizedDefinitions.size() + "/" + tmpWsdlDefinitions.size()); } } else { log.warn("Can't find valid WSDL definition for Task" + task.getName() + ", Service: " + taskService); } QName callbackService = task.getCallback().getService().getName(); Definition callbackServiceDefinition = getDefinition(callbackService, tmpWsdlDefinitions); if (callbackServiceDefinition != null) { optimizedDefinitions.add(callbackServiceDefinition); if (log.isDebugEnabled()) { log.debug("Added WSDL for Task : " + task.getName() + ", Callback Service : " + callbackService + ", Imported/Total definition : " + optimizedDefinitions.size() + "/" + tmpWsdlDefinitions.size()); } } else { log.warn("Can't find valid WSDL definition for Task : " + task.getName() + ", Callback Service" + callbackService); } } } // Iterating Notifications. THTDeploymentConfig.Notification[] notificationsArray = htDeploymentConfigDocument.getHTDeploymentConfig() .getNotificationArray(); if (notificationsArray != null) { for (THTDeploymentConfig.Notification notification : notificationsArray) { QName notificationService = notification.getPublish().getService().getName(); Definition notificationServiceDefinition = getDefinition(notificationService, tmpWsdlDefinitions); if (notificationServiceDefinition != null) { optimizedDefinitions.add(notificationServiceDefinition); if (log.isDebugEnabled()) { log.debug("Added WSDL for Task : " + notification.getName() + ", Callback Service : " + notificationService + ", Imported/Total definition : " + optimizedDefinitions.size() + "/" + tmpWsdlDefinitions.size()); } } else { log.warn("Can't find valid WSDL definition for Notification " + notification.getName() + ", Service: " + notificationService); } } } // Converting HashSet to ArrayList. wsdlDefinitions = new ArrayList<>(optimizedDefinitions); if (log.isDebugEnabled()) { log.debug("Optimized Imported/Total definition : " + wsdlDefinitions.size() + "/" + tmpWsdlDefinitions.size()); } }
From source file:org.geoserver.wms.web.data.ExternalGraphicPanel.java
/** * @param id//from w ww . j a va2 s . c om * @param model Must return a {@link ResourceInfo} */ public ExternalGraphicPanel(String id, final CompoundPropertyModel<StyleInfo> styleModel, final Form<?> styleForm) { super(id, styleModel); // container for ajax updates final WebMarkupContainer container = new WebMarkupContainer("externalGraphicContainer"); container.setOutputMarkupId(true); add(container); table = new WebMarkupContainer("list"); table.setOutputMarkupId(true); IModel<String> bind = styleModel.bind("legend.onlineResource"); onlineResource = new TextField<String>("onlineResource", bind); onlineResource.add(new IValidator<String>() { final List<String> EXTENSIONS = Arrays.asList(new String[] { "png", "gif", "jpeg", "jpg" }); @Override public void validate(IValidatable<String> input) { String value = input.getValue(); int last = value == null ? -1 : value.lastIndexOf('.'); if (last == -1 || !EXTENSIONS.contains(value.substring(last + 1).toLowerCase())) { ValidationError error = new ValidationError(); error.setMessage("Not an image"); error.addKey("nonImage"); input.error(error); return; } URI uri = null; try { uri = new URI(value); } catch (URISyntaxException e1) { // Unable to check if absolute } if (uri != null && uri.isAbsolute()) { try { String baseUrl = baseURL(onlineResource.getForm()); if (!value.startsWith(baseUrl)) { onlineResource.warn("Recommend use of styles directory at " + baseUrl); } URL url = uri.toURL(); URLConnection conn = url.openConnection(); if ("text/html".equals(conn.getContentType())) { ValidationError error = new ValidationError(); error.setMessage("Unable to access image"); error.addKey("imageUnavailable"); input.error(error); return; // error message back! } } catch (MalformedURLException e) { ValidationError error = new ValidationError(); error.setMessage("Unable to access image"); error.addKey("imageUnavailable"); input.error(error); } catch (IOException e) { ValidationError error = new ValidationError(); error.setMessage("Unable to access image"); error.addKey("imageUnavailable"); input.error(error); } return; // no further checks possible } else { GeoServerResourceLoader resources = GeoServerApplication.get().getResourceLoader(); try { File styles = resources.find("styles"); String[] path = value.split(Pattern.quote(File.separator)); WorkspaceInfo wsInfo = styleModel.getObject().getWorkspace(); File test = null; if (wsInfo != null) { String wsName = wsInfo.getName(); List<String> list = new ArrayList(); list.addAll(Arrays.asList("workspaces", wsName, "styles")); list.addAll(Arrays.asList(path)); test = resources.find(list.toArray(new String[list.size()])); } if (test == null) { test = resources.find(styles, path); } if (test == null) { ValidationError error = new ValidationError(); error.setMessage("File not found in styles directory"); error.addKey("imageNotFound"); input.error(error); } } catch (IOException e) { ValidationError error = new ValidationError(); error.setMessage("File not found in styles directory"); error.addKey("imageNotFound"); input.error(error); } } } }); onlineResource.setOutputMarkupId(true); table.add(onlineResource); // add the autofill button autoFill = new GeoServerAjaxFormLink("autoFill", styleForm) { @Override public void onClick(AjaxRequestTarget target, Form<?> form) { URLConnection conn = getExternalGraphic(target, form); if (conn == null) { ValidationError error = new ValidationError(); error.setMessage("Unable to access image"); error.addKey("imageUnavailable"); onlineResource.error(error); } else { format.setModelValue(new String[] { conn.getContentType() }); BufferedImage image; try { image = ImageIO.read(conn.getInputStream()); width.setModelValue(new String[] { "" + image.getWidth() }); height.setModelValue(new String[] { "" + image.getHeight() }); } catch (IOException e) { e.printStackTrace(); } target.add(format); target.add(width); target.add(height); } } }; table.add(autoFill); format = new TextField<String>("format", styleModel.bind("legend.format")); format.setOutputMarkupId(true); table.add(format); width = new TextField<Integer>("width", styleModel.bind("legend.width"), Integer.class); width.add(RangeValidator.minimum(0)); width.setRequired(true); width.setOutputMarkupId(true); table.add(width); height = new TextField<Integer>("height", styleModel.bind("legend.height"), Integer.class); height.add(RangeValidator.minimum(0)); height.setRequired(true); height.setOutputMarkupId(true); table.add(height); table.add(new AttributeModifier("style", showhideStyleModel)); container.add(table); showhideForm = new Form<StyleInfo>("showhide") { @Override protected void onSubmit() { super.onSubmit(); } }; showhideForm.setMarkupId("showhideForm"); container.add(showhideForm); showhideForm.setMultiPart(true); show = new AjaxButton("show") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { updateVisibility(true); target.add(ExternalGraphicPanel.this); } }; container.add(show); showhideForm.add(show); hide = new AjaxButton("hide") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { onlineResource.setModelObject(""); onlineResource.clearInput(); format.setModelObject(""); format.clearInput(); width.setModelObject(0); width.clearInput(); height.setModelObject(0); height.clearInput(); updateVisibility(false); target.add(ExternalGraphicPanel.this); } }; container.add(hide); showhideForm.add(hide); LegendInfo legend = styleModel.getObject().getLegend(); boolean visible = legend != null && legend.getOnlineResource() != null && !legend.getOnlineResource().isEmpty(); updateVisibility(visible); }
From source file:org.lilyproject.indexer.model.impl.IndexerModelImpl.java
private void assertValid(IndexDefinition index) throws IndexValidityException { if (index.getName() == null || index.getName().length() == 0) throw new IndexValidityException("Name should not be null or zero-length"); if (index.getConfiguration() == null) throw new IndexValidityException("Configuration should not be null."); if (index.getGeneralState() == null) throw new IndexValidityException("General state should not be null."); if (index.getBatchBuildState() == null) throw new IndexValidityException("Build state should not be null."); if (index.getUpdateState() == null) throw new IndexValidityException("Update state should not be null."); if (index.getActiveBatchBuildInfo() != null) { ActiveBatchBuildInfo info = index.getActiveBatchBuildInfo(); if (info.getJobId() == null) throw new IndexValidityException("Job id of active batch build cannot be null."); }/*from www . j a va 2 s . c o m*/ if (index.getLastBatchBuildInfo() != null) { BatchBuildInfo info = index.getLastBatchBuildInfo(); if (info.getJobId() == null) throw new IndexValidityException("Job id of last batch build cannot be null."); if (info.getJobState() == null) throw new IndexValidityException("Job state of last batch build cannot be null."); } if (index.getSolrShards() == null || index.getSolrShards().isEmpty()) throw new IndexValidityException("SOLR shards should not be null or empty."); for (String shard : index.getSolrShards().values()) { try { URI uri = new URI(shard); if (!uri.isAbsolute()) { throw new IndexValidityException("SOLR shard URI is not absolute: " + shard); } } catch (URISyntaxException e) { throw new IndexValidityException("Invalid SOLR shard URI: " + shard); } } if (index.getShardingConfiguration() != null) { // parse it + check used shards -> requires dependency on the engine or moving the relevant classes // to the model ShardSelector selector; try { selector = JsonShardSelectorBuilder.build(index.getShardingConfiguration()); } catch (ShardingConfigException e) { throw new IndexValidityException("Error with sharding configuration.", e); } Set<String> shardNames = index.getSolrShards().keySet(); for (String shard : selector.getShards()) { if (!shardNames.contains(shard)) { throw new IndexValidityException("The sharding configuration refers to a shard that is not" + " in the set of available shards. Shard: " + shard); } } } try { IndexerConfBuilder.validate(new ByteArrayInputStream(index.getConfiguration())); } catch (IndexerConfException e) { throw new IndexValidityException("The indexer configuration is not XML well-formed or valid.", e); } }
From source file:com.soundcloud.playerapi.ApiWrapper.java
protected HttpHost determineTarget(HttpUriRequest request) { // A null target may be acceptable if there is a default target. // Otherwise, the null target is detected in the director. URI requestURI = request.getURI(); if (requestURI.isAbsolute()) { return new HttpHost(requestURI.getHost(), requestURI.getPort(), requestURI.getScheme()); } else {//from ww w . j av a 2s. c o m return null; } }
From source file:org.fluentlenium.core.Fluent.java
/** * Open the url page/* w w w .j a v a 2s . c o m*/ * * @param url */ public Fluent goTo(String url) { if (url == null) { throw new IllegalArgumentException("Url is mandatory"); } if (baseUrl != null) { URI uri = URI.create(url); if (!uri.isAbsolute()) { url = baseUrl + url; } } getDriver().get(url); return this; }
From source file:org.fluentlenium.core.Fluent.java
/** * Open the url page in a new tab// w w w. j a v a 2 s .c om * * @param url */ public Fluent goToInNewTab(String url) { if (url == null) { throw new IllegalArgumentException("Url is mandatory"); } if (baseUrl != null) { URI uri = URI.create(url); if (!uri.isAbsolute()) { url = baseUrl + url; } } Set<String> initialTabs = getDriver().getWindowHandles(); executeScript("window.open('" + url + "', '_blank');"); Set<String> tabs = getDriver().getWindowHandles(); tabs.removeAll(initialTabs); String newTab = tabs.iterator().next(); getDriver().switchTo().window(newTab); return this; }
From source file:eu.esdihumboldt.hale.common.core.io.project.impl.ArchiveProjectWriter.java
/** * Update the resources and copy them into the target directory * // w ww. j a va 2 s . c o m * @param targetDirectory target directory * @param includeWebResources whether to include web resources in the copy * @param progress the progress indicator * @param reporter the reporter to use for the execution report * @throws IOException if an I/O operation fails */ protected void updateResources(File targetDirectory, boolean includeWebResources, ProgressIndicator progress, IOReporter reporter) throws IOException { progress.begin("Copy resources", ProgressIndicator.UNKNOWN); try { List<IOConfiguration> resources = getProject().getResources(); // every resource needs his own directory int count = 1; // true if excluded files should be skipped; false is default boolean excludeDataFiles = getParameter(EXLUDE_DATA_FILES).as(Boolean.class, false); // resource locations mapped to new resource path Map<URI, String> handledResources = new HashMap<>(); Iterator<IOConfiguration> iter = resources.iterator(); while (iter.hasNext()) { IOConfiguration resource = iter.next(); // check if ActionId is equal to // eu.esdihumboldt.hale.common.instance.io.InstanceIO.ACTION_LOAD_SOURCE_DATA // import not possible due to cycle errors if (excludeDataFiles && resource.getActionId().equals("eu.esdihumboldt.hale.io.instance.read.source")) { // delete reference in project file iter.remove(); continue; } // get resource path Map<String, Value> providerConfig = resource.getProviderConfiguration(); String path = providerConfig.get(ImportProvider.PARAM_SOURCE).toString(); URI pathUri; try { pathUri = new URI(path); } catch (URISyntaxException e1) { reporter.error(new IOMessageImpl("Skipped resource because of invalid URI: " + path, e1)); continue; } if (!pathUri.isAbsolute()) { if (getPreviousTarget() != null) { pathUri = getPreviousTarget().resolve(pathUri); } else { log.warn("Could not resolve relative path " + pathUri.toString()); } } // check if path was already handled if (handledResources.containsKey(pathUri)) { providerConfig.put(ImportProvider.PARAM_SOURCE, Value.of(handledResources.get(pathUri))); // skip copying the resource continue; } String scheme = pathUri.getScheme(); LocatableInputSupplier<? extends InputStream> input = null; if (scheme != null) { if (scheme.equals("http") || scheme.equals("https")) { // web resource if (includeWebResources) { input = new DefaultInputSupplier(pathUri); } else { // web resource that should not be included this // time // but the resolved URI should be stored // nevertheless // otherwise the URI may be invalid if it was // relative providerConfig.put(ImportProvider.PARAM_SOURCE, Value.of(pathUri.toASCIIString())); continue; } } else if (scheme.equals("file") || scheme.equals("platform") || scheme.equals("bundle") || scheme.equals("jar")) { // files need always to be included // platform resources (or other internal resources) // should be included as well input = new DefaultInputSupplier(pathUri); } else { // other type of URI, e.g. JDBC // not to be included providerConfig.put(ImportProvider.PARAM_SOURCE, Value.of(pathUri.toASCIIString())); continue; } } else { // now can't open that, can we? reporter.error(new IOMessageImpl( "Skipped resource because it cannot be loaded from " + pathUri.toString(), null)); continue; } progress.setCurrentTask("Copying resource at " + path); // every resource file is copied into an own resource // directory in the target directory String resourceFolder = "resource" + count; File newDirectory = new File(targetDirectory, resourceFolder); try { newDirectory.mkdir(); } catch (SecurityException e) { throw new IOException("Can not create directory " + newDirectory.toString(), e); } // Extract the file name from pathUri.getPath(). // This will produce a non-URL-encoded file name to be used in // the File(File parent, String child) constructor below String fileName = FilenameUtils.getName(pathUri.getPath().toString()); if (path.isEmpty()) { fileName = "file"; } File newFile = new File(newDirectory, fileName); Path target = newFile.toPath(); // retrieve the resource advisor Value ct = providerConfig.get(ImportProvider.PARAM_CONTENT_TYPE); IContentType contentType = null; if (ct != null) { contentType = HalePlatform.getContentTypeManager().getContentType(ct.as(String.class)); } ResourceAdvisor ra = ResourceAdvisorExtension.getInstance().getAdvisor(contentType); // copy the resource progress.setCurrentTask("Copying resource at " + path); // Extract the URL-encoded file name of the copied resource and // build the new relative resource path String resourceName = FilenameUtils.getName(target.toUri().toString()); String newPath = resourceFolder + "/" + resourceName; boolean skipCopy = getParameter(EXCLUDE_CACHED_RESOURCES).as(Boolean.class, false) && !resource.getCache().isEmpty(); if (!skipCopy) { ra.copyResource(input, target, contentType, includeWebResources, reporter); // store new path for resource handledResources.put(pathUri, newPath); } // update the provider configuration providerConfig.put(ImportProvider.PARAM_SOURCE, Value.of(newPath)); count++; } } finally { progress.end(); } }
From source file:org.apache.ignite.hadoop.fs.v2.IgniteHadoopFileSystem.java
/** {@inheritDoc} */ @Override/*from w ww . j av a 2 s . com*/ public void checkPath(Path path) { URI uri = path.toUri(); if (uri.isAbsolute()) { if (!F.eq(uri.getScheme(), IGFS_SCHEME)) throw new InvalidPathException( "Wrong path scheme [expected=" + IGFS_SCHEME + ", actual=" + uri.getAuthority() + ']'); if (!F.eq(uri.getAuthority(), uriAuthority)) throw new InvalidPathException( "Wrong path authority [expected=" + uriAuthority + ", actual=" + uri.getAuthority() + ']'); } }
From source file:org.apache.http.HC4.impl.nio.client.MainClientExec.java
private void rewriteRequestURI(final HttpRequestWrapper request, final HttpRoute route) throws ProtocolException { try {/*from ww w. java 2 s. c o m*/ URI uri = request.getURI(); if (uri != null) { if (route.getProxyHost() != null && !route.isTunnelled()) { // Make sure the request URI is absolute if (!uri.isAbsolute()) { final HttpHost target = route.getTargetHost(); uri = URIUtils.rewriteURI(uri, target, true); } else { uri = URIUtils.rewriteURI(uri); } } else { // Make sure the request URI is relative if (uri.isAbsolute()) { uri = URIUtils.rewriteURI(uri, null, true); } else { uri = URIUtils.rewriteURI(uri); } } request.setURI(uri); } } catch (final URISyntaxException ex) { throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex); } }