Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 211380 | Differences between
and this patch

Collapse All | Expand All

(-)src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLGenerator.java (-1 / +17 lines)
Lines 23-36 Link Here
23
import javax.xml.parsers.DocumentBuilderFactory;
23
import javax.xml.parsers.DocumentBuilderFactory;
24
24
25
import org.eclipse.core.resources.IFile;
25
import org.eclipse.core.resources.IFile;
26
import org.eclipse.core.resources.ProjectScope;
26
import org.eclipse.core.runtime.Platform;
27
import org.eclipse.core.runtime.Platform;
27
import org.eclipse.core.runtime.Preferences;
28
import org.eclipse.core.runtime.Preferences;
28
import org.eclipse.core.runtime.content.IContentType;
29
import org.eclipse.core.runtime.content.IContentType;
30
import org.eclipse.core.runtime.preferences.IScopeContext;
31
import org.eclipse.core.runtime.preferences.InstanceScope;
29
import org.eclipse.jface.util.Assert;
32
import org.eclipse.jface.util.Assert;
30
import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver;
33
import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver;
31
import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin;
34
import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin;
32
import org.eclipse.wst.common.uriresolver.internal.util.URIHelper;
35
import org.eclipse.wst.common.uriresolver.internal.util.URIHelper;
33
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
36
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
37
import org.eclipse.wst.sse.core.utils.StringUtils;
34
import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
38
import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
35
import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry;
39
import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry;
36
import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
40
import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
Lines 113-118 Link Here
113
117
114
		return cmDocument;
118
		return cmDocument;
115
	}
119
	}
120
	
121
	private String applyLineDelimiter(IFile file, String text) {
122
		String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, System.getProperty("line.separator"), new IScopeContext[] {new ProjectScope(file.getProject()), new InstanceScope() });//$NON-NLS-1$
123
		String convertedText = StringUtils.replace(text, "\r\n", "\n");
124
		convertedText = StringUtils.replace(convertedText, "\r", "\n");
125
		convertedText = StringUtils.replace(convertedText, "\n", lineDelimiter);
126
		return convertedText;
127
	}
116
128
117
	/**
129
	/**
118
	 * @deprecated use createTemplateXMLDocument(IFile, String) instead
130
	 * @deprecated use createTemplateXMLDocument(IFile, String) instead
Lines 129-134 Link Here
129
			ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
141
			ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
130
	
142
	
131
			PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, charSet));
143
			PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, charSet));
144
			contents = applyLineDelimiter(newFile, contents);
132
			writer.println(contents);
145
			writer.println(contents);
133
			writer.flush();
146
			writer.flush();
134
			outputStream.close();
147
			outputStream.close();
Lines 164-170 Link Here
164
		String charset = newFile.getCharset();
177
		String charset = newFile.getCharset();
165
		ByteArrayOutputStream outputStream = createXMLDocument(xmlFileName, charset);
178
		ByteArrayOutputStream outputStream = createXMLDocument(xmlFileName, charset);
166
179
167
		ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
180
		String contents = outputStream.toString(charset);
181
		contents = applyLineDelimiter(newFile, contents);
182
183
		ByteArrayInputStream inputStream = new ByteArrayInputStream(contents.getBytes(charset));
168
		newFile.setContents(inputStream, true, true, null);
184
		newFile.setContents(inputStream, true, true, null);
169
		inputStream.close();
185
		inputStream.close();
170
	}
186
	}
(-)src/org/eclipse/wst/xml/ui/internal/preferences/XMLFilesPreferencePage.java (-95 / +1 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2001, 2006 IBM Corporation and others.
2
 * Copyright (c) 2001, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-22 Link Here
16
import java.util.Arrays;
16
import java.util.Arrays;
17
import java.util.Iterator;
17
import java.util.Iterator;
18
import java.util.List;
18
import java.util.List;
19
import java.util.Vector;
20
19
21
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.core.runtime.Preferences;
21
import org.eclipse.core.runtime.Preferences;
Lines 41-48 Link Here
41
public class XMLFilesPreferencePage extends AbstractPreferencePage {
40
public class XMLFilesPreferencePage extends AbstractPreferencePage {
42
	protected EncodingSettings fEncodingSettings = null;
41
	protected EncodingSettings fEncodingSettings = null;
43
42
44
	protected Combo fEndOfLineCode = null;
45
	private Vector fEOLCodes = null;
46
	private Combo fDefaultSuffix = null;
43
	private Combo fDefaultSuffix = null;
47
	private List fValidExtensions = null;
44
	private List fValidExtensions = null;
48
	private Button fWarnNoGrammar = null;
45
	private Button fWarnNoGrammar = null;
Lines 50-56 Link Here
50
	protected Control createContents(Composite parent) {
47
	protected Control createContents(Composite parent) {
51
		Composite composite = (Composite) super.createContents(parent);
48
		Composite composite = (Composite) super.createContents(parent);
52
		PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.XML_PREFWEBX_FILES_HELPID);
49
		PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.XML_PREFWEBX_FILES_HELPID);
53
		createContentsForCreatingOrSavingGroup(composite);
54
		createContentsForCreatingGroup(composite);
50
		createContentsForCreatingGroup(composite);
55
		createContentsForValidatingGroup(composite);
51
		createContentsForValidatingGroup(composite);
56
52
Lines 78-96 Link Here
78
		((GridData) fEncodingSettings.getLayoutData()).horizontalSpan = 2;
74
		((GridData) fEncodingSettings.getLayoutData()).horizontalSpan = 2;
79
	}
75
	}
80
76
81
	protected void createContentsForCreatingOrSavingGroup(Composite parent) {
82
		Group creatingOrSavingGroup = createGroup(parent, 2);
83
		creatingOrSavingGroup.setText(XMLUIMessages.Creating_or_saving_files);
84
85
		Label label = createLabel(creatingOrSavingGroup, XMLUIMessages.End_of_line_code_desc);
86
		((GridData) label.getLayoutData()).horizontalSpan = 2;
87
		((GridData) label.getLayoutData()).grabExcessHorizontalSpace = true;
88
89
		createLabel(creatingOrSavingGroup, XMLUIMessages.End_of_line_code);
90
		fEndOfLineCode = createDropDownBox(creatingOrSavingGroup);
91
		populateLineDelimiters();
92
	}
93
94
	protected void createContentsForValidatingGroup(Composite parent) {
77
	protected void createContentsForValidatingGroup(Composite parent) {
95
		Group validatingGroup = createGroup(parent, 2);
78
		Group validatingGroup = createGroup(parent, 2);
96
		validatingGroup.setText(XMLUIMessages.Validating_files);
79
		validatingGroup.setText(XMLUIMessages.Validating_files);
Lines 131-149 Link Here
131
		return fValidExtensions;
114
		return fValidExtensions;
132
	}
115
	}
133
116
134
	/**
135
	 * Return the currently selected line delimiter preference
136
	 * 
137
	 * @return a line delimiter constant from CommonEncodingPreferenceNames
138
	 */
139
	private String getCurrentEOLCode() {
140
		int i = fEndOfLineCode.getSelectionIndex();
141
		if (i >= 0) {
142
			return (String) (fEOLCodes.elementAt(i));
143
		}
144
		return ""; //$NON-NLS-1$
145
	}
146
147
	/*
117
	/*
148
	 * (non-Javadoc)
118
	 * (non-Javadoc)
149
	 * 
119
	 * 
Lines 154-160 Link Here
154
	}
124
	}
155
125
156
	protected void initializeValues() {
126
	protected void initializeValues() {
157
		initializeValuesForCreatingOrSavingGroup();
158
		initializeValuesForCreatingGroup();
127
		initializeValuesForCreatingGroup();
159
		initializeValuesForValidatingGroup();
128
		initializeValuesForValidatingGroup();
160
	}
129
	}
Lines 168-184 Link Here
168
		fEncodingSettings.setIANATag(encoding);
137
		fEncodingSettings.setIANATag(encoding);
169
	}
138
	}
170
139
171
	protected void initializeValuesForCreatingOrSavingGroup() {
172
		String endOfLineCode = getModelPreferences().getString(CommonEncodingPreferenceNames.END_OF_LINE_CODE);
173
174
		if (endOfLineCode.length() > 0) {
175
			setCurrentEOLCode(endOfLineCode);
176
		}
177
		else {
178
			setCurrentEOLCode(CommonEncodingPreferenceNames.NO_TRANSLATION);
179
		}
180
	}
181
182
	protected void initializeValuesForValidatingGroup() {
140
	protected void initializeValuesForValidatingGroup() {
183
		boolean warnNoGrammarButtonSelected = getModelPreferences().getBoolean(XMLCorePreferenceNames.WARN_NO_GRAMMAR);
141
		boolean warnNoGrammarButtonSelected = getModelPreferences().getBoolean(XMLCorePreferenceNames.WARN_NO_GRAMMAR);
184
142
Lines 189-195 Link Here
189
	}
147
	}
190
148
191
	protected void performDefaults() {
149
	protected void performDefaults() {
192
		performDefaultsForCreatingOrSavingGroup();
193
		performDefaultsForCreatingGroup();
150
		performDefaultsForCreatingGroup();
194
		performDefaultsForValidatingGroup();
151
		performDefaultsForValidatingGroup();
195
152
Lines 206-222 Link Here
206
		// fEncodingSettings.resetToDefaultEncoding();
163
		// fEncodingSettings.resetToDefaultEncoding();
207
	}
164
	}
208
165
209
	protected void performDefaultsForCreatingOrSavingGroup() {
210
		String endOfLineCode = getModelPreferences().getDefaultString(CommonEncodingPreferenceNames.END_OF_LINE_CODE);
211
212
		if (endOfLineCode.length() > 0) {
213
			setCurrentEOLCode(endOfLineCode);
214
		}
215
		else {
216
			setCurrentEOLCode(CommonEncodingPreferenceNames.NO_TRANSLATION);
217
		}
218
	}
219
220
	protected void performDefaultsForValidatingGroup() {
166
	protected void performDefaultsForValidatingGroup() {
221
		boolean warnNoGrammarButtonSelected = getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.WARN_NO_GRAMMAR);
167
		boolean warnNoGrammarButtonSelected = getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.WARN_NO_GRAMMAR);
222
168
Lines 233-274 Link Here
233
		return result;
179
		return result;
234
	}
180
	}
235
181
236
	/**
237
	 * Populates the vector containing the line delimiter to display string
238
	 * mapping and the combobox displaying line delimiters
239
	 */
240
	private void populateLineDelimiters() {
241
		fEOLCodes = new Vector();
242
		fEndOfLineCode.add(XMLUIMessages.EOL_Unix);
243
		fEOLCodes.add(CommonEncodingPreferenceNames.LF);
244
245
		fEndOfLineCode.add(XMLUIMessages.EOL_Mac);
246
		fEOLCodes.add(CommonEncodingPreferenceNames.CR);
247
248
		fEndOfLineCode.add(XMLUIMessages.EOL_Windows);
249
		fEOLCodes.add(CommonEncodingPreferenceNames.CRLF);
250
251
		fEndOfLineCode.add(XMLUIMessages.EOL_NoTranslation);
252
		fEOLCodes.add(CommonEncodingPreferenceNames.NO_TRANSLATION);
253
	}
254
255
	/**
256
	 * Select the line delimiter in the eol combobox
257
	 * 
258
	 */
259
	private void setCurrentEOLCode(String eolCode) {
260
		// Clear the current selection.
261
		fEndOfLineCode.clearSelection();
262
		fEndOfLineCode.deselectAll();
263
264
		int i = fEOLCodes.indexOf(eolCode);
265
		if (i >= 0) {
266
			fEndOfLineCode.select(i);
267
		}
268
	}
269
270
	protected void storeValues() {
182
	protected void storeValues() {
271
		storeValuesForCreatingOrSavingGroup();
272
		storeValuesForCreatingGroup();
183
		storeValuesForCreatingGroup();
273
		storeValuesForValidatingGroup();
184
		storeValuesForValidatingGroup();
274
	}
185
	}
Lines 280-290 Link Here
280
		getModelPreferences().setValue(CommonEncodingPreferenceNames.OUTPUT_CODESET, fEncodingSettings.getIANATag());
191
		getModelPreferences().setValue(CommonEncodingPreferenceNames.OUTPUT_CODESET, fEncodingSettings.getIANATag());
281
	}
192
	}
282
193
283
	protected void storeValuesForCreatingOrSavingGroup() {
284
		String eolCode = getCurrentEOLCode();
285
		getModelPreferences().setValue(CommonEncodingPreferenceNames.END_OF_LINE_CODE, eolCode);
286
	}
287
288
	protected void storeValuesForValidatingGroup() {
194
	protected void storeValuesForValidatingGroup() {
289
		if (fWarnNoGrammar != null) {
195
		if (fWarnNoGrammar != null) {
290
			boolean warnNoGrammarButtonSelected = fWarnNoGrammar.getSelection();
196
			boolean warnNoGrammarButtonSelected = fWarnNoGrammar.getSelection();
(-)src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLWizard.java (+14 lines)
Lines 15-21 Link Here
15
import java.io.OutputStreamWriter;
15
import java.io.OutputStreamWriter;
16
16
17
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.ProjectScope;
19
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.core.runtime.Preferences;
20
import org.eclipse.core.runtime.Preferences;
21
import org.eclipse.core.runtime.preferences.IScopeContext;
22
import org.eclipse.core.runtime.preferences.InstanceScope;
19
import org.eclipse.jface.resource.ImageDescriptor;
23
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.jface.viewers.StructuredSelection;
25
import org.eclipse.jface.viewers.StructuredSelection;
Lines 32-37 Link Here
32
import org.eclipse.wst.html.ui.internal.editor.HTMLEditorPluginImageHelper;
36
import org.eclipse.wst.html.ui.internal.editor.HTMLEditorPluginImageHelper;
33
import org.eclipse.wst.html.ui.internal.editor.HTMLEditorPluginImages;
37
import org.eclipse.wst.html.ui.internal.editor.HTMLEditorPluginImages;
34
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
38
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
39
import org.eclipse.wst.sse.core.utils.StringUtils;
35
40
36
public class NewHTMLWizard extends Wizard implements INewWizard {
41
public class NewHTMLWizard extends Wizard implements INewWizard {
37
	
42
	
Lines 48-53 Link Here
48
		fNewFileTemplatesPage = new NewHTMLTemplatesWizardPage();
53
		fNewFileTemplatesPage = new NewHTMLTemplatesWizardPage();
49
		addPage(fNewFileTemplatesPage);
54
		addPage(fNewFileTemplatesPage);
50
	}
55
	}
56
	
57
	private String applyLineDelimiter(IFile file, String text) {
58
		String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, System.getProperty("line.separator"), new IScopeContext[] {new ProjectScope(file.getProject()), new InstanceScope() });//$NON-NLS-1$
59
		String convertedText = StringUtils.replace(text, "\r\n", "\n");
60
		convertedText = StringUtils.replace(convertedText, "\r", "\n");
61
		convertedText = StringUtils.replace(convertedText, "\n", lineDelimiter);
62
		return convertedText;
63
	}
51
64
52
	public void init(IWorkbench aWorkbench, IStructuredSelection aSelection) {
65
	public void init(IWorkbench aWorkbench, IStructuredSelection aSelection) {
53
		fSelection = aSelection;
66
		fSelection = aSelection;
Lines 94-99 Link Here
94
			// put template contents into file
107
			// put template contents into file
95
			String templateString = fNewFileTemplatesPage.getTemplateString();
108
			String templateString = fNewFileTemplatesPage.getTemplateString();
96
			if (templateString != null) {
109
			if (templateString != null) {
110
				templateString = applyLineDelimiter(file, templateString);
97
				// determine the encoding for the new file
111
				// determine the encoding for the new file
98
				Preferences preference = HTMLCorePlugin.getDefault().getPluginPreferences();
112
				Preferences preference = HTMLCorePlugin.getDefault().getPluginPreferences();
99
				String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
113
				String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
(-)src/org/eclipse/wst/html/ui/internal/preferences/ui/HTMLFilesPreferencePage.java (-1 lines)
Lines 54-60 Link Here
54
	 */
54
	 */
55
	protected Control createContents(Composite parent) {
55
	protected Control createContents(Composite parent) {
56
		Composite scrolledComposite = createScrolledComposite(parent);
56
		Composite scrolledComposite = createScrolledComposite(parent);
57
		createContentsForCreatingOrSavingGroup(scrolledComposite);
58
		createContentsForCreatingGroup(scrolledComposite);
57
		createContentsForCreatingGroup(scrolledComposite);
59
		createContentsForLoadingGroup(scrolledComposite);
58
		createContentsForLoadingGroup(scrolledComposite);
60
59
(-)src/org/eclipse/wst/dtd/ui/internal/wizard/NewDTDWizard.java (+13 lines)
Lines 21-32 Link Here
21
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.resources.IResource;
23
import org.eclipse.core.resources.IWorkspace;
23
import org.eclipse.core.resources.IWorkspace;
24
import org.eclipse.core.resources.ProjectScope;
24
import org.eclipse.core.resources.ResourcesPlugin;
25
import org.eclipse.core.resources.ResourcesPlugin;
25
import org.eclipse.core.runtime.IPath;
26
import org.eclipse.core.runtime.IPath;
26
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.Platform;
28
import org.eclipse.core.runtime.Platform;
28
import org.eclipse.core.runtime.Preferences;
29
import org.eclipse.core.runtime.Preferences;
29
import org.eclipse.core.runtime.content.IContentType;
30
import org.eclipse.core.runtime.content.IContentType;
31
import org.eclipse.core.runtime.preferences.IScopeContext;
32
import org.eclipse.core.runtime.preferences.InstanceScope;
30
import org.eclipse.jface.resource.ImageDescriptor;
33
import org.eclipse.jface.resource.ImageDescriptor;
31
import org.eclipse.jface.viewers.IStructuredSelection;
34
import org.eclipse.jface.viewers.IStructuredSelection;
32
import org.eclipse.jface.viewers.StructuredSelection;
35
import org.eclipse.jface.viewers.StructuredSelection;
Lines 47-52 Link Here
47
import org.eclipse.wst.dtd.ui.internal.editor.DTDEditorPluginImageHelper;
50
import org.eclipse.wst.dtd.ui.internal.editor.DTDEditorPluginImageHelper;
48
import org.eclipse.wst.dtd.ui.internal.editor.DTDEditorPluginImages;
51
import org.eclipse.wst.dtd.ui.internal.editor.DTDEditorPluginImages;
49
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
52
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
53
import org.eclipse.wst.sse.core.utils.StringUtils;
50
54
51
public class NewDTDWizard extends Wizard implements INewWizard {
55
public class NewDTDWizard extends Wizard implements INewWizard {
52
	private WizardNewFileCreationPage fNewFilePage;
56
	private WizardNewFileCreationPage fNewFilePage;
Lines 97-102 Link Here
97
		return fValidExtensions;
101
		return fValidExtensions;
98
	}
102
	}
99
103
104
	private String applyLineDelimiter(IFile file, String text) {
105
		String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, System.getProperty("line.separator"), new IScopeContext[] {new ProjectScope(file.getProject()), new InstanceScope() });//$NON-NLS-1$
106
		String convertedText = StringUtils.replace(text, "\r\n", "\n");
107
		convertedText = StringUtils.replace(convertedText, "\r", "\n");
108
		convertedText = StringUtils.replace(convertedText, "\n", lineDelimiter);
109
		return convertedText;
110
	}
111
100
	/**
112
	/**
101
	 * Verifies if fileName is valid name for content type. Takes base content
113
	 * Verifies if fileName is valid name for content type. Takes base content
102
	 * type into consideration.
114
	 * type into consideration.
Lines 213-218 Link Here
213
			// put template contents into file
225
			// put template contents into file
214
			String templateString = fNewFileTemplatesPage.getTemplateString();
226
			String templateString = fNewFileTemplatesPage.getTemplateString();
215
			if (templateString != null) {
227
			if (templateString != null) {
228
				templateString = applyLineDelimiter(file, templateString);
216
				// determine the encoding for the new file
229
				// determine the encoding for the new file
217
				Preferences preference = DTDCorePlugin.getInstance().getPluginPreferences();
230
				Preferences preference = DTDCorePlugin.getInstance().getPluginPreferences();
218
				String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
231
				String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
(-)src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPWizard.java (+14 lines)
Lines 15-21 Link Here
15
import java.io.OutputStreamWriter;
15
import java.io.OutputStreamWriter;
16
16
17
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.ProjectScope;
19
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.core.runtime.Preferences;
20
import org.eclipse.core.runtime.Preferences;
21
import org.eclipse.core.runtime.preferences.IScopeContext;
22
import org.eclipse.core.runtime.preferences.InstanceScope;
19
import org.eclipse.jface.resource.ImageDescriptor;
23
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.jface.viewers.StructuredSelection;
25
import org.eclipse.jface.viewers.StructuredSelection;
Lines 32-37 Link Here
32
import org.eclipse.ui.PlatformUI;
36
import org.eclipse.ui.PlatformUI;
33
import org.eclipse.ui.ide.IDE;
37
import org.eclipse.ui.ide.IDE;
34
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
38
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
39
import org.eclipse.wst.sse.core.utils.StringUtils;
35
40
36
public class NewJSPWizard extends Wizard implements INewWizard {
41
public class NewJSPWizard extends Wizard implements INewWizard {
37
	private NewJSPFileWizardPage fNewFilePage;
42
	private NewJSPFileWizardPage fNewFilePage;
Lines 48-53 Link Here
48
		addPage(fNewFileTemplatesPage);
53
		addPage(fNewFileTemplatesPage);
49
	}
54
	}
50
55
56
	private String applyLineDelimiter(IFile file, String text) {
57
		String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, System.getProperty("line.separator"), new IScopeContext[] {new ProjectScope(file.getProject()), new InstanceScope() });//$NON-NLS-1$
58
		String convertedText = StringUtils.replace(text, "\r\n", "\n");
59
		convertedText = StringUtils.replace(convertedText, "\r", "\n");
60
		convertedText = StringUtils.replace(convertedText, "\n", lineDelimiter);
61
		return convertedText;
62
	}
63
51
	public void init(IWorkbench aWorkbench, IStructuredSelection aSelection) {
64
	public void init(IWorkbench aWorkbench, IStructuredSelection aSelection) {
52
		fSelection = aSelection;
65
		fSelection = aSelection;
53
		setWindowTitle(JSPUIMessages._UI_WIZARD_NEW_TITLE);
66
		setWindowTitle(JSPUIMessages._UI_WIZARD_NEW_TITLE);
Lines 94-99 Link Here
94
			// put template contents into file
107
			// put template contents into file
95
			String templateString = fNewFileTemplatesPage.getTemplateString();
108
			String templateString = fNewFileTemplatesPage.getTemplateString();
96
			if (templateString != null) {
109
			if (templateString != null) {
110
				templateString = applyLineDelimiter(file, templateString);
97
				// determine the encoding for the new file
111
				// determine the encoding for the new file
98
				Preferences preference = JSPCorePlugin.getDefault().getPluginPreferences();
112
				Preferences preference = JSPCorePlugin.getDefault().getPluginPreferences();
99
				String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
113
				String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
(-)src/org/eclipse/wst/css/ui/internal/preferences/ui/CSSFilesPreferencePage.java (-4 lines)
Lines 38-44 Link Here
38
38
39
	protected Control createContents(Composite parent) {
39
	protected Control createContents(Composite parent) {
40
		Composite scrolledComposite = createScrolledComposite(parent);
40
		Composite scrolledComposite = createScrolledComposite(parent);
41
		createContentsForCreatingOrSavingGroup(scrolledComposite);
42
		createContentsForCreatingGroup(scrolledComposite);
41
		createContentsForCreatingGroup(scrolledComposite);
43
42
44
		PlatformUI.getWorkbench().getHelpSystem().setHelp(scrolledComposite, IHelpContextIds.CSS_PREFWEBX_FILES_HELPID);
43
		PlatformUI.getWorkbench().getHelpSystem().setHelp(scrolledComposite, IHelpContextIds.CSS_PREFWEBX_FILES_HELPID);
Lines 53-71 Link Here
53
	}
52
	}
54
	
53
	
55
	protected void initializeValues() {
54
	protected void initializeValues() {
56
		initializeValuesForCreatingOrSavingGroup();
57
		initializeValuesForCreatingGroup();
55
		initializeValuesForCreatingGroup();
58
	}
56
	}
59
	
57
	
60
	protected void performDefaults() {
58
	protected void performDefaults() {
61
		performDefaultsForCreatingOrSavingGroup();
62
		performDefaultsForCreatingGroup();
59
		performDefaultsForCreatingGroup();
63
60
64
        updateApplyButton();
61
        updateApplyButton();
65
	}
62
	}
66
	
63
	
67
	protected void storeValues() {
64
	protected void storeValues() {
68
		storeValuesForCreatingOrSavingGroup();
69
		storeValuesForCreatingGroup();
65
		storeValuesForCreatingGroup();
70
	}
66
	}
71
}
67
}
(-)src/org/eclipse/wst/css/ui/internal/wizard/NewCSSWizard.java (+14 lines)
Lines 16-22 Link Here
16
import java.io.OutputStreamWriter;
16
import java.io.OutputStreamWriter;
17
17
18
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.ProjectScope;
20
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.core.runtime.Preferences;
21
import org.eclipse.core.runtime.Preferences;
22
import org.eclipse.core.runtime.preferences.IScopeContext;
23
import org.eclipse.core.runtime.preferences.InstanceScope;
20
import org.eclipse.jface.resource.ImageDescriptor;
24
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.jface.viewers.IStructuredSelection;
25
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.jface.viewers.StructuredSelection;
26
import org.eclipse.jface.viewers.StructuredSelection;
Lines 33-38 Link Here
33
import org.eclipse.wst.css.ui.internal.editor.CSSEditorPluginImages;
37
import org.eclipse.wst.css.ui.internal.editor.CSSEditorPluginImages;
34
import org.eclipse.wst.css.ui.internal.image.CSSImageHelper;
38
import org.eclipse.wst.css.ui.internal.image.CSSImageHelper;
35
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
39
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
40
import org.eclipse.wst.sse.core.utils.StringUtils;
36
41
37
public class NewCSSWizard extends Wizard implements INewWizard {
42
public class NewCSSWizard extends Wizard implements INewWizard {
38
	private NewCSSFileWizardPage fNewFilePage;
43
	private NewCSSFileWizardPage fNewFilePage;
Lines 49-54 Link Here
49
		addPage(fNewFileTemplatesPage);
54
		addPage(fNewFileTemplatesPage);
50
	}
55
	}
51
56
57
	private String applyLineDelimiter(IFile file, String text) {
58
		String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, System.getProperty("line.separator"), new IScopeContext[] {new ProjectScope(file.getProject()), new InstanceScope() });//$NON-NLS-1$
59
		String convertedText = StringUtils.replace(text, "\r\n", "\n");
60
		convertedText = StringUtils.replace(convertedText, "\r", "\n");
61
		convertedText = StringUtils.replace(convertedText, "\n", lineDelimiter);
62
		return convertedText;
63
	}
64
52
	public void init(IWorkbench aWorkbench, IStructuredSelection aSelection) {
65
	public void init(IWorkbench aWorkbench, IStructuredSelection aSelection) {
53
		fSelection = aSelection;
66
		fSelection = aSelection;
54
		setWindowTitle(CSSUIMessages._UI_WIZARD_NEW_TITLE); //$NON-NLS-1$
67
		setWindowTitle(CSSUIMessages._UI_WIZARD_NEW_TITLE); //$NON-NLS-1$
Lines 94-99 Link Here
94
			// put template contents into file
107
			// put template contents into file
95
			String templateString = fNewFileTemplatesPage.getTemplateString();
108
			String templateString = fNewFileTemplatesPage.getTemplateString();
96
			if (templateString != null) {
109
			if (templateString != null) {
110
				templateString = applyLineDelimiter(file, templateString);
97
				// determine the encoding for the new file
111
				// determine the encoding for the new file
98
				Preferences preference = CSSCorePlugin.getDefault().getPluginPreferences();
112
				Preferences preference = CSSCorePlugin.getDefault().getPluginPreferences();
99
				String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
113
				String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
(-)src-encoding/org/eclipse/wst/sse/core/internal/encoding/CommonEncodingPreferenceNames.java (+8 lines)
Lines 23-36 Link Here
23
23
24
	/**
24
	/**
25
	 * Constant to be used when referring to CR/MAC line delimiter
25
	 * Constant to be used when referring to CR/MAC line delimiter
26
	 * @deprecated - no longer used
26
	 */
27
	 */
27
	public static final String CR = "EOL_Mac"; //$NON-NLS-1$
28
	public static final String CR = "EOL_Mac"; //$NON-NLS-1$
28
	/**
29
	/**
29
	 * Constant to be used when referring to CRLF/WINDOWS line delimiter
30
	 * Constant to be used when referring to CRLF/WINDOWS line delimiter
31
	 * @deprecated - no longer used
30
	 */
32
	 */
31
	public static final String CRLF = "EOL_Windows"; //$NON-NLS-1$
33
	public static final String CRLF = "EOL_Windows"; //$NON-NLS-1$
32
	/**
34
	/**
33
	 * The end-of-line character(s) to use.
35
	 * The end-of-line character(s) to use.
36
	 * @deprecated - no longer used
34
	 */
37
	 */
35
	public static final String END_OF_LINE_CODE = "endOfLineCode";//$NON-NLS-1$
38
	public static final String END_OF_LINE_CODE = "endOfLineCode";//$NON-NLS-1$
36
	/**
39
	/**
Lines 40-49 Link Here
40
43
41
	/**
44
	/**
42
	 * Constant to be used when referring to LF/UNIX line delimiter
45
	 * Constant to be used when referring to LF/UNIX line delimiter
46
	 * @deprecated - no longer used
43
	 */
47
	 */
44
	public static final String LF = "EOL_Unix"; //$NON-NLS-1$
48
	public static final String LF = "EOL_Unix"; //$NON-NLS-1$
45
	/**
49
	/**
46
	 * Constant to be used when referring to No translation of line delimiters
50
	 * Constant to be used when referring to No translation of line delimiters
51
	 * @deprecated - no longer used
47
	 */
52
	 */
48
	public static final String NO_TRANSLATION = ""; //$NON-NLS-1$
53
	public static final String NO_TRANSLATION = ""; //$NON-NLS-1$
49
	/**
54
	/**
Lines 53-68 Link Here
53
58
54
	/**
59
	/**
55
	 * String representation of CR/MAC line delimiter
60
	 * String representation of CR/MAC line delimiter
61
	 * @deprecated - no longer used
56
	 */
62
	 */
57
	public static final String STRING_CR = "\r";//$NON-NLS-1$
63
	public static final String STRING_CR = "\r";//$NON-NLS-1$
58
64
59
	/**
65
	/**
60
	 * String representation of CRLF/WINDOWS line delimiter
66
	 * String representation of CRLF/WINDOWS line delimiter
67
	 * @deprecated - no longer used
61
	 */
68
	 */
62
	public static final String STRING_CRLF = "\r\n";//$NON-NLS-1$
69
	public static final String STRING_CRLF = "\r\n";//$NON-NLS-1$
63
70
64
	/**
71
	/**
65
	 * String representation of LF/UNIX line delimiter
72
	 * String representation of LF/UNIX line delimiter
73
	 * @deprecated - no longer used
66
	 */
74
	 */
67
	public static final String STRING_LF = "\n";//$NON-NLS-1$
75
	public static final String STRING_LF = "\n";//$NON-NLS-1$
68
76
(-)src/org/eclipse/wst/sse/core/internal/text/BasicStructuredDocument.java (-27 / +30 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2001, 2007 IBM Corporation and others.
2
 * Copyright (c) 2001, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 22-27 Link Here
22
import java.util.Map;
22
import java.util.Map;
23
23
24
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.core.runtime.Platform;
25
import org.eclipse.core.runtime.preferences.IScopeContext;
26
import org.eclipse.core.runtime.preferences.InstanceScope;
25
import org.eclipse.jface.text.BadLocationException;
27
import org.eclipse.jface.text.BadLocationException;
26
import org.eclipse.jface.text.BadPartitioningException;
28
import org.eclipse.jface.text.BadPartitioningException;
27
import org.eclipse.jface.text.BadPositionCategoryException;
29
import org.eclipse.jface.text.BadPositionCategoryException;
Lines 299-315 Link Here
299
	private byte[] listenerLock = new byte[0];
301
	private byte[] listenerLock = new byte[0];
300
	private NullDocumentEvent NULL_DOCUMENT_EVENT;
302
	private NullDocumentEvent NULL_DOCUMENT_EVENT;
301
303
302
	//
303
	/**
304
	/**
304
	 * in case preferred delimiter is not set, we'll assume the platform
305
	 * Theoretically, a document can contain mixed line delimiters, but the
305
	 * default Note: it is not final static to make sure it won't be inlined
306
	 * user's preference is usually to be internally consistent.
306
	 * by compiler.
307
	 */
307
	 */
308
	private final String PlatformLineDelimiter = System.getProperty("line.separator"); //$NON-NLS-1$
308
	private String fInitialLineDelimiter;
309
	/**
310
	 * theoretically, a document can contain mixed line delimiters
311
	 */
312
	private String preferedDelimiter;
313
	private final String READ_ONLY_REGIONS_CATEGORY = "_READ_ONLY_REGIONS_CATEGORY_"; //$NON-NLS-1$
309
	private final String READ_ONLY_REGIONS_CATEGORY = "_READ_ONLY_REGIONS_CATEGORY_"; //$NON-NLS-1$
314
	/**
310
	/**
315
	 * Current rewrite session, or none if not presently rewriting.
311
	 * Current rewrite session, or none if not presently rewriting.
Lines 1320-1347 Link Here
1320
	 * @see org.eclipse.jface.text.IDocumentExtension4#getDefaultLineDelimiter()
1316
	 * @see org.eclipse.jface.text.IDocumentExtension4#getDefaultLineDelimiter()
1321
	 */
1317
	 */
1322
	public String getDefaultLineDelimiter() {
1318
	public String getDefaultLineDelimiter() {
1323
		// specific preferred line delimiter
1319
		
1324
		if (preferedDelimiter != null)
1320
		String lineDelimiter= null;
1325
			return preferedDelimiter;
1321
		
1322
		try {
1323
			lineDelimiter= getLineDelimiter(0);
1324
		} catch (BadLocationException x) {
1325
		}
1326
	
1327
		if (lineDelimiter != null)
1328
			return lineDelimiter;
1326
1329
1330
		if (fInitialLineDelimiter != null)
1331
			return fInitialLineDelimiter;
1327
1332
1328
		// no line delimiter has been used so just use platform's default
1333
		String sysLineDelimiter= System.getProperty("line.separator"); //$NON-NLS-1$
1329
		String lineDelimiter = null;
1334
		String[] delimiters= getLegalLineDelimiters();
1330
		String sysLineDelimiter = PlatformLineDelimiter;
1331
		String[] delimiters = getLegalLineDelimiters();
1332
		Assert.isTrue(delimiters.length > 0);
1335
		Assert.isTrue(delimiters.length > 0);
1333
		for (int i = 0; i < delimiters.length; i++) {
1336
		for (int i= 0; i < delimiters.length; i++) {
1334
			if (delimiters[i].equals(sysLineDelimiter)) {
1337
			if (delimiters[i].equals(sysLineDelimiter)) {
1335
				lineDelimiter = sysLineDelimiter;
1338
				lineDelimiter= sysLineDelimiter;
1336
				break;
1339
				break;
1337
			}
1340
			}
1338
		}
1341
		}
1339
1342
		
1340
		// no platform default so just use first legal delimiter
1341
		if (lineDelimiter == null)
1343
		if (lineDelimiter == null)
1342
			lineDelimiter = delimiters[0];
1344
			lineDelimiter= delimiters[0];
1343
1345
	
1344
		return lineDelimiter;
1346
		return lineDelimiter;
1347
		
1345
	}
1348
	}
1346
1349
1347
	/**
1350
	/**
Lines 2530-2545 Link Here
2530
	 * 
2533
	 * 
2531
	 * @see org.eclipse.jface.text.IDocumentExtension4#setInitialLineDelimiter(java.lang.String)
2534
	 * @see org.eclipse.jface.text.IDocumentExtension4#setInitialLineDelimiter(java.lang.String)
2532
	 */
2535
	 */
2533
	public void setInitialLineDelimiter(String delimiter) {
2536
	public void setInitialLineDelimiter(String lineDelimiter) {
2534
		// make sure our preferred delimiter is
2537
		// make sure our preferred delimiter is
2535
		// one of the legal ones
2538
		// one of the legal ones
2536
		if (Utilities.containsString(getLegalLineDelimiters(), delimiter)) {
2539
		if (Utilities.containsString(getLegalLineDelimiters(), lineDelimiter)) {
2537
			preferedDelimiter = delimiter;
2540
			fInitialLineDelimiter= lineDelimiter;
2538
		}
2541
		}
2539
		else {
2542
		else {
2540
			if (Logger.DEBUG_DOCUMENT)
2543
			if (Logger.DEBUG_DOCUMENT)
2541
				Logger.log(Logger.INFO, "Attempt to set linedelimiter to non-legal delimiter"); //$NON-NLS-1$ //$NON-NLS-2$
2544
				Logger.log(Logger.INFO, "Attempt to set linedelimiter to non-legal delimiter"); //$NON-NLS-1$ //$NON-NLS-2$
2542
			preferedDelimiter = PlatformLineDelimiter;
2545
			fInitialLineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, System.getProperty("line.separator"), new IScopeContext[] { new InstanceScope() });//$NON-NLS-1$
2543
		}
2546
		}
2544
	}
2547
	}
2545
2548
(-)src/org/eclipse/wst/sse/core/internal/cleanup/AbstractStructuredCleanupProcessor.java (-27 / +5 lines)
Lines 22-27 Link Here
22
22
23
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IFile;
24
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.Platform;
26
import org.eclipse.core.runtime.preferences.IScopeContext;
27
import org.eclipse.core.runtime.preferences.InstanceScope;
25
import org.eclipse.jface.text.BadLocationException;
28
import org.eclipse.jface.text.BadLocationException;
26
import org.eclipse.jface.text.DocumentRewriteSession;
29
import org.eclipse.jface.text.DocumentRewriteSession;
27
import org.eclipse.jface.text.DocumentRewriteSessionType;
30
import org.eclipse.jface.text.DocumentRewriteSessionType;
Lines 31-40 Link Here
31
import org.eclipse.jface.text.TextUtilities;
34
import org.eclipse.jface.text.TextUtilities;
32
import org.eclipse.wst.sse.core.StructuredModelManager;
35
import org.eclipse.wst.sse.core.StructuredModelManager;
33
import org.eclipse.wst.sse.core.internal.Logger;
36
import org.eclipse.wst.sse.core.internal.Logger;
34
import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
35
import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor;
37
import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor;
36
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
38
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
37
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
38
import org.w3c.dom.Attr;
39
import org.w3c.dom.Attr;
39
import org.w3c.dom.Node;
40
import org.w3c.dom.Node;
40
41
Lines 300-329 Link Here
300
							IStructuredFormatProcessor formatProcessor = getFormatProcessor();
301
							IStructuredFormatProcessor formatProcessor = getFormatProcessor();
301
							formatProcessor.formatModel(structuredModel);
302
							formatProcessor.formatModel(structuredModel);
302
						}
303
						}
303
304
						// convert EOL codes
305
						if (getConvertEOLCodesPreference(structuredModel)) {
306
							IDocument document = structuredModel.getStructuredDocument();
307
							String endOfLineCode = getEOLCodePreference(structuredModel);
308
							String endOfLineCodeString = null;
309
							if (endOfLineCode.compareTo(CommonEncodingPreferenceNames.LF) == 0)
310
								endOfLineCodeString = CommonEncodingPreferenceNames.STRING_LF;
311
							else if (endOfLineCode.compareTo(CommonEncodingPreferenceNames.CR) == 0)
312
								endOfLineCodeString = CommonEncodingPreferenceNames.STRING_CR;
313
							else if (endOfLineCode.compareTo(CommonEncodingPreferenceNames.CRLF) == 0)
314
								endOfLineCodeString = CommonEncodingPreferenceNames.STRING_CRLF;
315
							if (endOfLineCodeString != null) {
316
								convertLineDelimiters(document, endOfLineCodeString);
317
								// DMW: 8/24/2002 setting line delimiter in
318
								// document allows
319
								// subsequent editing to insert the same line
320
								// delimiter.
321
								if (document instanceof IStructuredDocument) {
322
									((IStructuredDocument) document).setLineDelimiter(endOfLineCodeString);
323
								}
324
								structuredModel.setDirtyState(true);
325
							}
326
						}
327
					}
304
					}
328
					finally {
305
					finally {
329
						// we need two finally's, just in case first fails
306
						// we need two finally's, just in case first fails
Lines 444-450 Link Here
444
421
445
	protected String getEOLCodePreference(IStructuredModel structuredModel) {
422
	protected String getEOLCodePreference(IStructuredModel structuredModel) {
446
423
447
		String eolCode = System.getProperty("line.separator"); //$NON-NLS-1$
424
		IScopeContext[] scopeContext = new IScopeContext[]{new InstanceScope()};
425
		String eolCode = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);
448
426
449
		IStructuredCleanupHandler cleanupHandler = getCleanupHandler((Node) structuredModel.getIndexedRegion(0));
427
		IStructuredCleanupHandler cleanupHandler = getCleanupHandler((Node) structuredModel.getIndexedRegion(0));
450
		if (cleanupHandler != null) {
428
		if (cleanupHandler != null) {

Return to bug 211380