source: trunk/libdjvu/XMLTags.h @ 280

Last change on this file since 280 was 280, checked in by rbri, 11 years ago

DJVU plugin: djvulibre updated to version 3.5.22

File size: 7.5 KB
Line 
1//C-  -*- C++ -*-
2//C- -------------------------------------------------------------------
3//C- DjVuLibre-3.5
4//C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
5//C- Copyright (c) 2001  AT&T
6//C-
7//C- This software is subject to, and may be distributed under, the
8//C- GNU General Public License, either Version 2 of the license,
9//C- or (at your option) any later version. The license should have
10//C- accompanied the software or you may obtain a copy of the license
11//C- from the Free Software Foundation at http://www.fsf.org .
12//C-
13//C- This program is distributed in the hope that it will be useful,
14//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
15//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16//C- GNU General Public License for more details.
17//C-
18//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
19//C- Lizardtech Software.  Lizardtech Software has authorized us to
20//C- replace the original DjVu(r) Reference Library notice by the following
21//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
22//C-
23//C-  ------------------------------------------------------------------
24//C- | DjVu (r) Reference Library (v. 3.5)
25//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
26//C- | The DjVu Reference Library is protected by U.S. Pat. No.
27//C- | 6,058,214 and patents pending.
28//C- |
29//C- | This software is subject to, and may be distributed under, the
30//C- | GNU General Public License, either Version 2 of the license,
31//C- | or (at your option) any later version. The license should have
32//C- | accompanied the software or you may obtain a copy of the license
33//C- | from the Free Software Foundation at http://www.fsf.org .
34//C- |
35//C- | The computer code originally released by LizardTech under this
36//C- | license and unmodified by other parties is deemed "the LIZARDTECH
37//C- | ORIGINAL CODE."  Subject to any third party intellectual property
38//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
39//C- | non-exclusive license to make, use, sell, or otherwise dispose of
40//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
41//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
42//C- | General Public License.   This grant only confers the right to
43//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
44//C- | the extent such infringement is reasonably necessary to enable
45//C- | recipient to make, have made, practice, sell, or otherwise dispose
46//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
47//C- | any greater extent that may be necessary to utilize further
48//C- | modifications or combinations.
49//C- |
50//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
51//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
52//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
53//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
54//C- +------------------------------------------------------------------
55//
56// $Id: XMLTags.h,v 1.11 2008/01/27 11:36:27 leonb Exp $
57// $Name: release_3_5_22 $
58
59#ifndef _LT_XMLTAGS__
60#define _LT_XMLTAGS__
61#ifdef HAVE_CONFIG_H
62#include "config.h"
63#endif
64#if NEED_GNUG_PRAGMAS
65# pragma interface
66#endif
67
68// From: Leon Bottou, 1/31/2002
69// This is purely Lizardtech stuff.
70
71#include "GContainer.h"
72#include "GString.h"
73
74#ifdef HAVE_NAMESPACES
75namespace DJVU {
76# ifdef NOT_DEFINED // Just to fool emacs c++ mode
77}
78#endif
79#endif
80
81class lt_XMLContents;
82class DjVuFile;
83class DjVuDocument;
84class ByteStream;
85class XMLByteStream;
86class GURL;
87
88class DJVUAPI lt_XMLTags : public GPEnabled
89{
90protected:
91  lt_XMLTags();
92  lt_XMLTags(const char n[]);
93
94public:
95  /// Empty creator.
96  static GP<lt_XMLTags> create(void) { return new lt_XMLTags; }
97  /// Default the specified tag.
98  static GP<lt_XMLTags> create(const char n[]) { return new lt_XMLTags(n); }
99  /// Initialize from the specified URL.
100  void init(const GURL & url);
101  /// Create from the specified URL.
102  static GP<lt_XMLTags> create(const GURL &url);
103  /// Initialize from the specified bytestream.
104  void init(const GP<ByteStream> &bs);
105  /// Create from the specified bytestream.
106  static GP<lt_XMLTags> create(const GP<ByteStream> &bs);
107  /// Initialize from an XMLByteStream.
108  void init(XMLByteStream &xmlbs);
109  /// Create from an XML bytestream.
110  static GP<lt_XMLTags> create(XMLByteStream &xmlbs);
111  /// Non-virtual destructor.
112  ~lt_XMLTags();
113
114  inline int get_Line(void) const;
115  inline const GUTF8String& get_raw(void) const;
116  inline const GUTF8String& get_name(void) const;
117  inline const GList<lt_XMLContents>& get_content(void) const;
118  inline const GMap<GUTF8String,GUTF8String>& get_args(void) const;
119  inline const GMap<GUTF8String,GPList<lt_XMLTags> >& get_allTags(void) const;
120
121  GPList<lt_XMLTags> get_Tags(char const tagname[]) const;
122  inline void set_Line(const int xstartline) { startline=xstartline; }
123
124  inline void addtag(GP<lt_XMLTags> x);
125  inline void addraw(GUTF8String raw);
126  inline GPosition contains(GUTF8String name) const;
127  inline const GPList<lt_XMLTags> & operator [] (const GUTF8String name) const;
128  inline const GPList<lt_XMLTags> & operator [] (const GPosition &pos) const;
129  static void ParseValues(char const *t, GMap<GUTF8String,GUTF8String> &args,bool downcase=true);
130  static void get_Maps(char const tagname[],char const argn[],
131    GPList<lt_XMLTags> list, GMap<GUTF8String, GP<lt_XMLTags> > &map);
132  void write(ByteStream &bs,bool const top=true) const;
133
134protected:
135  GUTF8String name;
136  GMap<GUTF8String,GUTF8String> args;
137  GList<lt_XMLContents> content;
138  GUTF8String raw;
139  GMap<GUTF8String,GPList<lt_XMLTags> > allTags;
140  int startline;
141};
142
143class lt_XMLContents
144{
145public:
146  lt_XMLContents(void);
147  lt_XMLContents(GP<lt_XMLTags> tag);
148  GP<lt_XMLTags> tag;
149  GUTF8String raw;
150  void write(ByteStream &bs) const;
151};
152
153inline GP<lt_XMLTags>
154lt_XMLTags::create(const GURL &url)
155{
156  const GP<lt_XMLTags> retval(new lt_XMLTags);
157  retval->init(url);
158  return retval;
159}
160
161inline GP<lt_XMLTags>
162lt_XMLTags::create(const GP<ByteStream> &bs)
163{
164  const GP<lt_XMLTags> retval(new lt_XMLTags);
165  retval->init(bs);
166  return retval;
167}
168
169inline GP<lt_XMLTags>
170lt_XMLTags::create(XMLByteStream &xmlbs)
171{
172  const GP<lt_XMLTags> retval(new lt_XMLTags);
173  retval->init(xmlbs);
174  return retval;
175}
176
177/// Non-virtual destructor.
178inline void
179lt_XMLTags::addtag (GP<lt_XMLTags> x)
180{
181  content.append(lt_XMLContents(x));
182  allTags[x->name].append(x);
183}
184
185inline void
186lt_XMLTags::addraw (GUTF8String r)
187{
188  GPosition pos=content;
189  if(pos)
190  {
191    content[pos].raw+=r;
192  }else
193  {
194    raw+=r;
195  }
196}
197
198inline int
199lt_XMLTags::get_Line(void) const
200{ return startline; }
201
202inline const GUTF8String &
203lt_XMLTags::get_name(void) const { return name; }
204
205inline const GUTF8String &
206lt_XMLTags::get_raw(void) const { return raw; }
207
208inline const GList<lt_XMLContents> &
209lt_XMLTags::get_content(void) const { return content; }
210
211inline const GMap<GUTF8String,GUTF8String> &
212lt_XMLTags::get_args(void) const { return args; }
213
214inline const GMap<GUTF8String,GPList<lt_XMLTags> > &
215lt_XMLTags::get_allTags(void) const { return allTags; }
216
217inline GPosition
218lt_XMLTags::contains(GUTF8String name) const
219{
220  return allTags.contains(name);
221}
222
223inline const GPList<lt_XMLTags> &
224lt_XMLTags::operator [] (const GUTF8String name) const
225{
226  return allTags[name];
227}
228
229inline const GPList<lt_XMLTags> &
230lt_XMLTags::operator [] (const GPosition &pos) const
231{
232  return allTags[pos];
233}
234
235
236#ifdef HAVE_NAMESPACES
237}
238# ifndef NOT_USING_DJVU_NAMESPACE
239using namespace DJVU;
240# endif
241#endif
242#endif /* _LT_XMLTAGS__ */
243
244
Note: See TracBrowser for help on using the repository browser.