Skip to main content
summaryrefslogtreecommitdiffstats
blob: b6f9af7a02e83317892f0529902b9d7a7d1a206b (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
/*******************************************************************************
 * 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.wst.html.core.internal.contentmodel.HTMLElementDeclaration;
import org.eclipse.wst.html.core.internal.provisional.HTMLCMProperties;
import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentModelGenerator;
import org.w3c.dom.Node;

public class XHTMLMinimalContentModelGenerator extends XMLContentModelGenerator {

	private static XHTMLMinimalContentModelGenerator instance = null;

	private XHTMLMinimalContentModelGenerator() {
		super();
	}

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


	public String getStartTagClose(Node parentNode, CMElementDeclaration elementDecl) {
		String other = getOtherClose(parentNode);
		if (other != null)
			return other;
		if (elementDecl == null)
			return ">"; //$NON-NLS-1$
		// EMPTY tag, do a self-close
		if (elementDecl.getContentType() == CMElementDeclaration.EMPTY) {
			// if it's a JSP element, don't add the space since the JSP container doesn't/shouldn't care
			if (elementDecl instanceof HTMLElementDeclaration && (((Boolean) elementDecl.getProperty(HTMLCMProperties.IS_JSP)).booleanValue()))
				// if it's not JSP, conform to XHTML guidelines and add the space
				return "/>"; //$NON-NLS-1$
			else
				return " />"; //$NON-NLS-1$
		}
		// not defined as EMPTY, but should be treated as such anyway
		else if (elementDecl instanceof HTMLElementDeclaration) {
			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$
	}

	public synchronized static XHTMLMinimalContentModelGenerator getInstance() {
		if (instance == null)
			instance = new XHTMLMinimalContentModelGenerator();
		return instance;
	}
}

Back to the top