|
1 |
|
2 #include "xmlditadocvisitor.h" |
|
3 #include "docparser.h" |
|
4 #include "language.h" |
|
5 #include "doxygen.h" |
|
6 #include "outputgen.h" |
|
7 #include "xmlgen.h" |
|
8 #include "dot.h" |
|
9 #include "message.h" |
|
10 #include "util.h" |
|
11 #include <qfileinfo.h> |
|
12 #include "parserintf.h" |
|
13 |
|
14 |
|
15 XmlDitaDocVisitor::XmlDitaDocVisitor(XmlStream &s,CodeOutputInterface &ci) |
|
16 : DocVisitor(DocVisitor_XML), xmlStream(s), xmlElemStack(s), m_ci(ci), m_insidePre(FALSE), m_hide(FALSE), |
|
17 m_insideParamlist(FALSE), paramMap(), paramDict(), currParam() |
|
18 {} |
|
19 |
|
20 |
|
21 //-------------------------------------- |
|
22 // visitor functions for leaf nodes |
|
23 //-------------------------------------- |
|
24 |
|
25 void XmlDitaDocVisitor::visit(DocWord *w) |
|
26 { |
|
27 if (m_hide) { |
|
28 return; |
|
29 } |
|
30 // Catches normal text (text outside of a tag or command) |
|
31 // and puts it in a "p" |
|
32 if (xmlElemStack.isEmpty()) { |
|
33 visitPreDefault("p"); |
|
34 } |
|
35 write(w->word()); |
|
36 } |
|
37 |
|
38 void XmlDitaDocVisitor::visit(DocLinkedWord *w) |
|
39 { |
|
40 if (m_hide) { |
|
41 return; |
|
42 } |
|
43 if (w->getDefinition() != 0) { |
|
44 startLink("", w->getDefinition()->qualifiedName(), ""); |
|
45 } else { |
|
46 startLink(w->ref(), w->file(), w->anchor()); |
|
47 } |
|
48 write(w->word()); |
|
49 endLink(); |
|
50 } |
|
51 |
|
52 void XmlDitaDocVisitor::visit(DocWhiteSpace *w) |
|
53 { |
|
54 if (m_hide) { |
|
55 return; |
|
56 } |
|
57 if (m_insidePre) { |
|
58 write(w->chars()); |
|
59 } else { |
|
60 write(" "); |
|
61 } |
|
62 } |
|
63 |
|
64 void XmlDitaDocVisitor::visit(DocSymbol *s) |
|
65 { |
|
66 if (m_hide) { |
|
67 return; |
|
68 } |
|
69 |
|
70 switch(s->symbol()) |
|
71 { |
|
72 case DocSymbol::BSlash: write("\\"); break; |
|
73 case DocSymbol::At: write("@"); break; |
|
74 // NOTE: The XMl stream will translate entities i.e. "&" to "&" |
|
75 case DocSymbol::Less: write("<"); break; |
|
76 case DocSymbol::Greater: write(">"); break; |
|
77 case DocSymbol::Amp: write("&"); break; |
|
78 case DocSymbol::Dollar: write("$"); break; |
|
79 case DocSymbol::Hash: write("#"); break; |
|
80 case DocSymbol::Percent: write("%"); break; |
|
81 case DocSymbol::Apos: write("'"); break; |
|
82 case DocSymbol::Quot: write("\""); break; |
|
83 case DocSymbol::Copy: xmlStream.writeUnicode("copy"); break; |
|
84 case DocSymbol::Tm: xmlStream.writeUnicode("trade"); break; |
|
85 case DocSymbol::Reg: xmlStream.writeUnicode("reg"); break; |
|
86 case DocSymbol::Lsquo: xmlStream.writeUnicode("lsquo"); break; |
|
87 case DocSymbol::Rsquo: xmlStream.writeUnicode("rsquo"); break; |
|
88 case DocSymbol::Ldquo: xmlStream.writeUnicode("ldquo"); break; |
|
89 case DocSymbol::Rdquo: xmlStream.writeUnicode("rdquo"); break; |
|
90 case DocSymbol::Ndash: xmlStream.writeUnicode("ndash"); break; |
|
91 case DocSymbol::Mdash: xmlStream.writeUnicode("mdash"); break; |
|
92 case DocSymbol::Uml: xmlStream.writeUnicode((const char*)(QString(QChar(s->letter()))+"uml")); break; |
|
93 case DocSymbol::Acute: xmlStream.writeUnicode((const char*)(QString(QChar(s->letter()))+"acute")); break; |
|
94 case DocSymbol::Grave: xmlStream.writeUnicode((const char*)(QString(QChar(s->letter()))+"grave")); break; |
|
95 case DocSymbol::Circ: xmlStream.writeUnicode((const char*)(QString(QChar(s->letter()))+"circ")); break; |
|
96 case DocSymbol::Tilde: xmlStream.writeUnicode((const char*)(QString(QChar(s->letter()))+"tilde")); break; |
|
97 case DocSymbol::Cedil: xmlStream.writeUnicode((const char*)(QString(QChar(s->letter()))+"cedil")); break; |
|
98 case DocSymbol::Ring: xmlStream.writeUnicode((const char*)(QString(QChar(s->letter()))+"ring")); break; |
|
99 case DocSymbol::Slash: xmlStream.writeUnicode((const char*)(QString(QChar(s->letter()))+"slash")); break; |
|
100 case DocSymbol::Szlig: xmlStream.writeUnicode("szlig"); break; |
|
101 case DocSymbol::Nbsp: xmlStream.writeUnicode("nbsp"); break; |
|
102 case DocSymbol::Aelig: xmlStream.writeUnicode("aelig"); break; |
|
103 case DocSymbol::AElig: xmlStream.writeUnicode("AElig"); break; |
|
104 default: |
|
105 err("Error: unknown symbol found\n"); |
|
106 } |
|
107 } |
|
108 |
|
109 void XmlDitaDocVisitor::visit(DocURL *u) |
|
110 { |
|
111 if (m_hide) { |
|
112 return; |
|
113 } |
|
114 if (u->isEmail()) { |
|
115 startXref(QString("mailto:")+QString(u->url()), u->url()); |
|
116 } else { |
|
117 startXref(u->url(), u->url()); |
|
118 } |
|
119 endXref(); |
|
120 } |
|
121 |
|
122 void XmlDitaDocVisitor::visit(DocLineBreak *lb) |
|
123 { |
|
124 if (m_hide){ |
|
125 return; |
|
126 } |
|
127 //pushpop("linebreak"); |
|
128 //if (lb->parent()->kind() == lb->Kind_Verbatim) { |
|
129 if (m_insidePre) { |
|
130 write("\n"); |
|
131 } |
|
132 } |
|
133 |
|
134 void XmlDitaDocVisitor::visit(DocHorRuler *) |
|
135 { |
|
136 if (m_hide) { |
|
137 return; |
|
138 } |
|
139 //pushpop("hruler"); |
|
140 xmlStream.comment("hruler not supported by DITA 1.1"); |
|
141 } |
|
142 |
|
143 void XmlDitaDocVisitor::visit(DocStyleChange *s) |
|
144 { |
|
145 if (m_hide) { |
|
146 return; |
|
147 } |
|
148 switch (s->style()) |
|
149 { |
|
150 case DocStyleChange::Bold: |
|
151 if (s->enable()) { |
|
152 push("b"); |
|
153 } else { |
|
154 pop("b"); |
|
155 } |
|
156 break; |
|
157 case DocStyleChange::Italic: |
|
158 if (s->enable()) { |
|
159 push("i"); |
|
160 } else { |
|
161 pop("i"); |
|
162 } |
|
163 break; |
|
164 case DocStyleChange::Code: |
|
165 if (s->enable()) { |
|
166 push("tt"); |
|
167 } else { |
|
168 pop("tt"); |
|
169 } |
|
170 break; |
|
171 case DocStyleChange::Subscript: |
|
172 if (s->enable()) { |
|
173 push("sub"); |
|
174 } else { |
|
175 pop("sub"); |
|
176 } |
|
177 break; |
|
178 case DocStyleChange::Superscript: |
|
179 if (s->enable()) { |
|
180 push("sup"); |
|
181 } else { |
|
182 pop("sup"); |
|
183 } |
|
184 break; |
|
185 case DocStyleChange::Center: |
|
186 if (s->enable()) { |
|
187 xmlStream.comment("center not supported by DITA 1.1"); |
|
188 //push("center"); |
|
189 } else { |
|
190 //pop("center"); |
|
191 } |
|
192 break; |
|
193 case DocStyleChange::Small: |
|
194 if (s->enable()) { |
|
195 xmlStream.comment("small not supported by DITA 1.1"); |
|
196 //push("small"); |
|
197 } else { |
|
198 //pop("small"); |
|
199 } |
|
200 break; |
|
201 case DocStyleChange::Preformatted: |
|
202 if (s->enable()) |
|
203 { |
|
204 push("pre"); |
|
205 m_insidePre = TRUE; |
|
206 } else { |
|
207 pop("pre"); |
|
208 m_insidePre = FALSE; |
|
209 } |
|
210 break; |
|
211 case DocStyleChange::Div: /* HTML only */ break; |
|
212 case DocStyleChange::Span: /* HTML only */ break; |
|
213 } |
|
214 } |
|
215 |
|
216 void XmlDitaDocVisitor::visit(DocVerbatim *s) |
|
217 { |
|
218 if (m_hide) { |
|
219 return; |
|
220 } |
|
221 switch(s->type()) |
|
222 { |
|
223 case DocVerbatim::Code: |
|
224 push("codeblock"); |
|
225 write(s->text()); |
|
226 pop("codeblock"); |
|
227 break; |
|
228 case DocVerbatim::Verbatim: |
|
229 pushpop("pre", s->text()); |
|
230 break; |
|
231 case DocVerbatim::HtmlOnly: |
|
232 //pushpop("htmlonly", s->text()); |
|
233 break; |
|
234 case DocVerbatim::ManOnly: |
|
235 //pushpop("manonly", s->text()); |
|
236 break; |
|
237 case DocVerbatim::LatexOnly: |
|
238 //pushpop("latexonly", s->text()); |
|
239 break; |
|
240 case DocVerbatim::XmlOnly: |
|
241 write(s->text()); |
|
242 break; |
|
243 case DocVerbatim::Dot: |
|
244 //pushpop("dot", s->text()); |
|
245 break; |
|
246 case DocVerbatim::Msc: |
|
247 //pushpop("msc", s->text()); |
|
248 break; |
|
249 } |
|
250 } |
|
251 |
|
252 void XmlDitaDocVisitor::visit(DocAnchor *anc) |
|
253 { |
|
254 if (m_hide) { |
|
255 return; |
|
256 } |
|
257 xmlElemStack.addAttribute("id", anc->file()+"_1"+anc->anchor()); |
|
258 //push("anchor", "id", anc->file()+"_1"+anc->anchor()); |
|
259 //pop("anchor"); |
|
260 } |
|
261 |
|
262 void XmlDitaDocVisitor::visit(DocInclude *inc) |
|
263 { |
|
264 if (m_hide) { |
|
265 return; |
|
266 } |
|
267 switch(inc->type()) |
|
268 { |
|
269 case DocInclude::IncWithLines: |
|
270 { |
|
271 push("codeblock"); |
|
272 QFileInfo cfi( inc->file() ); |
|
273 FileDef fd( cfi.dirPath(), cfi.fileName() ); |
|
274 Doxygen::parserManager->getParser(inc->extension()) |
|
275 ->parseCode(m_ci,inc->context(), |
|
276 inc->text().latin1(), |
|
277 inc->isExample(), |
|
278 inc->exampleFile(), &fd); |
|
279 pop("codeblock"); |
|
280 } |
|
281 break; |
|
282 case DocInclude::Include: |
|
283 push("codeblock"); |
|
284 Doxygen::parserManager->getParser(inc->extension()) |
|
285 ->parseCode(m_ci,inc->context(), |
|
286 inc->text().latin1(), |
|
287 inc->isExample(), |
|
288 inc->exampleFile()); |
|
289 pop("codeblock"); |
|
290 break; |
|
291 case DocInclude::DontInclude: |
|
292 break; |
|
293 case DocInclude::HtmlInclude: |
|
294 //pushpop("htmlonly", inc->text()); |
|
295 break; |
|
296 case DocInclude::VerbInclude: |
|
297 pushpop("pre", inc->text()); |
|
298 break; |
|
299 } |
|
300 } |
|
301 |
|
302 void XmlDitaDocVisitor::visit(DocIncOperator *op) |
|
303 { |
|
304 DITA_DOC_VISITOR_TRACE("visit(DocIncOperator*)",op); |
|
305 if (op->isFirst()) |
|
306 { |
|
307 if (!m_hide) { |
|
308 push("codeblock"); |
|
309 } |
|
310 pushEnabled(); |
|
311 m_hide = TRUE; |
|
312 } |
|
313 if (op->type()!=DocIncOperator::Skip) |
|
314 { |
|
315 popEnabled(); |
|
316 if (!m_hide) { |
|
317 Doxygen::parserManager->getParser(m_langExt) |
|
318 ->parseCode(m_ci,op->context(), |
|
319 op->text().latin1(),op->isExample(), |
|
320 op->exampleFile()); |
|
321 } |
|
322 pushEnabled(); |
|
323 m_hide=TRUE; |
|
324 } |
|
325 if (op->isLast()) |
|
326 { |
|
327 popEnabled(); |
|
328 if (!m_hide) { |
|
329 pop("codeblock"); |
|
330 } |
|
331 } |
|
332 } |
|
333 |
|
334 void XmlDitaDocVisitor::visit(DocFormula *f) |
|
335 { |
|
336 write(f->text()); |
|
337 #if 0 |
|
338 if (m_hide) { |
|
339 return; |
|
340 } |
|
341 QString s; |
|
342 s.setNum(f->id()); |
|
343 push("formula", "id", s); |
|
344 write(f->text()); |
|
345 pop("formula"); |
|
346 #endif |
|
347 } |
|
348 |
|
349 void XmlDitaDocVisitor::visit(DocIndexEntry *ie) |
|
350 { |
|
351 if (m_hide) { |
|
352 return; |
|
353 } |
|
354 |
|
355 push("indexterm"); |
|
356 write(ie->entry()); |
|
357 pop("indexterm"); |
|
358 #if 0 |
|
359 push("indexentry"); |
|
360 push("primaryie"); |
|
361 write(ie->entry()); |
|
362 pop("primaryie"); |
|
363 pushpop("secondaryie"); |
|
364 pop("indexentry"); |
|
365 #endif |
|
366 } |
|
367 |
|
368 void XmlDitaDocVisitor::visit(DocSimpleSectSep *) |
|
369 { |
|
370 //pushpop("simplesectsep"); |
|
371 } |
|
372 |
|
373 //-------------------------------------- |
|
374 // visitor functions for compound nodes |
|
375 //-------------------------------------- |
|
376 |
|
377 void XmlDitaDocVisitor::visitPre(DocAutoList *l) |
|
378 { |
|
379 if (m_hide) { |
|
380 return; |
|
381 } |
|
382 if (l->isEnumList()) { |
|
383 push("ol"); |
|
384 } else { |
|
385 push("ul"); |
|
386 } |
|
387 } |
|
388 |
|
389 void XmlDitaDocVisitor::visitPost(DocAutoList *l) |
|
390 { |
|
391 if (l->isEnumList()) { |
|
392 visitPostDefault("ol"); |
|
393 } else { |
|
394 visitPostDefault("ul"); |
|
395 } |
|
396 } |
|
397 |
|
398 void XmlDitaDocVisitor::visitPre(DocAutoListItem *) |
|
399 { |
|
400 visitPreDefault("li"); |
|
401 } |
|
402 |
|
403 void XmlDitaDocVisitor::visitPost(DocAutoListItem *) |
|
404 { |
|
405 visitPostDefault("li"); |
|
406 } |
|
407 |
|
408 void XmlDitaDocVisitor::visitPre(DocPara *p) |
|
409 { |
|
410 if (xmlElemStack.isEmpty() || xmlElemStack.peek().getElemName() != "p") { |
|
411 visitPreDefault("p"); |
|
412 } |
|
413 } |
|
414 |
|
415 void XmlDitaDocVisitor::visitPost(DocPara *) |
|
416 { |
|
417 if (!xmlElemStack.isEmpty() && xmlElemStack.peek().getElemName() == "p") { |
|
418 visitPostDefault("p"); |
|
419 } |
|
420 } |
|
421 |
|
422 void XmlDitaDocVisitor::visitPre(DocRoot *) |
|
423 {} |
|
424 |
|
425 void XmlDitaDocVisitor::visitPost(DocRoot *) |
|
426 {} |
|
427 |
|
428 void XmlDitaDocVisitor::visitPre(DocSimpleSect *s) |
|
429 { |
|
430 if (m_hide) { |
|
431 return; |
|
432 } |
|
433 switch(s->type()) |
|
434 { |
|
435 // Fall through |
|
436 case DocSimpleSect::See: |
|
437 case DocSimpleSect::Return: |
|
438 case DocSimpleSect::Author: |
|
439 case DocSimpleSect::Authors: |
|
440 case DocSimpleSect::Version: |
|
441 case DocSimpleSect::Since: |
|
442 case DocSimpleSect::Date: |
|
443 case DocSimpleSect::Pre: |
|
444 case DocSimpleSect::Post: |
|
445 case DocSimpleSect::Invar: |
|
446 case DocSimpleSect::User: |
|
447 case DocSimpleSect::Rcs: |
|
448 if (xmlElemStack.isEmpty() || xmlElemStack.peek().getElemName() != "p") { |
|
449 push("p"); |
|
450 } |
|
451 break; |
|
452 case DocSimpleSect::Note: |
|
453 push("note", "type", "note"); |
|
454 break; |
|
455 case DocSimpleSect::Warning: |
|
456 push("note", "type", "caution"); |
|
457 break; |
|
458 case DocSimpleSect::Remark: |
|
459 push("note", "type", "other"); |
|
460 break; |
|
461 case DocSimpleSect::Attention: |
|
462 push("note", "type", "attention"); |
|
463 break; |
|
464 case DocSimpleSect::Unknown: |
|
465 break; |
|
466 default: |
|
467 ASSERT(0); |
|
468 #if 0 |
|
469 case DocSimpleSect::See: push("simplesect", "kind", "see"); break; |
|
470 case DocSimpleSect::Return: push("simplesect", "kind", "return"); break; |
|
471 case DocSimpleSect::Author: push("simplesect", "kind", "author"); break; |
|
472 case DocSimpleSect::Authors: push("simplesect", "kind", "authors"); break; |
|
473 case DocSimpleSect::Version: push("simplesect", "kind", "version"); break; |
|
474 case DocSimpleSect::Since: push("simplesect", "kind", "since"); break; |
|
475 case DocSimpleSect::Date: push("simplesect", "kind", "date"); break; |
|
476 case DocSimpleSect::Note: push("simplesect", "kind", "note"); break; |
|
477 case DocSimpleSect::Warning: push("simplesect", "kind", "warning"); break; |
|
478 case DocSimpleSect::Pre: push("simplesect", "kind", "pre"); break; |
|
479 case DocSimpleSect::Post: push("simplesect", "kind", "post"); break; |
|
480 case DocSimpleSect::Invar: push("simplesect", "kind", "invariant"); break; |
|
481 case DocSimpleSect::Remark: push("simplesect", "kind", "remark"); break; |
|
482 case DocSimpleSect::Attention: push("simplesect", "kind", "attention"); break; |
|
483 case DocSimpleSect::User: push("simplesect", "kind", "par"); break; |
|
484 case DocSimpleSect::Rcs: push("simplesect", "kind", "rcs"); break; |
|
485 case DocSimpleSect::Unknown: break; |
|
486 #endif |
|
487 } |
|
488 } |
|
489 |
|
490 void XmlDitaDocVisitor::visitPost(DocSimpleSect *s) |
|
491 { |
|
492 if (m_hide) { |
|
493 return; |
|
494 } |
|
495 switch(s->type()) |
|
496 { |
|
497 // Fall through |
|
498 case DocSimpleSect::Note: |
|
499 case DocSimpleSect::Warning: |
|
500 case DocSimpleSect::Remark: |
|
501 case DocSimpleSect::Attention: |
|
502 pop("note"); |
|
503 break; |
|
504 case DocSimpleSect::Unknown: |
|
505 break; |
|
506 default: |
|
507 if (!xmlElemStack.isEmpty() && xmlElemStack.peek().getElemName() == "p") { |
|
508 pop("p"); |
|
509 } |
|
510 break; |
|
511 } |
|
512 //visitPostDefault("simplesect"); |
|
513 } |
|
514 |
|
515 void XmlDitaDocVisitor::visitPre(DocTitle *) |
|
516 { |
|
517 if (!xmlElemStack.isEmpty() && xmlElemStack.peek().getElemName() == "concept") { |
|
518 visitPreDefault("title"); |
|
519 } else { |
|
520 if (xmlElemStack.isEmpty() || xmlElemStack.peek().getElemName() != "p") { |
|
521 visitPreDefault("p"); |
|
522 } |
|
523 visitPreDefault("b"); |
|
524 } |
|
525 |
|
526 } |
|
527 |
|
528 void XmlDitaDocVisitor::visitPost(DocTitle *) |
|
529 { |
|
530 if (xmlElemStack.peek().getElemName() == "title") { |
|
531 visitPostDefault("title"); |
|
532 } else { |
|
533 visitPostDefault("b"); |
|
534 if (!xmlElemStack.isEmpty() && xmlElemStack.peek().getElemName() == "p") { |
|
535 visitPostDefault("p"); |
|
536 } |
|
537 } |
|
538 } |
|
539 |
|
540 void XmlDitaDocVisitor::visitPre(DocSimpleList *) |
|
541 { |
|
542 visitPreDefault("ul"); |
|
543 } |
|
544 |
|
545 void XmlDitaDocVisitor::visitPost(DocSimpleList *) |
|
546 { |
|
547 visitPostDefault("ul"); |
|
548 } |
|
549 |
|
550 void XmlDitaDocVisitor::visitPre(DocSimpleListItem *) |
|
551 { |
|
552 visitPreDefault("li"); |
|
553 } |
|
554 |
|
555 void XmlDitaDocVisitor::visitPost(DocSimpleListItem *) |
|
556 { |
|
557 visitPostDefault("li"); |
|
558 } |
|
559 |
|
560 void XmlDitaDocVisitor::visitPre(DocSection *s) |
|
561 { |
|
562 // Currently unsupported |
|
563 #if 0 |
|
564 if (m_hide) { |
|
565 return; |
|
566 } |
|
567 QString sectNum; |
|
568 sectNum.setNum(s->level()); |
|
569 QString sectAnchor(s->file()); |
|
570 if (!s->anchor().isEmpty()) { |
|
571 sectAnchor.append("_1"); |
|
572 sectAnchor.append(s->anchor()); |
|
573 } |
|
574 push("sect"+sectNum, "id", sectAnchor); |
|
575 pushpop("title", s->title()); |
|
576 #endif |
|
577 } |
|
578 |
|
579 void XmlDitaDocVisitor::visitPost(DocSection *s) |
|
580 { |
|
581 #if 0 |
|
582 // The original did not have the if(m_hide) test. |
|
583 // I assume that is an error so visitPostDefault() uses it. |
|
584 QString level; |
|
585 level.setNum(s->level()); |
|
586 visitPostDefault("sect" + level); |
|
587 #endif |
|
588 } |
|
589 |
|
590 void XmlDitaDocVisitor::visitPre(DocHtmlList *s) |
|
591 { |
|
592 if (m_hide) { |
|
593 return; |
|
594 } |
|
595 if (s->type()==DocHtmlList::Ordered) { |
|
596 push("ol"); |
|
597 } else { |
|
598 push("ul"); |
|
599 } |
|
600 } |
|
601 |
|
602 void XmlDitaDocVisitor::visitPost(DocHtmlList *s) |
|
603 { |
|
604 if (s->type()==DocHtmlList::Ordered) { |
|
605 visitPostDefault("ol"); |
|
606 } else { |
|
607 visitPostDefault("ul"); |
|
608 } |
|
609 } |
|
610 |
|
611 void XmlDitaDocVisitor::visitPre(DocHtmlListItem *) |
|
612 { |
|
613 visitPreDefault("li"); |
|
614 } |
|
615 |
|
616 void XmlDitaDocVisitor::visitPost(DocHtmlListItem *) |
|
617 { |
|
618 visitPostDefault("li"); |
|
619 } |
|
620 |
|
621 void XmlDitaDocVisitor::visitPre(DocHtmlDescList *) |
|
622 { |
|
623 visitPreDefault("dl"); |
|
624 } |
|
625 |
|
626 void XmlDitaDocVisitor::visitPost(DocHtmlDescList *) |
|
627 { |
|
628 visitPostDefault("dl"); |
|
629 } |
|
630 |
|
631 void XmlDitaDocVisitor::visitPre(DocHtmlDescTitle *) |
|
632 { |
|
633 if (m_hide) { |
|
634 return; |
|
635 } |
|
636 push("dlentry"); |
|
637 push("dt"); |
|
638 //push("varlistentry"); |
|
639 //push("term"); |
|
640 } |
|
641 |
|
642 void XmlDitaDocVisitor::visitPost(DocHtmlDescTitle *) |
|
643 { |
|
644 if (m_hide) { |
|
645 return; |
|
646 } |
|
647 pop("dt"); |
|
648 //pop("dlentry"); |
|
649 // pop("term"); |
|
650 // pop("varlistentry"); |
|
651 } |
|
652 |
|
653 void XmlDitaDocVisitor::visitPre(DocHtmlDescData *) |
|
654 { |
|
655 push("dd"); |
|
656 //visitPreDefault("li"); |
|
657 } |
|
658 |
|
659 void XmlDitaDocVisitor::visitPost(DocHtmlDescData *) |
|
660 { |
|
661 pop("dd"); |
|
662 pop("dlentry"); |
|
663 //visitPostDefault("li"); |
|
664 } |
|
665 |
|
666 void XmlDitaDocVisitor::visitPre(DocHtmlTable *t) |
|
667 { |
|
668 if (m_hide) { |
|
669 return; |
|
670 } |
|
671 push("simpletable"); |
|
672 #if 0 |
|
673 AttributeMap attrs; |
|
674 QString vR, vC; |
|
675 vR.setNum(t->numRows()); |
|
676 attrs["rows"] = vR; |
|
677 vC.setNum(t->numCols()); |
|
678 attrs["cols"] = vC; |
|
679 push("table", attrs); |
|
680 #endif |
|
681 } |
|
682 |
|
683 void XmlDitaDocVisitor::visitPost(DocHtmlTable *) |
|
684 { |
|
685 visitPostDefault("simpletable"); |
|
686 } |
|
687 |
|
688 void XmlDitaDocVisitor::visitPre(DocHtmlRow *) |
|
689 { |
|
690 // FIXME look ahead to first cell |
|
691 // if isHeading is true do |
|
692 // visitPreDefault("sthead"); |
|
693 // else |
|
694 visitPreDefault("strow"); |
|
695 } |
|
696 |
|
697 void XmlDitaDocVisitor::visitPost(DocHtmlRow *) |
|
698 { |
|
699 visitPostDefault("strow"); |
|
700 } |
|
701 |
|
702 void XmlDitaDocVisitor::visitPre(DocHtmlCell *c) |
|
703 { |
|
704 visitPreDefault("stentry"); |
|
705 #if 0 |
|
706 if (m_hide) { |
|
707 return; |
|
708 } |
|
709 if (c->isHeading()) { |
|
710 push("entry", "thead", "yes"); |
|
711 } else { |
|
712 push("entry", "thead", "no"); |
|
713 } |
|
714 #endif |
|
715 } |
|
716 |
|
717 void XmlDitaDocVisitor::visitPost(DocHtmlCell *c) |
|
718 { |
|
719 visitPostDefault("stentry"); |
|
720 } |
|
721 |
|
722 void XmlDitaDocVisitor::visitPre(DocHtmlCaption *) |
|
723 { |
|
724 // Caption is unsupported |
|
725 } |
|
726 |
|
727 void XmlDitaDocVisitor::visitPost(DocHtmlCaption *) |
|
728 { |
|
729 // Caption is unsupported |
|
730 } |
|
731 |
|
732 void XmlDitaDocVisitor::visitPre(DocInternal *) |
|
733 { |
|
734 //visitPreDefault("internal"); |
|
735 } |
|
736 |
|
737 void XmlDitaDocVisitor::visitPost(DocInternal *) |
|
738 { |
|
739 //visitPostDefault("internal"); |
|
740 } |
|
741 |
|
742 void XmlDitaDocVisitor::visitPre(DocHRef *href) |
|
743 { |
|
744 push("xref", "href", href->url()); |
|
745 } |
|
746 |
|
747 void XmlDitaDocVisitor::visitPost(DocHRef *) |
|
748 { |
|
749 visitPostDefault("xref"); |
|
750 } |
|
751 |
|
752 void XmlDitaDocVisitor::visitPre(DocHtmlHeader *header) |
|
753 { |
|
754 visitPreDefault("b"); |
|
755 #if 0 |
|
756 QString hdgLevel; |
|
757 hdgLevel.setNum(header->level()); |
|
758 push("heading", "level", hdgLevel); |
|
759 #endif |
|
760 } |
|
761 |
|
762 void XmlDitaDocVisitor::visitPost(DocHtmlHeader *) |
|
763 { |
|
764 visitPostDefault("b"); |
|
765 } |
|
766 |
|
767 void XmlDitaDocVisitor::visitPre(DocImage *img) |
|
768 { |
|
769 // Currently unsupported |
|
770 #if 0 |
|
771 AttributeMap imgAttrs; |
|
772 // First the image type |
|
773 switch(img->type()) |
|
774 { |
|
775 case DocImage::Html: |
|
776 imgAttrs["type"] = "html"; |
|
777 break; |
|
778 case DocImage::Latex: |
|
779 imgAttrs["type"] = "latex"; |
|
780 break; |
|
781 case DocImage::Rtf: |
|
782 imgAttrs["type"] = "rtf"; |
|
783 break; |
|
784 default: |
|
785 ASSERT(0); |
|
786 break; |
|
787 } |
|
788 // Now the image name |
|
789 QString baseName=img->name(); |
|
790 int i; |
|
791 if ((i=baseName.findRev('/'))!=-1 || (i=baseName.findRev('\\'))!=-1) |
|
792 { |
|
793 baseName=baseName.right(baseName.length()-i-1); |
|
794 } |
|
795 imgAttrs["name"] = baseName; |
|
796 // Image width |
|
797 if (!img->width().isEmpty()) |
|
798 { |
|
799 imgAttrs["width"] = img->width(); |
|
800 } |
|
801 // Image height |
|
802 // NOTE: In the original this was an else if. I assume that this is an error |
|
803 if (!img->height().isEmpty()) |
|
804 { |
|
805 imgAttrs["height"] = img->height(); |
|
806 } |
|
807 push("image", imgAttrs); |
|
808 |
|
809 // copy the image to the output dir |
|
810 QFile inImage(img->name()); |
|
811 QFile outImage(Config_getString("XML_DITA_OUTPUT")+"/"+baseName.ascii()); |
|
812 if (inImage.open(IO_ReadOnly)) |
|
813 { |
|
814 if (outImage.open(IO_WriteOnly)) |
|
815 { |
|
816 char *buffer = new char[inImage.size()]; |
|
817 inImage.readBlock(buffer,inImage.size()); |
|
818 outImage.writeBlock(buffer,inImage.size()); |
|
819 outImage.flush(); |
|
820 delete[] buffer; |
|
821 } |
|
822 } |
|
823 #endif |
|
824 } |
|
825 |
|
826 void XmlDitaDocVisitor::visitPost(DocImage *) |
|
827 { |
|
828 //visitPostDefault("image"); |
|
829 } |
|
830 |
|
831 void XmlDitaDocVisitor::visitPre(DocDotFile *df) |
|
832 { |
|
833 // Currently unsupported |
|
834 #if 0 |
|
835 if (m_hide) { |
|
836 return; |
|
837 } |
|
838 push("dotfile", "name", df->file()); |
|
839 #endif |
|
840 } |
|
841 |
|
842 void XmlDitaDocVisitor::visitPost(DocDotFile *) |
|
843 { |
|
844 // visitPostDefault("dotfile"); |
|
845 } |
|
846 |
|
847 void XmlDitaDocVisitor::visitPre(DocLink *lnk) |
|
848 { |
|
849 if (m_hide) { |
|
850 return; |
|
851 } |
|
852 if (lnk->getDefinition() != 0) { |
|
853 startLink("", lnk->getDefinition()->qualifiedName(), ""); |
|
854 } else { |
|
855 startLink(lnk->ref(),lnk->file(),lnk->anchor()); |
|
856 } |
|
857 } |
|
858 |
|
859 void XmlDitaDocVisitor::visitPost(DocLink *) |
|
860 { |
|
861 if (m_hide) { |
|
862 return; |
|
863 } |
|
864 endLink(); |
|
865 } |
|
866 |
|
867 void XmlDitaDocVisitor::visitPre(DocRef *ref) |
|
868 { |
|
869 if (m_hide) { |
|
870 return; |
|
871 } |
|
872 if (!ref->file().isEmpty()) { |
|
873 if (ref->getDefinition() != 0) { |
|
874 startLink("", ref->getDefinition()->qualifiedName(), ""); |
|
875 } else { |
|
876 startLink(ref->ref(), ref->file(), ref->anchor()); |
|
877 } |
|
878 } |
|
879 if (!ref->hasLinkText()) { |
|
880 write(ref->targetTitle()); |
|
881 } |
|
882 } |
|
883 |
|
884 void XmlDitaDocVisitor::visitPost(DocRef *ref) |
|
885 { |
|
886 if (m_hide) { |
|
887 return; |
|
888 } |
|
889 if (!ref->file().isEmpty()) { |
|
890 endLink(); |
|
891 } |
|
892 write(" "); |
|
893 } |
|
894 |
|
895 void XmlDitaDocVisitor::visitPre(DocSecRefItem *ref) |
|
896 { |
|
897 if (m_hide) { |
|
898 return; |
|
899 } |
|
900 push("li", "id", ref->file()+"_1"+ref->anchor()); |
|
901 } |
|
902 |
|
903 void XmlDitaDocVisitor::visitPost(DocSecRefItem *) |
|
904 { |
|
905 visitPostDefault("li"); |
|
906 } |
|
907 |
|
908 void XmlDitaDocVisitor::visitPre(DocSecRefList *) |
|
909 { |
|
910 visitPreDefault("ul"); |
|
911 } |
|
912 |
|
913 void XmlDitaDocVisitor::visitPost(DocSecRefList *) |
|
914 { |
|
915 visitPostDefault("ul"); |
|
916 } |
|
917 |
|
918 void XmlDitaDocVisitor::visitPre(DocParamSect *s) |
|
919 { |
|
920 m_insideParamlist = TRUE; |
|
921 if (m_hide) { |
|
922 return; |
|
923 } |
|
924 switch(s->type()) { |
|
925 case DocParamSect::Param: |
|
926 push("paraml", "class", "param"); |
|
927 break; |
|
928 case DocParamSect::RetVal: |
|
929 push("paraml", "class", "retval"); |
|
930 break; |
|
931 case DocParamSect::Exception: |
|
932 push("paraml", "class", "exception"); |
|
933 break; |
|
934 case DocParamSect::TemplateParam: |
|
935 push("paraml", "class", "templateparam"); |
|
936 break; |
|
937 default: |
|
938 ASSERT(0); |
|
939 } |
|
940 } |
|
941 |
|
942 void XmlDitaDocVisitor::visitPost(DocParamSect *) |
|
943 { |
|
944 visitPostDefault("paraml"); |
|
945 m_insideParamlist = FALSE; |
|
946 } |
|
947 |
|
948 void XmlDitaDocVisitor::visitPre(DocParamList *pl) |
|
949 { |
|
950 if (m_hide) { |
|
951 return; |
|
952 } |
|
953 QListIterator<DocNode> li(pl->parameters()); |
|
954 DocNode *param; |
|
955 for (li.toFirst();(param=li.current());++li) { |
|
956 if (param->kind() == DocNode::Kind_Word) { |
|
957 currParam = ((DocWord*)param)->word(); |
|
958 } else if (param->kind() == DocNode::Kind_LinkedWord) { |
|
959 currParam = ((DocLinkedWord*)param)->word(); |
|
960 } else { |
|
961 // FIXME, what should we use here |
|
962 currParam = ""; |
|
963 } |
|
964 paramDict.insert(currParam, new QString("")); |
|
965 } |
|
966 |
|
967 #if 0 |
|
968 push("parameteritem"); |
|
969 push("parameternamelist"); |
|
970 QListIterator<DocNode> li(pl->parameters()); |
|
971 DocNode *param; |
|
972 for (li.toFirst();(param=li.current());++li) { |
|
973 AttributeMap attrs; |
|
974 if (pl->direction() != DocParamSect::Unspecified) { |
|
975 if (pl->direction() == DocParamSect::In) { |
|
976 attrs["direction"] = "in"; |
|
977 } else if (pl->direction() == DocParamSect::Out) { |
|
978 attrs["direction"] = "out"; |
|
979 } else if (pl->direction() == DocParamSect::InOut) { |
|
980 attrs["direction"] = "inout"; |
|
981 } else{ |
|
982 ASSERT(0); |
|
983 } |
|
984 } |
|
985 push("parametername", attrs); |
|
986 if (param->kind() == DocNode::Kind_Word) |
|
987 { |
|
988 visit((DocWord*)param); |
|
989 } |
|
990 else if (param->kind() == DocNode::Kind_LinkedWord) |
|
991 { |
|
992 visit((DocLinkedWord*)param); |
|
993 } |
|
994 pop("parametername"); |
|
995 } |
|
996 pop("parameternamelist"); |
|
997 push("parameterdescription"); |
|
998 #endif |
|
999 } |
|
1000 |
|
1001 void XmlDitaDocVisitor::visitPost(DocParamList *) |
|
1002 { |
|
1003 if (m_hide) { |
|
1004 return; |
|
1005 } |
|
1006 pop("parameterdescription"); |
|
1007 pop("parameteritem"); |
|
1008 } |
|
1009 |
|
1010 void XmlDitaDocVisitor::visitPre(DocXRefItem *x) |
|
1011 { |
|
1012 if (m_hide) { |
|
1013 return; |
|
1014 } |
|
1015 // \deprecated commands result in DocXRefItem |
|
1016 // with "deprecated" as the filename |
|
1017 if (x->file() == "deprecated"){ |
|
1018 // Fall through to start new paragraph for deprecated description |
|
1019 }else |
|
1020 { |
|
1021 push("xref", "id", x->file()+"_1"+x->anchor()); |
|
1022 write(x->title()); |
|
1023 } |
|
1024 #if 0 |
|
1025 push("xrefsect", "id", x->file()+"_1"+x->anchor()); |
|
1026 pushpop("xreftitle", x->title()); |
|
1027 push("xrefdescription"); |
|
1028 #endif |
|
1029 } |
|
1030 |
|
1031 void XmlDitaDocVisitor::visitPost(DocXRefItem *) |
|
1032 { |
|
1033 if (m_hide) { |
|
1034 return; |
|
1035 } |
|
1036 // An xref will be top of stack unless the current |
|
1037 // DocXRefItem was caused by a \deprecated command |
|
1038 if (!xmlElemStack.isEmpty() && xmlElemStack.peek().getElemName() == "xref") { |
|
1039 pop("xref"); |
|
1040 } |
|
1041 |
|
1042 #if 0 |
|
1043 pop("xrefdescription"); |
|
1044 pop("xrefsect"); |
|
1045 #endif |
|
1046 } |
|
1047 |
|
1048 void XmlDitaDocVisitor::visitPre(DocInternalRef *ref) |
|
1049 { |
|
1050 if (m_hide) { |
|
1051 return; |
|
1052 } |
|
1053 startLink(0, ref->file(), ref->anchor()); |
|
1054 } |
|
1055 |
|
1056 void XmlDitaDocVisitor::visitPost(DocInternalRef *) |
|
1057 { |
|
1058 if (m_hide) { |
|
1059 return; |
|
1060 } |
|
1061 endLink(); |
|
1062 write(" "); |
|
1063 } |
|
1064 |
|
1065 void XmlDitaDocVisitor::visitPre(DocCopy *c) |
|
1066 { |
|
1067 // Currently unsupported |
|
1068 #if 0 |
|
1069 if (m_hide) { |
|
1070 return; |
|
1071 } |
|
1072 push("copydoc", "link", c->link()); |
|
1073 #endif |
|
1074 } |
|
1075 |
|
1076 void XmlDitaDocVisitor::visitPost(DocCopy *) |
|
1077 { |
|
1078 // visitPostDefault("copydoc"); |
|
1079 } |
|
1080 |
|
1081 void XmlDitaDocVisitor::visitPre(DocText *) |
|
1082 {} |
|
1083 |
|
1084 void XmlDitaDocVisitor::visitPost(DocText *) |
|
1085 {} |
|
1086 |
|
1087 void XmlDitaDocVisitor::startXref(const QString &href,const QString &text) |
|
1088 { |
|
1089 push("xref", "href", href); |
|
1090 write(text); |
|
1091 } |
|
1092 |
|
1093 void XmlDitaDocVisitor::endXref() |
|
1094 { |
|
1095 pop("xref"); |
|
1096 } |
|
1097 |
|
1098 void XmlDitaDocVisitor::startLink(const QString &ref,const QString &file,const QString &anchor) |
|
1099 { |
|
1100 AttributeMap refAttrs; |
|
1101 if (!anchor.isEmpty()) { |
|
1102 refAttrs["href"] = file+"_1"+anchor; |
|
1103 } else { |
|
1104 refAttrs["href"] = file; |
|
1105 } |
|
1106 push("xref", refAttrs); |
|
1107 #if 0 |
|
1108 AttributeMap refAttrs; |
|
1109 if (!anchor.isEmpty()) { |
|
1110 refAttrs["refid"] = file+"_1"+anchor; |
|
1111 refAttrs["kindref"] = "member"; |
|
1112 } else { |
|
1113 refAttrs["refid"] = file; |
|
1114 refAttrs["kindref"] = "compound"; |
|
1115 } |
|
1116 if (!ref.isEmpty()) { |
|
1117 refAttrs["external"] = ref; |
|
1118 } |
|
1119 push("ref", refAttrs); |
|
1120 #endif |
|
1121 } |
|
1122 |
|
1123 void XmlDitaDocVisitor::endLink() |
|
1124 { |
|
1125 visitPostDefault("xref"); |
|
1126 } |
|
1127 |
|
1128 void XmlDitaDocVisitor::pushEnabled() |
|
1129 { |
|
1130 m_enabled.push(new bool(m_hide)); |
|
1131 } |
|
1132 |
|
1133 void XmlDitaDocVisitor::popEnabled() |
|
1134 { |
|
1135 bool *v = m_enabled.pop(); |
|
1136 ASSERT(v!=0); |
|
1137 m_hide = *v; |
|
1138 delete v; |
|
1139 } |
|
1140 |
|
1141 |
|
1142 void XmlDitaDocVisitor::write(const QString &string) |
|
1143 { |
|
1144 if (m_insideParamlist) { |
|
1145 // TODO: Review the use of paramDict as I think that there is a |
|
1146 // memory leak here [PaulRo 2010-01-20] |
|
1147 QString *pStr = paramDict.find(currParam); |
|
1148 if (pStr) { |
|
1149 paramDict.replace(currParam, new QString(*pStr + string)); |
|
1150 } else { |
|
1151 paramDict.replace(currParam, new QString(string)); |
|
1152 } |
|
1153 } else { |
|
1154 xmlStream << string; |
|
1155 } |
|
1156 } |
|
1157 |
|
1158 void XmlDitaDocVisitor::push(const QString &tagName) |
|
1159 { |
|
1160 if (m_insideParamlist) { |
|
1161 // TODO |
|
1162 } else { |
|
1163 xmlElemStack.push(tagName); |
|
1164 } |
|
1165 } |
|
1166 |
|
1167 void XmlDitaDocVisitor::push(const QString &tagName, const QString &key, const QString &value) |
|
1168 { |
|
1169 if (m_insideParamlist) { |
|
1170 // TODO |
|
1171 } else { |
|
1172 xmlElemStack.push(tagName, key, value); |
|
1173 } |
|
1174 } |
|
1175 |
|
1176 void XmlDitaDocVisitor::push(const QString &tagName, AttributeMap &map) |
|
1177 { |
|
1178 if (m_insideParamlist) { |
|
1179 // TODO |
|
1180 } else { |
|
1181 xmlElemStack.push(tagName, map); |
|
1182 } |
|
1183 } |
|
1184 |
|
1185 void XmlDitaDocVisitor::pop(const QString &tagName) |
|
1186 { |
|
1187 if (m_insideParamlist) { |
|
1188 // TODO |
|
1189 } else { |
|
1190 xmlElemStack.pop(tagName); |
|
1191 } |
|
1192 } |
|
1193 |
|
1194 void XmlDitaDocVisitor::pushpop(const QString &tagName) |
|
1195 { |
|
1196 if (m_insideParamlist) { |
|
1197 // TODO |
|
1198 } else { |
|
1199 xmlElemStack.pushpop(tagName); |
|
1200 } |
|
1201 } |
|
1202 |
|
1203 void XmlDitaDocVisitor::pushpop(const QString &tagName, const QString &text) |
|
1204 { |
|
1205 if (m_insideParamlist) { |
|
1206 paramDict.replace(currParam, new QString(*paramDict[currParam] + text)); |
|
1207 } else { |
|
1208 xmlElemStack.pushpop(tagName, text); |
|
1209 } |
|
1210 } |
|
1211 |
|
1212 const QString XmlDitaDocVisitor::query(const QString ¶mName) const |
|
1213 { |
|
1214 if (paramDict.find(paramName)) { |
|
1215 return *paramDict[paramName]; |
|
1216 } else { |
|
1217 // TODO positional option |
|
1218 return ""; |
|
1219 } |
|
1220 } |
|
1221 |
|
1222 /** Default treatment of a post traversal visit, this just |
|
1223 pushes a single element with no attributes. */ |
|
1224 void XmlDitaDocVisitor::visitPreDefault(const QString& elem) |
|
1225 { |
|
1226 if (m_hide) { |
|
1227 return; |
|
1228 } |
|
1229 push(elem); |
|
1230 } |
|
1231 |
|
1232 /** Default treatment of a post traversal visit, this just |
|
1233 pops a single element. */ |
|
1234 void XmlDitaDocVisitor::visitPostDefault(const QString& elem) |
|
1235 { |
|
1236 if (m_hide) { |
|
1237 return; |
|
1238 } |
|
1239 pop(elem); |
|
1240 } |
|
1241 |