当前位置: 首页>>代码示例>>Java>>正文


Java URI.isAbsolute方法代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:WebUrlHyperlinkSupport.java

示例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();
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:31,代码来源:ManageReposActivity.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:AutoUpdateCatalogParser.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:CatalogModelImpl.java

示例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);
}
 
开发者ID:stefanhaustein,项目名称:nativehtml,代码行数:25,代码来源:Document.java

示例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;
  }
}
 
开发者ID:spotify,项目名称:hype,代码行数:10,代码来源:Submitter.java

示例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;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:30,代码来源:ModuleSourceProviderBase.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:SelectRootsPanel.java

示例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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:20,代码来源:JavacFileManager.java

示例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
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:LibrariesSupport.java

示例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()]);
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:NbMavenProjectImpl.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:ReferenceHelper.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:URLResourceRetriever.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:JavacFileManager.java

示例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;
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:30,代码来源:ModuleSourceProviderBase.java


注:本文中的java.net.URI.isAbsolute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。