4
* Phoebe DOM Implementation.
6
* This is a C++ approximation of the W3C DOM model, which follows
7
* fairly closely the specifications in the various .idl files, copies of
8
* which are provided for reference. Most important is this one:
10
* http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
15
* Copyright (C) 2005 Bob Jamison
17
* This library is free software; you can redistribute it and/or
18
* modify it under the terms of the GNU Lesser General Public
19
* License as published by the Free Software Foundation; either
20
* version 2.1 of the License, or (at your option) any later version.
22
* This library is distributed in the hope that it will be useful,
23
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
* Lesser General Public License for more details.
27
* You should have received a copy of the GNU Lesser General Public
28
* License along with this library; if not, write to the Free Software
29
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35
#include "traversal.h"
37
#include "io/domstream.h"
51
//The idl said Object. Since this is undefined, we will
52
//use our own class which is designed to be a bit similar to
55
typedef dom::io::InputStream LSInputStream;
56
typedef dom::io::OutputStream LSOutputStream;
57
typedef dom::io::Reader LSReader;
58
typedef dom::io::Writer LSWriter;
62
typedef dom::DOMString DOMString;
63
typedef dom::DOMConfiguration DOMConfiguration;
64
typedef dom::Node Node;
65
typedef dom::NodePtr NodePtr;
66
typedef dom::Document Document;
67
typedef dom::DocumentPtr DocumentPtr;
68
typedef dom::Element Element;
69
typedef dom::ElementPtr ElementPtr;
72
//forward declarations
78
class LSSerializerFilter;
82
/*#########################################################################
84
#########################################################################*/
87
* Maybe this should inherit from DOMException?
94
LSException(const DOMString &reasonMsg)
97
LSException(short theCode)
102
virtual ~LSException() throw()
116
* Get a string, translated from the code.
117
* Like std::exception. Not in spec.
120
{ return msg.c_str(); }
134
} XPathExceptionCode;
137
/*#########################################################################
139
#########################################################################*/
148
// Constants returned by startElement and acceptNode
161
virtual unsigned short startElement(const ElementPtr elementArg) =0;
166
virtual unsigned short acceptNode(const NodePtr nodeArg) =0;
171
virtual unsigned long getWhatToShow() =0;
180
virtual ~LSParserFilter() {}
186
/*#########################################################################
188
#########################################################################*/
200
virtual LSReader *getCharacterStream() const
201
{ return characterStream; }
206
virtual void setCharacterStream(const LSReader *val)
207
{ characterStream = (LSReader *)val; }
212
virtual LSInputStream *getByteStream() const
213
{ return byteStream; }
218
virtual void setByteStream(const LSInputStream *val)
219
{ byteStream = (LSInputStream *)val; }
224
virtual DOMString getStringData() const
225
{ return stringData; }
230
virtual void setStringData(const DOMString &val)
231
{ stringData = val; }
236
virtual DOMString getSystemId() const
242
virtual void setSystemId(const DOMString &val)
248
virtual DOMString getPublicId() const
254
virtual void setPublicId(const DOMString &val)
260
virtual DOMString getBaseURI() const
266
virtual void setBaseURI(const DOMString &val)
272
virtual DOMString getEncoding() const
278
virtual void setEncoding(const DOMString &val)
284
virtual bool getCertifiedText() const
285
{ return certifiedText; }
290
virtual void setCertifiedText(bool val)
291
{ certifiedText = val; }
303
characterStream = NULL;
310
certifiedText = false;
318
LSInput(const LSInput &other)
320
characterStream = other.characterStream;
321
byteStream = other.byteStream;
322
stringData = other.stringData;
323
systemId = other.systemId;
324
publicId = other.publicId;
325
baseURI = other.baseURI;
326
encoding = other.encoding;
327
certifiedText = other.certifiedText;
338
LSReader *characterStream;
339
LSInputStream *byteStream;
340
DOMString stringData;
351
/*#########################################################################
353
#########################################################################*/
366
virtual DOMConfiguration *getDomConfig()
372
virtual LSParserFilter *getFilter()
378
virtual void setFilter(const LSParserFilter *val)
379
{ filter = (LSParserFilter *)val; }
384
virtual bool getAsync()
390
virtual bool getBusy()
396
virtual DocumentPtr parse(const LSInput &/*input*/)
397
throw(dom::DOMException, LSException)
404
virtual DocumentPtr parseURI(const DOMString &/*uri*/)
405
throw(dom::DOMException, LSException)
410
ACTION_APPEND_AS_CHILDREN = 1,
411
ACTION_REPLACE_CHILDREN = 2,
412
ACTION_INSERT_BEFORE = 3,
413
ACTION_INSERT_AFTER = 4,
421
virtual NodePtr parseWithContext(const LSInput &/*input*/,
422
const NodePtr /*contextArg*/,
423
unsigned short /*action*/)
424
throw(dom::DOMException, LSException)
450
LSParser(const LSParser &other)
452
filter = other.filter;
458
virtual ~LSParser() {}
462
LSParserFilter *filter;
467
/*#########################################################################
468
## LSResourceResolver
469
#########################################################################*/
474
class LSResourceResolver
481
virtual LSInput resolveResource(const DOMString &/*type*/,
482
const DOMString &/*namespaceURI*/,
483
const DOMString &/*publicId*/,
484
const DOMString &/*systemId*/,
485
const DOMString &/*baseURI*/)
499
LSResourceResolver() {}
504
LSResourceResolver(const LSResourceResolver &/*other*/)
511
virtual ~LSResourceResolver() {}
517
/*#########################################################################
519
#########################################################################*/
531
virtual LSWriter *getCharacterStream() const
532
{ return characterStream; }
537
virtual void setCharacterStream(const LSWriter *val)
538
{ characterStream = (LSWriter *)val; }
543
virtual LSOutputStream *getByteStream() const
544
{ return byteStream; }
549
virtual void setByteStream(const LSOutputStream *val)
550
{ byteStream = (LSOutputStream *) val; }
555
virtual DOMString getSystemId() const
561
virtual void setSystemId(const DOMString &val)
567
virtual DOMString getEncoding() const
573
virtual void setEncoding(const DOMString &val)
586
characterStream = NULL;
596
LSOutput(const LSOutput &other)
598
characterStream = other.characterStream;
599
byteStream = other.byteStream;
600
systemId = other.systemId;
601
encoding = other.encoding;
612
LSWriter *characterStream;
613
LSOutputStream *byteStream;
620
/*#########################################################################
622
#########################################################################*/
634
virtual DOMConfiguration *getDomConfig()
640
virtual DOMString getNewLine()
645
virtual void setNewLine(const DOMString &val)
651
virtual LSSerializerFilter *getFilter()
657
virtual void setFilter(const LSSerializerFilter *val)
658
{ filter = (LSSerializerFilter *)val; }
663
virtual bool write(const NodePtr /*nodeArg*/,
664
const LSOutput &/*destination*/)
671
virtual bool writeToURI(const NodePtr /*nodeArg*/,
672
const DOMString &/*uri*/)
679
virtual DOMString writeToString(const NodePtr /*nodeArg*/)
680
throw(dom::DOMException, LSException)
702
LSSerializer(const LSSerializer &other)
704
filter = other.filter;
705
newLine = other.newLine;
711
virtual ~LSSerializer() {}
715
LSSerializerFilter *filter;
720
/*#########################################################################
722
#########################################################################*/
727
class LSProgressEvent : virtual public events::Event
734
virtual LSInput &getInput()
742
virtual unsigned long getPosition()
748
virtual unsigned long getTotalSize()
749
{ return totalSize; }
758
LSProgressEvent(const LSInput &inputArg, unsigned long positionArg,
759
unsigned long totalSizeArg) : input((LSInput &)inputArg)
761
position = positionArg;
762
totalSize = totalSizeArg;
769
LSProgressEvent(const LSProgressEvent &other)
770
: events::Event(other) , input(other.input)
772
position = other.position;
773
totalSize = other.totalSize;
780
virtual ~LSProgressEvent() {}
785
unsigned long position;
786
unsigned long totalSize;
790
/*#########################################################################
792
#########################################################################*/
797
class LSLoadEvent : public events::Event
804
virtual DocumentPtr getNewDocument()
805
{ return newDocument; }
810
virtual LSInput &getInput()
820
LSLoadEvent(const LSInput &inputArg,
821
const DocumentPtr docArg)
822
: input((LSInput &)inputArg)
823
{ newDocument = docArg; }
828
LSLoadEvent(const LSLoadEvent &other)
829
: events::Event(other) , input(other.input)
831
newDocument = other.newDocument;
837
virtual ~LSLoadEvent() {}
841
DocumentPtr newDocument;
850
/*#########################################################################
851
## LSSerializerFilter
852
#########################################################################*/
857
class LSSerializerFilter : virtual public traversal::NodeFilter
864
virtual unsigned long getWhatToShow() =0;
873
virtual ~LSSerializerFilter() {}
879
/*#########################################################################
880
## DOMImplementationLS
881
#########################################################################*/
886
class DOMImplementationLS
892
MODE_SYNCHRONOUS = 1,
893
MODE_ASYNCHRONOUS = 2
894
} DOMImplementationLSMode;
897
* To use, for this and subclasses:
898
* LSParser &parser = myImplementation.createLSParser(mode, schemaType);
900
virtual LSParser &createLSParser(unsigned short mode,
901
const DOMString &schemaType)
902
throw (dom::DOMException) =0;
905
* To use, for this and subclasses:
906
* LSSerializer &serializer = myImplementation.createLSSerializer();
909
virtual LSSerializer &createLSSerializer() =0;
914
virtual LSInput createLSInput() =0;
919
virtual LSOutput createLSOutput() =0;
928
virtual ~DOMImplementationLS() {}
942
/*#########################################################################
944
#########################################################################*/