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: 2dbf6ed7646d1d233a5ffa8640340ea6509a134b (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
/*******************************************************************************
 * 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.internal.document;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;

/**
 */
class HTMLDocumentTypeRegistryReader {

	//
	private final static String PLUGIN_ID = "org.eclipse.wst.sse.core"; //$NON-NLS-1$
	private final static String EXTENSION_POINT_ID = "documentTypes"; //$NON-NLS-1$
	private final static String TAG_NAME = "documentType"; //$NON-NLS-1$
	private final static String ATT_PID = "publicID"; //$NON-NLS-1$
	private final static String ATT_SID = "systemID"; //$NON-NLS-1$
	private final static String ATT_IS_XHTML = "isXHTML"; //$NON-NLS-1$
	private final static String ATT_IS_WML = "isWML"; //$NON-NLS-1$
	private final static String ATT_HAS_FRAMESET = "hasFrameset"; //$NON-NLS-1$
	private final static String ATT_NSURI = "namespaceURI"; //$NON-NLS-1$
	private final static String ATT_ENAME = "elementName"; //$NON-NLS-1$
	private final static String ATT_DNAME = "displayName"; //$NON-NLS-1$
	private final static String ATT_IS_DEFAULT_XHTML = "defaultXHTML"; //$NON-NLS-1$
	private final static String ATT_IS_DEFAULT_WML = "defaultWML"; //$NON-NLS-1$
	private final static String ATV_TRUE = "true"; //$NON-NLS-1$
	private final static String ATV_NULL_STRING = ""; //$NON-NLS-1$

	/**
	 */
	HTMLDocumentTypeRegistryReader() {
		super();
	}

	/**
	 */
	void readRegistry(HTMLDocumentTypeRegistry reg) {
		if (reg == null)
			return;
		IExtensionRegistry registry = Platform.getExtensionRegistry();
		IExtensionPoint point = registry.getExtensionPoint(PLUGIN_ID, EXTENSION_POINT_ID);
		if (point != null) {
			IConfigurationElement[] elements = point.getConfigurationElements();
			for (int i = 0; i < elements.length; i++) {
				HTMLDocumentTypeEntry doctype = readElement(elements[i]);
				// null can be returned if there's an error reading the element
				if (doctype != null) {
					reg.regist(doctype.getPublicId(), doctype);
				}
			}
		}
	}

	/**
	 */
	private HTMLDocumentTypeEntry readElement(IConfigurationElement element) {
		HTMLDocumentTypeEntry doctype = null;
		String pid = null;
		String sid = null;
		String nsuri = null;
		String root = null;
		boolean xhtml = true;
		boolean frameset = false;
		String dname = null;
		boolean defaultXhtml = false;
		boolean defaultWML = false;
		boolean isWML = false;

		if (element.getName().equals(TAG_NAME)) {
			pid = element.getAttribute(ATT_PID);
			// publicID attribute is mandatory.
			if (pid == null || pid.equals(ATV_NULL_STRING))
				return null;

			sid = element.getAttribute(ATT_SID);
			nsuri = element.getAttribute(ATT_NSURI);
			root = element.getAttribute(ATT_ENAME);
			xhtml = getBoolean(element, ATT_IS_XHTML);
			frameset = getBoolean(element, ATT_HAS_FRAMESET);
			dname = element.getAttribute(ATT_DNAME);
			defaultXhtml = getBoolean(element, ATT_IS_DEFAULT_XHTML);
			defaultWML = getBoolean(element, ATT_IS_DEFAULT_WML);
			isWML = getBoolean(element, ATT_IS_WML);
			doctype = new HTMLDocumentTypeEntry(root, pid, sid, nsuri, xhtml, frameset, dname, defaultXhtml, defaultWML, isWML);
		}
		return doctype;
	}

	/**
	 */
	private boolean getBoolean(IConfigurationElement element, String att) {
		String value = element.getAttribute(att);
		if (value != null && value.equals(ATV_TRUE))
			return true;
		return false;
	}
}

Back to the top