Code

Extensions. Check element now search in the extension directory (see Bug #668895...
[inkscape.git] / src / dom / ls.h
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 "io/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::io::InputStream  LSInputStream;
56 typedef dom::io::OutputStream LSOutputStream;
57 typedef dom::io::Reader       LSReader;
58 typedef dom::io::Writer       LSWriter;
61 //local definitions
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
73 class LSParser;
74 class LSSerializer;
75 class LSInput;
76 class LSOutput;
77 class LSParserFilter;
78 class LSSerializerFilter;
82 /*#########################################################################
83 ## LSException
84 #########################################################################*/
86 /**
87  *  Maybe this should inherit from DOMException?
88  */
89 class LSException
90 {
92 public:
94     LSException(const DOMString &reasonMsg)
95         { msg = reasonMsg; }
97     LSException(short theCode)
98         {
99         code = theCode;
100         }
102     virtual ~LSException() throw()
103        {}
105     /**
106      *
107      */
108     unsigned short code;
110     /**
111      *
112      */
113     DOMString msg;
115     /**
116      * Get a string, translated from the code.
117      * Like std::exception. Not in spec.
118      */
119     const char *what()
120         { return msg.c_str(); }
124 };
127 /**
128  * LSExceptionCode
129  */
130 typedef enum
131     {
132     PARSE_ERR                      = 81,
133     SERIALIZE_ERR                  = 82
134     } XPathExceptionCode;
137 /*#########################################################################
138 ## LSParserFilter
139 #########################################################################*/
141 /**
142  *
143  */
144 class LSParserFilter
146 public:
148     // Constants returned by startElement and acceptNode
149     typedef enum
150         {
151         FILTER_ACCEPT                  = 1,
152         FILTER_REJECT                  = 2,
153         FILTER_SKIP                    = 3,
154         FILTER_INTERRUPT               = 4
155         } ReturnValues;
158     /**
159      *
160      */
161     virtual unsigned short startElement(const ElementPtr elementArg) =0;
163     /**
164      *
165      */
166     virtual unsigned short acceptNode(const NodePtr nodeArg) =0;
168     /**
169      *
170      */
171     virtual unsigned long getWhatToShow() =0;
173     //##################
174     //# Non-API methods
175     //##################
177     /**
178      *
179      */
180     virtual ~LSParserFilter() {}
184 };
186 /*#########################################################################
187 ## LSInput
188 #########################################################################*/
190 /**
191  *
192  */
193 class LSInput
195 public:
197     /**
198      *
199      */
200     virtual LSReader *getCharacterStream() const
201         { return characterStream; }
203     /**
204      *
205      */
206     virtual void setCharacterStream(const LSReader *val)
207         { characterStream = (LSReader *)val; }
209     /**
210      *
211      */
212     virtual LSInputStream *getByteStream() const
213         { return byteStream; }
215     /**
216      *
217      */
218     virtual void setByteStream(const LSInputStream *val)
219         { byteStream =  (LSInputStream *)val; }
221     /**
222      *
223      */
224     virtual DOMString getStringData() const
225         { return stringData; }
227     /**
228      *
229      */
230     virtual void setStringData(const DOMString &val)
231         { stringData = val; }
233     /**
234      *
235      */
236     virtual DOMString getSystemId() const
237         { return systemId; }
239     /**
240      *
241      */
242     virtual void setSystemId(const DOMString &val)
243         { systemId = val; }
245     /**
246      *
247      */
248     virtual DOMString getPublicId() const
249         { return publicId; }
251     /**
252      *
253      */
254     virtual void setPublicId(const DOMString &val)
255         { publicId = val; }
257     /**
258      *
259      */
260     virtual DOMString getBaseURI() const
261         { return baseURI; }
263     /**
264      *
265      */
266     virtual void setBaseURI(const DOMString &val)
267         { baseURI = val; }
269     /**
270      *
271      */
272     virtual DOMString getEncoding() const
273         { return encoding; }
275     /**
276      *
277      */
278     virtual void setEncoding(const DOMString &val)
279         { encoding = val; }
281     /**
282      *
283      */
284     virtual bool getCertifiedText() const
285         { return certifiedText; }
287     /**
288      *
289      */
290     virtual void setCertifiedText(bool val)
291         { certifiedText = val; }
293     //##################
294     //# Non-API methods
295     //##################
298     /**
299      *
300      */
301     LSInput()
302         {
303         characterStream = NULL;
304         byteStream      = NULL;
305         stringData      = "";
306         systemId        = "";
307         publicId        = "";
308         baseURI         = "";
309         encoding        = "";
310         certifiedText   = false;
311         }
315     /**
316      *
317      */
318     LSInput(const LSInput &other)
319         {
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;
328         }
330     /**
331      *
332      */
333     virtual ~LSInput()
334         {}
336 private:
338     LSReader      *characterStream;
339     LSInputStream *byteStream;
340     DOMString     stringData;
341     DOMString     systemId;
342     DOMString     publicId;
343     DOMString     baseURI;
344     DOMString     encoding;
345     bool          certifiedText;
348 };
351 /*#########################################################################
352 ## LSParser
353 #########################################################################*/
355 /**
356  *
357  */
358 class LSParser
360 public:
363     /**
364      *
365      */
366     virtual DOMConfiguration *getDomConfig()
367         { return NULL; }
369     /**
370      *
371      */
372     virtual LSParserFilter *getFilter()
373         { return filter; }
375     /**
376      *
377      */
378     virtual void setFilter(const LSParserFilter *val)
379         { filter = (LSParserFilter *)val; }
381     /**
382      *
383      */
384     virtual bool getAsync()
385         { return false; }
387     /**
388      *
389      */
390     virtual bool getBusy()
391         { return false; }
393     /**
394      *
395      */
396     virtual DocumentPtr parse(const LSInput &/*input*/)
397                               throw(dom::DOMException, LSException)
398         { return NULL; }
401     /**
402      *
403      */
404     virtual DocumentPtr parseURI(const DOMString &/*uri*/)
405                                  throw(dom::DOMException, LSException)
406         { return NULL; }
408     typedef enum
409         {
410         ACTION_APPEND_AS_CHILDREN      = 1,
411         ACTION_REPLACE_CHILDREN        = 2,
412         ACTION_INSERT_BEFORE           = 3,
413         ACTION_INSERT_AFTER            = 4,
414         ACTION_REPLACE                 = 5
415         } ActionTypes;
418     /**
419      *
420      */
421     virtual NodePtr parseWithContext(const LSInput &/*input*/,
422                                      const NodePtr /*contextArg*/,
423                                      unsigned short /*action*/)
424                                      throw(dom::DOMException, LSException)
425         { return NULL; }
427     /**
428      *
429      */
430     virtual void abort()
431         {}
435     //##################
436     //# Non-API methods
437     //##################
439     /**
440      *
441      */
442     LSParser()
443         {
444         filter = NULL;
445         }
447     /**
448      *
449      */
450     LSParser(const LSParser &other)
451         {
452         filter = other.filter;
453         }
455     /**
456      *
457      */
458     virtual ~LSParser() {}
460 protected:
462     LSParserFilter *filter;
463 };
467 /*#########################################################################
468 ## LSResourceResolver
469 #########################################################################*/
471 /**
472  *
473  */
474 class LSResourceResolver
476 public:
478     /**
479      *
480      */
481     virtual LSInput resolveResource(const DOMString &/*type*/,
482                                     const DOMString &/*namespaceURI*/,
483                                     const DOMString &/*publicId*/,
484                                     const DOMString &/*systemId*/,
485                                     const DOMString &/*baseURI*/)
486         {
487         LSInput input;
488         //do something
489         return input;
490         }
492     //##################
493     //# Non-API methods
494     //##################
496     /**
497      *
498      */
499     LSResourceResolver() {}
501     /**
502      *
503      */
504     LSResourceResolver(const LSResourceResolver &/*other*/)
505         {
506         }
508     /**
509      *
510      */
511     virtual ~LSResourceResolver() {}
515 };
517 /*#########################################################################
518 ## LSOutput
519 #########################################################################*/
521 /**
522  *
523  */
524 class LSOutput
526 public:
528     /**
529      *
530      */
531     virtual LSWriter *getCharacterStream() const
532         { return characterStream; }
534     /**
535      *
536      */
537     virtual void setCharacterStream(const LSWriter *val)
538         { characterStream = (LSWriter *)val; }
540     /**
541      *
542      */
543     virtual LSOutputStream *getByteStream() const
544         { return byteStream; }
546     /**
547      *
548      */
549     virtual void setByteStream(const LSOutputStream *val)
550         { byteStream = (LSOutputStream *) val; }
552     /**
553      *
554      */
555     virtual DOMString getSystemId() const
556         { return systemId; }
558     /**
559      *
560      */
561     virtual void setSystemId(const DOMString &val)
562         { systemId = val; }
564     /**
565      *
566      */
567     virtual DOMString getEncoding() const
568         { return encoding; }
570     /**
571      *
572      */
573     virtual void setEncoding(const DOMString &val)
574         { encoding = val; }
577     //##################
578     //# Non-API methods
579     //##################
581     /**
582      *
583      */
584     LSOutput()
585         {
586         characterStream = NULL;
587         byteStream      = NULL;
588         systemId        = "";
589         encoding        = "";
590         }
593     /**
594      *
595      */
596     LSOutput(const LSOutput &other)
597         {
598         characterStream = other.characterStream;
599         byteStream      = other.byteStream;
600         systemId        = other.systemId;
601         encoding        = other.encoding;
602         }
604     /**
605      *
606      */
607     virtual ~LSOutput()
608         {}
610 private:
612     LSWriter       *characterStream;
613     LSOutputStream *byteStream;
614     DOMString      systemId;
615     DOMString      encoding;
617 };
620 /*#########################################################################
621 ## LSSerializer
622 #########################################################################*/
624 /**
625  *
626  */
627 class LSSerializer
629 public:
631     /**
632      *
633      */
634     virtual DOMConfiguration *getDomConfig()
635         { return NULL; }
637     /**
638      *
639      */
640     virtual DOMString getNewLine()
641         { return newLine; }
642     /**
643      *
644      */
645     virtual void setNewLine(const DOMString &val)
646         { newLine = val; }
648     /**
649      *
650      */
651     virtual LSSerializerFilter *getFilter()
652         { return filter; }
654     /**
655      *
656      */
657     virtual void setFilter(const LSSerializerFilter *val)
658         { filter = (LSSerializerFilter *)val; }
660     /**
661      *
662      */
663     virtual bool write(const NodePtr /*nodeArg*/,
664                        const LSOutput &/*destination*/)
665                        throw (LSException)
666         { return false; }
668     /**
669      *
670      */
671     virtual bool writeToURI(const NodePtr /*nodeArg*/,
672                             const DOMString &/*uri*/)
673                             throw(LSException)
674         { return false; }
676     /**
677      *
678      */
679     virtual DOMString writeToString(const NodePtr /*nodeArg*/)
680                                     throw(dom::DOMException, LSException)
681         {
682         DOMString str;
683         return str;
684         }
686     //##################
687     //# Non-API methods
688     //##################
690     /**
691      *
692      */
693     LSSerializer()
694        {
695        filter  = NULL;
696        newLine = "\n";
697        }
699     /**
700      *
701      */
702     LSSerializer(const LSSerializer &other)
703        {
704        filter  = other.filter;
705        newLine = other.newLine;
706        }
708     /**
709      *
710      */
711     virtual ~LSSerializer() {}
713 protected:
715     LSSerializerFilter *filter;
716     DOMString newLine;
718 };
720 /*#########################################################################
721 ## LSProgressEvent
722 #########################################################################*/
724 /**
725  *
726  */
727 class LSProgressEvent : virtual public events::Event
729 public:
731     /**
732      *
733      */
734     virtual LSInput &getInput()
735         {
736         return input;
737         }
739     /**
740      *
741      */
742     virtual unsigned long getPosition()
743         { return position; }
745     /**
746      *
747      */
748     virtual unsigned long getTotalSize()
749         { return totalSize; }
751     //##################
752     //# Non-API methods
753     //##################
755     /**
756      *
757      */
758     LSProgressEvent(const LSInput &inputArg, unsigned long positionArg,
759                     unsigned long totalSizeArg) : input((LSInput &)inputArg)
760         {
761         position  = positionArg;
762         totalSize = totalSizeArg;
763         }
766     /**
767      *
768      */
769     LSProgressEvent(const LSProgressEvent &other)
770                 : events::Event(other) , input(other.input)
771         {
772         position  = other.position;
773         totalSize = other.totalSize;
774         }
777     /**
778      *
779      */
780     virtual ~LSProgressEvent() {}
782 protected:
784     LSInput &input;
785     unsigned long position;
786     unsigned long totalSize;
788 };
790 /*#########################################################################
791 ## LSLoadEvent
792 #########################################################################*/
794 /**
795  *
796  */
797 class LSLoadEvent : public events::Event
799 public:
801     /**
802      *
803      */
804     virtual DocumentPtr getNewDocument()
805         { return newDocument; }
807     /**
808      *
809      */
810     virtual LSInput &getInput()
811         { return input; }
813     //##################
814     //# Non-API methods
815     //##################
817     /**
818      *
819      */
820     LSLoadEvent(const LSInput &inputArg,
821                     const DocumentPtr docArg)
822                   : input((LSInput &)inputArg)
823         { newDocument = docArg; }
825     /**
826      *
827      */
828     LSLoadEvent(const LSLoadEvent &other) 
829                : events::Event(other) , input(other.input)
830         {
831         newDocument = other.newDocument;
832         }
834     /**
835      *
836      */
837     virtual ~LSLoadEvent() {}
839 protected:
841     DocumentPtr newDocument;
843     LSInput &input;
846 };
850 /*#########################################################################
851 ## LSSerializerFilter
852 #########################################################################*/
854 /**
855  *
856  */
857 class LSSerializerFilter : virtual public traversal::NodeFilter
859 public:
861     /**
862      *
863      */
864     virtual unsigned long  getWhatToShow() =0;
866     //##################
867     //# Non-API methods
868     //##################
870     /**
871      *
872      */
873     virtual ~LSSerializerFilter() {}
874 };
879 /*#########################################################################
880 ## DOMImplementationLS
881 #########################################################################*/
883 /**
884  *
885  */
886 class DOMImplementationLS
888 public:
890     typedef enum
891         {
892         MODE_SYNCHRONOUS               = 1,
893         MODE_ASYNCHRONOUS              = 2
894         } DOMImplementationLSMode;
896     /**
897      * To use, for this and subclasses:
898      *  LSParser &parser = myImplementation.createLSParser(mode, schemaType);
899      */
900     virtual LSParser &createLSParser(unsigned short mode,
901                                     const DOMString &schemaType)
902                                     throw (dom::DOMException) =0;
904     /**
905      * To use, for this and subclasses:
906      *  LSSerializer &serializer = myImplementation.createLSSerializer();
907      *
908      */
909     virtual LSSerializer &createLSSerializer() =0;
911     /**
912      *
913      */
914     virtual LSInput createLSInput() =0;
916     /**
917      *
918      */
919     virtual LSOutput createLSOutput() =0;
921     //##################
922     //# Non-API methods
923     //##################
925     /**
926      *
927      */
928     virtual ~DOMImplementationLS() {}
929 };
934 }  //namespace ls
935 }  //namespace dom
936 }  //namespace w3c
937 }  //namespace org
940 #endif // __LS_H__
942 /*#########################################################################
943 ## E N D    O F    F I L E
944 #########################################################################*/