LTMTopicMapReader extends AbstractTopicMapReader { @Override protected TopicMapIF read(TopicMapStoreFactoryIF store_factory) throws IOException { TopicMapStoreIF store = store_factory.createStore(); TopicMapIF topicmap = store.getTopicMap(); if ((store instanceof net.ontopia.topicmaps.impl.utils.AbstractTopicMapStore) && store.getBaseAddress() == null) ((net.ontopia.topicmaps.impl.utils.AbstractTopicMapStore)store) .setBaseAddress(getBaseAddress()); try (Reader reader = makeReader((String) null, new LTMEncodingSniffer())) { LTMLexer lexer = new LTMLexer(reader); LTMParser parser = new LTMParser(lexer); parser.setBase(getBaseAddress()); parser.setTopicMap(topicmap); parser.init(); parser.topicmap(); reader.close(); } catch (AntlrWrapException ex) { throw (IOException) ex.getException(); } catch (RecognitionException ex) { throw new IOException("Lexical error at " + getBaseAddress().getAddress() + ":" + ex.line + ":" + ex.column + ": "+ ex.getMessage()); } catch (TokenStreamRecognitionException e) { RecognitionException ex = e.recog; throw new IOException("Lexical error at " + getBaseAddress().getAddress() + ":" + ex.line + ":" + ex.column + ": "+ ex.getMessage()); } catch (TokenStreamIOException ex) { throw ex.io; } catch (TokenStreamException ex) { throw new IOException("Lexical error: " + ex.getMessage()); } catch (java.io.CharConversionException e) { throw new IOException("Problem decoding character encoding." + "Did you declare the right encoding?"); } ClassInstanceUtils.resolveAssociations1(topicmap); return topicmap; } LTMTopicMapReader(URL url);  LTMTopicMapReader(URL url, LocatorIF base_address);  LTMTopicMapReader(Reader reader, LocatorIF base_address);  LTMTopicMapReader(InputStream stream, LocatorIF base_address);  LTMTopicMapReader(File file);   }
@Test public void testReadFromURL() throws IOException { TopicMapIF tm = read("tmreify.ltm"); Assert.assertNotNull(tm); Assert.assertEquals(2, tm.getTopics().size()); }
@Test public void testReadFromFile() throws IOException { File in = TestFileUtils.getTransferredTestInputFile(testdataDirectory, "extra", "tmreify.ltm"); TopicMapIF tm = new LTMTopicMapReader(in).read(); Assert.assertNotNull(tm); Assert.assertEquals(2, tm.getTopics().size()); }
@Test public void testReadFromInputStream() throws IOException { File in = TestFileUtils.getTransferredTestInputFile(testdataDirectory, "extra", "tmreify.ltm"); TopicMapIF tm = new LTMTopicMapReader(new FileInputStream(in), new URILocator(in)).read(); Assert.assertNotNull(tm); Assert.assertEquals(2, tm.getTopics().size()); }
@Test public void testReadFromReader() throws IOException { File in = TestFileUtils.getTransferredTestInputFile(testdataDirectory, "extra", "tmreify.ltm"); TopicMapIF tm = new LTMTopicMapReader(new FileReader(in), new URILocator(in)).read(); Assert.assertNotNull(tm); Assert.assertEquals(2, tm.getTopics().size()); }
@Test public void testReifiedTopicMap() throws IOException { TopicMapIF tm = read("tmreify.ltm"); LocatorIF loc = tm.getStore().getBaseAddress(). resolveAbsolute("#example"); Assert.assertTrue("Topic map does not have correct source locator", tm.getItemIdentifiers().contains(loc)); TopicIF reifier = tm.getTopicBySubjectIdentifier(loc); Assert.assertTrue("No topic reifying topic map", reifier != null); }
@Test public void testMergedInReifiedTopicMap() throws IOException { TopicMapIF tm = read("tmreify-mergemap.ltm"); Assert.assertTrue("Source locator of merged-in TM applied to master TM", tm.getItemIdentifiers().isEmpty()); }
@Test public void testMergedInReifiedTopicMapWithBaseURI() throws IOException { TopicMapIF tm = read("baseuri-reifytm.ltm"); Assert.assertNull("Internal subject indicator ref affected by base URI", tm.getReifier()); }
@Test public void testSourceLocatorForId() throws IOException { TopicMapIF tm = read("tmreify.ltm"); LocatorIF base = tm.getStore().getBaseAddress(); LocatorIF tmtopic = base.resolveAbsolute("#tm-topic"); LocatorIF example = base.resolveAbsolute("#example"); Assert.assertNotNull("Can't find topic with ID 'tm-topic'", tm.getObjectByItemIdentifier(tmtopic)); Assert.assertNotNull("Can't find topic map with ID 'example'", tm.getObjectByItemIdentifier(example)); Assert.assertNotNull("Can't find topic with subject indicator '#example'", tm.getTopicBySubjectIdentifier(example)); }
@Test public void testSubfileErrorReporting() throws IOException { try { TopicMapIF tm = read("mergemap-error.ltm"); Assert.fail("No error found!"); } catch (IOException e) { String msg = e.getMessage(); Assert.assertTrue("error message does not mention file containing error: " + msg, msg.indexOf("mergemap-error-sub.ltm") != -1); } }