blob: b037fbc6e6b05da85dd7dbd8b244559ca93d3b82 (
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
|
/*******************************************************************************
* Copyright (c) 2006 Sybase, Inc. 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:
* Sybase, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.pagedesigner.dom;
import org.w3c.dom.Node;
/**
* This ref position use a parent node as reference. And provide whether this
* location is at the beginning of its parent or last of its parent.
*
* @author mengbo
* @version 1.5
*/
public class DOMRefPosition2 implements IDOMRefPosition {
Node _parentNode;
boolean _last;
/**
* @param replacement
* @param _last2
*/
public DOMRefPosition2(Node parent, boolean last) {
_parentNode = parent;
_last = last;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jst.pagedesigner.dom.IDOMRefPosition#getReferenceNode()
*/
public Node getReferenceNode() {
return _parentNode;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jst.pagedesigner.dom.IDOMPosition#getSibling(boolean)
*/
public Node getSibling(boolean forward) {
if (forward) {
if (_last) {
return null;
}
return _parentNode.getFirstChild();
} else if (_last) {
return _parentNode.getLastChild();
} else {
return null;
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jst.pagedesigner.dom.IDOMPosition#getNextSiblingNode()
*/
public Node getNextSiblingNode() {
return getSibling(true);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jst.pagedesigner.dom.IDOMPosition#getPreviousSiblingNode()
*/
public Node getPreviousSiblingNode() {
return getSibling(false);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jst.pagedesigner.dom.IDOMPosition#getContainerNode()
*/
public Node getContainerNode() {
return _parentNode;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jst.pagedesigner.dom.IDOMPosition#getOffset()
*/
public int getOffset() {
if (!_last) {
return 0;
}
return _parentNode.getChildNodes().getLength();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jst.pagedesigner.dom.IDOMPosition#isText()
*/
public boolean isText() {
return false;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jst.pagedesigner.dom.IDOMPosition#handleReplacement(org.w3c.dom.Node,
* org.w3c.dom.Node)
*/
public IDOMPosition handleReplacement(Node original, Node replacement) {
if (original == _parentNode) {
return new DOMRefPosition2(replacement, _last);
}
return this;
}
}
|