Example usage for java.net URL toURI

List of usage examples for java.net URL toURI

Introduction

In this page you can find the example usage for java.net URL toURI.

Prototype

public URI toURI() throws URISyntaxException 

Source Link

Document

Returns a java.net.URI equivalent to this URL.

Usage

From source file:org.openxdata.server.service.impl.UserServiceTest.java

@Test
public void testUserImport() throws Exception {
    URL resource = this.getClass().getClassLoader().getResource("org/openxdata/server/service/impl/import.csv");
    String importString = FileUtils.readFileToString(new File(resource.toURI()), "UTF-8");

    resource = this.getClass().getClassLoader()
            .getResource("org/openxdata/server/service/impl/importErrors.csv");
    String expectedErrorString = FileUtils.readFileToString(new File(resource.toURI()), "UTF-8");
    expectedErrorString = expectedErrorString.trim().replaceAll("\\n*\\r*", "");

    String errorString = null;/*w  w w.  j  a  v a  2  s.  c  o  m*/
    try {
        errorString = userService.importUsers(importString);
    } catch (Throwable e) {
        e.printStackTrace();
    }
    System.out.println(errorString);
    errorString = errorString.trim().replaceAll("\\n*\\r*", "");

    Assert.assertEquals(expectedErrorString, errorString);
    User user = userService.findUserByUsername("name1");
    Assert.assertNotNull(user);
    Assert.assertEquals("name1", user.getName());
    Assert.assertEquals("firstName1", user.getFirstName());
    Assert.assertEquals("middleName1", user.getMiddleName());
    Assert.assertEquals("lastName1", user.getLastName());
    Assert.assertEquals("phoneNo1", user.getPhoneNo());
    Assert.assertEquals("email1", user.getEmail());
    Assert.assertTrue(user.getRoles() != null);
    Assert.assertTrue(user.getRoles().size() == 2);
}

From source file:ee.ioc.cs.vsle.ccl.PackageClassLoader.java

private void initNameEnvironment() {
    ArrayList<String> fileNames = new ArrayList<String>();
    for (URL u : getURLs()) {
        try {//from www .j  a v  a  2  s .c o m
            fileNames.add(new File(u.toURI()).getAbsolutePath());
        } catch (URISyntaxException e) {
            logger.error(null, e);
        }
    }

    for (String s : getCompilerClassPath()) {
        if (!fileNames.contains(s)) {
            fileNames.add(s);
        }
    }
    environment = new FileSystem(fileNames.toArray(new String[fileNames.size()]), new String[] {}, null);
}

From source file:it.pronetics.madstore.server.jaxrs.atom.search.impl.DefaultCollectionSearchResourceHandler.java

private void configureFeed(Feed feed, PagingList<Entry> entries) throws Exception {
    URL baseUrl = resourceResolver.resolveResourceUriFor(ResourceName.COLLECTION_SEARCH,
            uriInfo.getBaseUri().toString(), collectionKey);
    URL nextUrl = UriBuilder.fromUri(baseUrl.toURI()).queryParam(HttpConstants.TITLE_PARAMETER, searchTitle)
            .queryParam(HttpConstants.TERMS_PARAMETER, searchTerms)
            .queryParam(HttpConstants.PAGE_PARAMETER, new Integer(pageNumberOfEntries + 1))
            .queryParam(HttpConstants.MAX_PARAMETER, maxNumberOfEntries).build().toURL();
    URL prevUrl = UriBuilder.fromUri(baseUrl.toURI()).queryParam(HttpConstants.TITLE_PARAMETER, searchTitle)
            .queryParam(HttpConstants.TERMS_PARAMETER, searchTerms)
            .queryParam(HttpConstants.PAGE_PARAMETER, new Integer(pageNumberOfEntries - 1))
            .queryParam(HttpConstants.MAX_PARAMETER, maxNumberOfEntries).build().toURL();
    String id = resourceResolver.resolveResourceIdFor(uriInfo.getBaseUri().toString(),
            ResourceName.COLLECTION_SEARCH, collectionKey);

    feed.setId(id);/*from w  w  w .ja  v a 2  s . c o m*/
    feed.setTitle(searchTitle);
    feed.addAuthor(Abdera.getInstance().getFactory().newAuthor().getText());

    for (Entry entry : entries) {
        feed.addEntry(entry);
    }

    if (entries.size() > 0) {
        int currentLastResult = ((pageNumberOfEntries - 1) * maxNumberOfEntries) + entries.size();
        if (currentLastResult < entries.getTotal()) {
            feed.addLink(nextUrl.toString(), "next");
        }
        if (pageNumberOfEntries > 1) {
            feed.addLink(prevUrl.toString(), "previous");
        }
        IntegerElement totalResults = feed.addExtension(OpenSearchConstants.TOTAL_RESULTS);
        totalResults.setValue(entries.getTotal());
        IntegerElement itemsPerPage = feed.addExtension(OpenSearchConstants.ITEMS_PER_PAGE);
        itemsPerPage.setValue(entries.getMax());
        IntegerElement startIndex = feed.addExtension(OpenSearchConstants.START_INDEX);
        startIndex.setValue(entries.getOffset() + 1);
    }
}

From source file:io.cloudslang.lang.compiler.CompileOperationTest.java

@Test
public void testCompileOperationWithMissingNamespace() throws Exception {
    URL resource = getClass().getResource("/corrupted/op_without_namespace.sl");
    exception.expect(RuntimeException.class);
    exception.expectMessage("namespace");
    compiler.compile(SlangSource.fromFile(resource.toURI()), null);
}

From source file:com.spotify.helios.testing.TemporaryJobBuilderTest.java

private void deleteFromClasspath(final String path) throws URISyntaxException {
    final URL url;
    try {/*from  ww  w . j ava2  s.  c  o m*/
        url = Resources.getResource(path);
    } catch (IllegalArgumentException e) {
        // file not found, cool
        return;
    }
    deleteFile(new File(url.toURI()));
}

From source file:org.atomserver.core.dbstore.utils.DBSeeder.java

public int seedWidgets() throws AtomServerException {
    try {// w w w. j  a  v  a2s  .  c  o  m
        Locale en = new Locale("en");

        if (contentStorage instanceof FileBasedContentStorage) {
            FileBasedContentStorage fileStorage = (FileBasedContentStorage) contentStorage;
            File rootDir = fileStorage.getRootDir();
            log.debug("ROOT DIR = " + rootDir);

            // root dir is the actual data dir. In tests this is "target/var"
            File widgetsDir = new File(rootDir, "widgets");

            FileUtils.deleteDirectory(widgetsDir);

            URL widgetsORIGURL = getClass().getClassLoader().getResource(SAMPLE_WIDGETS_DIR);
            if (JarUtils.isJarURL(widgetsORIGURL)) {
                URL widgetsORIGJarURL = JarUtils.getJarFromJarURL(widgetsORIGURL);
                File jarFile = new File(widgetsORIGJarURL.toURI());
                JarUtils.copyJarFolder(jarFile, SAMPLE_WIDGETS_DIR, rootDir);
            } else {
                File widgetsOrigDir = new File(widgetsORIGURL.toURI());
                FileUtils.copyDirectory(widgetsOrigDir, widgetsDir);
            }

        }

        entriesDAO.deleteAllEntries(new BaseServiceDescriptor("widgets"));
        categoriesDAO.deleteAllEntryCategories("widgets");

        entriesDAO.ensureCollectionExists("widgets", "acme");
        insertWidget(new BaseEntryDescriptor("widgets", "acme", "2787", en, 0));
        insertWidget(new BaseEntryDescriptor("widgets", "acme", "2788", en, 0));
        insertWidget(new BaseEntryDescriptor("widgets", "acme", "2797", en, 0));
        insertWidget(new BaseEntryDescriptor("widgets", "acme", "2799", en, 0));
        insertWidget(new BaseEntryDescriptor("widgets", "acme", "4", en, 0));
        insertWidget(new BaseEntryDescriptor("widgets", "acme", "9991", en, 0));
        insertWidget(new BaseEntryDescriptor("widgets", "acme", "9993", en, 0));
        insertWidget(new BaseEntryDescriptor("widgets", "acme", "9995", en, 0));
        insertWidget(new BaseEntryDescriptor("widgets", "acme", "9998", en, 0));
        insertWidget(new BaseEntryDescriptor("widgets", "acme", "9999", en, 0));
    } catch (Exception ee) {
        throw new AtomServerException("Unknown Exception when seeding the DB", ee);
    }
    return 10;
}

From source file:it.geosolutions.geobatch.nrl.ndvi.BaseTest.java

protected File loadFile(String name) {
    try {//w  w  w  . j a  va2  s  . c om
        URL url = this.getClass().getClassLoader().getResource(name);
        if (url == null) {
            throw new IllegalArgumentException("Cant get file '" + name + "'");
        }
        File file = new File(url.toURI());
        return file;
    } catch (URISyntaxException e) {
        LOGGER.error("Can't load file " + name + ": " + e.getMessage(), e);
        return null;
    }
}

From source file:org.jboss.jdf.stacks.client.StacksClient.java

private InputStream retrieveStacksFromRemoteRepository(final URL url) throws Exception {
    if (url.getProtocol().startsWith("http")) {
        HttpGet httpGet = new HttpGet(url.toURI());
        DefaultHttpClient client = new DefaultHttpClient();
        configureProxy(client);/* w w w. j  a  v a 2  s.c om*/
        HttpResponse httpResponse = client.execute(httpGet);
        switch (httpResponse.getStatusLine().getStatusCode()) {
        case 200:
            msg.showDebugMessage("Connected to repository! Getting available Stacks");
            break;

        case 404:
            msg.showErrorMessage("Failed! (Stacks file not found: " + url + ")");
            return null;

        default:
            msg.showErrorMessage(
                    "Failed! (server returned status code: " + httpResponse.getStatusLine().getStatusCode());
            return null;
        }
        return httpResponse.getEntity().getContent();
    } else if (url.getProtocol().startsWith("file")) {
        return new FileInputStream(new File(url.toURI()));
    }
    return null;
}