source: NonGTP/Xerces/xercesc/dom/DOMRange.hpp @ 188

Revision 188, 23.5 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1#ifndef DOMRange_HEADER_GUARD_
2#define DOMRange_HEADER_GUARD_
3
4/*
5 * The Apache Software License, Version 1.1
6 *
7 * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
8 * reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in
19 *    the documentation and/or other materials provided with the
20 *    distribution.
21 *
22 * 3. The end-user documentation included with the redistribution,
23 *    if any, must include the following acknowledgment:
24 *       "This product includes software developed by the
25 *        Apache Software Foundation (http://www.apache.org/)."
26 *    Alternately, this acknowledgment may appear in the software itself,
27 *    if and wherever such third-party acknowledgments normally appear.
28 *
29 * 4. The names "Xerces" and "Apache Software Foundation" must
30 *    not be used to endorse or promote products derived from this
31 *    software without prior written permission. For written
32 *    permission, please contact apache\@apache.org.
33 *
34 * 5. Products derived from this software may not be called "Apache",
35 *    nor may "Apache" appear in their name, without prior written
36 *    permission of the Apache Software Foundation.
37 *
38 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49 * SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This software consists of voluntary contributions made by many
53 * individuals on behalf of the Apache Software Foundation, and was
54 * originally based on software copyright (c) 2001, International
55 * Business Machines, Inc., http://www.ibm.com .  For more information
56 * on the Apache Software Foundation, please see
57 * <http://www.apache.org/>.
58 */
59
60/*
61 * $Id: DOMRange.hpp,v 1.8 2003/03/07 19:59:08 tng Exp $
62 */
63
64#include <xercesc/util/XercesDefs.hpp>
65
66XERCES_CPP_NAMESPACE_BEGIN
67
68class DOMNode;
69class DOMDocumentFragment;
70
71/**
72 * <p>See also the <a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113'>Document Object Model (DOM) Level 2 Traversal and Range Specification</a>.
73 * @since DOM Level 2
74 */
75class CDOM_EXPORT DOMRange {
76protected:
77    // -----------------------------------------------------------------------
78    //  Hidden constructors
79    // -----------------------------------------------------------------------
80    /** @name Hidden constructors */
81    //@{   
82    DOMRange() {};
83    //@}
84
85private:
86    // -----------------------------------------------------------------------
87    // Unimplemented constructors and operators
88    // -----------------------------------------------------------------------
89    /** @name Unimplemented constructors and operators */
90    //@{
91    DOMRange(const DOMRange &);
92    DOMRange & operator = (const DOMRange &);
93    //@}
94
95public:
96    // -----------------------------------------------------------------------
97    //  All constructors are hidden, just the destructor is available
98    // -----------------------------------------------------------------------
99    /** @name Destructor */
100    //@{
101    /**
102     * Destructor
103     *
104     */
105    virtual ~DOMRange() {};
106    //@}
107
108    // -----------------------------------------------------------------------
109    //  Class Types
110    // -----------------------------------------------------------------------
111    /** @name Public Contants */
112    //@{
113    /**
114     * Constants CompareHow.
115     *
116     * <p><code>START_TO_START:</code>
117     * Compare start boundary-point of <code>sourceRange</code> to start
118     * boundary-point of Range on which <code>compareBoundaryPoints</code>
119     * is invoked.</p>
120     *
121     * <p><code>START_TO_END:</code>
122     * Compare start boundary-point of <code>sourceRange</code> to end
123     * boundary-point of Range on which <code>compareBoundaryPoints</code>
124     * is invoked.</p>
125     *
126     * <p><code>END_TO_END:</code>
127     * Compare end boundary-point of <code>sourceRange</code> to end
128     * boundary-point of Range on which <code>compareBoundaryPoints</code>
129     * is invoked.</p>
130     *
131     * <p><code>END_TO_START:</code>
132     * Compare end boundary-point of <code>sourceRange</code> to start
133     * boundary-point of Range on which <code>compareBoundaryPoints</code>
134     * is invoked.</p>
135     *
136     * @since DOM Level 2
137     */
138    enum CompareHow {
139        START_TO_START  = 0,
140        START_TO_END    = 1,
141        END_TO_END      = 2,
142        END_TO_START    = 3
143    };
144
145    //@}
146
147    // -----------------------------------------------------------------------
148    //  Virtual DOMRange interface
149    // -----------------------------------------------------------------------
150    /** @name Functions introduced in DOM Level 2 */
151    //@{
152    // -----------------------------------------------------------------------
153    //  Getter methods
154    // -----------------------------------------------------------------------
155    /**
156     * DOMNode within which the Range begins
157     * @exception DOMException
158     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
159     *   invoked on this object.
160     *
161     * @since DOM Level 2
162     */
163    virtual DOMNode* getStartContainer() const = 0;
164
165    /**
166     * Offset within the starting node of the Range.
167     * @exception DOMException
168     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
169     *   invoked on this object.
170     *
171     * @since DOM Level 2
172     */
173    virtual XMLSize_t getStartOffset() const = 0;
174
175    /**
176     * DOMNode within which the Range ends
177     * @exception DOMException
178     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
179     *   invoked on this object.
180     *
181     * @since DOM Level 2
182     */
183    virtual DOMNode* getEndContainer() const = 0;
184
185    /**
186     * Offset within the ending node of the Range.
187     * @exception DOMException
188     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
189     *   invoked on this object.
190     *
191     * @since DOM Level 2
192     */
193    virtual XMLSize_t getEndOffset() const = 0;
194
195    /**
196     * TRUE if the Range is collapsed
197     * @exception DOMException
198     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
199     *   invoked on this object.
200     *
201     * @since DOM Level 2
202     */
203    virtual bool getCollapsed() const = 0;
204
205    /**
206     * The deepest common ancestor container of the Range's two
207     * boundary-points.
208     * @exception DOMException
209     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
210     *   invoked on this object.
211     *
212     * @since DOM Level 2
213     */
214    virtual const DOMNode* getCommonAncestorContainer() const = 0;
215
216    // -----------------------------------------------------------------------
217    //  Setter methods
218    // -----------------------------------------------------------------------
219    /**
220     * Sets the attributes describing the start of the Range.
221     * @param refNode The <code>refNode</code> value. This parameter must be
222     *   different from <code>null</code>.
223     * @param offset The <code>startOffset</code> value.
224     * @exception DOMRangeException
225     *   INVALID_NODE_TYPE_ERR: Raised if <code>refNode</code> or an ancestor
226     *   of <code>refNode</code> is an DOMEntity, DOMNotation, or DOMDocumentType
227     *   node.
228     * @exception DOMException
229     *   INDEX_SIZE_ERR: Raised if <code>offset</code> is negative or greater
230     *   than the number of child units in <code>refNode</code>. Child units
231     *   are 16-bit units if <code>refNode</code> is a type of DOMCharacterData
232     *   node (e.g., a DOMText or DOMComment node) or a DOMProcessingInstruction
233     *   node. Child units are Nodes in all other cases.
234     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
235     *   been invoked on this object.
236     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
237     *   from a different document than the one that created this range.
238     *
239     * @since DOM Level 2
240     */
241    virtual void setStart(const DOMNode *refNode, XMLSize_t offset) = 0;
242
243    /**
244     * Sets the attributes describing the end of a Range.
245     * @param refNode The <code>refNode</code> value. This parameter must be
246     *   different from <code>null</code>.
247     * @param offset The <code>endOffset</code> value.
248     * @exception DOMRangeException
249     *   INVALID_NODE_TYPE_ERR: Raised if <code>refNode</code> or an ancestor
250     *   of <code>refNode</code> is an DOMEntity, DOMNotation, or DOMDocumentType
251     *   node.
252     * @exception DOMException
253     *   INDEX_SIZE_ERR: Raised if <code>offset</code> is negative or greater
254     *   than the number of child units in <code>refNode</code>. Child units
255     *   are 16-bit units if <code>refNode</code> is a type of DOMCharacterData
256     *   node (e.g., a DOMText or DOMComment node) or a DOMProcessingInstruction
257     *   node. Child units are Nodes in all other cases.
258     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
259     *   been invoked on this object.
260     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
261     *   from a different document than the one that created this range.
262     *
263     * @since DOM Level 2
264     */
265    virtual void setEnd(const DOMNode *refNode, XMLSize_t offset) = 0;
266
267    /**
268     * Sets the start position to be before a node
269     * @param refNode Range starts before <code>refNode</code>
270     * @exception DOMRangeException
271     *   INVALID_NODE_TYPE_ERR: Raised if the root container of
272     *   <code>refNode</code> is not an DOMAttr, DOMDocument, or DOMDocumentFragment
273     *   node or if <code>refNode</code> is a DOMDocument, DOMDocumentFragment,
274     *   DOMAttr, DOMEntity, or DOMNotation node.
275     * @exception DOMException
276     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
277     *   invoked on this object.
278     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
279     *   from a different document than the one that created this range.
280     *
281     * @since DOM Level 2
282     */
283    virtual void setStartBefore(const DOMNode *refNode) = 0;
284
285    /**
286     * Sets the start position to be after a node
287     * @param refNode Range starts after <code>refNode</code>
288     * @exception DOMRangeException
289     *   INVALID_NODE_TYPE_ERR: Raised if the root container of
290     *   <code>refNode</code> is not an DOMAttr, DOMDocument, or DOMDocumentFragment
291     *   node or if <code>refNode</code> is a DOMDocument, DOMDocumentFragment,
292     *   DOMAttr, DOMEntity, or DOMNotation node.
293     * @exception DOMException
294     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
295     *   invoked on this object.
296     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
297     *   from a different document than the one that created this range.
298     *
299     * @since DOM Level 2
300     */
301    virtual void setStartAfter(const DOMNode *refNode) = 0;
302
303    /**
304     * Sets the end position to be before a node.
305     * @param refNode Range ends before <code>refNode</code>
306     * @exception DOMRangeException
307     *   INVALID_NODE_TYPE_ERR: Raised if the root container of
308     *   <code>refNode</code> is not an DOMAttr, DOMDocument, or DOMDocumentFragment
309     *   node or if <code>refNode</code> is a DOMDocument, DOMDocumentFragment,
310     *   DOMAttr, DOMEntity, or DOMNotation node.
311     * @exception DOMException
312     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
313     *   invoked on this object.
314     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
315     *   from a different document than the one that created this range.
316     *
317     * @since DOM Level 2
318     */
319    virtual void setEndBefore(const DOMNode *refNode) = 0;
320
321    /**
322     * Sets the end of a Range to be after a node
323     * @param refNode Range ends after <code>refNode</code>.
324     * @exception DOMRangeException
325     *   INVALID_NODE_TYPE_ERR: Raised if the root container of
326     *   <code>refNode</code> is not a DOMAttr, DOMDocument or DOMDocumentFragment
327     *   node or if <code>refNode</code> is a DOMDocument, DOMDocumentFragment,
328     *   DOMAttr, DOMEntity, or DOMNotation node.
329     * @exception DOMException
330     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
331     *   invoked on this object.
332     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
333     *   from a different document than the one that created this range.
334     *
335     * @since DOM Level 2
336     */
337    virtual void setEndAfter(const DOMNode *refNode) = 0;
338
339    // -----------------------------------------------------------------------
340    //  Misc methods
341    // -----------------------------------------------------------------------
342    /**
343     * Collapse a Range onto one of its boundary-points
344     * @param toStart If TRUE, collapses the Range onto its start; if FALSE,
345     *   collapses it onto its end.
346     * @exception DOMException
347     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
348     *   invoked on this object.
349     *
350     * @since DOM Level 2
351     */
352    virtual void collapse(bool toStart) = 0;
353
354    /**
355     * Select a node and its contents
356     * @param refNode The node to select.
357     * @exception DOMRangeException
358     *   INVALID_NODE_TYPE_ERR: Raised if an ancestor of <code>refNode</code>
359     *   is an DOMEntity, DOMNotation or DOMDocumentType node or if
360     *   <code>refNode</code> is a DOMDocument, DOMDocumentFragment, DOMAttr, DOMEntity,
361     *   or DOMNotation node.
362     * @exception DOMException
363     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
364     *   invoked on this object.
365     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
366     *   from a different document than the one that created this range.
367     *
368     * @since DOM Level 2
369     */
370    virtual void selectNode(const DOMNode *refNode) = 0;
371
372    /**
373     * Select the contents within a node
374     * @param refNode DOMNode to select from
375     * @exception DOMRangeException
376     *   INVALID_NODE_TYPE_ERR: Raised if <code>refNode</code> or an ancestor
377     *   of <code>refNode</code> is an DOMEntity, DOMNotation or DOMDocumentType node.
378     * @exception DOMException
379     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
380     *   invoked on this object.
381     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
382     *   from a different document than the one that created this range.
383     *
384     * @since DOM Level 2
385     */
386    virtual void selectNodeContents(const DOMNode *refNode) = 0;
387
388    /**
389     * Compare the boundary-points of two Ranges in a document.
390     * @param how A code representing the type of comparison, as defined
391     *   above.
392     * @param sourceRange The <code>Range</code> on which this current
393     *   <code>Range</code> is compared to.
394     * @return  -1, 0 or 1 depending on whether the corresponding
395     *   boundary-point of the Range is respectively before, equal to, or
396     *   after the corresponding boundary-point of <code>sourceRange</code>.
397     * @exception DOMException
398     *   WRONG_DOCUMENT_ERR: Raised if the two Ranges are not in the same
399     *   DOMDocument or DOMDocumentFragment.
400     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
401     *   been invoked on this object.
402     *
403     * @since DOM Level 2
404     */
405    virtual short compareBoundaryPoints(CompareHow how, const DOMRange* sourceRange) const = 0;
406
407    /**
408     * Removes the contents of a Range from the containing document or
409     * document fragment without returning a reference to the removed
410     * content.
411     * @exception DOMException
412     *   NO_MODIFICATION_ALLOWED_ERR: Raised if any portion of the content of
413     *   the Range is read-only or any of the nodes that contain any of the
414     *   content of the Range are read-only.
415     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
416     *   been invoked on this object.
417     *
418     * @since DOM Level 2
419     */
420    virtual void deleteContents() = 0;
421
422    /**
423     * Moves the contents of a Range from the containing document or document
424     * fragment to a new DOMDocumentFragment.
425     * @return A DOMDocumentFragment containing the extracted contents.
426     * @exception DOMException
427     *   NO_MODIFICATION_ALLOWED_ERR: Raised if any portion of the content of
428     *   the Range is read-only or any of the nodes which contain any of the
429     *   content of the Range are read-only.
430     *   <br>HIERARCHY_REQUEST_ERR: Raised if a DOMDocumentType node would be
431     *   extracted into the new DOMDocumentFragment.
432     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
433     *   been invoked on this object.
434     *
435     * @since DOM Level 2
436     */
437    virtual DOMDocumentFragment* extractContents() = 0;
438
439    /**
440     * Duplicates the contents of a Range
441     * @return A DOMDocumentFragment that contains content equivalent to this
442     *   Range.
443     * @exception DOMException
444     *   HIERARCHY_REQUEST_ERR: Raised if a DOMDocumentType node would be
445     *   extracted into the new DOMDocumentFragment.
446     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
447     *   been invoked on this object.
448     *
449     * @since DOM Level 2
450     */
451    virtual DOMDocumentFragment* cloneContents() const = 0;
452
453    /**
454     * Inserts a node into the DOMDocument or DOMDocumentFragment at the start of
455     * the Range. If the container is a DOMText node, this will be split at the
456     * start of the Range (as if the DOMText node's splitText method was
457     * performed at the insertion point) and the insertion will occur
458     * between the two resulting DOMText nodes. Adjacent DOMText nodes will not be
459     * automatically merged. If the node to be inserted is a
460     * DOMDocumentFragment node, the children will be inserted rather than the
461     * DOMDocumentFragment node itself.
462     * @param newNode The node to insert at the start of the Range
463     * @exception DOMException
464     *   NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of the
465     *   start of the Range is read-only.
466     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>newNode</code> and the
467     *   container of the start of the Range were not created from the same
468     *   document.
469     *   <br>HIERARCHY_REQUEST_ERR: Raised if the container of the start of
470     *   the Range is of a type that does not allow children of the type of
471     *   <code>newNode</code> or if <code>newNode</code> is an ancestor of
472     *   the container.
473     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
474     *   been invoked on this object.
475     * @exception DOMRangeException
476     *   INVALID_NODE_TYPE_ERR: Raised if <code>newNode</code> is an DOMAttr,
477     *   DOMEntity, DOMNotation, or DOMDocument node.
478     *
479     * @since DOM Level 2
480     */
481    virtual void insertNode(DOMNode *newNode) = 0;
482
483    /**
484     * Reparents the contents of the Range to the given node and inserts the
485     * node at the position of the start of the Range.
486     * @param newParent The node to surround the contents with.
487     * @exception DOMException
488     *   NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of
489     *   either boundary-point of the Range is read-only.
490     *   <br>WRONG_DOCUMENT_ERR: Raised if <code> newParent</code> and the
491     *   container of the start of the Range were not created from the same
492     *   document.
493     *   <br>HIERARCHY_REQUEST_ERR: Raised if the container of the start of
494     *   the Range is of a type that does not allow children of the type of
495     *   <code>newParent</code> or if <code>newParent</code> is an ancestor
496     *   of the container or if <code>node</code> would end up with a child
497     *   node of a type not allowed by the type of <code>node</code>.
498     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
499     *   been invoked on this object.
500     * @exception DOMRangeException
501     *   BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially selects a
502     *   non-text node.
503     *   <br>INVALID_NODE_TYPE_ERR: Raised if <code> node</code> is an DOMAttr,
504     *   DOMEntity, DOMDocumentType, DOMNotation, DOMDocument, or DOMDocumentFragment node.
505     *
506     * @since DOM Level 2
507     */
508    virtual void surroundContents(DOMNode *newParent) = 0;
509
510    /**
511     * Produces a new Range whose boundary-points are equal to the
512     * boundary-points of the Range.
513     * @return The duplicated Range.
514     * @exception DOMException
515     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
516     *   invoked on this object.
517     *
518     * @since DOM Level 2
519     */
520    virtual DOMRange* cloneRange() const = 0;
521
522    /**
523     * Returns the contents of a Range as a string. This string contains only
524     * the data characters, not any markup.
525     * @return The contents of the Range.
526     * @exception DOMException
527     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
528     *   invoked on this object.
529     *
530     * @since DOM Level 2
531     */
532    virtual const XMLCh* toString() const = 0;
533
534    /**
535     * Called to indicate that the Range is no longer in use and that the
536     * implementation may relinquish any resources associated with this
537     * Range. Subsequent calls to any methods or attribute getters on this
538     * Range will result in a <code>DOMException</code> being thrown with an
539     * error code of <code>INVALID_STATE_ERR</code>.
540     * @exception DOMException
541     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
542     *   invoked on this object.
543     *
544     * @since DOM Level 2
545     */
546    virtual void detach() = 0;
547
548    //@}
549
550    // -----------------------------------------------------------------------
551    //  Non-standard Extension
552    // -----------------------------------------------------------------------
553    /** @name Non-standard Extension */
554    //@{
555    /**
556     * Called to indicate that this Range is no longer in use
557     * and that the implementation may relinquish any resources associated with it.
558     * (release() will call detach() where appropriate)
559     *
560     * Access to a released object will lead to unexpected result.
561     */
562    virtual void release() = 0;
563    //@}
564};
565
566
567XERCES_CPP_NAMESPACE_END
568
569#endif
Note: See TracBrowser for help on using the repository browser.