blob: 53a3da814a8172b1a0d48af4629a0dd3a48cc373 [file] [log] [blame]
david_williams96213482004-11-11 09:07:12 +00001/*******************************************************************************
2 * Copyright (c) 2001, 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 * Jens Lukowski/Innoopract - initial renaming/restructuring
11 *
12 *******************************************************************************/
david_williamsd8a74fb2005-03-18 02:41:46 +000013package org.eclipse.wst.xml.core.internal.cleanup;
david_williams96213482004-11-11 09:07:12 +000014
15import org.eclipse.core.runtime.Preferences;
david_williamsd8a74fb2005-03-18 02:41:46 +000016import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor;
17import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupHandler;
18import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences;
19import org.eclipse.wst.sse.core.internal.cleanup.StructuredCleanupPreferences;
pavery40dd89e2005-04-01 21:09:29 +000020import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor;
david_williams2e7166e2005-04-13 05:28:38 +000021import org.eclipse.wst.sse.core.internal.preferences.CommonModelPreferenceNames;
david_williams425ffe72004-12-07 21:46:39 +000022import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
david_williams4ad020f2005-04-18 08:00:30 +000023import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML;
david_williams56777022005-04-11 06:21:55 +000024import org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML;
david_williams96213482004-11-11 09:07:12 +000025import org.w3c.dom.Node;
26
27
28public class CleanupProcessorXML extends AbstractStructuredCleanupProcessor {
29 protected IStructuredCleanupPreferences fCleanupPreferences = null;
30
31 protected IStructuredCleanupHandler getCleanupHandler(Node node) {
32 short nodeType = node.getNodeType();
33 IStructuredCleanupHandler cleanupHandler = null;
34 switch (nodeType) {
35 case Node.ELEMENT_NODE : {
36 cleanupHandler = new ElementNodeCleanupHandler();
37 break;
38 }
39 case Node.TEXT_NODE : {
40 cleanupHandler = new NodeCleanupHandler();
41 break;
42 }
43 default : {
44 cleanupHandler = new NodeCleanupHandler();
45 }
46 }
47
48 // init CleanupPreferences
49 cleanupHandler.setCleanupPreferences(getCleanupPreferences());
50
51 return cleanupHandler;
52 }
53
54 public IStructuredCleanupPreferences getCleanupPreferences() {
55 if (fCleanupPreferences == null) {
56 fCleanupPreferences = new StructuredCleanupPreferences();
57
58 Preferences preferences = getModelPreferences();
59 if (preferences != null) {
60 fCleanupPreferences.setTagNameCase(preferences.getInt(CommonModelPreferenceNames.CLEANUP_TAG_NAME_CASE));
61 fCleanupPreferences.setAttrNameCase(preferences.getInt(CommonModelPreferenceNames.CLEANUP_ATTR_NAME_CASE));
62 fCleanupPreferences.setCompressEmptyElementTags(preferences.getBoolean(CommonModelPreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS));
63 fCleanupPreferences.setInsertRequiredAttrs(preferences.getBoolean(CommonModelPreferenceNames.INSERT_REQUIRED_ATTRS));
64 fCleanupPreferences.setInsertMissingTags(preferences.getBoolean(CommonModelPreferenceNames.INSERT_MISSING_TAGS));
65 fCleanupPreferences.setQuoteAttrValues(preferences.getBoolean(CommonModelPreferenceNames.QUOTE_ATTR_VALUES));
66 fCleanupPreferences.setFormatSource(preferences.getBoolean(CommonModelPreferenceNames.FORMAT_SOURCE));
67 fCleanupPreferences.setConvertEOLCodes(preferences.getBoolean(CommonModelPreferenceNames.CONVERT_EOL_CODES));
68 fCleanupPreferences.setEOLCode(preferences.getString(CommonModelPreferenceNames.CLEANUP_EOL_CODE));
69 }
70 }
71
72 return fCleanupPreferences;
73 }
74
75 protected String getContentType() {
david_williams282b8f42005-02-14 07:00:56 +000076 return ContentTypeIdForXML.ContentTypeID_XML;
david_williams96213482004-11-11 09:07:12 +000077 }
78
79 protected IStructuredFormatProcessor getFormatProcessor() {
80 return new FormatProcessorXML();
81 }
82
83 protected Preferences getModelPreferences() {
david_williams425ffe72004-12-07 21:46:39 +000084 return XMLCorePlugin.getDefault().getPluginPreferences();
david_williams96213482004-11-11 09:07:12 +000085 }
86
87 protected void refreshCleanupPreferences() {
88 fCleanupPreferences = null;
89 }
90}