/** * Constructor that accepts a File object as argument (XTM file). */ public SanityChecker(File file) throws MalformedURLException, IOException { this(ImportExportUtils.getReader(file).read()); }
/** * Constructor that accepts a url as argument (XTM file). */ public SanityChecker(String url) throws MalformedURLException, IOException { this(ImportExportUtils.getReader(url).read()); }
@Override public Object construct() { TopicMapIF result = null; try { result = r.read(); } catch (IOException e) { dialog.setVisible(false); ErrorDialog.showError(vpanel, e.getMessage()); } return result; }
protected static TopicMapIF merge(String stm1, String stm2) throws ConstraintViolationException, java.io.IOException { TopicMapIF source1 = ImportExportUtils.getReader(stm1).read(); TopicMapIF source2 = ImportExportUtils.getReader(stm2).read(); MergeUtils.mergeInto(source1, source2); return source1; }
/** * Creates a schema from the given topic map which is read in fist. * * @param input filename of the input topic map. */ public OSLSchema createSchema(String input) throws IOException { TopicMapIF tm = ImportExportUtils.getReader(input).read(); return createSchema(tm); }
protected static TopicMapIF merge(TopicMapIF target, String source) throws ConstraintViolationException, java.io.IOException { TopicMapIF sourcetm = ImportExportUtils.getReader(source).read(); MergeUtils.mergeInto(target, sourcetm); return target; }
private static void validate(String tmfile, String schemafile) throws java.io.IOException, SchemaViolationException, SchemaSyntaxException { log.info("Reading schema"); OSLSchemaReader sreader = new OSLSchemaReader(new File(schemafile)); SchemaIF schema = sreader.read(); SchemaValidatorIF validator = schema.getValidator(); validator.setValidationHandler(new TextValidationHandler()); log.info("Reading topic map"); TopicMapReaderIF tmreader = ImportExportUtils.getReader(tmfile); TopicMapIF tm = tmreader.read(); log.info("Validating topic map"); validator.validate(tm); log.info("Done validating"); }
private static void convert(String infile, String outfile, OptionsListener options) throws java.io.IOException, java.net.MalformedURLException { TopicMapReaderIF reader = ImportExportUtils.getReader(infile); if (options.rdfmap != null) { Map<String, Object> config = new HashMap<String, Object>(); config.put("mappingFile", new File(options.rdfmap)); config.put("mappingSyntax", getSyntax(options.rdfmap)); reader.setAdditionalProperties(config); } if (reader instanceof XTMTopicMapReader) ((XTMTopicMapReader) reader).setValidation(options.validate); TopicMapIF tm = reader.read(); DuplicateSuppressionUtils.removeDuplicates(tm); if (options.xtm) { if (options.encoding != null) new XTMTopicMapWriter(new File(outfile), options.encoding).write(tm); else new XTMTopicMapWriter(new File(outfile)).write(tm); } else ImportExportUtils.getWriter(new File(outfile), options.encoding).write(tm); }
@Override public <T> T toObject(Representation source, Class<T> target, Resource resource) throws IOException { LocatorIF base_address = null; // todo from header/params try { TopicMapReaderIF reader = getFragmentReader(source.getStream(), base_address); TopicMapIF fragment = reader.read(); return objectFromFragment(fragment, target, resource); } catch (OntopiaRuntimeException ore) { throw OntopiaRestErrors.COULD_NOT_READ_FRAGMENT.build(ore); } }
public static void main(String[] args) throws Exception { String tmuri = args[0]; TopicMapIF tm = ImportExportUtils.getReader(tmuri).read(); TopicMapStoreIF store = tm.getStore(); try { RandomTopicMapGenerator rg = new RandomTopicMapGenerator(tm); rg.topics = Integer.parseInt(args[1]); rg.populateTopicMap(); if (args.length > 2) ImportExportUtils.getWriter(new File(args[2])).write(tm); store.commit(); } finally { store.close(); } }
private TopicMapIF load(String filename) throws IOException { return ImportExportUtils.getReader(TestFileUtils.getTestInputFile(testdataDirectory, "bk", filename)).read(); }
protected static void canonicalize(String stm, String ctm, boolean readall) throws IOException, MalformedURLException { TopicMapIF source; try { if (readall) { TopicMapReaderIF importer = ImportExportUtils.getReader(stm); source = new InMemoryTopicMapStore().getTopicMap(); importer.importInto(source); } else { TopicMapReaderIF reader = ImportExportUtils.getReader(stm); source = reader.read(); } DuplicateSuppressionUtils.removeDuplicates(source); } catch (InvalidTopicMapException e) { System.err.println("ERROR reading file: " + e.getMessage()); return; } new CanonicalXTMWriter(new File(ctm)).write(source); }
@Override protected void setUp() { if (tm == null) { try { TopicMapReaderIF reader = new XTMTopicMapReader(TestFileUtils.getTestInputURL(testdataDirectory, "package-test.xtm")); tm = reader.read(); base = tm.getStore().getBaseAddress(); } catch (java.io.IOException e) { throw new RuntimeException("IMPOSSIBLE ERROR! " + e.getMessage()); } } }
public void testMergeSelf() throws IOException { TopicMapIF tm1 = ImportExportUtils.getReader(TestFileUtils.getTestInputFile("query", "jill.xtm")).read(); TopicMapIF tm2 = ImportExportUtils.getReader(TestFileUtils.getTestInputFile("query", "jill.xtm")).read(); MergeUtils.mergeInto(tm1, tm2); assertEquals(tm1.getTopics().size(), tm2.getTopics().size()); assertEquals(tm1.getAssociations().size(), tm2.getAssociations().size()); }
private void canonicalize(String infile1, String infile2, String outfile) throws IOException { TopicMapIF target = ImportExportUtils.getReader(infile1).read(); TopicMapIF source = ImportExportUtils.getReader(infile2).read(); LocatorIF base = source.getStore().getBaseAddress(); TopicIF sourcet = (TopicIF) source.getObjectByItemIdentifier(base.resolveAbsolute("#source")); TopicMapSynchronizer.update(target, sourcet); new CanonicalXTMWriter(new File(outfile)).write(target); } }
protected void readFile(String fileName) { try { TopicMapReaderIF reader = ImportExportUtils.getReader(TestFileUtils.getTestInputFile(testdataDirectory, fileName)); tm = reader.read(); baseAddress = tm.getStore().getBaseAddress(); } catch(IOException ex) { assertTrue("Topic map read failed!\n" + ex.getMessage(), false); } }
protected void load(String dir, String filename) throws IOException { filename = TestFileUtils.getTestInputFile(dir, filename); topicmap = ImportExportUtils.getReader(filename).read(); base = topicmap.getStore().getBaseAddress(); }
public void testHugeReifiedOccurrenceMerge() throws Exception { TopicMapIF source = ImportExportUtils.getReader(TestFileUtils.getTestInputFile("various", "huge-occurrence.ltm")).read(); MergeUtils.mergeInto(topicmap, source); topicmap.getStore().commit(); }
public void testMergeDuplicateAssociations() throws IOException { TopicMapIF tm = ImportExportUtils.getReader(TestFileUtils.getTestInputFile("various", "merge-duplicate-assoc.ltm")).read(); LocatorIF base = tm.getStore().getBaseAddress(); TopicIF puccini1 = (TopicIF) tm.getObjectByItemIdentifier(base.resolveAbsolute("#puccini1")); TopicIF puccini2 = (TopicIF) tm.getObjectByItemIdentifier(base.resolveAbsolute("#puccini2")); MergeUtils.mergeInto(puccini1, puccini2); // the new puccini should have only a single place of birth; in // fact, only a single association assertTrue("Merge did not remove duplicate associations", puccini1.getRoles().size() == 1); }
@Test public void testFile() throws IOException { TestFileUtils.verifyDirectory(base, "out"); // Path to the input topic map document. String in = TestFileUtils.getTestInputFile(testdataDirectory, "in", filename); // Path to the baseline String baseline = TestFileUtils.getTestInputFile(testdataDirectory, "baseline", filename + ".cxtm"); // Path to the canonicalized output. File out = new File(base + File.separator + "out" + File.separator + filename + ".cxtm"); // Import topic map from arbitrary source. TopicMapIF sourceMap = ImportExportUtils.getReader(in).read(); // Canonicalize the source topic map. new CanonicalXTMWriter(out).write(sourceMap); // compare results Assert.assertTrue("The test file " + out + " is different from the baseline.", TestFileUtils.compareFileToResource(out, baseline)); } }