xref: /onnv-gate/usr/src/cmd/man/src/util/nsgmls.src/include/Entity.h (revision 0:68f95e015346)
1 // Copyright (c) 1994 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident	"%Z%%M%	%I%	%E% SMI"
4 
5 #ifndef Entity_INCLUDED
6 #define Entity_INCLUDED 1
7 #ifdef __GNUG__
8 #pragma interface
9 #endif
10 
11 #include "types.h"
12 #include "StringC.h"
13 #include "NamedResource.h"
14 #include "Location.h"
15 #include "Owner.h"
16 #include "Attribute.h"
17 #include "ExternalId.h"
18 #include "Text.h"
19 #include "SubstTable.h"
20 #include "StringResource.h"
21 #include "Allocator.h"
22 #include "EntityDecl.h"
23 #include "Markup.h"
24 
25 #ifdef SP_NAMESPACE
26 namespace SP_NAMESPACE {
27 #endif
28 
29 class Messenger;
30 class InputSource;
31 class EntityOrigin;
32 class ParserState;
33 class ExternalEntity;
34 class ExternalDataEntity;
35 class SubdocEntity;
36 class InternalEntity;
37 class Notation;
38 
39 class Entity : public EntityDecl {
40 public:
41   Entity(const StringC &name, DeclType declType, DataType dataType,
42 	 const Location &defLocation);
43   // reference in a literal
44   virtual void litReference(Text &, ParserState &,
45 			    const Ptr<EntityOrigin> &,
46 			    Boolean squeezeSpaces)
47     const;
48   // reference in a declaration
49   virtual void declReference(ParserState &,
50 			     const Ptr<EntityOrigin> &)
51     const;
52   // reference in a declaration subset
53   virtual void dsReference(ParserState &,
54 			   const Ptr<EntityOrigin> &)
55     const;
56   // reference in content
57   virtual void contentReference(ParserState &,
58 				const Ptr<EntityOrigin> &)
59     const;
60   // reference in rcdata
61   virtual void rcdataReference(ParserState &,
62 			       const Ptr<EntityOrigin> &)
63     const;
64   // for entity name attribute checking
65   virtual Boolean isDataOrSubdoc() const;
66   // for determining whether we need to validate as character data
67   virtual Boolean isCharacterData() const;
68   virtual const ExternalDataEntity *asExternalDataEntity() const;
69   virtual const SubdocEntity *asSubdocEntity() const;
70   virtual const InternalEntity *asInternalEntity() const;
71   virtual const ExternalEntity *asExternalEntity() const;
72   // needed for default entity
73   virtual Entity *copy() const = 0;
74   virtual void generateSystemId(ParserState &);
75   void setUsed();
76   Boolean used() const;
77   void setDefaulted();
78   Boolean defaulted() const;
79 protected:
80   static void checkEntlvl(ParserState &);
81   Boolean checkNotOpen(ParserState &) const;
82 private:
83   virtual void normalReference(ParserState &,
84 			       const Ptr<EntityOrigin> &,
85 			       Boolean generateEvent) const = 0;
86   PackedBoolean used_;
87   PackedBoolean defaulted_;
88 };
89 
90 class InternalEntity : public Entity {
91 public:
92   InternalEntity(const StringC &, DeclType declType, DataType dataType,
93 		 const Location &, Text &);
94   const StringC &string() const;
95   const Text &text() const;
96   const InternalEntity *asInternalEntity() const;
97 protected:
98   Text text_;
99 };
100 
101 class PiEntity : public InternalEntity {
102 public:
103   PiEntity(const StringC &, DeclType, const Location &, Text &);
104   void litReference(Text &, ParserState &,
105 		    const Ptr<EntityOrigin> &,
106 		    Boolean) const;
107   void normalReference(ParserState &,
108 		       const Ptr<EntityOrigin> &,
109 		       Boolean) const;
110   void declReference(ParserState &,
111 		     const Ptr<EntityOrigin> &) const;
112   void rcdataReference(ParserState &,
113 		       const Ptr<EntityOrigin> &) const;
114   Entity *copy() const;
115 };
116 
117 class InternalDataEntity : public InternalEntity {
118 public:
119   InternalDataEntity(const StringC &, DataType, const Location &, Text &);
120   void declReference(ParserState &,
121 		     const Ptr<EntityOrigin> &) const;
122   Boolean isDataOrSubdoc() const;
123 };
124 
125 class InternalCdataEntity : public InternalDataEntity {
126 public:
127   InternalCdataEntity(const StringC &, const Location &, Text &);
128   void normalReference(ParserState &,
129 		       const Ptr<EntityOrigin> &,
130 		       Boolean) const;
131   void litReference(Text &, ParserState &,
132 		    const Ptr<EntityOrigin> &,
133 		    Boolean) const;
134   Entity *copy() const;
135   Boolean isCharacterData() const;
136 };
137 
138 class InternalSdataEntity : public InternalDataEntity {
139 public:
140   InternalSdataEntity(const StringC &, const Location &, Text &);
141   void normalReference(ParserState &,
142 		       const Ptr<EntityOrigin> &,
143 		       Boolean) const;
144   void litReference(Text &, ParserState &,
145 		    const Ptr<EntityOrigin> &,
146 		    Boolean) const;
147   Entity *copy() const;
148   Boolean isCharacterData() const;
149 };
150 
151 class InternalTextEntity : public InternalEntity {
152 public:
153   enum Bracketed {
154     none,
155     starttag,
156     endtag,
157     ms,
158     md
159     };
160   InternalTextEntity(const StringC &, DeclType, const Location &, Text &,
161 		     Bracketed);
162   Entity *copy() const;
163 private:
164   void normalReference(ParserState &,
165 		       const Ptr<EntityOrigin> &,
166 		       Boolean) const;
167   void litReference(Text &, ParserState &,
168 		    const Ptr<EntityOrigin> &,
169 		    Boolean) const;
170   Bracketed bracketed_;
171 };
172 
173 class ExternalEntity : public Entity {
174 public:
175   ExternalEntity(const StringC &, DeclType, DataType, const Location &,
176 		 const ExternalId &);
177   const ExternalId &externalId() const;
178   const ExternalEntity *asExternalEntity() const;
179   void generateSystemId(ParserState &);
180   const StringC *systemIdPointer() const;
181   const StringC *effectiveSystemIdPointer() const;
182   const StringC *publicIdPointer() const;
183 private:
184   ExternalId externalId_;
185 };
186 
187 class ExternalTextEntity : public ExternalEntity {
188 public:
189   ExternalTextEntity(const StringC &, DeclType, const Location &,
190 		     const ExternalId &);
191   Entity *copy() const;
192 private:
193   void normalReference(ParserState &,
194 		       const Ptr<EntityOrigin> &,
195 		       Boolean) const;
196   void litReference(Text &, ParserState &,
197 		    const Ptr<EntityOrigin> &,
198 		    Boolean) const;
199 };
200 
201 class ExternalNonTextEntity : public ExternalEntity {
202 public:
203   ExternalNonTextEntity(const StringC &, DataType,
204 			const Location &, const ExternalId &);
205   Boolean isDataOrSubdoc() const;
206   void litReference(Text &, ParserState &,
207 		    const Ptr<EntityOrigin> &,
208 		    Boolean) const;
209   void rcdataReference(ParserState &,
210 		       const Ptr<EntityOrigin> &) const;
211   void normalReference(ParserState &,
212 		       const Ptr<EntityOrigin> &,
213 		       Boolean) const;
214   Boolean isCharacterData() const;
215 };
216 
217 class ExternalDataEntity : public ExternalNonTextEntity {
218 public:
219   ExternalDataEntity(const StringC &, DataType, const Location &,
220 		     const ExternalId &, const ConstPtr<Notation> &,
221 		     AttributeList &);
222   const AttributeList &attributes() const;
223   const Notation *notation() const;
224   const ExternalDataEntity *asExternalDataEntity() const;
225   Entity *copy() const;
226   void contentReference(ParserState &,
227 			const Ptr<EntityOrigin> &) const;
228   void setNotation(const ConstPtr<Notation>  &, AttributeList &);
229 private:
230   ConstPtr<Notation> notation_;
231   AttributeList attributes_;
232 };
233 
234 class SubdocEntity : public ExternalNonTextEntity {
235 public:
236   SubdocEntity(const StringC &, const Location &, const ExternalId &);
237   const SubdocEntity *asSubdocEntity() const;
238   Entity *copy() const;
239   void contentReference(ParserState &,
240 			const Ptr<EntityOrigin> &) const;
241 private:
242 };
243 
244 class IgnoredEntity : public Entity {
245 public:
246   IgnoredEntity(const StringC &, DeclType declType);
247   Entity *copy() const;
248   void litReference(Text &, ParserState &,
249 		    const Ptr<EntityOrigin> &,
250 		    Boolean squeezeSpaces) const;
251   void declReference(ParserState &,
252 		     const Ptr<EntityOrigin> &) const;
253 private:
254   void normalReference(ParserState &,
255 		       const Ptr<EntityOrigin> &,
256 		       Boolean generateEvent) const;
257 };
258 
259 class SP_API EntityOrigin : public InputSourceOrigin {
260 public:
261   static EntityOrigin *make(Allocator &, const ConstPtr<Entity> &);
262   static EntityOrigin *make(Allocator &,
263 			    const ConstPtr<Entity> &,
264 			    const Location &refLocation);
265   static EntityOrigin *make(Allocator &,
266 			    const ConstPtr<Entity> &,
267 			    const Location &refLocation,
268 			    Index refLength,
269 			    Owner<Markup> &markup);
270   static EntityOrigin *make(const ConstPtr<Entity> &,
271 			    const Location &refLocation,
272 			    Index refLength,
273 			    Owner<Markup> &markup);
274   static EntityOrigin *make(const ConstPtr<Entity> &,
275 			    const Location &refLocation);
276   static const size_t allocSize;
277 };
278 
279 inline
used()280 Boolean Entity::used() const
281 {
282   return used_;
283 }
284 
285 inline
setUsed()286 void Entity::setUsed()
287 {
288   used_ = 1;
289 }
290 
291 inline
defaulted()292 Boolean Entity::defaulted() const
293 {
294   return defaulted_;
295 }
296 
297 inline
setDefaulted()298 void Entity::setDefaulted()
299 {
300   defaulted_ = 1;
301 }
302 
303 inline
string()304 const StringC &InternalEntity::string() const
305 {
306   return text_.string();
307 }
308 
309 inline
text()310 const Text &InternalEntity::text() const
311 {
312   return text_;
313 }
314 
315 inline
externalId()316 const ExternalId &ExternalEntity::externalId() const
317 {
318   return externalId_;
319 }
320 
321 inline
attributes()322 const AttributeList &ExternalDataEntity::attributes() const
323 {
324   return attributes_;
325 }
326 
327 inline
notation()328 const Notation *ExternalDataEntity::notation() const
329 {
330   return notation_.pointer();
331 }
332 
333 #ifdef SP_NAMESPACE
334 }
335 #endif
336 
337 #endif /* not Entity_INCLUDED */
338