}
public void serialize(OutputStream out) throws IOException {
XMLSerializer ser = new XMLSerializer(out);
ser.startDocument("1.0", "UTF-8");
SMapImpl attrs = new SMapImpl();
attrs.put(null, "version", "2005-1");
String lang = epub.getDCMetadata("language");
if (lang != null)
attrs.put(null, "xml:lang", lang);
ser.startElement(ncxns, "ncx", attrs, true);
ser.newLine();
ser.startElement(ncxns, "head", null, false);
ser.newLine();
attrs = new SMapImpl();
attrs.put(null, "name", "dtb:uid");
String uid = epub.getDCMetadata("identifier");
if (uid == null)
uid = "";
attrs.put(null, "content", uid);
ser.startElement(ncxns, "meta", attrs, false);
ser.endElement(ncxns, "meta");
ser.newLine();
attrs = new SMapImpl();
attrs.put(null, "name", "dtb:depth");
int depth = calculateDepth(rootTOCEntry);
attrs.put(null, "content", Integer.toString(depth));
ser.startElement(ncxns, "meta", attrs, false);
ser.endElement(ncxns, "meta");
ser.newLine();
attrs = new SMapImpl();
attrs.put(null, "name", "dtb:totalPageNumber");
attrs.put(null, "content", Integer.toString(pages.size()));
ser.startElement(ncxns, "meta", attrs, false);
ser.endElement(ncxns, "meta");
ser.newLine();
attrs = new SMapImpl();
attrs.put(null, "name", "dtb:maxPageNumber");
attrs.put(null, "content", Integer.toString(pages.size()));
ser.startElement(ncxns, "meta", attrs, false);
ser.endElement(ncxns, "meta");
ser.newLine();
ser.endElement(ncxns, "head");
ser.newLine();
ser.startElement(ncxns, "docTitle", null, false);
ser.startElement(ncxns, "text", null, false);
String title = epub.getDCMetadata("title");
if (title == null)
title = "";
if (epub.isTranslit())
title = Translit.translit(title);
char[] arr = title.toCharArray();
ser.text(arr, 0, arr.length);
ser.endElement(ncxns, "text");
ser.endElement(ncxns, "docTitle");
ser.newLine();
ser.startElement(ncxns, "navMap", null, false);
ser.newLine();
entryCount = 1;
serializeChildEntries(rootTOCEntry, ser);
ser.endElement(ncxns, "navMap");
ser.newLine();
if (pages.size() > 0) {
ser.startElement(ncxns, "pageList", null, false);
ser.startElement(ncxns, "navLabel", null, false);
ser.startElement(ncxns, "text", null, false);
ser.endElement(ncxns, "text");
ser.endElement(ncxns, "navLabel");
ser.newLine();
Iterator pages = this.pages.iterator();
int count = 1;
while (pages.hasNext()) {
Page page = (Page) pages.next();
attrs = new SMapImpl();
String countStr = Integer.toString(count++);
attrs.put(null, "value", countStr);
attrs.put(null, "type", "normal");
attrs.put(null, "playOrder", Integer.toString(page.xref.getPlayOrder()));
ser.startElement(ncxns, "pageTarget", attrs, false);
ser.newLine();
ser.startElement(ncxns, "navLabel", null, false);
ser.startElement(ncxns, "text", null, false);
char[] text = page.name.toCharArray();
ser.text(text, 0, text.length);
ser.endElement(ncxns, "text");
ser.endElement(ncxns, "navLabel");
ser.newLine();
attrs = new SMapImpl();
attrs.put(null, "src", page.xref.makeReference(this));
ser.startElement(ncxns, "content", attrs, false);
ser.endElement(ncxns, "content");
ser.newLine();
ser.endElement(ncxns, "pageTarget");
ser.newLine();