00001
00002
00003
00004
00005
00006
00007
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 #include "sax2formatter.hpp"
00044
00045
00046
00047 #include <xercesc/util/XMLUniDefs.hpp>
00048 #include <xercesc/sax2/Attributes.hpp>
00049
00050
00051 BEGIN_XDFLENGINE_NS
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 static const XMLCh gEndElement[] = { chOpenAngle, chForwardSlash, chNull };
00064 static const XMLCh gEndPI[] = { chQuestion, chCloseAngle, chNull };
00065 static const XMLCh gStartPI[] = { chOpenAngle, chQuestion, chNull };
00066 static const XMLCh gXMLDecl1[] =
00067 {
00068 chOpenAngle, chQuestion, chLatin_x, chLatin_m, chLatin_l
00069 , chSpace, chLatin_v, chLatin_e, chLatin_r, chLatin_s, chLatin_i
00070 , chLatin_o, chLatin_n, chEqual, chDoubleQuote, chDigit_1, chPeriod
00071 , chDigit_0, chDoubleQuote, chSpace, chLatin_e, chLatin_n, chLatin_c
00072 , chLatin_o, chLatin_d, chLatin_i, chLatin_n, chLatin_g, chEqual
00073 , chDoubleQuote, chNull
00074 };
00075
00076 static const XMLCh gXMLDecl2[] =
00077 {
00078 chDoubleQuote, chQuestion, chCloseAngle
00079 , chLF, chNull
00080 };
00081
00082
00083
00084
00085
00086
00087
00088 SAX2Formatter::SAX2Formatter( const char* const encodingName , const XMLFormatter::UnRepFlags unRepFlags , const bool expandNamespaces , XMLStreamConsumer* outStreamConsumer) :
00089 fFormatter( (const char *)encodingName , (const char *)0, this , XMLFormatter::NoEscapes , unRepFlags ),
00090 fExpandNS ( expandNamespaces )
00091 {
00092 setConsumer(outStreamConsumer);
00093 fFormatter << gXMLDecl1 << fFormatter.getEncodingName() << gXMLDecl2;
00094 }
00095
00096
00097
00098
00099 SAX2Formatter::~SAX2Formatter()
00100 {
00101 }
00102
00103
00104
00105
00106
00107 void SAX2Formatter::setConsumer(XMLStreamConsumer* outStreamConsumer)
00108 {
00109 pStreamConsumer = outStreamConsumer;
00110 }
00111
00112
00113
00114
00115
00116 void SAX2Formatter::writeChars(const XMLByte* const toWrite, const unsigned int count, XMLFormatter* const formatter)
00117 {
00118 if(pStreamConsumer)
00119 {
00120 pStreamConsumer->writeData( (const char *) toWrite, (unsigned int) count);
00121 }
00122 }
00123
00124
00125
00126
00127
00128
00129 void SAX2Formatter::unparsedEntityDecl(const XMLCh* const name
00130 , const XMLCh* const publicId
00131 , const XMLCh* const systemId
00132 , const XMLCh* const notationName)
00133 {
00134
00135 }
00136
00137
00138 void SAX2Formatter::notationDecl(const XMLCh* const name
00139 , const XMLCh* const publicId
00140 , const XMLCh* const systemId)
00141 {
00142
00143 }
00144
00145
00146
00147
00148
00149 void SAX2Formatter::characters(const XMLCh* const chars
00150 , const unsigned int length)
00151 {
00152 fFormatter.formatBuf(chars, length, XMLFormatter::CharEscapes);
00153 }
00154
00155
00156 void SAX2Formatter::endDocument()
00157 {
00158 }
00159
00160
00161 void SAX2Formatter::endElement(const XMLCh* const uri,
00162 const XMLCh* const localname,
00163 const XMLCh* const qname)
00164 {
00165
00166 fFormatter << XMLFormatter::NoEscapes << gEndElement ;
00167 if ( fExpandNS )
00168 {
00169 if (XMLString::compareIString(uri,XMLUni::fgZeroLenString) != 0)
00170 fFormatter << uri << chColon;
00171 fFormatter << localname << chCloseAngle;
00172 }
00173 else
00174 fFormatter << qname << chCloseAngle;
00175 }
00176
00177
00178 void SAX2Formatter::ignorableWhitespace( const XMLCh* const chars
00179 ,const unsigned int length)
00180 {
00181 fFormatter.formatBuf(chars, length, XMLFormatter::NoEscapes);
00182 }
00183
00184
00185 void SAX2Formatter::processingInstruction(const XMLCh* const target
00186 , const XMLCh* const data)
00187 {
00188 fFormatter << XMLFormatter::NoEscapes << gStartPI << target;
00189 if (data)
00190 fFormatter << chSpace << data;
00191 fFormatter << XMLFormatter::NoEscapes << gEndPI;
00192 }
00193
00194
00195 void SAX2Formatter::startDocument()
00196 {
00197 }
00198
00199
00200 void SAX2Formatter::startElement(const XMLCh* const uri,
00201 const XMLCh* const localname,
00202 const XMLCh* const qname,
00203 const Attributes& attributes)
00204 {
00205
00206 fFormatter << XMLFormatter::NoEscapes << chOpenAngle ;
00207 if ( fExpandNS )
00208 {
00209 if (XMLString::compareIString(uri,XMLUni::fgZeroLenString) != 0)
00210 fFormatter << uri << chColon;
00211 fFormatter << localname ;
00212 }
00213 else
00214 fFormatter << qname ;
00215
00216 unsigned int len = attributes.getLength();
00217 for (unsigned int index = 0; index < len; index++)
00218 {
00219
00220 fFormatter << XMLFormatter::NoEscapes << chSpace ;
00221 if ( fExpandNS )
00222 {
00223 if (XMLString::compareIString(attributes.getURI(index),XMLUni::fgZeroLenString) != 0)
00224 fFormatter << attributes.getURI(index) << chColon;
00225 fFormatter << attributes.getLocalName(index) ;
00226 }
00227 else
00228 fFormatter << attributes.getQName(index) ;
00229
00230 fFormatter << chEqual << chDoubleQuote
00231 << XMLFormatter::AttrEscapes
00232 << attributes.getValue(index)
00233 << XMLFormatter::NoEscapes
00234 << chDoubleQuote;
00235 }
00236 fFormatter << chCloseAngle;
00237 }
00238
00239
00240 END_XDFLENGINE_NS