Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 7d58e15b57df90da8ffbbbbac93679c4f4581910 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*******************************************************************************
 * 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.ui.internal.contentassist;

import org.eclipse.core.runtime.Preferences;
import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
import org.eclipse.wst.html.core.internal.contentmodel.HTMLElementDeclaration;
import org.eclipse.wst.html.core.internal.provisional.HTMLCMProperties;
import org.eclipse.wst.sse.core.internal.preferences.CommonModelPreferenceNames;
import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentModelGenerator;
import org.w3c.dom.Node;

public class HTMLMinimalContentModelGenerator extends XMLContentModelGenerator {

	private static HTMLMinimalContentModelGenerator instance = null;
	protected int fTagCase;
	protected int fAttrCase;

	/**
	 * HTMLMinimalContentModelGenerator constructor comment.
	 */
	private HTMLMinimalContentModelGenerator() {
		super();
	}

	private void init() {
		//IPreferenceStore prefs = CommonPreferencesPlugin.getDefault().getPreferenceStore(ContentType.ContentTypeID_HTML);
		Preferences prefs = HTMLCorePlugin.getDefault().getPluginPreferences();
		fTagCase = prefs.getInt(CommonModelPreferenceNames.TAG_NAME_CASE);
		fAttrCase = prefs.getInt(CommonModelPreferenceNames.ATTR_NAME_CASE);
	}

	protected void generateEndTag(String tagName, Node parentNode, CMElementDeclaration elementDecl, StringBuffer buffer) {
		if (elementDecl == null)
			return;
		if (elementDecl instanceof HTMLElementDeclaration) {
			if (((Boolean) elementDecl.getProperty(HTMLCMProperties.IS_JSP)).booleanValue()) {
				if (elementDecl.getContentType() == CMElementDeclaration.EMPTY)
					return;
			}
			else {
				String ommission = (String) elementDecl.getProperty(HTMLCMProperties.OMIT_TYPE);
				if (ommission.equals(HTMLCMProperties.Values.OMIT_END) || ommission.equals(HTMLCMProperties.Values.OMIT_END_DEFAULT) || ommission.equals(HTMLCMProperties.Values.OMIT_END_MUST)) {
					return;
				}
			}
		}

		if (elementDecl.getContentType() == CMElementDeclaration.EMPTY)
			return;
		buffer.append("</" + tagName + ">"); //$NON-NLS-2$//$NON-NLS-1$
		return;
	}

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

	public String getRequiredName(Node ownerNode, CMNode cmnode) {
		String name = super.getRequiredName(ownerNode, cmnode);
		// don't change the case unless we're certain it is meaningless
		if (shouldIgnoreCase(cmnode)) {
			int caseVal = -1;
			if (cmnode.getNodeType() == CMNode.ELEMENT_DECLARATION)
				caseVal = fTagCase;
			else if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION)
				caseVal = fAttrCase;
			switch (caseVal) {
				case CommonModelPreferenceNames.LOWER :
					{
						name = name.toLowerCase();
					}
					break;
				case CommonModelPreferenceNames.UPPER :
					{
						name = name.toUpperCase();
					}
					break;
			}
		}
		return name;
	}

	public String getStartTagClose(Node parentNode, CMElementDeclaration elementDecl) {
		String other = getOtherClose(parentNode);
		if (other != null)
			return other;
		if (elementDecl == null)
			return ">"; //$NON-NLS-1$
		if (elementDecl instanceof HTMLElementDeclaration) {
			if (((Boolean) elementDecl.getProperty(HTMLCMProperties.IS_JSP)).booleanValue()) {
				if (elementDecl.getContentType() == CMElementDeclaration.EMPTY)
					return "/>"; //$NON-NLS-1$
			}
			else {
				String ommission = (String) elementDecl.getProperty(HTMLCMProperties.OMIT_TYPE);
				if (ommission.equals(HTMLCMProperties.Values.OMIT_END) || ommission.equals(HTMLCMProperties.Values.OMIT_END_DEFAULT) || ommission.equals(HTMLCMProperties.Values.OMIT_END_MUST)) {
					return ">"; //$NON-NLS-1$
				}
			}
		}

		return ">"; //$NON-NLS-1$
	}

	/**
	 * Gets the instance.
	 * @return Returns a HTMLMinimalContentModelGenerator
	 */
	public synchronized static HTMLMinimalContentModelGenerator getInstance() {
		if (instance == null)
			instance = new HTMLMinimalContentModelGenerator();
		instance.init();
		return instance;
	}


}

Back to the top