use of org.eclipse.emf.ecore.resource.URIConverter in project tdi-studio-se by Talend.
the class ImportItemUtil method computeProperty.
private void computeProperty(ResourcesManager manager, ItemRecord itemRecord) {
InputStream stream = null;
try {
stream = manager.getStream(itemRecord.getPath());
final Resource resource = createResource(itemRecord, itemRecord.getPath(), false);
URIConverter uriConverter = resource.getResourceSet().getURIConverter();
resource.getResourceSet().setURIConverter(new ExtensibleURIConverterImpl() {
/*
* (non-Javadoc)
*
* @see org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl#createInputStream(org.eclipse.
* emf.common.util.URI, java.util.Map)
*/
@Override
public InputStream createInputStream(URI uri, Map<?, ?> options) throws IOException {
InputStream inputStream = null;
EPackage ePackage = resource.getResourceSet().getPackageRegistry().getEPackage(uri.toString());
if (ePackage != null || !"http".equals(uri.scheme())) {
inputStream = super.createInputStream(uri, options);
} else {
inputStream = null;
}
return inputStream;
}
});
EmfHelper.loadResource(resource, stream, null);
resource.getResourceSet().setURIConverter(uriConverter);
itemRecord.setProperty((Property) EcoreUtil.getObjectByType(resource.getContents(), PropertiesPackage.eINSTANCE.getProperty()));
} catch (Exception e) {
// ignore, must be one invalid or unknown item
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
// ignore
}
}
}
}
use of org.eclipse.emf.ecore.resource.URIConverter in project xtext-eclipse by eclipse.
the class HyperlinkHelper method createHyperlinksTo.
/**
* Produces hyperlinks for the given {@code region} that point to the referenced {@code target}.
*/
public void createHyperlinksTo(XtextResource from, Region region, EObject target, IHyperlinkAcceptor acceptor) {
final URIConverter uriConverter = from.getResourceSet().getURIConverter();
final String hyperlinkText = labelProvider.getText(target);
final URI uri = EcoreUtil.getURI(target);
final URI normalized = uri.isPlatformResource() ? uri : uriConverter.normalize(uri);
XtextHyperlink result = hyperlinkProvider.get();
result.setHyperlinkRegion(region);
result.setURI(normalized);
result.setHyperlinkText(hyperlinkText);
acceptor.accept(result);
}
use of org.eclipse.emf.ecore.resource.URIConverter in project xtext-eclipse by eclipse.
the class XtextHyperlinkHelper method createLinksToBase.
protected void createLinksToBase(ITextRegion nameLocation, AbstractRule rule, IHyperlinkAcceptor acceptor) {
Set<AbstractRule> visited = Sets.newHashSet();
Grammar grammar = GrammarUtil.getGrammar(rule);
for (Grammar used : grammar.getUsedGrammars()) {
String ruleName = rule.getName();
AbstractRule overwritten = GrammarUtil.findRuleForName(used, ruleName);
if (overwritten != null && visited.add(overwritten)) {
URIConverter uriConverter = rule.eResource().getResourceSet().getURIConverter();
String hyperlinkText = getLabelProvider().getText(rule) + " - " + GrammarUtil.getGrammar(overwritten).getName();
URI uri = uriConverter.normalize(EcoreUtil.getURI(overwritten));
XtextHyperlink result = getHyperlinkProvider().get();
result.setHyperlinkRegion(toRegion(nameLocation));
result.setURI(uri);
result.setHyperlinkText(hyperlinkText);
result.setTypeLabel("Go To Base");
acceptor.accept(result);
}
}
}
use of org.eclipse.emf.ecore.resource.URIConverter in project xtext-core by eclipse.
the class XtendXtext2EcorePostProcessor method loadXtendFile.
/**
* Expects an Xtend file named <code>MyDsl</code>PostProcessor.ext with an extension with signature
* process(xtext::GeneratedMetamodel) in the same folder as the grammar file.
*
* @param metamodel
* the metamodel to augment
* @return the xtendFile to execute
*/
protected Resource loadXtendFile(GeneratedMetamodel metamodel) {
if (xtendFile == null) {
final String extension = getExtensionName(metamodel);
try {
URI uri = getXtendFileLocation(metamodel);
if (uri != null) {
URIConverter uriConverter = metamodel.eResource().getResourceSet().getURIConverter();
if (uriConverter.exists(uri, null)) {
InputStream in = uriConverter.createInputStream(uri);
try {
XtendResourceParser parser = new XtendResourceParser();
xtendFile = parser.parse(new InputStreamReader(in), extension + '.' + XtendFile.FILE_EXTENSION);
fireXtendFileLoaded();
} finally {
if (in != null)
in.close();
}
}
}
} catch (ClasspathUriResolutionException ignored) {
// no xtend file found
} catch (Exception e) {
logger.error("Could not parse " + extension, e);
}
}
return xtendFile;
}
use of org.eclipse.emf.ecore.resource.URIConverter in project xtext-core by eclipse.
the class FlatResourceSetBasedAllContainersState method getContainedURIs.
@Override
public Collection<URI> getContainedURIs(String containerHandle) {
if (!HANDLE.equals(containerHandle))
return Collections.emptySet();
if (resourceSet instanceof XtextResourceSet) {
ResourceDescriptionsData descriptionsData = findResourceDescriptionsData(resourceSet);
if (descriptionsData != null) {
return descriptionsData.getAllURIs();
}
return newArrayList(((XtextResourceSet) resourceSet).getNormalizationMap().values());
}
List<URI> uris = Lists.newArrayListWithCapacity(resourceSet.getResources().size());
URIConverter uriConverter = resourceSet.getURIConverter();
for (Resource r : resourceSet.getResources()) uris.add(uriConverter.normalize(r.getURI()));
return uris;
}
Aggregations