1 29 30 package com.caucho.xtpdoc; 31 32 import javax.xml.stream.XMLStreamException; 33 import javax.xml.stream.XMLStreamWriter; 34 import java.io.IOException ; 35 import java.io.PrintWriter ; 36 37 public class Localtoc implements ContentItem { 38 Document _document; 39 40 Localtoc(Document doc) 41 { 42 _document = doc; 43 } 44 45 public void writeHtml(XMLStreamWriter out) 46 throws XMLStreamException 47 { 48 ContainerNode container = _document.getBody(); 49 50 writeContainer(out, container); 51 } 52 53 private void writeContainer(XMLStreamWriter out, ContainerNode container) 54 throws XMLStreamException 55 { 56 if (container == null) 57 return; 58 59 out.writeStartElement("div"); 60 out.writeAttribute("class", "toc"); 61 out.writeStartElement("ol"); 62 63 for (ContentItem item : container.getItems()) { 64 if (item instanceof Section) { 65 Section section = (Section) item; 66 67 if (section.getTitle() != null 68 && ! "".equals(section.getTitle())) { 69 out.writeStartElement("li"); 70 out.writeStartElement("a"); 71 out.writeAttribute("href", "#" + section.getHref()); 72 out.writeCharacters(section.getTitle()); 73 out.writeEndElement(); 74 out.writeEndElement(); 75 76 writeContainer(out, section); 77 } 78 } 79 } 80 out.writeEndElement(); out.writeEndElement(); } 83 84 public void writeLaTeX(PrintWriter writer) 85 throws IOException 86 { 87 } 88 89 public void writeLaTeXTop(PrintWriter out) 90 throws IOException 91 { 92 } 93 94 public void writeLaTeXEnclosed(PrintWriter out) 95 throws IOException 96 { 97 } 98 } 99 | Popular Tags |