1 // Copyright (c) 1995 James Clark
2 // See the file COPYING for copying permission.
3
4 #ifndef CopyEventHandler_INCLUDED
5 #define CopyEventHandler_INCLUDED 1
6 #ifdef __GNUG__
7 #pragma interface
8 #endif
9
10 #include "Event.h"
11 #include "OutputCharStream.h"
12 #include "Vector.h"
13 #include "NCVector.h"
14 #include "MarkupEventHandler.h"
15
16 // This should be local to CopyEventHandler, but some compilers
17 // can't handle this.
18
19 #ifdef SP_NAMESPACE
20 namespace SP_NAMESPACE {
21 #endif
22
23 struct CopyEventHandlerEntityInfo {
24 StrOutputCharStream str;
25 ConstPtr<EntityOrigin> ref;
26 };
27
28 class CopyEventHandler : public MarkupEventHandler {
29 public:
30 enum NormalizeFlags {
31 normalizeOmittag = 01,
32 normalizeShortref = 02,
33 normalizeNet = 04,
34 normalizeEmptytag = 010,
35 normalizeUnclosed = 020,
36 normalizeAttname = 040,
37 normalizeAttvalue = 0100,
38 normalizeAttspec = 0200,
39 normalizeShorttag = (normalizeNet|normalizeEmptytag|normalizeUnclosed
40 |normalizeAttname|normalizeAttvalue|normalizeAttspec),
41 normalizeRank = 0400,
42 normalizeOmittagHoist = 01000,
43 normalizeExpand = 02000,
44 normalizeExpandAll = 04000,
45 normalizeCurrent = 010000,
46 normalizeLower = 020000,
47 normalizeReserved = 040000,
48 normalizeExpandProlog = 0100000,
49 normalizeIncludeProlog = 0200000,
50 normalizeMarkedSection = 0400000
51 };
52 CopyEventHandler(OutputCharStream *, unsigned flags,
53 const StringC &outputEntity);
54 ~CopyEventHandler();
55 void reOrigin(ReOriginEvent *);
56 void sSep(SSepEvent *);
57 void ignoredRs(IgnoredRsEvent *);
58 void data(DataEvent *);
59 void startElement(StartElementEvent *);
60 void endElement(EndElementEvent *);
61 void sdataEntity(SdataEntityEvent *);
62 void externalDataEntity(ExternalDataEntityEvent *);
63 void subdocEntity(SubdocEntityEvent *);
64 void nonSgmlChar(NonSgmlCharEvent *);
65 void pi(PiEvent *);
66 void endProlog(EndPrologEvent *);
67 void markedSectionStart(MarkedSectionStartEvent *);
68 void markedSectionEnd(MarkedSectionEndEvent *);
69 void entityStart(EntityStartEvent *);
70 void entityEnd(EntityEndEvent *);
71 void ignoredChars(IgnoredCharsEvent *);
72 void sgmlDecl(SgmlDeclEvent *);
73 void usemap(UsemapEvent *);
74 void uselink(UselinkEvent *);
75 void startDtd(StartDtdEvent *);
76 void startLpd(StartLpdEvent *);
77 void endDtd(EndDtdEvent *);
78 void endLpd(EndLpdEvent *);
79 void entityDecl(EntityDeclEvent *);
80 void shortrefDecl(ShortrefDeclEvent *);
81 void markup(const Location &loc, const Markup &markup);
82 private:
83 virtual void reportTagInSpecialMarkedSection(const Location &) = 0;
84 OutputCharStream &os();
85 void startSubset(StartSubsetEvent *);
86 void endSubset(MarkupEvent *);
87 void literal(const Text &text);
88 void attributeSpecList(MarkupIter &, const AttributeList &);
89 void unspecifiedAttributeValues(const AttributeList &atts,
90 const StringC &beforeFirst);
91 void withNamedCharRef(const StringC &, const Location &loc);
92 void withNamedCharRef(const Char *p, size_t n, const Location &loc);
93 void writeData(const Char *p, size_t n, const Location &loc);
94 void sdParamLiteral(const SdText &text);
95 void entityRef(const EntityOrigin *);
96 Boolean doNothing(Event *);
97 Boolean noOutput();
98 Boolean isSgmlChar(Char);
99 const StringC &elementTypeOrigName(const ElementType *, StringC &buf);
100 const StringC &generalName(const StringC &name, StringC &buf);
101 const StringC &entityName(const StringC &name, StringC &buf);
102 const StringC &lowerCaseName(const StringC &name, StringC &buf);
103 void handleChange();
104 void outputMarkup(const Location &loc, const Markup &markup);
105 OutputCharStream *os_;
106 OutputCharStream *topOs_;
107 Boolean inInstance_;
108 unsigned entityLevel_;
109 unsigned outputEntityLevel_;
110 ConstPtr<Syntax> syntax_;
111 ConstPtr<Syntax> instanceSyntax_;
112 ConstPtr<Sd> sd_;
113 SubstTable lowerSubst_;
114 unsigned normalizeFlags_;
115 StringC outputEntity_;
116 Vector<StringC> elementTypeOrigNames_;
117 unsigned omittagHoist_;
118 ConstPtr<EntityOrigin> entityOrigin_;
119 NCVector<CopyEventHandlerEntityInfo> entityStack_;
120 Boolean inSpecialMarkedSection_;
121 Boolean hasInternalSubset_;
122 Boolean mustOmitEnd_;
123 Boolean emptyElementNormal_;
124 const AttributeList *currentAttributes_;
125 };
126
127 inline
os()128 OutputCharStream &CopyEventHandler::os()
129 {
130 return *os_;
131 }
132
133 #ifdef SP_NAMESPACE
134 }
135 #endif
136
137 #endif /* not CopyEventHandler_INCLUDED */
138