135 *mStreamP << "<" << aElemName; |
135 *mStreamP << "<" << aElemName; |
136 // Attributes in sorted order |
136 // Attributes in sorted order |
137 AttributeMapIter it = aAttrs.begin(); |
137 AttributeMapIter it = aAttrs.begin(); |
138 while (it != aAttrs.end()){ |
138 while (it != aAttrs.end()){ |
139 QString attrVal = encodeText(it.data()); |
139 QString attrVal = encodeText(it.data()); |
140 #ifdef DITA_OT_BUG_ATTRIBUTE_VALUE_HACK |
|
141 // DITA Open Toolkit error, it fails to re-encode files properly |
|
142 // Replace "<" with "&lt;" |
|
143 // Replace ">" with "&gt;" |
|
144 int fIdx = 0; |
|
145 QString toFind; |
|
146 QString toReplace; |
|
147 toFind = "<"; |
|
148 toReplace = "&lt;"; |
|
149 fIdx = attrVal.find(toFind, 0); |
|
150 while (fIdx != -1) { |
|
151 attrVal.replace(fIdx, toFind.length(), toReplace); |
|
152 fIdx = attrVal.find(toFind, 0); |
|
153 } |
|
154 toFind = ">"; |
|
155 toReplace = "&gt;"; |
|
156 fIdx = attrVal.find(toFind, 0); |
|
157 while (fIdx != -1) { |
|
158 attrVal.replace(fIdx, toFind.length(), toReplace); |
|
159 fIdx = attrVal.find(toFind, 0); |
|
160 } |
|
161 #endif |
|
162 *mStreamP << " " << it.key() << "=\"" << attrVal << "\""; |
140 *mStreamP << " " << it.key() << "=\"" << attrVal << "\""; |
163 ++it; |
141 ++it; |
164 } |
142 } |
165 // Update internals |
143 // Update internals |
166 mInElement = true; |
144 mInElement = true; |
167 //mCanIndent = true; |
145 //mCanIndent = true; |
168 mElemStack.push(&aElemName); |
146 mElemStack.push(&aElemName); |
169 mCanIndentList.append(new bool(true)); |
147 mCanIndentList.append(new bool(true)); |
170 } |
148 } |
|
149 flushStream(); |
171 } |
150 } |
172 |
151 |
173 void XmlStream::characters(const QString& aText) |
152 void XmlStream::characters(const QString& aText) |
174 { |
153 { |
175 // If this test was not here then if passed an empty string the stream |
154 // If this test was not here then if passed an empty string the stream |
181 } |
160 } |
182 // Don't indent mixed content |
161 // Don't indent mixed content |
183 //mCanIndent = false; |
162 //mCanIndent = false; |
184 setLastIndent(false); |
163 setLastIndent(false); |
185 } |
164 } |
186 #ifdef DITA_TRACE |
165 flushStream(); |
187 #ifdef DITA_TRACE_TO_XML |
|
188 // Useful for assertion crashes where otherwise the buffer would be lost |
|
189 flush(*mStreamP); |
|
190 #endif |
|
191 #endif |
|
192 } |
166 } |
193 |
167 |
194 void XmlStream::characters(char c) |
168 void XmlStream::characters(char c) |
195 { |
169 { |
196 if (mStreamP && mIsOpen && mCanWrite) { |
170 if (mStreamP && mIsOpen && mCanWrite) { |
206 } |
180 } |
207 } |
181 } |
208 // Don't indent mixed content |
182 // Don't indent mixed content |
209 //mCanIndent = false; |
183 //mCanIndent = false; |
210 setLastIndent(false); |
184 setLastIndent(false); |
211 #ifdef DITA_TRACE |
185 flushStream(); |
212 #ifdef DITA_TRACE_TO_XML |
|
213 // Useful for assertion crashes where otherwise the buffer would be lost |
|
214 flush(*mStreamP); |
|
215 #endif |
|
216 #endif |
|
217 } |
186 } |
218 |
187 |
219 XmlStream& XmlStream::operator<<(const QCString& s) |
188 XmlStream& XmlStream::operator<<(const QCString& s) |
220 { |
189 { |
221 characters(s); |
190 characters(s); |
251 } |
220 } |
252 } |
221 } |
253 // Don't indent mixed content |
222 // Don't indent mixed content |
254 //mCanIndent = false; |
223 //mCanIndent = false; |
255 setLastIndent(false); |
224 setLastIndent(false); |
|
225 flushStream(); |
256 return *this; |
226 return *this; |
257 } |
227 } |
258 |
228 |
259 void XmlStream::processingInstruction(const QString& aText) |
229 void XmlStream::processingInstruction(const QString& aText) |
260 { |
230 { |
261 if (mStreamP && mIsOpen && mCanWrite) { |
231 if (mStreamP && mIsOpen && mCanWrite) { |
262 closeElementDeclIfOpen(); |
232 closeElementDeclIfOpen(); |
263 *mStreamP << "<?" << aText << "?>"; |
233 *mStreamP << "<?" << aText << "?>"; |
264 } |
234 } |
265 //mCanIndent = true; |
235 //mCanIndent = true; |
|
236 flushStream(); |
266 } |
237 } |
267 |
238 |
268 void XmlStream::comment(const QString& aText) |
239 void XmlStream::comment(const QString& aText) |
269 { |
240 { |
270 if (mStreamP && mIsOpen && mCanWrite) { |
241 if (mStreamP && mIsOpen && mCanWrite) { |
271 closeElementDeclIfOpen(); |
242 closeElementDeclIfOpen(); |
272 *mStreamP << "<!-- " << aText << " -->"; |
243 *mStreamP << "<!-- " << aText << " -->"; |
273 } |
244 } |
274 //mCanIndent = true; |
245 //mCanIndent = true; |
|
246 flushStream(); |
275 } |
247 } |
276 |
248 |
277 void XmlStream::endElement(const QString& aElemName) |
249 void XmlStream::endElement(const QString& aElemName) |
278 { |
250 { |
279 if (mStreamP && mIsOpen && mCanWrite) { |
251 if (mStreamP && mIsOpen && mCanWrite) { |
286 indent(1); |
258 indent(1); |
287 *mStreamP << "</" << *(mElemStack.pop()) << ">"; |
259 *mStreamP << "</" << *(mElemStack.pop()) << ">"; |
288 } |
260 } |
289 } |
261 } |
290 mCanIndentList.removeLast(); |
262 mCanIndentList.removeLast(); |
|
263 flushStream(); |
291 } |
264 } |
292 |
265 |
293 void XmlStream::closeElementDeclIfOpen() |
266 void XmlStream::closeElementDeclIfOpen() |
294 { |
267 { |
295 if (mStreamP && mIsOpen && mCanWrite) { |
268 if (mStreamP && mIsOpen && mCanWrite) { |
296 if (mInElement) { |
269 if (mInElement) { |
297 *mStreamP << ">"; |
270 *mStreamP << ">"; |
298 mInElement = false; |
271 mInElement = false; |
299 } |
272 } |
300 } |
273 } |
|
274 flushStream(); |
301 } |
275 } |
302 |
276 |
303 void XmlStream::indent(unsigned int aInitVal) |
277 void XmlStream::indent(unsigned int aInitVal) |
304 { |
278 { |
305 if (mStreamP && mIsOpen && canIndent() && mCanWrite) { |
279 if (mStreamP && mIsOpen && canIndent() && mCanWrite) { |
306 *mStreamP << XML_OUTPUT_ENDL; |
280 *mStreamP << XML_OUTPUT_ENDL; |
307 for (unsigned int i = aInitVal; i < mElemStack.count(); i++) { |
281 for (unsigned int i = aInitVal; i < mElemStack.count(); i++) { |
308 *mStreamP << XML_INDENT; |
282 *mStreamP << XML_INDENT; |
309 } |
283 } |
310 } |
284 } |
|
285 flushStream(); |
311 } |
286 } |
312 |
287 |
313 /** Returns 1 if the character is in the legal unicode range |
288 /** Returns 1 if the character is in the legal unicode range |
314 See: http://www.w3.org/TR/REC-xml/#charsets |
289 See: http://www.w3.org/TR/REC-xml/#charsets |
315 */ |
290 */ |
404 { |
379 { |
405 mCanIndentList.removeLast(); |
380 mCanIndentList.removeLast(); |
406 mCanIndentList.append(new bool(theB)); |
381 mCanIndentList.append(new bool(theB)); |
407 } |
382 } |
408 |
383 |
|
384 /// Flush the stream for debugg/trace |
|
385 void XmlStream::flushStream() |
|
386 { |
|
387 #ifdef DITA_TRACE |
|
388 #ifdef DITA_TRACE_TO_XML |
|
389 // Useful for assertion crashes where otherwise the buffer would be lost |
|
390 if (mStreamP) { |
|
391 // Call QT's global function (!) |
|
392 flush(*mStreamP); |
|
393 } |
|
394 #endif |
|
395 #endif |
|
396 } |
|
397 |
409 /// Suspend output |
398 /// Suspend output |
410 void XmlStream::outputSuspend() |
399 void XmlStream::outputSuspend() |
411 { |
400 { |
412 mCanWrite = false; |
401 mCanWrite = false; |
413 } |
402 } |
529 |
518 |
530 void XmlElementStack::pop(const QString &aElementName) |
519 void XmlElementStack::pop(const QString &aElementName) |
531 { |
520 { |
532 XmlElement *pElem = mElemStack.pop(); |
521 XmlElement *pElem = mElemStack.pop(); |
533 if (pElem->getElemName() != aElementName) { |
522 if (pElem->getElemName() != aElementName) { |
534 err(pElem->getElemName() + " is not equal to " + aElementName +"\n"); |
523 QString errStr("XmlElementStack::pop(\"" + aElementName + "\") is not equal to \"" + pElem->getElemName() +"\"\n"); |
|
524 mStream.comment(errStr); |
|
525 err(errStr); |
535 } |
526 } |
536 ASSERT(pElem->getElemName() == aElementName); |
527 ASSERT(pElem->getElemName() == aElementName); |
537 delete pElem; |
528 delete pElem; |
538 } |
529 } |
539 |
530 |