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 |
} |