Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 303688

Summary: [ImageSupport] GMF fails export to image of any file:// or relative URL
Product: [Modeling] GMF-Runtime Reporter: Anthony Hunter <ahunter.eclipse>
Component: GeneralAssignee: Anthony Hunter <ahunter.eclipse>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: cbmcgee
Version: 2.3   
Target Milestone: 2.3   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Anthony Hunter CLA 2010-02-23 15:43:32 EST
From Chris McGee:

In our application the way that we integrate the input stream opening logic is through the EMF editing domain's URI Converter. However, the URLImageEditPart in GMF uses the java.net.URL mechanism which is much more difficult to integrate our specific logic in a thread-safe way. Note that EMF will delegate to java.net.URL.openConnection() as a fall-back.

Without the necessary change then user's diagrams do not appear.

Here is a patch that I applied to the URLImageEditPart to get images to be rendered inline in our application:

	final protected RenderedImage regenerateImageFromSource() {
		URL url = getURL();
		if (url != null) {
			URI uri = URI.createURI(url.toString());
			
			try {
				InputStream is = getEditingDomain().getResourceSet().getURIConverter().createInputStream(uri);
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				
				int b = is.read();
				while (b != -1) {
					baos.write(b);
					b = is.read();
				}
				
				// read in the file source specified by the URI, otherwise return null;
				return RenderedImageFactory.getInstance(baos.toByteArray());
			} catch (IOException e) {
				// Ignore and return null;
			}
		}
		
		return null;
	}

If this patch cannot be applied at the GMF level then perhaps this method could be made non-final so we could apply the necessary changes on their end.
Comment 1 Anthony Hunter CLA 2010-02-23 15:45:20 EST
I applied the requested change and ran the JUnit tests in diagram.ui and the changes seem fine.

Committing to HEAD.
Comment 2 Eclipse Webmaster CLA 2010-07-16 23:38:19 EDT
[target cleanup] 2.3 M6 was the original target milestone for this
bug
Comment 3 Eclipse Webmaster CLA 2010-07-19 21:56:43 EDT
[GMF Restructure] Bug 319140 : product GMF and component
Runtime was the original product and component for this bug