1 #ifndef __LS_H__
2 #define __LS_H__
3 /**
4 * Phoebe DOM Implementation.
5 *
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:
9 *
10 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
11 *
12 * Authors:
13 * Bob Jamison
14 *
15 * Copyright (C) 2005 Bob Jamison
16 *
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.
21 *
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.
26 *
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
30 */
33 #include "dom.h"
34 #include "events.h"
35 #include "traversal.h"
37 #include "domstream.h"
39 namespace org
40 {
41 namespace w3c
42 {
43 namespace dom
44 {
45 namespace ls
46 {
50 //Local definitions
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
53 //java.io streams
55 typedef dom::InputStream LSInputStream;
56 typedef dom::OutputStream LSOutputStream;
57 typedef dom::Reader LSReader;
58 typedef dom::Writer LSWriter;
61 //local definitions
62 typedef dom::DOMString DOMString;
63 typedef dom::DOMConfiguration DOMConfiguration;
64 typedef dom::Node Node;
65 typedef dom::Document Document;
66 typedef dom::Element Element;
69 //forward declarations
70 class LSParser;
71 class LSSerializer;
72 class LSInput;
73 class LSOutput;
74 class LSParserFilter;
75 class LSSerializerFilter;
79 /*#########################################################################
80 ## LSException
81 #########################################################################*/
83 /**
84 * Maybe this should inherit from DOMException?
85 */
86 class LSException
87 {
89 public:
91 LSException(const DOMString &reasonMsg)
92 { msg = reasonMsg; }
94 LSException(short theCode)
95 {
96 code = theCode;
97 }
99 virtual ~LSException() throw()
100 {}
102 /**
103 *
104 */
105 unsigned short code;
107 /**
108 *
109 */
110 DOMString msg;
112 /**
113 * Get a string, translated from the code.
114 * Like std::exception. Not in spec.
115 */
116 const char *what()
117 { return msg.c_str(); }
121 };
124 /**
125 * LSExceptionCode
126 */
127 typedef enum
128 {
129 PARSE_ERR = 81,
130 SERIALIZE_ERR = 82
131 } XPathExceptionCode;
134 /*#########################################################################
135 ## LSParserFilter
136 #########################################################################*/
138 /**
139 *
140 */
141 class LSParserFilter
142 {
143 public:
145 // Constants returned by startElement and acceptNode
146 typedef enum
147 {
148 FILTER_ACCEPT = 1,
149 FILTER_REJECT = 2,
150 FILTER_SKIP = 3,
151 FILTER_INTERRUPT = 4
152 } ReturnValues;
155 /**
156 *
157 */
158 virtual unsigned short startElement(const Element *elementArg) =0;
160 /**
161 *
162 */
163 virtual unsigned short acceptNode(const Node *nodeArg) =0;
165 /**
166 *
167 */
168 virtual unsigned long getWhatToShow() =0;
170 //##################
171 //# Non-API methods
172 //##################
174 /**
175 *
176 */
177 virtual ~LSParserFilter() {}
181 };
183 /*#########################################################################
184 ## LSInput
185 #########################################################################*/
187 /**
188 *
189 */
190 class LSInput
191 {
192 public:
194 /**
195 *
196 */
197 virtual LSReader *getCharacterStream() const
198 { return characterStream; }
200 /**
201 *
202 */
203 virtual void setCharacterStream(const LSReader *val)
204 { characterStream = (LSReader *)val; }
206 /**
207 *
208 */
209 virtual LSInputStream *getByteStream() const
210 { return byteStream; }
212 /**
213 *
214 */
215 virtual void setByteStream(const LSInputStream *val)
216 { byteStream = (LSInputStream *)val; }
218 /**
219 *
220 */
221 virtual DOMString getStringData() const
222 { return stringData; }
224 /**
225 *
226 */
227 virtual void setStringData(const DOMString &val)
228 { stringData = val; }
230 /**
231 *
232 */
233 virtual DOMString getSystemId() const
234 { return systemId; }
236 /**
237 *
238 */
239 virtual void setSystemId(const DOMString &val)
240 { systemId = val; }
242 /**
243 *
244 */
245 virtual DOMString getPublicId() const
246 { return publicId; }
248 /**
249 *
250 */
251 virtual void setPublicId(const DOMString &val)
252 { publicId = val; }
254 /**
255 *
256 */
257 virtual DOMString getBaseURI() const
258 { return baseURI; }
260 /**
261 *
262 */
263 virtual void setBaseURI(const DOMString &val)
264 { baseURI = val; }
266 /**
267 *
268 */
269 virtual DOMString getEncoding() const
270 { return encoding; }
272 /**
273 *
274 */
275 virtual void setEncoding(const DOMString &val)
276 { encoding = val; }
278 /**
279 *
280 */
281 virtual bool getCertifiedText() const
282 { return certifiedText; }
284 /**
285 *
286 */
287 virtual void setCertifiedText(bool val)
288 { certifiedText = val; }
290 //##################
291 //# Non-API methods
292 //##################
295 /**
296 *
297 */
298 LSInput()
299 {
300 characterStream = NULL;
301 byteStream = NULL;
302 stringData = "";
303 systemId = "";
304 publicId = "";
305 baseURI = "";
306 encoding = "";
307 certifiedText = false;
308 }
312 /**
313 *
314 */
315 LSInput(const LSInput &other)
316 {
317 characterStream = other.characterStream;
318 byteStream = other.byteStream;
319 stringData = other.stringData;
320 systemId = other.systemId;
321 publicId = other.publicId;
322 baseURI = other.baseURI;
323 encoding = other.encoding;
324 certifiedText = other.certifiedText;
325 }
327 /**
328 *
329 */
330 virtual ~LSInput()
331 {}
333 private:
335 LSReader *characterStream;
336 LSInputStream *byteStream;
337 DOMString stringData;
338 DOMString systemId;
339 DOMString publicId;
340 DOMString baseURI;
341 DOMString encoding;
342 bool certifiedText;
345 };
348 /*#########################################################################
349 ## LSParser
350 #########################################################################*/
352 /**
353 *
354 */
355 class LSParser
356 {
357 public:
360 /**
361 *
362 */
363 virtual DOMConfiguration *getDomConfig()
364 { return NULL; }
366 /**
367 *
368 */
369 virtual LSParserFilter *getFilter()
370 { return filter; }
372 /**
373 *
374 */
375 virtual void setFilter(const LSParserFilter *val)
376 { filter = (LSParserFilter *)val; }
378 /**
379 *
380 */
381 virtual bool getAsync()
382 { return false; }
384 /**
385 *
386 */
387 virtual bool getBusy()
388 { return false; }
390 /**
391 *
392 */
393 virtual Document *parse(const LSInput &input)
394 throw(dom::DOMException, LSException)
395 { return NULL; }
398 /**
399 *
400 */
401 virtual Document *parseURI(const DOMString &uri)
402 throw(dom::DOMException, LSException)
403 { return NULL; }
405 typedef enum
406 {
407 ACTION_APPEND_AS_CHILDREN = 1,
408 ACTION_REPLACE_CHILDREN = 2,
409 ACTION_INSERT_BEFORE = 3,
410 ACTION_INSERT_AFTER = 4,
411 ACTION_REPLACE = 5
412 } ActionTypes;
415 /**
416 *
417 */
418 virtual Node *parseWithContext(const LSInput &input,
419 const Node *contextArg,
420 unsigned short action)
421 throw(dom::DOMException, LSException)
422 { return NULL; }
424 /**
425 *
426 */
427 virtual void abort()
428 {}
432 //##################
433 //# Non-API methods
434 //##################
436 /**
437 *
438 */
439 LSParser()
440 {
441 filter = NULL;
442 }
444 /**
445 *
446 */
447 LSParser(const LSParser &other)
448 {
449 filter = other.filter;
450 }
452 /**
453 *
454 */
455 virtual ~LSParser() {}
457 protected:
459 LSParserFilter *filter;
460 };
464 /*#########################################################################
465 ## LSResourceResolver
466 #########################################################################*/
468 /**
469 *
470 */
471 class LSResourceResolver
472 {
473 public:
475 /**
476 *
477 */
478 virtual LSInput resolveResource(const DOMString &type,
479 const DOMString &namespaceURI,
480 const DOMString &publicId,
481 const DOMString &systemId,
482 const DOMString &baseURI)
483 {
484 LSInput input;
485 //do something
486 return input;
487 }
489 //##################
490 //# Non-API methods
491 //##################
493 /**
494 *
495 */
496 LSResourceResolver() {}
498 /**
499 *
500 */
501 LSResourceResolver(const LSResourceResolver &other)
502 {
503 }
505 /**
506 *
507 */
508 virtual ~LSResourceResolver() {}
512 };
514 /*#########################################################################
515 ## LSOutput
516 #########################################################################*/
518 /**
519 *
520 */
521 class LSOutput
522 {
523 public:
525 /**
526 *
527 */
528 virtual LSWriter *getCharacterStream() const
529 { return characterStream; }
531 /**
532 *
533 */
534 virtual void setCharacterStream(const LSWriter *val)
535 { characterStream = (LSWriter *)val; }
537 /**
538 *
539 */
540 virtual LSOutputStream *getByteStream() const
541 { return byteStream; }
543 /**
544 *
545 */
546 virtual void setByteStream(const LSOutputStream *val)
547 { byteStream = (LSOutputStream *) val; }
549 /**
550 *
551 */
552 virtual DOMString getSystemId() const
553 { return systemId; }
555 /**
556 *
557 */
558 virtual void setSystemId(const DOMString &val)
559 { systemId = val; }
561 /**
562 *
563 */
564 virtual DOMString getEncoding() const
565 { return encoding; }
567 /**
568 *
569 */
570 virtual void setEncoding(const DOMString &val)
571 { encoding = val; }
574 //##################
575 //# Non-API methods
576 //##################
578 /**
579 *
580 */
581 LSOutput()
582 {
583 characterStream = NULL;
584 byteStream = NULL;
585 systemId = "";
586 encoding = "";
587 }
590 /**
591 *
592 */
593 LSOutput(const LSOutput &other)
594 {
595 characterStream = other.characterStream;
596 byteStream = other.byteStream;
597 systemId = other.systemId;
598 encoding = other.encoding;
599 }
601 /**
602 *
603 */
604 virtual ~LSOutput()
605 {}
607 private:
609 LSWriter *characterStream;
610 LSOutputStream *byteStream;
611 DOMString systemId;
612 DOMString encoding;
614 };
617 /*#########################################################################
618 ## LSSerializer
619 #########################################################################*/
621 /**
622 *
623 */
624 class LSSerializer
625 {
626 public:
628 /**
629 *
630 */
631 virtual DOMConfiguration *getDomConfig()
632 { return NULL; }
634 /**
635 *
636 */
637 virtual DOMString getNewLine()
638 { return newLine; }
639 /**
640 *
641 */
642 virtual void setNewLine(const DOMString &val)
643 { newLine = val; }
645 /**
646 *
647 */
648 virtual LSSerializerFilter *getFilter()
649 { return filter; }
651 /**
652 *
653 */
654 virtual void setFilter(const LSSerializerFilter *val)
655 { filter = (LSSerializerFilter *)val; }
657 /**
658 *
659 */
660 virtual bool write(const Node *nodeArg,
661 const LSOutput &destination)
662 throw (LSException)
663 { return false; }
665 /**
666 *
667 */
668 virtual bool writeToURI(const Node *nodeArg,
669 const DOMString &uri)
670 throw(LSException)
671 { return false; }
673 /**
674 *
675 */
676 virtual DOMString writeToString(const Node *nodeArg)
677 throw(dom::DOMException, LSException)
678 {
679 DOMString str;
680 return str;
681 }
683 //##################
684 //# Non-API methods
685 //##################
687 /**
688 *
689 */
690 LSSerializer()
691 {
692 filter = NULL;
693 newLine = "\n";
694 }
696 /**
697 *
698 */
699 LSSerializer(const LSSerializer &other)
700 {
701 filter = other.filter;
702 newLine = other.newLine;
703 }
705 /**
706 *
707 */
708 virtual ~LSSerializer() {}
710 protected:
712 LSSerializerFilter *filter;
713 DOMString newLine;
715 };
717 /*#########################################################################
718 ## LSProgressEvent
719 #########################################################################*/
721 /**
722 *
723 */
724 class LSProgressEvent : virtual public events::Event
725 {
726 public:
728 /**
729 *
730 */
731 virtual LSInput &getInput()
732 {
733 return input;
734 }
736 /**
737 *
738 */
739 virtual unsigned long getPosition()
740 { return position; }
742 /**
743 *
744 */
745 virtual unsigned long getTotalSize()
746 { return totalSize; }
748 //##################
749 //# Non-API methods
750 //##################
752 /**
753 *
754 */
755 LSProgressEvent(const LSInput &inputArg, unsigned long positionArg,
756 unsigned long totalSizeArg) : input((LSInput &)inputArg)
757 {
758 position = positionArg;
759 totalSize = totalSizeArg;
760 }
763 /**
764 *
765 */
766 LSProgressEvent(const LSProgressEvent &other)
767 : events::Event(other) , input(other.input)
768 {
769 position = other.position;
770 totalSize = other.totalSize;
771 }
774 /**
775 *
776 */
777 virtual ~LSProgressEvent() {}
779 protected:
781 LSInput &input;
782 unsigned long position;
783 unsigned long totalSize;
785 };
787 /*#########################################################################
788 ## LSLoadEvent
789 #########################################################################*/
791 /**
792 *
793 */
794 class LSLoadEvent : public events::Event
795 {
796 public:
798 /**
799 *
800 */
801 virtual Document *getNewDocument()
802 { return newDocument; }
804 /**
805 *
806 */
807 virtual LSInput &getInput()
808 { return input; }
810 //##################
811 //# Non-API methods
812 //##################
814 /**
815 *
816 */
817 LSLoadEvent(const LSInput &inputArg, const Document *docArg)
818 : input((LSInput &)inputArg)
819 { newDocument = (Document *)docArg; }
821 /**
822 *
823 */
824 LSLoadEvent(const LSLoadEvent &other) : events::Event(other) , input(other.input)
825 {
826 newDocument = other.newDocument;
827 }
829 /**
830 *
831 */
832 virtual ~LSLoadEvent() {}
834 protected:
836 Document *newDocument;
838 LSInput &input;
841 };
845 /*#########################################################################
846 ## LSSerializerFilter
847 #########################################################################*/
849 /**
850 *
851 */
852 class LSSerializerFilter : virtual public traversal::NodeFilter
853 {
854 public:
856 /**
857 *
858 */
859 virtual unsigned long getWhatToShow() =0;
861 //##################
862 //# Non-API methods
863 //##################
865 /**
866 *
867 */
868 virtual ~LSSerializerFilter() {}
869 };
874 /*#########################################################################
875 ## DOMImplementationLS
876 #########################################################################*/
878 /**
879 *
880 */
881 class DOMImplementationLS
882 {
883 public:
885 typedef enum
886 {
887 MODE_SYNCHRONOUS = 1,
888 MODE_ASYNCHRONOUS = 2
889 } DOMImplementationLSMode;
891 /**
892 * To use, for this and subclasses:
893 * LSParser &parser = myImplementation.createLSParser(mode, schemaType);
894 */
895 virtual LSParser &createLSParser(unsigned short mode,
896 const DOMString &schemaType)
897 throw (dom::DOMException) =0;
899 /**
900 * To use, for this and subclasses:
901 * LSSerializer &serializer = myImplementation.createLSSerializer();
902 *
903 */
904 virtual LSSerializer &createLSSerializer() =0;
906 /**
907 *
908 */
909 virtual LSInput createLSInput() =0;
911 /**
912 *
913 */
914 virtual LSOutput createLSOutput() =0;
916 //##################
917 //# Non-API methods
918 //##################
920 /**
921 *
922 */
923 virtual ~DOMImplementationLS() {}
924 };
929 } //namespace ls
930 } //namespace dom
931 } //namespace w3c
932 } //namespace org
935 #endif // __LS_H__
937 /*#########################################################################
938 ## E N D O F F I L E
939 #########################################################################*/