本文整理汇总了Java中java.net.URI.isAbsolute方法的典型用法代码示例。如果您正苦于以下问题:Java URI.isAbsolute方法的具体用法?Java URI.isAbsolute怎么用?Java URI.isAbsolute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.URI
的用法示例。
在下文中一共展示了URI.isAbsolute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkUrl
import java.net.URI; //导入方法依赖的package包/类
private boolean checkUrl(int start, int end) {
String hyperlink = text.subSequence(start, end).toString();
try {
URI uri = new URI(hyperlink);
if (!uri.isAbsolute()) {
return false;
}
String scheme = uri.getScheme();
if (uri.isOpaque() && !scheme.equals("mailto")) {
return false;
}
if (!scheme.equals("http") && !scheme.equals("https") && !scheme.equals("mailto")) {//NOI18N
return false;
}
uri.toURL(); //just a check
} catch (Exception ex) {
return false;
}
return true;
}
示例2: normalizeUrl
import java.net.URI; //导入方法依赖的package包/类
/**
* Some basic sanitization of URLs, so that two URLs which have the same semantic meaning
* are represented by the exact same string by F-Droid. This will help to make sure that,
* e.g. "http://10.0.1.50" and "http://10.0.1.50/" are not two different repositories.
* <p>
* Currently it normalizes the path so that "/./" are removed and "test/../" is collapsed.
* This is done using {@link URI#normalize()}. It also removes multiple consecutive forward
* slashes in the path and replaces them with one. Finally, it removes trailing slashes.
*/
private String normalizeUrl(String urlString) throws URISyntaxException {
if (urlString == null) {
return null;
}
URI uri = new URI(urlString);
if (!uri.isAbsolute()) {
throw new URISyntaxException(urlString, "Must provide an absolute URI for repositories");
}
uri = uri.normalize();
String path = uri.getPath();
if (path != null) {
path = path.replaceAll("//*/", "/"); // Collapse multiple forward slashes into 1.
if (path.length() > 0 && path.charAt(path.length() - 1) == '/') {
path = path.substring(0, path.length() - 1);
}
}
return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(),
path, uri.getQuery(), uri.getFragment()).toString();
}
示例3: getDistribution
import java.net.URI; //导入方法依赖的package包/类
private static URL getDistribution (String distribution, URI base) {
URL retval = null;
if (distribution != null && distribution.length () > 0) {
try {
URI distributionURI = new URI (distribution);
if (! distributionURI.isAbsolute ()) {
if (base != null) {
distributionURI = base.resolve (distributionURI);
}
}
retval = distributionURI.toURL ();
} catch (MalformedURLException | URISyntaxException ex) {
ERR.log (Level.INFO, null, ex);
}
}
return retval;
}
示例4: retrieveCacheAndLookup
import java.net.URI; //导入方法依赖的package包/类
private File retrieveCacheAndLookup(URI locationURI, FileObject sourceFileObject) throws IOException, CatalogModelException{
File result = null;
if((locationURI.isAbsolute()) && locationURI.getScheme().toLowerCase().
startsWith("http") && !CatalogFileWrapperDOMImpl.TEST_ENVIRONMENT){
// for all http and https absolute URI, just attempt downloading the
// file using the retriever API and store in the private cache.
//do not attempt this for a test environment.
boolean res = false;
try{
res = Util.retrieveAndCache(locationURI,
sourceFileObject,!fetchSynchronous,
registerInCatalog);
}catch (Exception e){//ignore all exceptions
}
if(res){
//now attempt onec more
result = resolveUsingPublicCatalog(locationURI);
if(result != null)
return result;
}
}
return result;
}
示例5: resolveUrl
import java.net.URI; //导入方法依赖的package包/类
public URI resolveUrl(String url) {
if (this.url.isOpaque()) {
try {
URI uri = new URI(url);
if (uri.isAbsolute()) {
return uri;
}
String s = this.url.toString();
int cut;
if (url.startsWith("#")) {
cut = s.indexOf('#');
if (cut == -1) {
cut = s.length();
}
} else {
cut = s.lastIndexOf('/') + 1;
}
return new URI(s.substring(0, cut) + url);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
return this.url.resolve(url);
}
示例6: getStagingURI
import java.net.URI; //导入方法依赖的package包/类
private URI getStagingURI(String stagingLocation) {
checkNotNull(stagingLocation);
URI uri = URI.create(stagingLocation);
if (!uri.isAbsolute()) {
return URI.create("file://" + uri.toString());
} else {
return uri;
}
}
示例7: loadFromPathArray
import java.net.URI; //导入方法依赖的package包/类
private ModuleSource loadFromPathArray(String moduleId,
Scriptable paths, Object validator) throws IOException
{
final long llength = ScriptRuntime.toUint32(
ScriptableObject.getProperty(paths, "length"));
// Yeah, I'll ignore entries beyond Integer.MAX_VALUE; so sue me.
int ilength = llength > Integer.MAX_VALUE ? Integer.MAX_VALUE :
(int)llength;
for(int i = 0; i < ilength; ++i) {
final String path = ensureTrailingSlash(
ScriptableObject.getTypedProperty(paths, i, String.class));
try {
URI uri = new URI(path);
if (!uri.isAbsolute()) {
uri = new File(path).toURI().resolve("");
}
final ModuleSource moduleSource = loadFromUri(
uri.resolve(moduleId), uri, validator);
if(moduleSource != null) {
return moduleSource;
}
}
catch(URISyntaxException e) {
throw new MalformedURLException(e.getMessage());
}
}
return null;
}
示例8: getListCellRendererComponent
import java.net.URI; //导入方法依赖的package包/类
@Override
public Component getListCellRendererComponent(
final JList<?> list,
Object value,
final int index,
final boolean isSelected,
final boolean cellHasFocus) {
if (value instanceof URI) {
final URI uri = (URI) value;
if (uri.isAbsolute()) {
try {
URL url = uri.toURL();
String offset = null;
if ("jar".equals(url.getProtocol())) { //NOI18N
final String surl = url.toExternalForm();
int offsetPos = surl.lastIndexOf("!/"); //NOI18N
if (offsetPos > 0 && offsetPos < surl.length()-3) {
offset = surl.substring(offsetPos+2);
}
url = FileUtil.getArchiveFile(url);
}
if ("file".equals(url.getProtocol())) { //NOI18N
final File file = Utilities.toFile(url.toURI());
value = offset == null ?
file.getAbsolutePath() :
NbBundle.getMessage(
SelectRootsPanel.class,
"PATTERN_RELPATH_IN_FILE",
offset,
file.getAbsolutePath());
}
} catch (MalformedURLException | URISyntaxException ex) {
//pass - value unchanged
}
}
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
示例9: isRelativeUri
import java.net.URI; //导入方法依赖的package包/类
/**
* Enforces the specification of a "relative" URI as used in
* {@linkplain #getFileForInput(Location, String, URI)
* getFileForInput}. This method must follow the rules defined in
* that method, do not make any changes without consulting the
* specification.
*/
protected static boolean isRelativeUri(URI uri) {
if (uri.isAbsolute())
return false;
String path = uri.normalize().getPath();
if (path.length() == 0 /* isEmpty() is mustang API */)
return false;
if (!path.equals(uri.getPath())) // implicitly checks for embedded . and ..
return false;
if (path.startsWith("/") || path.startsWith("./") || path.startsWith("../"))
return false;
return true;
}
示例10: convertURIToFilePath
import java.net.URI; //导入方法依赖的package包/类
/**
* Properly converts possibly relative URI to file path.
* @param uri URI convert; can be relative URI; cannot be null
* @return file path
* @since org.netbeans.modules.project.libraries/1 1.18
*/
public static String convertURIToFilePath(URI uri) {
if (uri.isAbsolute()) {
return BaseUtilities.toFile(uri).getPath();
} else {
String path = uri.getPath();
if (path.length() > 0 && path.charAt(path.length()-1) == '/') { //NOI18N
path = path.substring(0, path.length()-1);
}
return path.replace('/', File.separatorChar); //NOI18N
}
}
示例11: getResources
import java.net.URI; //导入方法依赖的package包/类
public URI[] getResources(boolean test) {
List<URI> toRet = new ArrayList<URI>();
URI projectroot = getProjectDirectory().toURI();
Set<URI> sourceRoots = null;
List<Resource> res = test ? getOriginalMavenProject().getTestResources() : getOriginalMavenProject().getResources();
LBL : for (Resource elem : res) {
String dir = elem.getDirectory();
if (dir == null) {
continue; // #191742
}
URI uri = FileUtilities.getDirURI(getProjectDirectory(), dir);
if (elem.getTargetPath() != null || !elem.getExcludes().isEmpty() || !elem.getIncludes().isEmpty()) {
URI rel = projectroot.relativize(uri);
if (rel.isAbsolute()) { //outside of project directory
continue;// #195928, #231517
}
if (sourceRoots == null) {
sourceRoots = new HashSet<URI>();
sourceRoots.addAll(Arrays.asList(getSourceRoots(true)));
sourceRoots.addAll(Arrays.asList(getSourceRoots(false)));
//should we also consider generated sources? most like not necessary
}
for (URI sr : sourceRoots) {
if (!uri.relativize(sr).isAbsolute()) {
continue LBL;// #195928, #231517
}
}
//hope for the best now
}
// if (new File(uri).exists()) {
toRet.add(uri);
// }
}
return toRet.toArray(new URI[toRet.size()]);
}
示例12: RawReference
import java.net.URI; //导入方法依赖的package包/类
private RawReference(String foreignProjectName, String artifactType, URI scriptLocation, String newScriptLocation, String targetName, String cleanTargetName, String artifactID, Properties props) throws IllegalArgumentException {
this.foreignProjectName = foreignProjectName;
this.artifactType = artifactType;
if (scriptLocation != null && scriptLocation.isAbsolute()) {
throw new IllegalArgumentException("Cannot use an absolute URI " + scriptLocation + " for script location"); // NOI18N
}
this.scriptLocation = scriptLocation;
this.newScriptLocation = newScriptLocation;
this.targetName = targetName;
this.cleanTargetName = cleanTargetName;
this.artifactID = artifactID;
this.props = props;
}
示例13: accept
import java.net.URI; //导入方法依赖的package包/类
public boolean accept(String baseAddr, String currentAddr) throws URISyntaxException {
URI currURI = new URI(currentAddr);
if( (currURI.isAbsolute()) && (currURI.getScheme().equalsIgnoreCase(URI_SCHEME)))
return true;
if(baseAddr != null){
if(!currURI.isAbsolute()){
URI baseURI = new URI(baseAddr);
if(baseURI.getScheme().equalsIgnoreCase(URI_SCHEME))
return true;
}
}
return false;
}
示例14: isRelativeUri
import java.net.URI; //导入方法依赖的package包/类
/**
* Enforces the specification of a "relative" name as used in
* {@linkplain #getFileForInput(Location,String,String)
* getFileForInput}. This method must follow the rules defined in
* that method, do not make any changes without consulting the
* specification.
*/
protected static boolean isRelativeUri(URI uri) {
if (uri.isAbsolute())
return false;
String path = uri.normalize().getPath();
if (path.length() == 0 /* isEmpty() is mustang API */)
return false;
if (!path.equals(uri.getPath())) // implicitly checks for embedded . and ..
return false;
if (path.startsWith("/") || path.startsWith("./") || path.startsWith("../"))
return false;
return true;
}
示例15: loadFromPathArray
import java.net.URI; //导入方法依赖的package包/类
private ModuleSource loadFromPathArray(String moduleId,
Scriptable paths, Object validator) throws IOException
{
final long llength = ScriptRuntime.toUint32(
ScriptableObject.getProperty(paths, "length"));
// Yeah, I'll ignore entries beyond Integer.MAX_VALUE; so sue me.
int ilength = llength > Integer.MAX_VALUE ? Integer.MAX_VALUE :
(int)llength;
for(int i = 0; i < ilength; ++i) {
final String path = ensureTrailingSlash(
ScriptableObject.getTypedProperty(paths, i, String.class));
try {
URI uri = new URI(path);
if (!uri.isAbsolute()) {
uri = new File(path).toURI().resolve("");
}
final ModuleSource moduleSource = loadFromUri(
uri.resolve(moduleId), uri, validator);
if(moduleSource != null) {
return moduleSource;
}
}
catch(URISyntaxException e) {
throw new MalformedURLException(e.getMessage());
}
}
return null;
}