kviewshell
XMLTags.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef _LT_XMLTAGS__
00058 #define _LT_XMLTAGS__
00059 #ifdef HAVE_CONFIG_H
00060 #include "config.h"
00061 #endif
00062 #if NEED_GNUG_PRAGMAS
00063 # pragma interface
00064 #endif
00065
00066
00067
00068
00069 #include "GContainer.h"
00070 #include "GString.h"
00071
00072 #ifdef HAVE_NAMESPACES
00073 namespace DJVU {
00074 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00075 }
00076 #endif
00077 #endif
00078
00079 class lt_XMLContents;
00080 class DjVuFile;
00081 class DjVuDocument;
00082 class ByteStream;
00083 class XMLByteStream;
00084 class GURL;
00085
00086 class lt_XMLTags : public GPEnabled
00087 {
00088 protected:
00089 lt_XMLTags();
00090 lt_XMLTags(const char n[]);
00091
00092 public:
00094 static GP<lt_XMLTags> create(void) { return new lt_XMLTags; }
00096 static GP<lt_XMLTags> create(const char n[]) { return new lt_XMLTags(n); }
00098 void init(const GURL & url);
00100 static GP<lt_XMLTags> create(const GURL &url);
00102 void init(const GP<ByteStream> &bs);
00104 static GP<lt_XMLTags> create(const GP<ByteStream> &bs);
00106 void init(XMLByteStream &xmlbs);
00108 static GP<lt_XMLTags> create(XMLByteStream &xmlbs);
00110 ~lt_XMLTags();
00111
00112 inline int get_Line(void) const;
00113 inline const GUTF8String& get_raw(void) const;
00114 inline const GUTF8String& get_name(void) const;
00115 inline const GList<lt_XMLContents>& get_content(void) const;
00116 inline const GMap<GUTF8String,GUTF8String>& get_args(void) const;
00117 inline const GMap<GUTF8String,GPList<lt_XMLTags> >& get_allTags(void) const;
00118
00119 GPList<lt_XMLTags> get_Tags(char const tagname[]) const;
00120 inline void set_Line(const int xstartline) { startline=xstartline; }
00121
00122 inline void addtag(GP<lt_XMLTags> x);
00123 inline void addraw(GUTF8String raw);
00124 inline GPosition contains(GUTF8String name) const;
00125 inline const GPList<lt_XMLTags> & operator [] (const GUTF8String name) const;
00126 inline const GPList<lt_XMLTags> & operator [] (const GPosition &pos) const;
00127 static void ParseValues(char const *t, GMap<GUTF8String,GUTF8String> &args,bool downcase=true);
00128 static void get_Maps(char const tagname[],char const argn[],
00129 GPList<lt_XMLTags> list, GMap<GUTF8String, GP<lt_XMLTags> > &map);
00130 void write(ByteStream &bs,bool const top=true) const;
00131
00132 protected:
00133 GUTF8String name;
00134 GMap<GUTF8String,GUTF8String> args;
00135 GList<lt_XMLContents> content;
00136 GUTF8String raw;
00137 GMap<GUTF8String,GPList<lt_XMLTags> > allTags;
00138 int startline;
00139 };
00140
00141 class lt_XMLContents
00142 {
00143 public:
00144 lt_XMLContents(void);
00145 lt_XMLContents(GP<lt_XMLTags> tag);
00146 GP<lt_XMLTags> tag;
00147 GUTF8String raw;
00148 void write(ByteStream &bs) const;
00149 };
00150
00151 inline GP<lt_XMLTags>
00152 lt_XMLTags::create(const GURL &url)
00153 {
00154 const GP<lt_XMLTags> retval(new lt_XMLTags);
00155 retval->init(url);
00156 return retval;
00157 }
00158
00159 inline GP<lt_XMLTags>
00160 lt_XMLTags::create(const GP<ByteStream> &bs)
00161 {
00162 const GP<lt_XMLTags> retval(new lt_XMLTags);
00163 retval->init(bs);
00164 return retval;
00165 }
00166
00167 inline GP<lt_XMLTags>
00168 lt_XMLTags::create(XMLByteStream &xmlbs)
00169 {
00170 const GP<lt_XMLTags> retval(new lt_XMLTags);
00171 retval->init(xmlbs);
00172 return retval;
00173 }
00174
00176 inline void
00177 lt_XMLTags::addtag (GP<lt_XMLTags> x)
00178 {
00179 content.append(lt_XMLContents(x));
00180 allTags[x->name].append(x);
00181 }
00182
00183 inline void
00184 lt_XMLTags::addraw (GUTF8String r)
00185 {
00186 GPosition pos=content;
00187 if(pos)
00188 {
00189 content[pos].raw+=r;
00190 }else
00191 {
00192 raw+=r;
00193 }
00194 }
00195
00196 inline int
00197 lt_XMLTags::get_Line(void) const
00198 { return startline; }
00199
00200 inline const GUTF8String &
00201 lt_XMLTags::get_name(void) const { return name; }
00202
00203 inline const GUTF8String &
00204 lt_XMLTags::get_raw(void) const { return raw; }
00205
00206 inline const GList<lt_XMLContents> &
00207 lt_XMLTags::get_content(void) const { return content; }
00208
00209 inline const GMap<GUTF8String,GUTF8String> &
00210 lt_XMLTags::get_args(void) const { return args; }
00211
00212 inline const GMap<GUTF8String,GPList<lt_XMLTags> > &
00213 lt_XMLTags::get_allTags(void) const { return allTags; }
00214
00215 inline GPosition
00216 lt_XMLTags::contains(GUTF8String name) const
00217 {
00218 return allTags.contains(name);
00219 }
00220
00221 inline const GPList<lt_XMLTags> &
00222 lt_XMLTags::operator [] (const GUTF8String name) const
00223 {
00224 return allTags[name];
00225 }
00226
00227 inline const GPList<lt_XMLTags> &
00228 lt_XMLTags::operator [] (const GPosition &pos) const
00229 {
00230 return allTags[pos];
00231 }
00232
00233
00234 #ifdef HAVE_NAMESPACES
00235 }
00236 # ifndef NOT_USING_DJVU_NAMESPACE
00237 using namespace DJVU;
00238 # endif
00239 #endif
00240 #endif
00241
00242