1 /*******************************************************************************
\r
2 * Copyright (c) 2006 Sybase, Inc. and others.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * Sybase, Inc. - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.eclipse.jst.pagedesigner.dom;
\r
14 import org.w3c.dom.Node;
\r
19 public class DOMRange {
\r
20 IDOMPosition _start;
\r
28 public DOMRange(IDOMPosition p1, IDOMPosition p2) {
\r
34 * @return the start position
\r
36 public IDOMPosition getStartPosition() {
\r
41 * @return the end position
\r
43 public IDOMPosition getEndPosition() {
\r
48 * @return true if is empty
\r
50 public boolean isEmpty() {
\r
51 return _start.getContainerNode() == _end.getContainerNode()
\r
52 && _start.getOffset() == _end.getOffset();
\r
56 * @return true if is ordered
\r
58 public boolean isOrdered() {
\r
59 Node common = DOMUtil.findCommonAncester(_start.getContainerNode(),
\r
60 _end.getContainerNode());
\r
61 if (common == null) {
\r
64 IDOMPosition s = moveUp(_start, common);
\r
65 IDOMPosition e = moveUp(_end, common);
\r
66 return e.getOffset() >= s.getOffset();
\r
69 private IDOMPosition moveUp(IDOMPosition p, Node ancester) {
\r
70 while (p.getContainerNode() != ancester) {
\r
71 p = new DOMRefPosition(p.getContainerNode(), false);
\r