/** * Fetches the contents of the URI into a byte[]. * * @param uri * @param options * @param response * @return The resource data * @throws IOException */ private static byte[] readUriResource(URI uri, ResourceSet resourceSet, Map<?, ?> response) throws IOException { Map<Object, Object> options = resourceSet.getLoadOptions(); URIConverter uriConverter = getUriConverter(resourceSet); Map<Object, Object> loadMap = new HashMap<>(options); loadMap.put(URIConverter.OPTION_RESPONSE, response); ByteArrayOutputStream out = new ByteArrayOutputStream(); try (InputStream inputStream = uriConverter.createInputStream(uri, loadMap)) { IOUtils.copy(inputStream, out); } return out.toByteArray(); }
Map<Object, Object> options = resourceSet.getLoadOptions(); Map<?, ?> response = getOrCreateResponseFrom(options); byte[] resourceData = readUriResource(uri, resourceSet, response);
protected String getCacheKey(String base, ResourceSet context) { Map<Object, Object> loadOptions = context.getLoadOptions(); if (loadOptions.containsKey(ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE)) { return base + "@" + ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE; } return base + "@DEFAULT_SCOPE"; }
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { // Use the animated flavour as we don't know beforehand how many ticks we need. // The task name will be displayed by the code in XSDResourceImpl. monitor.beginTask("", IProgressMonitor.UNKNOWN); //$NON-NLS-1$ Map loadOptions = resourceSet.getLoadOptions(); loadOptions.put(XSDResourceImpl.XSD_PROGRESS_MONITOR, monitor); schema.setElement(element); loadOptions.remove(XSDResourceImpl.XSD_PROGRESS_MONITOR); } };
@Override protected ResourceSet initialValue() { ResourceSet resourceSet = getResourceSetProvider().get(project); resourceSet.getLoadOptions().putAll(parent.getLoadOptions()); resourceSet.setURIConverter(parent.getURIConverter()); return resourceSet; } };
protected void configure(ResourceSet resourceSet) { resourceSet.getLoadOptions().put(org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider.LIVE_SCOPE, Boolean.TRUE); if (resourceSet instanceof ResourceSetImpl) { ((ResourceSetImpl) resourceSet).setURIResourceMap(Maps.<URI, Resource>newHashMap()); } externalContentSupport.configureResourceSet(resourceSet, dirtyStateManager.getActualContentProvider()); } }
public static void read(Resource resource, InputStream is) throws IOException { Map<Object, Object> loadOptions; if (resource.getResourceSet() != null) { loadOptions = resource.getResourceSet().getLoadOptions(); } else { loadOptions = new HashMap<Object, Object>(); } loadOptions.put(XMLResource.OPTION_URI_HANDLER, new URIHandlerImpl.PlatformSchemeAware()); loadOptions.put(XMIResource.OPTION_ENCODING, "UTF-8"); loadOptions.put(XMIResource.OPTION_EXTENDED_META_DATA, modelMetaData); loadOptions.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.FALSE); if (is != null) { resource.load(is, loadOptions); } else { resource.load(loadOptions); } }
@Before public void setUp() throws Exception { resourceSet = new XtextResourceSet(); resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap(false)); resourceSet.getLoadOptions().put(XMLResource.OPTION_URI_HANDLER, this); }
private Resource load(Resource resource, boolean loadOnDemand) { if (!loadOnDemand) try { resource.load(resource.getResourceSet().getLoadOptions()); } catch (IOException e) { throw new WrappedException(e); } return resource; }
public static final XSDSchema parse( String location, List locators, List resolvers ) throws IOException { //check for case of file url, make sure it is an absolute reference if (new File(location).exists()) { location = new File( location ).getCanonicalFile().toURI().toString(); //location = new File(location).getCanonicalPath(); } URI uri = URI.createURI(location); final ResourceSet resourceSet = new ResourceSetImpl(); //add the specialized schema location resolvers if ((resolvers != null) && !resolvers.isEmpty()) { AdapterFactory adapterFactory = new SchemaLocationResolverAdapterFactory(resolvers); resourceSet.getAdapterFactories().add(adapterFactory); } //add the specialized schema locators as adapters if ((locators != null) && !locators.isEmpty()) { AdapterFactory adapterFactory = new SchemaLocatorAdapterFactory(locators); resourceSet.getAdapterFactories().add(adapterFactory); } XSDResourceImpl xsdMainResource = (XSDResourceImpl) resourceSet .createResource(URI.createURI(".xsd")); // LOGGER.info("About to parse xsd schema: " + uri); xsdMainResource.setURI(uri); xsdMainResource.load(resourceSet.getLoadOptions()); return xsdMainResource.getSchema(); }
public static final XSDSchema parse(String location, List locators, List resolvers) throws IOException { //check for case of file url, make sure it is an absolute reference if (new File(location).exists()) { location = new File(location).getCanonicalFile().toURI().toString(); //location = new File(location).getCanonicalPath(); } URI uri = URI.createURI(location); final ResourceSet resourceSet = new ResourceSetImpl(); //add the specialized schema location resolvers if ((resolvers != null) && !resolvers.isEmpty()) { AdapterFactory adapterFactory = new SchemaLocationResolverAdapterFactory(resolvers); resourceSet.getAdapterFactories().add(adapterFactory); } //add the specialized schema locators as adapters if ((locators != null) && !locators.isEmpty()) { AdapterFactory adapterFactory = new SchemaLocatorAdapterFactory(locators); resourceSet.getAdapterFactories().add(adapterFactory); } XSDResourceImpl xsdMainResource = (XSDResourceImpl) resourceSet.createResource(URI.createURI( ".xsd")); xsdMainResource.setURI(uri); xsdMainResource.load(resourceSet.getLoadOptions()); return xsdMainResource.getSchema(); }
protected ResourceSet createResourceSet() { ResourceSet result = new ResourceSetImpl(); result.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_LOCATION, Boolean.TRUE); Map<String, Object> extensionToFactoryMap = result.getResourceFactoryRegistry().getExtensionToFactoryMap(); extensionToFactoryMap.put("wsdl", new XSDResourceFactoryImpl()); extensionToFactoryMap.put("xsd", new XSDResourceFactoryImpl()); if (ecoreResourceFactoryImplClass != null) { try { extensionToFactoryMap.put("ecore", ecoreResourceFactoryImplClass.newInstance()); } catch (Exception exception) { XSDPlugin.INSTANCE.log(exception); } } return result; }
public static final XSDSchema parse(String location, List locators, List resolvers) throws IOException { //check for case of file url, make sure it is an absolute reference if (new File(location).exists()) { location = new File(location).getCanonicalFile().toURI().toString(); //location = new File(location).getCanonicalPath(); } URI uri = URI.createURI(location); final ResourceSet resourceSet = new ResourceSetImpl(); //add the specialized schema location resolvers if ((resolvers != null) && !resolvers.isEmpty()) { AdapterFactory adapterFactory = new SchemaLocationResolverAdapterFactory(resolvers); resourceSet.getAdapterFactories().add(adapterFactory); } //add the specialized schema locators as adapters if ((locators != null) && !locators.isEmpty()) { AdapterFactory adapterFactory = new SchemaLocatorAdapterFactory(locators); resourceSet.getAdapterFactories().add(adapterFactory); } XSDResourceImpl xsdMainResource = (XSDResourceImpl) resourceSet.createResource(URI.createURI( ".xsd")); xsdMainResource.setURI(uri); xsdMainResource.load(resourceSet.getLoadOptions()); return xsdMainResource.getSchema(); }
protected ResourceSet createResourceSet() { ResourceSet result = new ResourceSetImpl(); result.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_LOCATION, Boolean.TRUE); Map<String, Object> extensionToFactoryMap = result.getResourceFactoryRegistry().getExtensionToFactoryMap(); extensionToFactoryMap.put("wsdl", new XSDResourceFactoryImpl()); extensionToFactoryMap.put("xsd", new XSDResourceFactoryImpl()); if (ecoreResourceFactoryImplClass != null) { try { extensionToFactoryMap.put("ecore", ecoreResourceFactoryImplClass.newInstance()); } catch (Exception exception) { XSDPlugin.INSTANCE.log(exception); } } return result; }
public void editModelChanged(EditModelEvent anEvent) { switch (anEvent.getEventCode()) { case EditModelEvent.UNLOADED_RESOURCE : if (anEvent.getChangedResources().contains(resource) && ! resource.isLoaded()) { try { resource.load(resource.getResourceSet().getLoadOptions()); } catch (IOException ioe) { JptCorePlugin.log(ioe); } } break; case EditModelEvent.REMOVED_RESOURCE : if (anEvent.getChangedResources().contains(resource)) { anEvent.getEditModel().removeListener(this); } break; // case EditModelEvent.SAVE : // case EditModelEvent.PRE_DISPOSE : } } // commenting out for now - this *was* a workaround for 202190, but with ArtifactEdit
public void editModelChanged(EditModelEvent anEvent) { switch (anEvent.getEventCode()) { case EditModelEvent.UNLOADED_RESOURCE : if (anEvent.getChangedResources().contains(resource) && ! resource.isLoaded()) { try { resource.load(resource.getResourceSet().getLoadOptions()); } catch (IOException ioe) { JptCorePlugin.log(ioe); } } break; case EditModelEvent.REMOVED_RESOURCE : if (anEvent.getChangedResources().contains(resource)) { anEvent.getEditModel().removeListener(this); } break; // case EditModelEvent.SAVE : // case EditModelEvent.PRE_DISPOSE : } } // commenting out for now - this *was* a workaround for 202190, but with ArtifactEdit
@Override public IFeatureScopeTracker track(EObject root) { Resource resource = root.eResource(); if (resource != null) { ResourceSet resourceSet = resource.getResourceSet(); if (resourceSet != null) { Map<Object, Object> loadOptions = resourceSet.getLoadOptions(); if (isBuilderScope(loadOptions)) { return IFeatureScopeTracker.NULL; } if (!isLiveScope(loadOptions) && !isPrimaryResource(resourceSet, resource)) { return IFeatureScopeTracker.NULL; } } } return new FeatureScopeTracker(); }
/** * @return an orm resource for the given file */ public OrmResource getOrmResource(IFile file) { // This *seems* to do the same basic thing as below, but circumvents the // URI munging that ArtifactEditModel does (see bug 209093) try { OrmResource resource = (OrmResource) getArtifactEditModel().createResource(URI.createPlatformResourceURI(file.getFullPath().toString())); if (! resource.isLoaded()) { resource.load(getArtifactEditModel().getResourceSet().getLoadOptions()); } return resource; } catch (ClassCastException cce) { return null; } catch (IOException ioe) { JptCorePlugin.log(ioe); return null; } }
/** * @return a persistence resource for the given file */ public PersistenceResource getPersistenceResource(IFile file) { // This *seems* to do the same basic thing as below, but circumvents the // URI munging that ArtifactEditModel does (see bug 209093) try { PersistenceResource resource = (PersistenceResource) getArtifactEditModel().createResource(URI.createPlatformResourceURI(file.getFullPath().toString())); if (! resource.isLoaded()) { resource.load(getArtifactEditModel().getResourceSet().getLoadOptions()); } return resource; } catch (ClassCastException cce) { return null; } catch (IOException ioe) { JptCorePlugin.log(ioe); return null; } }
resourceSet.getLoadOptions().put(ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE, Boolean.TRUE); if (resourceSet instanceof ResourceSetImpl) { ((ResourceSetImpl) resourceSet).setURIResourceMap(Maps.<URI, Resource> newHashMap());