Example usage for java.net URI isAbsolute

List of usage examples for java.net URI isAbsolute

Introduction

In this page you can find the example usage for java.net URI isAbsolute.

Prototype

public boolean isAbsolute() 

Source Link

Document

Tells whether or not this URI is absolute.

Usage

From source file:org.artifactory.util.HttpUtils.java

public static boolean isAbsolute(String url) {
    try {//from w  w  w .ja v a2  s.co m
        URI uri = new URIBuilder(url).build();
        return uri.isAbsolute();
    } catch (URISyntaxException e) {
        return false;
    }
}

From source file:org.apache.taverna.robundle.Bundles.java

public static Path uriToBundlePath(Bundle bundle, URI uri) {
    URI rootUri = bundle.getRoot().toUri();
    uri = relativizeFromBase(uri, rootUri);
    if (uri.isAbsolute() || uri.getFragment() != null)
        return null;
    return bundle.getFileSystem().provider().getPath(rootUri.resolve(uri));
}

From source file:org.openmidaas.library.MIDaaS.java

/**
 * This methods initializes the library. It first checks to see if the 
 * device is already registered. If it is, it calls the onSuccess()
 * method. Otherwise, it tries to register the device with the server and calls
 * onSuccess() or onError() accordingly. 
 * @param context - the Android context. 
 * @param attributeServerUrl - the attribute server that verifies and releases attributes. If null, the 
 * default server is used. This is defined in the Constants.java file. 
 * @param initCallback - the Initialization callback. 
 * @throws URISyntaxException /*from  w  ww  .j  av  a  2 s  . c  om*/
 */
public static void initialize(final Context context, final String attributeServerUrl,
        final InitializationCallback initCallback) throws URISyntaxException {
    if (context == null) {
        MIDaaS.logError(TAG, "context is null");
        throw new IllegalArgumentException("Context cannot be null");
    }
    if (initCallback == null) {
        MIDaaS.logError(TAG, "initialization callback is null");
        throw new IllegalArgumentException("InitializationCallback cannot be null");
    }
    mContext = context.getApplicationContext();
    /* *** initialization routines *** */
    logDebug(TAG, "Initializing library");
    if (attributeServerUrl == null || attributeServerUrl.isEmpty()) {
        ConnectionManager.setNetworkFactory(new AndroidNetworkFactory(Constants.AVP_SB_BASE_URL));
    } else {
        URI uri = new URI(attributeServerUrl);
        // check to see if we have a complete URL
        if (uri.isAbsolute()) {
            // since we're using the URI class, check that the scheme is http or https. 
            if (uri.getScheme().equals("http") || uri.getScheme().equals("https")) {
                ConnectionManager.setNetworkFactory(new AndroidNetworkFactory(attributeServerUrl));
            } else {
                MIDaaS.logError(TAG, "Unknown URI scheme: " + uri.getScheme());
                throw new URISyntaxException(attributeServerUrl, "Unknown URI scheme: " + uri.getScheme());
            }
        } else {
            MIDaaS.logError(TAG, "URI appears to be incomplete: " + attributeServerUrl);
            throw new URISyntaxException(attributeServerUrl,
                    "URI appears to be incomplete: " + attributeServerUrl);
        }
    }
    // we will use a SQLITE database to persist attributes. 
    AttributePersistenceCoordinator.setPersistenceDelegate(new AttributeDBPersistence());
    // set the authentication strategy to level0 device authentication 
    AuthenticationManager.getInstance().setDeviceAuthenticationStrategy(new SKDeviceAuthentication());
    // we will use our access token strategy that depends on level 0 device authentication
    AuthenticationManager.getInstance().setAccessTokenStrategy(new AVSAccessTokenStrategy());
    logDebug(TAG, "Checking to see if device is registered.");
    WorkQueueManager.getInstance().addWorkerToQueue(new WorkQueueManager.Worker() {
        @Override
        public void execute() {
            DeviceRegistrar.setDeviceRegistrationDelegate(new AVSDeviceRegistration());
            DeviceRegistrar.registerDevice(initCallback);
        }
    });
}

From source file:com.sunchenbin.store.feilong.core.net.URIUtil.java

/**
 * ?path??./* w ww.  j ava 2 s  .  co  m*/
 * 
 * <p>
 * ( {@link java.net.URI#isAbsolute()},?{@code url's scheme !=null} ).
 * </p>
 *
 * @param uriString
 *            
 * @return <tt>true</tt> if, and only if, this URI is absolute
 * @see java.net.URI#isAbsolute()
 */
public static boolean isAbsolutePath(String uriString) {
    URI uri = newURI(uriString);
    return null == uri ? false : uri.isAbsolute();
}

From source file:org.rssowl.core.util.URIUtils.java

/**
 * @param base the base {@link URI} to resolve against.
 * @param relative the relative {@link URI} to resolve.
 * @return a resolved {@link URI} that is absolute.
 * @throws URISyntaxException in case of an error while resolving.
 *///from  w w w. ja  va2  s .  com
public static URI resolve(URI base, URI relative) throws URISyntaxException {
    if (relative.isAbsolute())
        return relative;

    /* Resolve against Host */
    if (relative.toString().startsWith("/")) { //$NON-NLS-1$
        base = normalizeUri(base, true);
        return base.resolve(relative);
    }

    /* Resolve against Given Base */
    if (base.toString().endsWith("/")) //$NON-NLS-1$
        return base.resolve(relative);

    /* Resolve against Given Base By Appending Leading Slash */
    return new URI(base.toString() + "/").resolve(relative.toString()); //$NON-NLS-1$
}

From source file:com.ibm.jaggr.core.test.TestUtils.java

public static IAggregator createMockAggregator(Ref<IConfig> configRef, File workingDirectory,
        List<InitParam> initParams, Class<?> aggregatorProxyClass, IHttpTransport transport) throws Exception {

    final IAggregator mockAggregator = EasyMock.createNiceMock(IAggregator.class);
    IOptions options = new OptionsImpl(false, null);
    options.setOption(IOptions.DELETE_DELAY, "0");
    if (initParams == null) {
        initParams = new LinkedList<InitParam>();
    }//from  w  w w.  j  a  va 2 s.  co m
    final InitParams aggInitParams = new InitParams(initParams);
    boolean createConfig = (configRef == null);
    if (workingDirectory == null) {
        workingDirectory = new File(System.getProperty("java.io.tmpdir"));
    }
    final Ref<ICacheManager> cacheMgrRef = new Ref<ICacheManager>(null);
    final Ref<IHttpTransport> transportRef = new Ref<IHttpTransport>(
            transport == null ? new TestDojoHttpTransport() : transport);
    final Ref<IExecutors> executorsRef = new Ref<IExecutors>(new ExecutorsImpl(new SynchronousExecutor(), null,
            new SynchronousScheduledExecutor(), new SynchronousScheduledExecutor()));
    final File workdir = workingDirectory;

    EasyMock.expect(mockAggregator.getWorkingDirectory()).andReturn(workingDirectory).anyTimes();
    EasyMock.expect(mockAggregator.getName()).andReturn("test").anyTimes();
    EasyMock.expect(mockAggregator.getOptions()).andReturn(options).anyTimes();
    EasyMock.expect(mockAggregator.getExecutors()).andAnswer(new IAnswer<IExecutors>() {
        public IExecutors answer() throws Throwable {
            return executorsRef.get();
        }
    }).anyTimes();
    if (createConfig) {
        configRef = new Ref<IConfig>(null);
        // ConfigImpl constructor calls IAggregator.newResource()
        EasyMock.expect(mockAggregator.newResource((URI) EasyMock.anyObject()))
                .andAnswer(new IAnswer<IResource>() {
                    public IResource answer() throws Throwable {
                        return mockAggregatorNewResource((URI) EasyMock.getCurrentArguments()[0], workdir);
                    }
                }).anyTimes();
    }
    EasyMock.expect(mockAggregator.substituteProps((String) EasyMock.anyObject()))
            .andAnswer(new IAnswer<String>() {
                public String answer() throws Throwable {
                    return (String) EasyMock.getCurrentArguments()[0];
                }
            }).anyTimes();
    EasyMock.expect(mockAggregator.substituteProps((String) EasyMock.anyObject(),
            (IAggregator.SubstitutionTransformer) EasyMock.anyObject())).andAnswer(new IAnswer<String>() {
                public String answer() throws Throwable {
                    return (String) EasyMock.getCurrentArguments()[0];
                }
            }).anyTimes();
    EasyMock.expect(mockAggregator.newLayerCache()).andAnswer(new IAnswer<ILayerCache>() {
        public ILayerCache answer() throws Throwable {
            return new LayerCacheImpl(mockAggregator);
        }
    }).anyTimes();
    EasyMock.expect(mockAggregator.newModuleCache()).andAnswer(new IAnswer<IModuleCache>() {
        public IModuleCache answer() throws Throwable {
            return new ModuleCacheImpl();
        }
    }).anyTimes();
    EasyMock.expect(mockAggregator.newGzipCache()).andAnswer(new IAnswer<IGzipCache>() {
        public IGzipCache answer() throws Throwable {
            return new GzipCacheImpl();
        }
    }).anyTimes();
    EasyMock.expect(mockAggregator.getInitParams()).andAnswer(new IAnswer<InitParams>() {
        public InitParams answer() throws Throwable {
            return aggInitParams;
        }
    }).anyTimes();
    EasyMock.replay(mockAggregator);
    IAggregator mockAggregatorProxy = mockAggregator;
    if (aggregatorProxyClass != null) {
        mockAggregatorProxy = (IAggregator) aggregatorProxyClass
                .getConstructor(new Class[] { IAggregator.class }).newInstance(mockAggregator);
    }
    TestCacheManager cacheMgr = new TestCacheManager(mockAggregatorProxy, 1);
    cacheMgrRef.set(cacheMgr);
    //((IOptionsListener)cacheMgrRef.get()).optionsUpdated(options, 1);
    if (createConfig) {
        configRef.set(new ConfigImpl(mockAggregatorProxy, workingDirectory.toURI(), "{}"));
    }
    EasyMock.reset(mockAggregator);
    EasyMock.expect(mockAggregator.getWorkingDirectory()).andReturn(workingDirectory).anyTimes();
    EasyMock.expect(mockAggregator.getOptions()).andReturn(options).anyTimes();
    EasyMock.expect(mockAggregator.getName()).andReturn("test").anyTimes();
    EasyMock.expect(mockAggregator.getTransport()).andAnswer(new IAnswer<IHttpTransport>() {
        public IHttpTransport answer() throws Throwable {
            return transportRef.get();
        }
    }).anyTimes();
    EasyMock.expect(mockAggregator.newResource((URI) EasyMock.anyObject())).andAnswer(new IAnswer<IResource>() {
        public IResource answer() throws Throwable {
            return mockAggregatorNewResource((URI) EasyMock.getCurrentArguments()[0], workdir);
        }
    }).anyTimes();
    EasyMock.expect(mockAggregator.getResourceFactory(EasyMock.isA(Mutable.class)))
            .andAnswer(new IAnswer<IResourceFactory>() {
                public IResourceFactory answer() throws Throwable {
                    Mutable<URI> uriRef = (Mutable<URI>) EasyMock.getCurrentArguments()[0];
                    URI uri = uriRef.getValue();
                    if (!uri.isAbsolute() && uri.getPath().startsWith("/"))
                        return null;
                    return ("file".equals(uri.getScheme())) ? new FileResourceFactory() : null;
                }
            }).anyTimes();
    EasyMock.expect(
            mockAggregator.getModuleBuilder((String) EasyMock.anyObject(), (IResource) EasyMock.anyObject()))
            .andAnswer(new IAnswer<IModuleBuilder>() {
                public IModuleBuilder answer() throws Throwable {
                    String mid = (String) EasyMock.getCurrentArguments()[0];
                    return mid.contains(".") ? new TextModuleBuilder() : new JavaScriptModuleBuilder();
                }
            }).anyTimes();
    final Ref<IConfig> cfgRef = configRef;
    EasyMock.expect(mockAggregator.getConfig()).andAnswer(new IAnswer<IConfig>() {
        public IConfig answer() throws Throwable {
            return cfgRef.get();
        }
    }).anyTimes();
    EasyMock.expect(mockAggregator.getCacheManager()).andAnswer(new IAnswer<ICacheManager>() {
        public ICacheManager answer() throws Throwable {
            return cacheMgrRef.get();
        }
    }).anyTimes();
    EasyMock.expect(mockAggregator.newModule((String) EasyMock.anyObject(), (URI) EasyMock.anyObject()))
            .andAnswer(new IAnswer<IModule>() {
                public IModule answer() throws Throwable {
                    String mid = (String) EasyMock.getCurrentArguments()[0];
                    URI uri = (URI) EasyMock.getCurrentArguments()[1];
                    return new ModuleImpl(mid, uri);
                }
            }).anyTimes();
    EasyMock.expect(mockAggregator.getExecutors()).andAnswer(new IAnswer<IExecutors>() {
        public IExecutors answer() throws Throwable {
            return executorsRef.get();
        }
    }).anyTimes();
    EasyMock.expect(mockAggregator.newLayerCache()).andAnswer(new IAnswer<ILayerCache>() {
        public ILayerCache answer() throws Throwable {
            return new LayerCacheImpl(mockAggregator);
        }
    }).anyTimes();
    EasyMock.expect(mockAggregator.newModuleCache()).andAnswer(new IAnswer<IModuleCache>() {
        public IModuleCache answer() throws Throwable {
            return new ModuleCacheImpl();
        }
    }).anyTimes();
    EasyMock.expect(mockAggregator.newGzipCache()).andAnswer(new IAnswer<IGzipCache>() {
        public IGzipCache answer() throws Throwable {
            return new GzipCacheImpl();
        }
    }).anyTimes();
    EasyMock.expect(mockAggregator.substituteProps((String) EasyMock.anyObject()))
            .andAnswer(new IAnswer<String>() {
                public String answer() throws Throwable {
                    return (String) EasyMock.getCurrentArguments()[0];
                }
            }).anyTimes();
    EasyMock.expect(mockAggregator.substituteProps((String) EasyMock.anyObject(),
            (IAggregator.SubstitutionTransformer) EasyMock.anyObject())).andAnswer(new IAnswer<String>() {
                public String answer() throws Throwable {
                    return (String) EasyMock.getCurrentArguments()[0];
                }
            }).anyTimes();
    EasyMock.expect(mockAggregator.getInitParams()).andAnswer(new IAnswer<InitParams>() {
        public InitParams answer() throws Throwable {
            return aggInitParams;
        }
    }).anyTimes();
    EasyMock.expect(
            mockAggregator.buildAsync(EasyMock.isA(Callable.class), EasyMock.isA(HttpServletRequest.class)))
            .andAnswer((IAnswer) new IAnswer<Future<?>>() {
                @Override
                public Future<?> answer() throws Throwable {
                    Callable<?> builder = (Callable<?>) EasyMock.getCurrentArguments()[0];
                    return executorsRef.get().getBuildExecutor().submit(builder);
                }

            }).anyTimes();

    return mockAggregator;
}

From source file:org.ebayopensource.turmeric.eclipse.utils.wsdl.WSDLUtil.java

private static boolean isRelativeURI(String url) {
    if (StringUtils.isEmpty(url))
        return false;

    URI uri = null;
    try {/*from  ww  w  . j  a v a2  s .  com*/
        uri = URI.create(url);
    } catch (RuntimeException e) {
        // ignore it
    }

    return uri != null && !uri.isAbsolute();
}

From source file:org.dita.dost.util.XMLUtils.java

/**
 * Transform file with XML filters. Only file URIs are supported.
 *
 * @param input absolute URI to transform and replace
 * @param filters XML filters to transform file with, may be an empty list
 *///from  www. ja  va  2s.  c  o m
public static void transform(final URI input, final List<XMLFilter> filters) throws DITAOTException {
    assert input.isAbsolute();
    if (!input.getScheme().equals("file")) {
        throw new IllegalArgumentException("Only file URI scheme supported: " + input);
    }

    transform(new File(input), filters);
}

From source file:com.sworddance.util.UriFactoryImpl.java

public static boolean hasQuestionableScheme(URI uri) {
    if (uri.isAbsolute()) {
        String scheme = uri.getScheme();
        return !KNOWN_GOOD_SCHEMES.matcher(scheme).find();
    } else {/*  ww  w  . j  av  a 2 s.co  m*/
        return false;
    }
}

From source file:org.rhq.plugins.jbossas5.ApplicationServerComponent.java

private static void validateNamingURL(String namingURL) {
    URI namingURI;
    try {/*from www.j  a  va  2  s . c o  m*/
        namingURI = new URI(namingURL);
    } catch (URISyntaxException e) {
        throw new RuntimeException("Naming URL '" + namingURL + "' is not valid: " + e.getLocalizedMessage());
    }
    if (!namingURI.isAbsolute())
        throw new RuntimeException("Naming URL '" + namingURL + "' is not absolute.");
    if (!namingURI.getScheme().equals("jnp"))
        throw new RuntimeException(
                "Naming URL '" + namingURL + "' has an invalid protocol - the only valid protocol is 'jnp'.");
}