Search in sources :

Example 1 with StanbolNamespacePrefixService

use of org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService in project stanbol by apache.

the class IndexingConfig method initNamespacePrefixMapper.

/**
     * @param configDir
     * @throws IOException
     */
private void initNamespacePrefixMapper() throws IOException {
    File nsPrefixMappings = getConfigFile("namespaceprefix.mappings");
    if (!nsPrefixMappings.isFile()) {
        FileUtils.writeLines(nsPrefixMappings, "UTF-8", Arrays.asList("# Syntax: '{prefix}\\t{namespace}\\n", "# where:", "#   {prefix} ... [0..9A..Za..z-_]", "#   {namespace} ... must end with '#' or '/' for URLs and ':' for URNs", "# one mapping per line, multiple prefixes for the same namespace allowed"));
    }
    namespacePrefixService = new StanbolNamespacePrefixService(nsPrefixMappings);
}
Also used : StanbolNamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 2 with StanbolNamespacePrefixService

use of org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService in project stanbol by apache.

the class StanbolNamespacePrefixServiceTest method testInitialisationWithoutLocalMappingFIle.

@Test
public void testInitialisationWithoutLocalMappingFIle() throws IOException {
    StanbolNamespacePrefixService service = new StanbolNamespacePrefixService(null);
    service.setPrefix("dummy", "http://www.dummy.org/dummy#");
    Assert.assertEquals("http://www.dummy.org/dummy#", service.getNamespace("dummy"));
    service.importPrefixMappings(new ByteArrayInputStream("dummy2\thttp://www.dummy.org/dummy2#".getBytes(Charset.forName("UTF-8"))));
    Assert.assertEquals("http://www.dummy.org/dummy2#", service.getNamespace("dummy2"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StanbolNamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService) Test(org.junit.Test)

Example 3 with StanbolNamespacePrefixService

use of org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService in project stanbol by apache.

the class DefaultProviderTest method init.

@BeforeClass
public static void init() throws IOException {
    //this test for now does not use predefined mappings
    URL mappingURL = DefaultProviderTest.class.getClassLoader().getResource("testnamespaceprefix.mappings");
    //Assert.assertNotNull(mappingURL);
    File mappingFile;
    if (mappingURL != null) {
        try {
            mappingFile = new File(mappingURL.toURI());
        } catch (URISyntaxException e) {
            mappingFile = new File(mappingURL.getPath());
        }
    //Assert.assertTrue(mappingFile.isFile());
    } else {
        mappingFile = new File("testnamespaceprefix.mappings");
    }
    service = new StanbolNamespacePrefixService(mappingFile);
}
Also used : URISyntaxException(java.net.URISyntaxException) StanbolNamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService) File(java.io.File) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 4 with StanbolNamespacePrefixService

use of org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService in project stanbol by apache.

the class PrefixccProviderTest method testServiceLoader.

@Test
public void testServiceLoader() throws IOException {
    //this test works only if online
    if (!checkServiceAvailable()) {
        //skip test
        return;
    }
    //this test for now does not use predefined mappings
    URL mappingURL = PrefixccProviderTest.class.getClassLoader().getResource("testnamespaceprefix.mappings");
    //Assert.assertNotNull(mappingURL);
    File mappingFile;
    if (mappingURL != null) {
        try {
            mappingFile = new File(mappingURL.toURI());
        } catch (URISyntaxException e) {
            mappingFile = new File(mappingURL.getPath());
        }
    //Assert.assertTrue(mappingFile.isFile());
    } else {
        mappingFile = new File("testnamespaceprefix.mappings");
    }
    NamespacePrefixService service = new StanbolNamespacePrefixService(mappingFile);
    //assertMappings
    Assert.assertEquals(foaf_pf, service.getPrefix(foaf_ns));
    Assert.assertEquals(foaf_ns, service.getNamespace(foaf_pf));
}
Also used : URISyntaxException(java.net.URISyntaxException) StanbolNamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService) StanbolNamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService) NamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 5 with StanbolNamespacePrefixService

use of org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService in project stanbol by apache.

the class StanbolNamespacePrefixServiceTest method init.

@BeforeClass
public static void init() throws IOException {
    URL mappingURL = StanbolNamespacePrefixServiceTest.class.getClassLoader().getResource("testnamespaceprefix.mappings");
    Assert.assertNotNull(mappingURL);
    File mappingFile;
    try {
        mappingFile = new File(mappingURL.toURI());
    } catch (URISyntaxException e) {
        mappingFile = new File(mappingURL.getPath());
    }
    Assert.assertTrue(mappingFile.isFile());
    service = new StanbolNamespacePrefixService(mappingFile);
}
Also used : URISyntaxException(java.net.URISyntaxException) StanbolNamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService) File(java.io.File) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Aggregations

StanbolNamespacePrefixService (org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService)5 File (java.io.File)4 URISyntaxException (java.net.URISyntaxException)3 URL (java.net.URL)3 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 JarFile (java.util.jar.JarFile)1 NamespacePrefixService (org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService)1