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: 949941f87740663fad5a554f9d2581efd189a771 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*******************************************************************************
 * 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.contentmodel.ssi;

import java.util.Hashtable;
import java.util.Iterator;

import org.eclipse.wst.html.core.internal.contentmodel.HTMLCMDocumentFactory;
import org.eclipse.wst.html.core.internal.provisional.HTML40Namespace;
import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNamespace;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
import org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMDocType;

/**
 * CMDocument factory for SSI documents.
 */
public final class SSICMDocumentFactory {

	private final static String PREFIX = "SSI";//$NON-NLS-1$
	private final static String DOC_TYPE_NAME = "SSI";//$NON-NLS-1$

	static class CMNamespaceImpl implements CMNamespace {
		public CMNamespaceImpl() {
			super();
		}

		public String getPrefix() {
			return PREFIX;
		}

		public String getURI() {
			return ""; //$NON-NLS-1$
		}

		public String getNodeName() {
			return DOC_TYPE_NAME;
		}

		public int getNodeType() {
			return CMNode.NAME_SPACE;
		}

		public boolean supports(String propertyName) {
			return false;
		}

		public Object getProperty(String propertyName) {
			return null;
		}

	}

	static class CMDocImpl implements CMDocument {
		private static CMDocument hcm = HTMLCMDocumentFactory.getCMDocument(CMDocType.HTML_DOC_TYPE);

		static class Elements implements CMNamedNodeMap {
			private static String[] names = {HTML40Namespace.ElementName.SSI_CONFIG, HTML40Namespace.ElementName.SSI_ECHO, HTML40Namespace.ElementName.SSI_EXEC, HTML40Namespace.ElementName.SSI_FSIZE, HTML40Namespace.ElementName.SSI_FLASTMOD, HTML40Namespace.ElementName.SSI_INCLUDE, HTML40Namespace.ElementName.SSI_PRINTENV, HTML40Namespace.ElementName.SSI_SET};
			private Hashtable map = new Hashtable();

			public Elements() {
				CMNamedNodeMap elems = hcm.getElements();
				for (int i = 0; i < names.length; i++) {
					String name = names[i];
					CMElementDeclaration dec = (CMElementDeclaration) elems.getNamedItem(name);
					if (dec != null)
						map.put(name, dec);
				}
			}

			public int getLength() {
				return map.size();
			}

			public CMNode getNamedItem(String name) {
				String cooked = getCanonicalName(name);
				if (!map.containsKey(cooked))
					return null;
				return (CMNode) map.get(cooked);
			}

			public CMNode item(int index) {
				Iterator iter = iterator();
				while (iter.hasNext()) {
					Object node = iter.next();
					if (--index < 0)
						return (CMNode) node;
				}
				return null;
			}

			public Iterator iterator() {
				return map.values().iterator();
			}

			private String getCanonicalName(String rawName) {
				return rawName.toUpperCase();
			}
		}

		static private Elements elements = new Elements();


		public CMDocImpl() {
			super();
		}

		public String getNodeName() {
			return ""; //$NON-NLS-1$
		}

		public int getNodeType() {
			return CMNode.DOCUMENT;
		}

		public CMNamedNodeMap getElements() {
			return elements;
		}

		public CMNamedNodeMap getEntities() {
			return null;
		}

		public CMNamespace getNamespace() {
			return ssins;
		}

		public Object getProperty(String propertyName) {
			return null;
		}

		public boolean supports(String propertyName) {
			return false;
		}
	}

	private static CMNamespace ssins = new CMNamespaceImpl();
	private static CMDocument mycm = new CMDocImpl();

	private SSICMDocumentFactory() {
		super();
	}

	public static CMDocument getCMDocument() {
		return mycm;
	}

}

Back to the top