View | Details | Raw Unified | Return to bug 122234
Collapse All | Expand All

(-)src/org/eclipse/gmf/runtime/emf/core/internal/resources/GMFResource.java (-1 / +2 lines)
Lines 22-27 Link Here
22
import org.eclipse.emf.ecore.xmi.XMLLoad;
22
import org.eclipse.emf.ecore.xmi.XMLLoad;
23
import org.eclipse.emf.ecore.xmi.XMLSave;
23
import org.eclipse.emf.ecore.xmi.XMLSave;
24
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
24
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
25
import org.eclipse.emf.ecore.xmi.impl.XMISaveImpl;
25
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
26
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
26
import org.eclipse.gmf.runtime.emf.core.internal.util.Util;
27
import org.eclipse.gmf.runtime.emf.core.internal.util.Util;
27
28
Lines 78-84 Link Here
78
	}
79
	}
79
80
80
	protected XMLSave createXMLSave() {
81
	protected XMLSave createXMLSave() {
81
		return new GMFSave(createXMLHelper());
82
		return new XMISaveImpl(createXMLHelper());
82
	}
83
	}
83
84
84
	/**
85
	/**
(-)src/org/eclipse/gmf/runtime/emf/core/internal/resources/GMFSave.java (-154 lines)
Removed Link Here
1
/******************************************************************************
2
 * Copyright (c) 2002, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    IBM Corporation - initial API and implementation 
10
 ****************************************************************************/
11
12
package org.eclipse.gmf.runtime.emf.core.internal.resources;
13
14
import java.util.List;
15
import java.util.Map;
16
17
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.emf.ecore.xmi.XMLHelper;
19
import org.eclipse.emf.ecore.xmi.XMLResource;
20
import org.eclipse.emf.ecore.xmi.impl.XMISaveImpl;
21
import org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl;
22
23
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
24
25
/**
26
 * This class changes the behavior of the default XMISaver so that a ClearCase
27
 * token is written at the top of the file.
28
 * 
29
 * @author rafikj
30
 */
31
public class GMFSave
32
	extends XMISaveImpl {
33
34
	/**
35
	 * Discards control characters 0x00 - 0x1F except for TAB, CR, and LF, which
36
	 * are escaped by EMF.
37
	 * 
38
	 * @author khussey
39
	 * 
40
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=50403"
41
	 * @see "http://greenbytes.de/tech/webdav/rfc3470.html#binary"
42
	 */
43
	protected static class Escape
44
		extends XMLSaveImpl.Escape {
45
46
		private static final char[] NOTHING = {};
47
48
		public String convert(String input) {
49
			boolean changed = false;
50
			int inputLength = input.length();
51
			grow(inputLength);
52
			input.getChars(0, inputLength, value, 0);
53
			int pos = 0;
54
55
			while (inputLength-- > 0) {
56
57
				switch (value[pos]) {
58
					case '&':
59
						pos = replaceChars(pos, AMP, inputLength);
60
						changed = true;
61
						break;
62
					case '<':
63
						pos = replaceChars(pos, LESS, inputLength);
64
						changed = true;
65
						break;
66
					case '"':
67
						pos = replaceChars(pos, QUOTE, inputLength);
68
						changed = true;
69
						break;
70
					case '\n':
71
						pos = replaceChars(pos, LF, inputLength);
72
						changed = true;
73
						break;
74
					case '\r':
75
						pos = replaceChars(pos, CR, inputLength);
76
						changed = true;
77
						break;
78
					case '\t':
79
						pos = replaceChars(pos, TAB, inputLength);
80
						changed = true;
81
						break;
82
					default:
83
						if (value[pos] < 0x20) {
84
							// these characters are illegal in XML
85
							pos = replaceChars(pos, NOTHING, inputLength);
86
							changed = true;
87
						} else {
88
							pos++;
89
						}
90
						break;
91
				}
92
			}
93
94
			return changed ? new String(value, 0, pos)
95
				: input;
96
		}
97
	}
98
99
	/**
100
	 * Constructor.
101
	 */
102
	public GMFSave(XMLHelper helper) {
103
		super(helper);
104
	}
105
106
	/**
107
	 * @see org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl#init(org.eclipse.emf.ecore.xmi.XMLResource,
108
	 *      java.util.Map)
109
	 */
110
	protected void init(XMLResource resource, Map options) {
111
		super.init(resource, options);
112
113
		if (null != escape) {
114
			escape = new Escape();
115
		}
116
	}
117
118
	/**
119
	 * @see org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl#writeTopObjects(java.util.List)
120
	 */
121
	public Object writeTopObjects(List contents) {
122
123
		writeCCToken();
124
		writeArtifactVersionToken();
125
		return super.writeTopObjects(contents);
126
	}
127
128
	/**
129
	 * @see org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl#writeTopObject(org.eclipse.emf.ecore.EObject)
130
	 */
131
	protected Object writeTopObject(EObject top) {
132
133
		writeCCToken();
134
		writeArtifactVersionToken();
135
		return super.writeTopObject(top);
136
	}
137
138
	private void writeArtifactVersionToken() {
139
		// TODO The following token will be replaced by a future infrastructure that will
140
		//  allow client of MSL to specify their application ID and version number for
141
		//  backward/forward compatibility.
142
		doc.add("<?RSA version=\"7.0\"?>"); //$NON-NLS-1$
143
		doc.addLine();
144
	}
145
146
	/**
147
	 * Write ClearCase token.
148
	 */
149
	private void writeCCToken() {
150
		doc.add("<!--" + EMFCoreConstants.CC_TOKEN + "-->"); //$NON-NLS-1$ //$NON-NLS-2$
151
		
152
		doc.addLine();
153
	}
154
}
(-)src/org/eclipse/gmf/runtime/emf/core/clipboard/CopyingResource.java (-2 / +2 lines)
Lines 31-41 Link Here
31
import org.eclipse.emf.ecore.xmi.XMLSave;
31
import org.eclipse.emf.ecore.xmi.XMLSave;
32
import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl;
32
import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl;
33
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
33
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
34
import org.eclipse.emf.ecore.xmi.impl.XMISaveImpl;
34
import org.eclipse.gmf.runtime.common.core.util.Trace;
35
import org.eclipse.gmf.runtime.common.core.util.Trace;
35
import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCoreDebugOptions;
36
import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCoreDebugOptions;
36
import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCorePlugin;
37
import org.eclipse.gmf.runtime.emf.core.internal.plugin.EMFCorePlugin;
37
import org.eclipse.gmf.runtime.emf.core.internal.resources.GMFResource;
38
import org.eclipse.gmf.runtime.emf.core.internal.resources.GMFResource;
38
import org.eclipse.gmf.runtime.emf.core.internal.resources.GMFSave;
39
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
39
import org.eclipse.gmf.runtime.emf.core.internal.util.EMFCoreConstants;
40
import org.eclipse.gmf.runtime.emf.core.internal.util.Util;
40
import org.eclipse.gmf.runtime.emf.core.internal.util.Util;
41
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
41
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
Lines 192-198 Link Here
192
	}
192
	}
193
193
194
	protected XMLSave createXMLSave() {
194
	protected XMLSave createXMLSave() {
195
		return new GMFSave(createXMLHelper()) {
195
		return new XMISaveImpl(createXMLHelper()) {
196
196
197
			/**
197
			/**
198
			 * @see org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl#sameDocMany(org.eclipse.emf.ecore.EObject,
198
			 * @see org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl#sameDocMany(org.eclipse.emf.ecore.EObject,
(-)src/org/eclipse/gmf/runtime/emf/core/internal/util/EMFCoreConstants.java (-2 lines)
Lines 30-37 Link Here
30
30
31
	public final static String EMPTY_STRING = ""; //$NON-NLS-1$
31
	public final static String EMPTY_STRING = ""; //$NON-NLS-1$
32
32
33
	public final static String CC_TOKEN = "xtools2_universal_type_manager"; //$NON-NLS-1$
34
35
	public final static char META_CLASS_BEGIN = '<';
33
	public final static char META_CLASS_BEGIN = '<';
36
34
37
	public final static char META_CLASS_END = '>';
35
	public final static char META_CLASS_END = '>';
(-)src/org/eclipse/gmf/runtime/emf/core/internal/resources/MSLResource.java (+5 lines)
Lines 14-19 Link Here
14
import org.eclipse.emf.common.util.URI;
14
import org.eclipse.emf.common.util.URI;
15
import org.eclipse.emf.ecore.xmi.XMLHelper;
15
import org.eclipse.emf.ecore.xmi.XMLHelper;
16
import org.eclipse.emf.ecore.xmi.XMLLoad;
16
import org.eclipse.emf.ecore.xmi.XMLLoad;
17
import org.eclipse.emf.ecore.xmi.XMLSave;
17
18
18
/**
19
/**
19
 * Custom implementation of an XMIResource.
20
 * Custom implementation of an XMIResource.
Lines 40-43 Link Here
40
	protected XMLLoad createXMLLoad() {
41
	protected XMLLoad createXMLLoad() {
41
		return new MSLLoad(createXMLHelper());
42
		return new MSLLoad(createXMLHelper());
42
	}
43
	}
44
	
45
	protected XMLSave createXMLSave() {
46
		return new MSLSave(createXMLHelper());
47
	}
43
}
48
}
(-)src/org/eclipse/gmf/runtime/emf/core/internal/resources/MSLSave.java (+126 lines)
Added Link Here
1
/******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    IBM Corporation - initial API and implementation 
10
 ****************************************************************************/
11
12
package org.eclipse.gmf.runtime.emf.core.internal.resources;
13
14
import java.util.List;
15
import java.util.Map;
16
17
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.emf.ecore.xmi.XMLHelper;
19
import org.eclipse.emf.ecore.xmi.XMLResource;
20
import org.eclipse.emf.ecore.xmi.impl.XMISaveImpl;
21
import org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl;
22
23
public class MSLSave extends XMISaveImpl {
24
	private final static String CC_TOKEN = "xtools2_universal_type_manager"; //$NON-NLS-1$
25
	
26
	/**
27
	 * Discards control characters 0x00 - 0x1F except for TAB, CR, and LF, which
28
	 * are escaped by EMF.
29
	 * 
30
	 * @author khussey
31
	 * 
32
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=50403"
33
	 * @see "http://greenbytes.de/tech/webdav/rfc3470.html#binary"
34
	 */
35
	protected static class Escape
36
		extends XMLSaveImpl.Escape {
37
38
		private static final char[] NOTHING = {};
39
40
		public String convert(String input) {
41
			boolean changed = false;
42
			int inputLength = input.length();
43
			grow(inputLength);
44
			input.getChars(0, inputLength, value, 0);
45
			int pos = 0;
46
47
			while (inputLength-- > 0) {
48
49
				switch (value[pos]) {
50
					case '&':
51
						pos = replaceChars(pos, AMP, inputLength);
52
						changed = true;
53
						break;
54
					case '<':
55
						pos = replaceChars(pos, LESS, inputLength);
56
						changed = true;
57
						break;
58
					case '"':
59
						pos = replaceChars(pos, QUOTE, inputLength);
60
						changed = true;
61
						break;
62
					case '\n':
63
						pos = replaceChars(pos, LF, inputLength);
64
						changed = true;
65
						break;
66
					case '\r':
67
						pos = replaceChars(pos, CR, inputLength);
68
						changed = true;
69
						break;
70
					case '\t':
71
						pos = replaceChars(pos, TAB, inputLength);
72
						changed = true;
73
						break;
74
					default:
75
						if (value[pos] < 0x20) {
76
							// these characters are illegal in XML
77
							pos = replaceChars(pos, NOTHING, inputLength);
78
							changed = true;
79
						} else {
80
							pos++;
81
						}
82
						break;
83
				}
84
			}
85
86
			return changed ? new String(value, 0, pos)
87
				: input;
88
		}
89
	}
90
	
91
	public MSLSave(XMLHelper helper) {
92
		super(helper);
93
	}
94
	
95
	protected void init(XMLResource resource, Map options) {
96
		super.init(resource, options);
97
98
		if (null != escape) {
99
			escape = new Escape();
100
		}
101
	}
102
	
103
	/**
104
	 * @see org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl#writeTopObjects(java.util.List)
105
	 */
106
	public Object writeTopObjects(List contents) {
107
		writeCCToken();
108
		return super.writeTopObjects(contents);
109
	}
110
111
	/**
112
	 * @see org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl#writeTopObject(org.eclipse.emf.ecore.EObject)
113
	 */
114
	protected Object writeTopObject(EObject top) {
115
		writeCCToken();
116
		return super.writeTopObject(top);
117
	}
118
	
119
	/**
120
	 * Write ClearCase token.
121
	 */
122
	private void writeCCToken() {
123
		doc.add("<!--" + CC_TOKEN + "-->"); //$NON-NLS-1$ //$NON-NLS-2$
124
		doc.addLine();
125
	}
126
}

Return to bug 122234