Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 130369 Details for
Bug 260700
[Xpand] contentTypes configuration breaks existing projects
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fixes the encoding issue with xpt files.
patch-contentdescriber.txt (text/plain), 10.69 KB, created by
Torsten Krohn
on 2009-03-31 05:57:33 EDT
(
hide
)
Description:
Fixes the encoding issue with xpt files.
Filename:
MIME Type:
Creator:
Torsten Krohn
Created:
2009-03-31 05:57:33 EDT
Size:
10.69 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.gmf.xpand >Index: src/org/eclipse/gmf/internal/xpand/inactive/ContentDescriber.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/inactive/ContentDescriber.java,v >retrieving revision 1.2 >diff -u -r1.2 ContentDescriber.java >--- src/org/eclipse/gmf/internal/xpand/inactive/ContentDescriber.java 19 Mar 2009 12:41:20 -0000 1.2 >+++ src/org/eclipse/gmf/internal/xpand/inactive/ContentDescriber.java 31 Mar 2009 09:45:58 -0000 >@@ -11,40 +11,56 @@ > */ > package org.eclipse.gmf.internal.xpand.inactive; > >+import java.io.BufferedReader; > import java.io.IOException; > import java.io.InputStream; >+import java.io.InputStreamReader; > import java.io.Reader; >+import java.util.regex.Pattern; > > import org.eclipse.core.runtime.QualifiedName; > import org.eclipse.core.runtime.content.IContentDescription; > import org.eclipse.core.runtime.content.ITextContentDescriber; > > /** >- * Major difference from platform's default content describer (which uses BOM) is that we >- * supply ISO-8859-1 encoding for legacy template files (those with 0xAB and 0xBB), but keep >- * exposing UTF-8 as our default encoding. Besides, we do recognize UTF-8 encoding even if >- * there's no BOM in the file (looking for 0xC2 0xAB and 0xC2 0xBB sequences) >- * >+ * Major difference from platform's default content describer (which uses BOM) >+ * is that we supply ISO-8859-1 encoding for legacy template files (those with >+ * 0xAB and 0xBB), but keep exposing UTF-8 as our default encoding. Besides, we >+ * do recognize UTF-8 encoding even if there's no BOM in the file (looking for >+ * 0xC2 0xAB and 0xC2 0xBB sequences) >+ * > * @author artem > */ > public class ContentDescriber implements ITextContentDescriber { > >- public int describe(Reader contents, IContentDescription description) throws IOException { >- // no idea what I can tell here, but if I do not implement ITextContentDescriber, attempt to save >- // existing! UTF-8 xpt file under template folder with ISO encoding results in error "can't convert UTF to ISO" >- // - for some stupid reason Eclipse TextEditor tries to come up with new encoding for existing file >- return VALID; >+ private final static String PATTERN_IMPORT = "IMPORT\\s+(\"|\')"; >+ private final static Pattern PATTERN = Pattern.compile(PATTERN_IMPORT); >+ >+ public int describe(Reader contents, IContentDescription description) { >+ BufferedReader reader = new BufferedReader(contents); >+ if (isValid(reader)) >+ return VALID; >+ >+ return INVALID; > } > >- public int describe(InputStream contents, IContentDescription description) throws IOException { >- StreamDecoder sd = new StreamDecoder(contents, null); >- if (sd.getEncoding() == null) { >- return INDETERMINATE; >+ public int describe(InputStream contents, IContentDescription description) { >+ BufferedReader reader = new BufferedReader(new InputStreamReader( >+ contents)); >+ return describe(reader, description); >+ } >+ >+ private boolean isValid(BufferedReader reader) { >+ String line; >+ try { >+ for (int i = 0; (line = reader.readLine()) != null; i++) >+ if (PATTERN.matcher(line).find()) >+ return true; >+ } catch (IOException e) { >+ e.printStackTrace(); > } >- if (description != null) { >- description.setProperty(IContentDescription.CHARSET, sd.getEncoding().name()); >- } // otherwise, rely on Eclipse to detect encoding >- return VALID; >+ >+ return false; > } > > public QualifiedName[] getSupportedOptions() { >Index: .settings/org.eclipse.core.resources.prefs >=================================================================== >RCS file: .settings/org.eclipse.core.resources.prefs >diff -N .settings/org.eclipse.core.resources.prefs >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ .settings/org.eclipse.core.resources.prefs 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,3 @@ >+#Tue Mar 31 11:39:52 CEST 2009 >+eclipse.preferences.version=1 >+encoding//src/org/eclipse/gmf/internal/xpand/inactive/ContentDescriber.java=UTF-8 >#P org.eclipse.gmf.tests.xpand >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.gmf/tests/org.eclipse.gmf.tests.xpand/META-INF/MANIFEST.MF,v >retrieving revision 1.6 >diff -u -r1.6 MANIFEST.MF >--- META-INF/MANIFEST.MF 16 Mar 2009 10:24:44 -0000 1.6 >+++ META-INF/MANIFEST.MF 31 Mar 2009 09:45:58 -0000 >@@ -9,3 +9,4 @@ > org.junit, > org.eclipse.ocl.ecore;bundle-version="[1.2.0,2.0.0)", > org.eclipse.m2m.qvt.oml.runtime;bundle-version="[2.0.0,3.0.0)" >+Import-Package: org.eclipse.core.runtime.content >Index: .settings/org.eclipse.core.resources.prefs >=================================================================== >RCS file: .settings/org.eclipse.core.resources.prefs >diff -N .settings/org.eclipse.core.resources.prefs >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ .settings/org.eclipse.core.resources.prefs 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,3 @@ >+#Tue Mar 31 11:42:49 CEST 2009 >+eclipse.preferences.version=1 >+encoding//src/org/eclipse/gmf/internal/xpand/inactive/ContentDescriberTest.java=UTF-8 >Index: src/org/eclipse/gmf/internal/xpand/inactive/ContentDescriberTest.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/xpand/inactive/ContentDescriberTest.java >diff -N src/org/eclipse/gmf/internal/xpand/inactive/ContentDescriberTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/xpand/inactive/ContentDescriberTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,151 @@ >+package org.eclipse.gmf.internal.xpand.inactive; >+ >+import java.io.BufferedReader; >+import java.io.ByteArrayInputStream; >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.Reader; >+import java.io.StringReader; >+ >+import junit.framework.TestCase; >+ >+import org.eclipse.core.runtime.content.IContentDescriber; >+import org.eclipse.core.runtime.content.ITextContentDescriber; >+import org.eclipse.gmf.internal.xpand.inactive.ContentDescriber; >+import org.xml.sax.InputSource; >+ >+/** >+ * >+ * @author Torsten Krohn >+ * >+ */ >+ >+@SuppressWarnings("restriction") >+public class ContentDescriberTest extends TestCase { >+ >+ public static final String ENCODING_UTF8 = "UTF-8"; >+ public static final String ENCODING_ISO = "ISO-8859-1"; >+ public static final String ENCODING_MACROMAN = "MacRoman"; >+ >+ public Reader readerGmfXptUtf8; >+ public Reader readerGmfXptIso88591; >+ public Reader readerXtextXptUtf8; >+ public Reader readerXtextXptIso88591; >+ public Reader readerOther; >+ >+ public InputStream inputStreamGmfXptUtf8; >+ public InputStream inputStreamGmfXptIso; >+ public InputStream inputStreamXtextXptUtf8; >+ public InputStream inputStreamXtextXptIso; >+ public InputStream inputStreamOther; >+ >+ @Override >+ protected void setUp() throws Exception { >+ super.setUp(); >+ >+ String xtextxpt = "/*\n"; >+ xtextxpt += " * some comments with the word import included\n"; >+ xtextxpt += " */\n"; >+ xtextxpt += "\n"; >+ xtextxpt += "\u00ABIMPORT 'http://www.eclipse.org/gmf/2009/GenModel'\00BB\n"; >+ xtextxpt += "\u00ABEXTENSION xpt::diagram::parts::Common\u00BB\n"; >+ >+ byte[] utf8bytes = xtextxpt.getBytes(ENCODING_UTF8); >+ byte[] isobytes = xtextxpt.getBytes(ENCODING_ISO); >+ inputStreamXtextXptUtf8 = new ByteArrayInputStream(utf8bytes); >+ inputStreamXtextXptIso = new ByteArrayInputStream(isobytes); >+ >+ InputSource inputSourceXtextXptUtf8 = new InputSource(new StringReader( >+ xtextxpt)); >+ inputSourceXtextXptUtf8.setEncoding(ENCODING_UTF8); >+ readerXtextXptUtf8 = inputSourceXtextXptUtf8.getCharacterStream(); >+ >+ InputSource inputSourceXtextXptIso = new InputSource(new StringReader( >+ xtextxpt)); >+ inputSourceXtextXptIso.setEncoding(ENCODING_ISO); >+ readerXtextXptIso88591 = inputSourceXtextXptIso.getCharacterStream(); >+ >+ String gmfxpt = "/*\n"; >+ gmfxpt += " * some comments with the word import included\n"; >+ gmfxpt += " */\n"; >+ gmfxpt += "package org.eclipse.gmf.internal.xpand.inactive;\n"; >+ gmfxpt += "\n"; >+ gmfxpt += "import java.io.IOException;\n"; >+ gmfxpt += "public class MagicClass implements IMagic {\n"; >+ >+ utf8bytes = gmfxpt.getBytes(ENCODING_UTF8); >+ isobytes = gmfxpt.getBytes(ENCODING_ISO); >+ inputStreamGmfXptUtf8 = new ByteArrayInputStream(utf8bytes); >+ inputStreamGmfXptIso = new ByteArrayInputStream(isobytes); >+ >+ InputSource inputSourceGmfXptUtf8 = new InputSource(new StringReader( >+ gmfxpt)); >+ inputSourceGmfXptUtf8.setEncoding(ENCODING_UTF8); >+ readerGmfXptUtf8 = inputSourceGmfXptUtf8.getCharacterStream(); >+ InputSource inputStreamGmfXptIso = new InputSource(new StringReader( >+ gmfxpt)); >+ inputStreamGmfXptIso.setEncoding(ENCODING_ISO); >+ readerGmfXptIso88591 = inputStreamGmfXptIso.getCharacterStream(); >+ >+ String other = "/*"; >+ other += " * some comments with the word import included\n"; >+ other += " */\n"; >+ other += "package org.eclipse.gmf.internal.xpand.inactive;\n"; >+ >+ byte[] otherBytes = other.getBytes(ENCODING_MACROMAN); >+ inputStreamOther = new ByteArrayInputStream(otherBytes); >+ >+ InputSource otherInputSource = new InputSource(new StringReader(other)); >+ readerOther = otherInputSource.getCharacterStream(); >+ } >+ >+ public final void testDescribeReader() throws IOException { >+ BufferedReader contents = new BufferedReader(readerXtextXptUtf8); >+ ITextContentDescriber describer = new ContentDescriber(); >+ assertEquals(IContentDescriber.VALID, describer >+ .describe(contents, null)); >+ >+ contents = new BufferedReader(readerXtextXptIso88591); >+ assertEquals(IContentDescriber.VALID, describer >+ .describe(contents, null)); >+ >+ contents = new BufferedReader(readerGmfXptUtf8); >+ assertEquals(IContentDescriber.INVALID, describer.describe(contents, >+ null)); >+ >+ contents = new BufferedReader(readerGmfXptIso88591); >+ assertEquals(IContentDescriber.INVALID, describer.describe(contents, >+ null)); >+ >+ contents = new BufferedReader(readerOther); >+ assertEquals(IContentDescriber.INVALID, describer.describe(contents, >+ null)); >+ } >+ >+ public final void testDescribeInputStream() throws IOException { >+ ITextContentDescriber describer = new ContentDescriber(); >+ assertEquals(IContentDescriber.VALID, describer.describe( >+ inputStreamXtextXptUtf8, null)); >+ >+ assertEquals(IContentDescriber.VALID, describer.describe( >+ inputStreamXtextXptIso, null)); >+ >+ assertEquals(IContentDescriber.INVALID, describer.describe( >+ inputStreamGmfXptUtf8, null)); >+ >+ assertEquals(IContentDescriber.INVALID, describer.describe( >+ inputStreamGmfXptIso, null)); >+ >+ assertEquals(IContentDescriber.INVALID, describer.describe( >+ inputStreamOther, null)); >+ } >+ >+ @Override >+ protected void tearDown() throws Exception { >+ super.tearDown(); >+ readerGmfXptUtf8 = null; >+ readerGmfXptIso88591 = null; >+ readerXtextXptUtf8 = null; >+ readerXtextXptIso88591 = null; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 260700
: 130369