/** * Save the mapping to file. * * @param directory * Directory to put the file in. * @param filename * Name of the file (without extension). * @throws FileNotFoundException * @throws IOException */ public void save(URI directory, String filename) throws ModelMapException { URI uri = ModelMapUtils.createMappingURI(directory, filename); if (uri == null) { throw new ModelMapException(CANNOT_CREATE_URI); } try { OutputStream out = new ExtensibleURIConverterImpl().createOutputStream(uri); ObjectOutputStream stream = new ObjectOutputStream(out); stream.writeObject(path); stream.writeObject(map); stream.close(); } catch (IOException e) { throw new ModelMapException(e); } }
/** * Does a comparison of the contents of the two URIs, * ignoring comments in the contents. Will compare line-by-line. * * @param uri * @param uri2 * @throws IOException */ private void assertEqualContents(URI uri, URI uri2) throws IOException { URIConverter converter = new ExtensibleURIConverterImpl(); InputStream inputStream1 = converter.createInputStream(uri); BufferedReader reader1 = new BufferedReader(new InputStreamReader(inputStream1)); InputStream inputStream2 = converter.createInputStream(uri2); BufferedReader reader2 = new BufferedReader(new InputStreamReader(inputStream2)); while (true) { String line1 = readUncommentedLine(reader1); String line2 = readUncommentedLine(reader2); assertEquals(line1, line2); if (line1 == null) { break; } } }
private void loadData() throws ProfileLoadingException { if (sourceStream != null) { loadDataFromThisPointInStream(sourceStream); dataLoaded = true; } else { try { ExtensibleURIConverterImpl converter = new ExtensibleURIConverterImpl(); InputStream stream = converter.createInputStream(sourceURI); stream.skip(nCharactersPrecedingData); loadDataFromThisPointInStream(stream); dataLoaded = true; } catch (IOException e) { throw new ProfileLoadingException("Error opening " + sourceURI + " to position " + nCharactersPrecedingData + ": " + e); } } }
public void loadView(String viewPath) { EmfViewsFactory factory = new EmfViewsFactory(); URI viewURI = URI.createURI(viewPath, true); currentView = (EView) factory.createResource(viewURI); try { ExtensibleURIConverterImpl eui = new ExtensibleURIConverterImpl(); InputStream is = eui.createInputStream(viewURI); currentView.load(is, null); linkedElementsViewer.setInput(currentView.getVirtualLinkManager().getVirtualLinks()); ((LinksViewContentProvider) (linkedElementsViewer.getContentProvider())) .setLinkedModels(currentView.getContributingModels()); MessageDialog.openInformation(parent.getShell(), "View selected", "View selected"); } catch (IOException e) { e.printStackTrace(); } }
@Override protected synchronized URIConverter getURIConverter() { if (this.uriConverter == null) { List<ContentHandler> withoutPlatformDelegate = Lists.newArrayList(); for (ContentHandler contentHandler : ContentHandler.Registry.INSTANCE.contentHandlers()) { if (!isTooEager(contentHandler)) withoutPlatformDelegate.add(contentHandler); } this.uriConverter = new ExtensibleURIConverterImpl(URIHandler.DEFAULT_HANDLERS, withoutPlatformDelegate); } return this.uriConverter; }
public URIFragmentMapper(URI directory, String filename) throws ModelMapException { URI mappingURI = ModelMapUtils.createMappingURI(directory, filename); try { InputStream in = new ExtensibleURIConverterImpl().createInputStream(mappingURI); ObjectInputStream stream = new ObjectInputStream(in); Object modelPathObject = stream.readObject(); Object mapObject = stream.readObject(); if (modelPathObject == null || !(modelPathObject instanceof String) || mapObject == null || !(mapObject instanceof Map<?, ?>)) { throw new ModelMapException(INVALID_MAPPING_FILE_CONTENT); } modelPath = (String) modelPathObject; /* * The 'if' above verifies that the map has been successfully * retrieved from the file and it is really a map. However, key and * value types are not verified. It seems unnecessary overhead to * check those as well and to construct a new, type-safe map, * therefore the warning is suppressed. The localMap variable is * only needed to make the scope of the suppression minimal. */ @SuppressWarnings("unchecked") Map<String, String> localMap = (Map<String, String>) mapObject; map = localMap; stream.close(); } catch (IOException | ClassNotFoundException e) { throw new ModelMapException(e); } }
public EnsembleResourceSet() { super(); for (EnsembleResourceFactory factory : factories) { factory.setResourceSet(this); } List<URIHandler> handlers = new ArrayList<URIHandler>(URIHandler.DEFAULT_HANDLERS); handlers.addAll(0, getURIHandlerContributions()); setURIConverter(new ExtensibleURIConverterImpl(handlers, ContentHandler.Registry.INSTANCE.contentHandlers())); }
/** * @return a URIConverter that will normalise 'platform:/resource/' URIs to absolute file paths */ public static URIConverter editURIConverter() { URIConverter uc = new ExtensibleURIConverterImpl(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); URI uri1 = URI.createURI("platform:/resource/"); URI uri2 = URI.createURI("file:/" + root.getLocation().toString() + "/"); uc.getURIMap().put(uri1,uri2); return uc; }
private URIConverter createNewURIConverter() { URIConverter result = new ExtensibleURIConverterImpl(); registrar.registerScheme(result); return result; }
@Override public boolean hasStorageFor(final URI uri) { return new ExtensibleURIConverterImpl().exists(this.getBinaryStorageURI(uri), CollectionLiterals.<Object, Object>emptyMap()); }
@Test public void testConfigureConverter() { URIConverter converter = new ExtensibleURIConverterImpl(); support.configureConverter(converter, this); checkConverter(converter); }
public static boolean exists(URI uri) { return new ExtensibleURIConverterImpl().exists(uri, null); }