2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: Entity.h /main/1 1996/07/29 16:49:52 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
27 #ifndef Entity_INCLUDED
28 #define Entity_INCLUDED 1
35 #include "NamedResource.h"
38 #include "Attribute.h"
39 #include "ExternalId.h"
41 #include "SubstTable.h"
42 #include "StringResource.h"
43 #include "Allocator.h"
44 #include "EntityDecl.h"
48 namespace SP_NAMESPACE {
56 class ExternalDataEntity;
61 class Entity : public EntityDecl {
63 Entity(const StringC &name, DeclType declType, DataType dataType,
64 const Location &defLocation);
65 // reference in a literal
66 virtual void litReference(Text &, ParserState &,
67 const Ptr<EntityOrigin> &,
68 Boolean squeezeSpaces)
70 // reference in a declaration
71 virtual void declReference(ParserState &,
72 const Ptr<EntityOrigin> &)
74 // reference in a declaration subset
75 virtual void dsReference(ParserState &,
76 const Ptr<EntityOrigin> &)
78 // reference in content
79 virtual void contentReference(ParserState &,
80 const Ptr<EntityOrigin> &)
82 // reference in rcdata
83 virtual void rcdataReference(ParserState &,
84 const Ptr<EntityOrigin> &)
86 // for entity name attribute checking
87 virtual Boolean isDataOrSubdoc() const;
88 // for determining whether we need to validate as character data
89 virtual Boolean isCharacterData() const;
90 virtual const ExternalDataEntity *asExternalDataEntity() const;
91 virtual const SubdocEntity *asSubdocEntity() const;
92 virtual const InternalEntity *asInternalEntity() const;
93 virtual const ExternalEntity *asExternalEntity() const;
94 // needed for default entity
95 virtual Entity *copy() const = 0;
96 virtual void generateSystemId(ParserState &);
100 Boolean defaulted() const;
102 static void checkEntlvl(ParserState &);
103 Boolean checkNotOpen(ParserState &) const;
105 virtual void normalReference(ParserState &,
106 const Ptr<EntityOrigin> &,
107 Boolean generateEvent) const = 0;
109 PackedBoolean defaulted_;
112 class InternalEntity : public Entity {
114 InternalEntity(const StringC &, DeclType declType, DataType dataType,
115 const Location &, Text &);
116 const StringC &string() const;
117 const Text &text() const;
118 const InternalEntity *asInternalEntity() const;
123 class PiEntity : public InternalEntity {
125 PiEntity(const StringC &, DeclType, const Location &, Text &);
126 void litReference(Text &, ParserState &,
127 const Ptr<EntityOrigin> &,
129 void normalReference(ParserState &,
130 const Ptr<EntityOrigin> &,
132 void declReference(ParserState &,
133 const Ptr<EntityOrigin> &) const;
134 void rcdataReference(ParserState &,
135 const Ptr<EntityOrigin> &) const;
136 Entity *copy() const;
139 class InternalDataEntity : public InternalEntity {
141 InternalDataEntity(const StringC &, DataType, const Location &, Text &);
142 void declReference(ParserState &,
143 const Ptr<EntityOrigin> &) const;
144 Boolean isDataOrSubdoc() const;
147 class InternalCdataEntity : public InternalDataEntity {
149 InternalCdataEntity(const StringC &, const Location &, Text &);
150 void normalReference(ParserState &,
151 const Ptr<EntityOrigin> &,
153 void litReference(Text &, ParserState &,
154 const Ptr<EntityOrigin> &,
156 Entity *copy() const;
157 Boolean isCharacterData() const;
160 class InternalSdataEntity : public InternalDataEntity {
162 InternalSdataEntity(const StringC &, const Location &, Text &);
163 void normalReference(ParserState &,
164 const Ptr<EntityOrigin> &,
166 void litReference(Text &, ParserState &,
167 const Ptr<EntityOrigin> &,
169 Entity *copy() const;
170 Boolean isCharacterData() const;
173 class InternalTextEntity : public InternalEntity {
182 InternalTextEntity(const StringC &, DeclType, const Location &, Text &,
184 Entity *copy() const;
186 void normalReference(ParserState &,
187 const Ptr<EntityOrigin> &,
189 void litReference(Text &, ParserState &,
190 const Ptr<EntityOrigin> &,
192 Bracketed bracketed_;
195 class ExternalEntity : public Entity {
197 ExternalEntity(const StringC &, DeclType, DataType, const Location &,
199 const ExternalId &externalId() const;
200 const ExternalEntity *asExternalEntity() const;
201 void generateSystemId(ParserState &);
202 const StringC *systemIdPointer() const;
203 const StringC *effectiveSystemIdPointer() const;
204 const StringC *publicIdPointer() const;
206 ExternalId externalId_;
209 class ExternalTextEntity : public ExternalEntity {
211 ExternalTextEntity(const StringC &, DeclType, const Location &,
213 Entity *copy() const;
215 void normalReference(ParserState &,
216 const Ptr<EntityOrigin> &,
218 void litReference(Text &, ParserState &,
219 const Ptr<EntityOrigin> &,
223 class ExternalNonTextEntity : public ExternalEntity {
225 ExternalNonTextEntity(const StringC &, DataType,
226 const Location &, const ExternalId &);
227 Boolean isDataOrSubdoc() const;
228 void litReference(Text &, ParserState &,
229 const Ptr<EntityOrigin> &,
231 void rcdataReference(ParserState &,
232 const Ptr<EntityOrigin> &) const;
233 void normalReference(ParserState &,
234 const Ptr<EntityOrigin> &,
236 Boolean isCharacterData() const;
239 class ExternalDataEntity : public ExternalNonTextEntity {
241 ExternalDataEntity(const StringC &, DataType, const Location &,
242 const ExternalId &, const ConstPtr<Notation> &,
244 const AttributeList &attributes() const;
245 const Notation *notation() const;
246 const ExternalDataEntity *asExternalDataEntity() const;
247 Entity *copy() const;
248 void contentReference(ParserState &,
249 const Ptr<EntityOrigin> &) const;
250 void setNotation(const ConstPtr<Notation> &, AttributeList &);
252 ConstPtr<Notation> notation_;
253 AttributeList attributes_;
256 class SubdocEntity : public ExternalNonTextEntity {
258 SubdocEntity(const StringC &, const Location &, const ExternalId &);
259 const SubdocEntity *asSubdocEntity() const;
260 Entity *copy() const;
261 void contentReference(ParserState &,
262 const Ptr<EntityOrigin> &) const;
266 class IgnoredEntity : public Entity {
268 IgnoredEntity(const StringC &, DeclType declType);
269 Entity *copy() const;
270 void litReference(Text &, ParserState &,
271 const Ptr<EntityOrigin> &,
272 Boolean squeezeSpaces) const;
273 void declReference(ParserState &,
274 const Ptr<EntityOrigin> &) const;
276 void normalReference(ParserState &,
277 const Ptr<EntityOrigin> &,
278 Boolean generateEvent) const;
281 class SP_API EntityOrigin : public InputSourceOrigin {
283 void *operator new(size_t sz, Allocator &alloc) {
284 return alloc.alloc(sz);
286 void *operator new(size_t sz) {
287 return Allocator::allocSimple(sz);
289 void operator delete(void *p) {
293 EntityOrigin(const Location &refLocation);
294 EntityOrigin(const ConstPtr<Entity> &);
295 EntityOrigin(const ConstPtr<Entity> &,
296 const Location &refLocation);
297 EntityOrigin(const ConstPtr<Entity> &,
298 const Location &refLocation, Index refLength,
299 Owner<Markup> &markup);
301 InputSourceOrigin *copy() const;
302 const ConstPtr<Entity> &entity() const { return entity_; }
303 const StringC *entityName() const;
304 const EntityDecl *entityDecl() const;
305 const EntityOrigin *asEntityOrigin() const;
306 Boolean defLocation(Offset off, Location &loc) const;
307 Index refLength() const;
308 const Markup *markup() const;
310 EntityOrigin(const EntityOrigin &); // undefined
311 void operator=(const EntityOrigin &); // undefined
312 ConstPtr<Entity> entity_; // 0 for document entity
313 // total length of reference
314 // (characters that were replaced by the entity)
316 Owner<Markup> markup_;
320 Boolean Entity::used() const
326 void Entity::setUsed()
332 Boolean Entity::defaulted() const
338 void Entity::setDefaulted()
344 const StringC &InternalEntity::string() const
346 return text_.string();
350 const Text &InternalEntity::text() const
356 const ExternalId &ExternalEntity::externalId() const
362 const AttributeList &ExternalDataEntity::attributes() const
368 const Notation *ExternalDataEntity::notation() const
370 return notation_.pointer();
374 const Markup *EntityOrigin::markup() const
376 return markup_.pointer();
383 #endif /* not Entity_INCLUDED */