Example usage for java.net URL getPath

List of usage examples for java.net URL getPath

Introduction

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

Prototype

public String getPath() 

Source Link

Document

Gets the path part of this URL .

Usage

From source file:org.bpmscript.js.reload.LibraryFileMonitor.java

/**
 * Checks whether the internal libraries have changed. If they do, publishes
 * out to a queue the list of files that need to be reloaded as a result
 *//*ww  w . j a  v a  2 s.c o m*/
@SuppressWarnings("unchecked")
protected void checkLibraries() {
    ArrayList<ILibraryToFile> newLibraryToFiles = new ArrayList<ILibraryToFile>();
    libraryAssociationQueue.drainTo(newLibraryToFiles);
    for (ILibraryToFile libraryToFile : newLibraryToFiles) {
        Set set = libraryToFilesMap.get(libraryToFile.getLibrary());
        if (set == null) {
            set = new HashSet<String>();
            libraryToFilesMap.put(libraryToFile.getLibrary(), set);
        }
        set.add(libraryToFile.getFile());
    }
    Iterator iterator = libraryToFilesMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry entry = (Entry) iterator.next();
        String library = (String) entry.getKey();
        URL resource = this.getClass().getResource(library);
        if ("file".equals(resource.getProtocol())) {
            String path = resource.getPath();
            File file = new File(path);
            Long newLastModified = file.lastModified();
            Long oldLastModified = libraryToLastModifiedMap.get(library);
            if (oldLastModified != null && !(oldLastModified.equals(newLastModified))) {
                // library has changed, we should go through its files and notify listeners
                // that they need to reload. also, we need to check to see if the files are
                // libraries themselves...
                Collection values = (Collection) entry.getValue();
                for (Iterator valueIterator = values.iterator(); valueIterator.hasNext();) {
                    String value = (String) valueIterator.next();
                    if (libraryToFilesMap.containsKey(value)) {
                        // TODO: here we need to recurse
                    } else {
                        // notify listeners that the file has changed. consider notifying
                        // listeners that the library has changed...
                        libraryChangeQueue.add(new LibraryToFile(library, value));
                    }
                }
                libraryToLastModifiedMap.put(library, newLastModified);
            } else if (oldLastModified == null) {
                libraryToLastModifiedMap.put(library, newLastModified);
            }
        }
    }
}

From source file:org.dasein.cloud.azure.platform.AzureSQLDatabaseSupportRequests.java

private String getEncodedUri(String urlString) throws InternalException {
    try {/*from   w w w  .  j a  va2 s.  c o  m*/
        URL url = new URL(urlString);
        return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef()).toString();
    } catch (Exception e) {
        throw new InternalException(e.getMessage());
    }
}

From source file:com.stratio.ingestion.serializer.elasticsearch.ElasticSearchSerializerWithMappingTest.java

@Test(expected = NullPointerException.class)
public void badFileTest() throws IOException {

    URL resourceUrl = getClass().getResource(MAPPING_PATH);
    Context context = new Context();
    context.put("mappingFile2", resourceUrl.getPath());
    serializer = new ElasticSearchSerializerWithMapping();
    serializer.configure(context);//  w w  w  . j av a2s. c o m
}

From source file:com.stratio.ingestion.serializer.elasticsearch.ElasticSearchSerializerWithMappingTest.java

@Test
public void goodFileTest() throws IOException {
    URL resourceUrl = getClass().getResource(MAPPING_PATH);
    Context context = new Context();
    context.put("mappingFile", resourceUrl.getPath());
    serializer = new ElasticSearchSerializerWithMapping();
    serializer.configure(context);//ww  w . j  ava  2s. c o  m

    Assert.assertNotNull(serializer);
}

From source file:org.balloon_project.overflight.service.EndpointService.java

public Endpoint findOrigin(String url) {
    // TODO reimplement
    Endpoint result = null;//from w w  w.  ja v a2  s  .  c  om

    try {
        URL concept = new URL(url);
        String urlString = concept.getHost() + concept.getPath();

        // to find a suitable endpoint by the namespace, strip a "slash-fragment" e.g. http://dbpedia.org/resource/Indonesia --> http://dbpedia.org/resource
        // some endpoints have the same url prefix e.g. http://www4.wiwiss.fu-berlin.de/factbook/resource/ and http://www4.wiwiss.fu-berlin.de/dailymed/resource/
        // endpoint namespaces can even be more abstract like http://enipedia.tudelft.nl and a concept is http://enipedia.tudelft.nl/wiki/Indonesia.
        // Hence, the stripping should be looped.
        // difficult e.g. http://openei.org/resources/Indonesia  -->  http://en.openei.org/

        do {
            int lastIndexofSlash = urlString.lastIndexOf("/");
            if (lastIndexofSlash != -1) {
                urlString = urlString.substring(0, lastIndexofSlash);
                // TODO find endpoint with suitable namespace --> build offline map of namespace to endpoint id
                // TODO cache endpoint id if namepsace was found
                //Query query = Query.query(Criteria.where("ns").regex(concept.getProtocol() + PROTOCOL_DIVIDER + urlString +".*","i"));
                //result = mongo.findOne(query, Endpoint.class, COLLECTION);
            }
        } while (result == null && urlString.lastIndexOf("/") != -1);

        // if no result was found, maybe the subdomain is wrong
        if (result == null) {
            urlString = concept.getHost() + concept.getPath();
            do {
                int lastIndexofSlash = urlString.lastIndexOf("/");
                if (lastIndexofSlash != -1) {
                    urlString = urlString.substring(0, lastIndexofSlash);
                    // TODO implement
                    // Query query = Query.query(Criteria.where("ns").regex(concept.getProtocol() + PROTOCOL_DIVIDER + ".*" + urlString +".*","i"));
                    // result = mongo.findOne(query, Endpoint.class, COLLECTION);
                }
            } while (result == null && urlString.lastIndexOf("/") != -1);
        }

        // TODO extend to query datahub.io
    } catch (MalformedURLException e) {
        return null;
    }

    if (result == null) {
        logger.debug("No endpoint found for URL=" + url);
    } else {
        logger.debug("Endpoints found for URL=" + url + " --> " + result.getEndpointID());
    }
    return result;
}

From source file:com.datatorrent.demos.dimensions.generic.EnrichmentOperatorTest.java

@Test
public void testEnrichmentOperatorWithUpdateKeys() throws IOException, InterruptedException {
    URL origUrl = getClass().getResource("/productmapping.txt");

    URL fileUrl = new URL(getClass().getResource("/").toString() + "productmapping1.txt");
    FileUtils.deleteQuietly(new File(fileUrl.getPath()));
    FileUtils.copyFile(new File(origUrl.getPath()), new File(fileUrl.getPath()));

    EnrichmentOperator oper = new EnrichmentOperator();
    oper.setFilePath(fileUrl.toString());
    oper.setLookupKey("productId");
    oper.setUpdateKeys("subCategory");
    oper.setScanInterval(10);/*  ww  w .ja v  a 2s . c  om*/

    oper.setup(null);
    /* File contains 6 entries, but operator one entry is duplicate,
     * so cache should contains only 5 entries after scanning input file.
     */
    Assert.assertEquals("Number of mappings ", 7, oper.cache.size());

    CollectorTestSink<Map<String, Object>> sink = new CollectorTestSink<Map<String, Object>>();
    @SuppressWarnings({ "unchecked", "rawtypes" })
    CollectorTestSink<Object> tmp = (CollectorTestSink) sink;
    oper.outputPort.setSink(tmp);

    oper.beginWindow(0);
    Map<String, Object> tuple = Maps.newHashMap();
    tuple.put("productId", 7);
    tuple.put("channelId", 4);
    tuple.put("amount", 10.0);

    Kryo kryo = new Kryo();
    oper.inputPort.process(kryo.copy(tuple));

    oper.endWindow();

    /* Number of tuple, emitted */
    Assert.assertEquals("Number of tuple emitted ", 1, sink.collectedTuples.size());
    Map<String, Object> emitted = sink.collectedTuples.iterator().next();

    /* The fields present in original event is kept as it is */
    Assert.assertEquals("Number of fields in emitted tuple", 4, emitted.size());
    Assert.assertEquals("value of productId is 3", tuple.get("productId"), emitted.get("productId"));
    Assert.assertEquals("value of channelId is 4", tuple.get("channelId"), emitted.get("channelId"));
    Assert.assertEquals("value of amount is 10.0", tuple.get("amount"), emitted.get("amount"));

    /* Check if productCategory is added to the event */
    Assert.assertEquals("productCategory is not part of tuple", false, emitted.containsKey("productCategory"));
    Assert.assertEquals("subCategory is part of tuple", true, emitted.containsKey("subCategory"));
    Assert.assertEquals("value of product category is 1", 4, emitted.get("subCategory"));
}

From source file:fr.gael.dhus.server.http.webapp.owc.controller.OwcMenuController.java

@RequestMapping(value = "/settings/menu", method = RequestMethod.GET)
public ResponseEntity<?> getMenu() throws JSONException {
    URL configFile = ClassLoader.getSystemResource("../etc/conf/menu.json");
    if (configFile != null) {
        logger.debug("Loading configuration file " + configFile.getPath());

        try {//from w  w w  . ja  va 2s  .  c o  m

            File file = new File(configFile.getPath());
            FileReader fileReader = new FileReader(file);
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            String line = "";
            StringBuffer sb = new StringBuffer();
            while ((line = bufferedReader.readLine()) != null) {
                sb.append(line);
            }
            bufferedReader.close();
            JSONObject menu = new JSONObject(sb.toString());
            return new ResponseEntity<>(menu.toString(), HttpStatus.OK);
        } catch (IOException e) {

            logger.error(" Cannot load menu configration file content");
            e.printStackTrace();
            return new ResponseEntity<>("{\"code\":\"unauthorized\"}", HttpStatus.UNAUTHORIZED);
        }
    } else {
        logger.error(" Cannot get menu configration file ");
        return new ResponseEntity<>("{\"code\":\"unauthorized\"}", HttpStatus.UNAUTHORIZED);
    }

}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.rbmData.RbmLoadAnnotationListener.java

@Override
protected String getJobPath() throws Exception {
    URL jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_rbm_annotation.kjb");
    jobUrl = FileLocator.toFileURL(jobUrl);
    String jobPath = jobUrl.getPath();

    jobUrl = new URL(
            "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_rbm_annotation_to_de_gpl_info.ktr");
    jobUrl = FileLocator.toFileURL(jobUrl);
    jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_rbm_annotation_to_lt.ktr");
    jobUrl = FileLocator.toFileURL(jobUrl);
    jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/run_I2B2_LOAD_RBM_ANNOT_DEAPP.ktr");
    jobUrl = FileLocator.toFileURL(jobUrl);
    jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/cz_end_audit.ktr");
    jobUrl = FileLocator.toFileURL(jobUrl);
    jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/cz_start_audit.ktr");
    jobUrl = FileLocator.toFileURL(jobUrl);
    jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/cz_write_audit.ktr");
    jobUrl = FileLocator.toFileURL(jobUrl);

    return jobPath;
}

From source file:com.opensymphony.xwork2.util.finder.ResourceFinder.java

private static void readDirectoryEntries(URL location, Map<String, URL> resources)
        throws MalformedURLException {
    File dir = new File(URLDecoder.decode(location.getPath()));
    if (dir.isDirectory()) {
        File[] files = dir.listFiles();
        for (File file : files) {
            if (!file.isDirectory()) {
                String name = file.getName();
                URL url = file.toURL();
                resources.put(name, url);
            }/*from   w w w . jav a 2s .  c  o m*/
        }
    }
}

From source file:com.datatorrent.demos.dimensions.generic.EnrichmentOperatorTest.java

@Test
public void testEnrichmentOperator() throws IOException, InterruptedException {
    URL origUrl = getClass().getResource("/productmapping.txt");

    URL fileUrl = new URL(getClass().getResource("/").toString() + "productmapping1.txt");
    FileUtils.deleteQuietly(new File(fileUrl.getPath()));
    FileUtils.copyFile(new File(origUrl.getPath()), new File(fileUrl.getPath()));

    EnrichmentOperator oper = new EnrichmentOperator();
    oper.setFilePath(fileUrl.toString());
    oper.setLookupKey("productId");
    oper.setScanInterval(10);// ww  w  .  ja v  a  2 s .com

    oper.setup(null);
    /* File contains 6 entries, but operator one entry is duplicate,
     * so cache should contains only 5 entries after scanning input file.
     */
    Assert.assertEquals("Number of mappings ", 7, oper.cache.size());

    CollectorTestSink<Map<String, Object>> sink = new CollectorTestSink<Map<String, Object>>();
    @SuppressWarnings({ "unchecked", "rawtypes" })
    CollectorTestSink<Object> tmp = (CollectorTestSink) sink;
    oper.outputPort.setSink(tmp);

    oper.beginWindow(0);
    Map<String, Object> tuple = Maps.newHashMap();
    tuple.put("productId", 3);
    tuple.put("channelId", 4);
    tuple.put("amount", 10.0);

    Kryo kryo = new Kryo();
    oper.inputPort.process(kryo.copy(tuple));

    oper.endWindow();

    /* Number of tuple, emitted */
    Assert.assertEquals("Number of tuple emitted ", 1, sink.collectedTuples.size());
    Map<String, Object> emitted = sink.collectedTuples.iterator().next();

    /* The fields present in original event is kept as it is */
    Assert.assertEquals("Number of fields in emitted tuple", 4, emitted.size());
    Assert.assertEquals("value of productId is 3", tuple.get("productId"), emitted.get("productId"));
    Assert.assertEquals("value of channelId is 4", tuple.get("channelId"), emitted.get("channelId"));
    Assert.assertEquals("value of amount is 10.0", tuple.get("amount"), emitted.get("amount"));

    /* Check if productCategory is added to the event */
    Assert.assertEquals("productCategory is part of tuple", true, emitted.containsKey("productCategory"));
    Assert.assertEquals("value of product category is 1", 6, emitted.get("productCategory"));

    /* Check if modified file is reloaded in beginWindow */
    FileUtils.write(new File(fileUrl.getPath()), "{ \"productId\": 10, \"productCategory\": 5 }");
    Thread.sleep(100);
    oper.beginWindow(2);
    oper.endWindow();
    Assert.assertEquals("Number of mappings ", 1, oper.cache.size());
}