Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4613395cffb8deb6e4b063cd67c240e453029363 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*******************************************************************************
 * 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.modelquery;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.ranges.Range;

/**
 */
public interface DocumentQuery {

	/**
	 * isRenderRoot() returns true if - node is BODY element (both explicit
	 * and implicit) - node is portalhtml:body element - node is Document node
	 * and the document is treated as fragment (with BODY context) Note that
	 * in editing a fragment file, Document node should be treated as a
	 * substitute of BODY element.
	 */
	boolean isRenderRoot(Node node);

	/**
	 * isHeadCorrespondent() returns true if - node is HEAD element (both
	 * explicit and implicit) - node is portalhtml:head element - node is
	 * Document node and the document is treated as fragment (with HEAD
	 * context) Note that in editing a fragment file (with HEAD context),
	 * Document node should be treated as a substitute of HEAD element.
	 */
	boolean isHeadCorrespondent(Node node);

	/**
	 * Implicit BODY element will be gone in V6 SED model. So page designer
	 * provides an API to get a range whose content nodes are rendered in
	 * design view. getRenderRootRange() returns - a range from BODY's first
	 * to its last (if the document has BODY element) - a range form
	 * Document's first to its last (if the document is fragment with BODY
	 * context) - null (if the document is fragment with HEAD context) [The
	 * following cases will be supported since V6] - a range from a custom
	 * tag's first to its last (if the document has a custom tag which
	 * generates BODY element at runtime) - a range from Document's
	 * appropirate offset to its last (if the document does not have explicit
	 * BODY/HTML) - a range from HTML element's appropriate offset to its last
	 * (if the document does not have explicit BODY but have explicit HTML)
	 * 
	 * @param doc
	 * @return
	 */
	Range getRenderRootRange(Document doc);

	/**
	 * Implicit HEAD element will be gone in V6 SED model. So page designer
	 * provides an API to get a range whose content nodes are treated as HEAD
	 * element's child. getHeadCorrespondentRange() returns - a range from
	 * HEAD's first to its last (if the document has HEAD element) - a range
	 * form Document's first to its last (if the document is fragment with
	 * HEAD context) - null (if the document is fragment with BODY context)
	 * [The following cases will be supported since V6] - a range from a
	 * custom tag's first to its last (if the document has a custom tag which
	 * generates HEAD element at runtime) - a range from Document's first to
	 * appropirate offset (if the document does not have explicit HEAD/HTML) -
	 * a range from HTML element's first to appropriate offset (if the
	 * document does not have explicit HEAD but have explicit HTML)
	 * 
	 * @param doc
	 * @return
	 */
	Range getHeadCorrespondentRange(Document doc);

	/**
	 * getRenderRootNode() with [create=false] returns - BODY element if this
	 * document is not fragment and has BODY element - null if this document
	 * is not fragment and does not have BODY element - Document node if this
	 * document is fragment with BODY context - null if this document is
	 * fragment with HEAD context [The following cases will be supported since
	 * V6] - a custom tag which generates BODY tag at runtime - Document node
	 * or HTML element if this document is not fragment but does not have
	 * explicit BODY element getRenderRootNode() with [create=true] returns -
	 * BODY element if this document is not fragment and has BODY element (no
	 * modifictation) - newly created BODY element if this document is not
	 * fragment but does not have BODY element - Document node if this
	 * document is fragment with BODY context (no modifictation) [The
	 * following cases will be supported since V6] - a custom tag which
	 * generates BODY tag at runtime (no modifictation) - newly created BODY
	 * element if this document is not fragment but does not have explicit
	 * BODY element getRenderRootNode() throws HTMLCommandException (since V6)
	 * if - this document is fragment with HEAD context and - "create"
	 * parameter is true Note that in editing a fragment file, Document node
	 * should be treated as a substitute of BODY element.
	 * 
	 * @param childOrDocument
	 * @param create
	 * @return
	 */
	Node getRenderRootNode(Node childOrDocument, boolean create);

	/**
	 * getHeadCorrespondentNode() with [create=false] returns - HEAD element
	 * if this document is not fragment and has HEAD element - null if this
	 * document is not fragment and does not have HEAD element - Document node
	 * if this document is fragment with HEAD context - null if this document
	 * is fragment with BODY context [The following cases will be supported
	 * since V6] - a custom tag which generates HEAD tag at runtime - Document
	 * node or HTML element if this document is not fragment but does not have
	 * explicit HEAD element getHeadCorrespondentNode() with [create=true]
	 * returns - HEAD element if this document is not fragment and has HEAD
	 * element (no modifictation) - newly created HEAD element if this
	 * document is not fragment but does not have HEAD element - Document node
	 * if this document is fragment with HEAD context (no modifictation) [The
	 * following cases will be supported since V6] - a custom tag which
	 * generates HEAD tag at runtime (no modifictation) - newly created HEAD
	 * element if this document is not fragment but does not have explicit
	 * HEAD element getHeadCorrespondentNode() throws HTMLCommandException
	 * (since V6) if - this document is fragment with BODY context and -
	 * "create" parameter is true Note that in editing a fragment file,
	 * Document node should be treated as a substitute of HEAD element.
	 * 
	 * @param childOrDocument
	 * @param create
	 * @return
	 */
	Node getHeadCorrespondentNode(Node childOrDocument, boolean create);

	/**
	 * getHtmlCorrespondentNode() throws HTMLCommandException (since V6) if -
	 * this document is fragment and "create" parameter is true
	 * 
	 * @param childOrDocument
	 * @param create
	 * @return
	 */
	Node getHtmlCorrespondentNode(Node childOrDocument, boolean create);

	/**
	 * This inner class is intended for insertion target. please use this like
	 * the following : DocumentQuery.InsertionTarget ins;
	 * ins.getParent().insertBefore(youInsertionNode, ins.getRef());
	 */
	public class InsertionTarget {
		private final Node parent;
		private final Node ref;

		public InsertionTarget(Node parent, Node ref) {
			this.parent = parent;
			this.ref = ref;
		}

		public Node getParent() {
			return parent;
		}

		public Node getRef() {
			return ref;
		}
	}

	/**
	 * getHeadInsertionTarget() returns appropriate insetion target location
	 * for HEAD child tags such as <script>, <style>, <meta>etc. Basically
	 * this function returns <HEAD>tag's the last position. Note that this
	 * would not create actual <HEAD>tag when the document does not have it.
	 * <HEAD>is omittable tag so this function returns appropriate position
	 * to which implicit <HEAD>can be inserted, if the document has no
	 * <HEAD>.
	 * 
	 * @param doc
	 * @return
	 */
	InsertionTarget getHeadInsertionTarget(Document doc);

	/**
	 * getPageInsertionTarget() returns appropriate insetion target location
	 * for page-level markups, such as JSP directives, usebean tags or <html>
	 * tag. Basically this function returns just before <HTML>tag. Note that
	 * this would not create actual <HTML>tag when the document does not have
	 * it. In such case, this function returns a position just before the
	 * meaningful tags such as HTML/JSP elements.
	 * 
	 * @param doc
	 * @return
	 */
	InsertionTarget getPageInsertionTarget(Document doc);

	/**
	 * isFragment() returns whether the document is fragment or complete
	 * document
	 * 
	 * @param doc
	 * @return
	 */
	boolean isFragment(Document doc);

}

Back to the top