Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9ff0cf743a1054697c4fd5d4af3e57f104f5015b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*******************************************************************************
 * Copyright (c) 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.html.core.preferences;



import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.wst.common.contentmodel.CMNode;
import org.eclipse.wst.html.core.HTMLCMProperties;
import org.eclipse.wst.html.core.PreferenceNames;
import org.eclipse.wst.sse.core.preferences.CommonModelPreferenceNames;
import org.w3c.dom.Node;

public class HTMLContentBuilder extends org.eclipse.wst.common.contentmodel.util.DOMContentBuilderImpl {

	private String fTagCase;
	private String fAttrCase;

	/**
	 * DOMContentBuilder constructor comment.
	 * @param document org.w3c.dom.Document
	 */
	public HTMLContentBuilder(org.w3c.dom.Document document) {
		super(document);
		Preferences prefs = Platform.getPlugin("org.eclipse.wst.html.core").getPluginPreferences();//$NON-NLS-1$
		fTagCase = prefs.getString(CommonModelPreferenceNames.TAG_NAME_CASE);
		fAttrCase = prefs.getString(CommonModelPreferenceNames.ATTR_NAME_CASE);
		//	Element caseSettings = HTMLPreferenceManager.getHTMLInstance().getElement(PreferenceNames.PREFERRED_CASE);
		//	fTagCase = caseSettings.getAttribute(PreferenceNames.TAGNAME);
		//	fAttrCase = caseSettings.getAttribute(PreferenceNames.ATTRIBUTENAME);
	}

	public String computeName(CMNode cmnode, Node parent) {
		String name = super.computeName(cmnode, parent);
		// don't change the case unless we're certain it is meaningless
		//	if (cmnode instanceof HTMLCMNode && ((HTMLCMNode) cmnode).shouldIgnoreCase()) {
		if (shouldIgnoreCase(cmnode)) {
			if (cmnode.getNodeType() == CMNode.ELEMENT_DECLARATION) {
				if (fTagCase.length() > 0) {
					if (fTagCase.equals(PreferenceNames.LOWER))
						name = name.toLowerCase();
					else if (fTagCase.equals(PreferenceNames.UPPER))
						name = name.toUpperCase();
					// else do nothing
				}
			}
			else if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
				if (fAttrCase.length() > 0) {
					if (fAttrCase.equals(PreferenceNames.LOWER))
						name = name.toLowerCase();
					else if (fAttrCase.equals(PreferenceNames.UPPER))
						name = name.toUpperCase();
					// else do nothing
				}
			}
		}
		return name;

	}

	private boolean shouldIgnoreCase(CMNode cmnode) {
		if (!cmnode.supports(HTMLCMProperties.SHOULD_IGNORE_CASE))
			return false;
		return ((Boolean) cmnode.getProperty(HTMLCMProperties.SHOULD_IGNORE_CASE)).booleanValue();
	}
}

Back to the top