org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl Java Examples

The following examples show how to use org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: M2DocNewProjectWizard.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates the sample template.
 * 
 * @param templateName
 *            the template name
 * @param variableName
 *            the variable name
 * @param variableValue
 *            the variable value
 * @param monitor
 *            the {@link IProgressMonitor}
 * @param project
 *            the {@link IllegalPropertySetDataException}
 * @return
 * @throws IOException
 *             if the template file can't be saved
 * @throws CoreException
 *             if the template file can't be saved
 * @throws InvalidFormatException
 *             if the sample template can't be read
 * @return the template {@link URI}
 */
private URI createSampleTemplate(final String templateName, final String variableName, final EObject variableValue,
        IProgressMonitor monitor, final IProject project)
        throws IOException, CoreException, InvalidFormatException {
    final URI res;

    final URIConverter uriConverter = new ExtensibleURIConverterImpl();
    final MemoryURIHandler handler = new MemoryURIHandler();
    uriConverter.getURIHandlers().add(0, handler);
    try (XWPFDocument sampleTemplate = M2DocUtils.createSampleTemplate(variableName, variableValue.eClass());) {
        final URI memoryURI = URI
                .createURI(MemoryURIHandler.PROTOCOL + "://resources/temp." + M2DocUtils.DOCX_EXTENSION_FILE);
        POIServices.getInstance().saveFile(uriConverter, sampleTemplate, memoryURI);

        try (InputStream source = uriConverter.createInputStream(memoryURI)) {
            final IFile templateFile = project.getFile(templateName);
            templateFile.create(source, true, monitor);
            res = URI.createPlatformResourceURI(templateFile.getFullPath().toString(), true);
        }
    }

    return res;
}
 
Example #2
Source File: ModelMapCollector.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example #3
Source File: PersistableResourceDescriptionsTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	fileSystem = Maps.newHashMap();
	builderState = builderInjector.getInstance(ClusteringBuilderState.class);
	uriConverter = new ExtensibleURIConverterImpl() {
		@Override
		public InputStream createInputStream(org.eclipse.emf.common.util.URI uri, Map<?, ?> options)
				throws IOException {
			return new StringInputStream(fileSystem.get(uri.toString()));
		}
	};

}
 
Example #4
Source File: ResourceServiceProviderRegistryImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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;
}
 
Example #5
Source File: URIFragmentMapper.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
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);
	}
}
 
Example #6
Source File: ResourceStorageFacade.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean hasStorageFor(URI uri) {
	return new ExtensibleURIConverterImpl().exists(getBinaryStorageURI(uri), Collections.emptyMap());
}
 
Example #7
Source File: ExternalContentSupportTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testConfigureConverter() {
	URIConverter converter = new ExtensibleURIConverterImpl();
	support.configureConverter(converter, this);
	checkConverter(converter);
}