1 16 package org.outerj.daisy.publisher.serverimpl.docpreparation; 17 18 import org.outerj.daisy.xmlutil.SaxBuffer; 19 import org.outerj.daisy.publisher.serverimpl.PublisherImpl; 20 import org.outerj.daisy.repository.VariantKey; 21 import org.xml.sax.ContentHandler ; 22 import org.xml.sax.SAXException ; 23 import org.xml.sax.helpers.AttributesImpl ; 24 25 import java.util.List ; 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 29 34 public class PreparedDocuments { 35 private List preparedDocuments = new ArrayList (); 36 private final VariantKey navigationDoc; 37 private final String pubReqSet; 38 39 public PreparedDocuments(VariantKey navigationDoc, String pubReqSet) { 40 this.navigationDoc = navigationDoc; 41 this.pubReqSet = pubReqSet; 42 } 43 44 public PreparedDocument getNewPreparedDocument(VariantKey document) { 45 int id = preparedDocuments.size() + 1; 46 PreparedDocument preparedDocument = new PreparedDocument(new SaxBuffer(), id, document); 47 preparedDocuments.add(preparedDocument); 48 return preparedDocument; 49 } 50 51 public static class PreparedDocument { 52 private VariantKey documentKey; 53 private SaxBuffer saxBuffer; 54 private int id; 55 56 public PreparedDocument(SaxBuffer saxBuffer, int id, VariantKey documentKey) { 57 this.saxBuffer = saxBuffer; 58 this.id = id; 59 this.documentKey = documentKey; 60 } 61 62 public SaxBuffer getSaxBuffer() { 63 return saxBuffer; 64 } 65 66 public int getId() { 67 return id; 68 } 69 70 public VariantKey getDocumentKey() { 71 return documentKey; 72 } 73 } 74 75 public void generateSax(ContentHandler contentHandler, boolean applyDocumentSpecificStyling) throws SAXException { 76 AttributesImpl rootAttrs = new AttributesImpl (); 77 rootAttrs.addAttribute("", "applyDocumentTypeStyling", "applyDocumentTypeStyling", "CDATA", String.valueOf(applyDocumentSpecificStyling)); 78 contentHandler.startElement(PublisherImpl.NAMESPACE, "preparedDocuments", "p:preparedDocuments", rootAttrs); 79 80 Iterator documentsIt = preparedDocuments.iterator(); 81 while (documentsIt.hasNext()) { 82 PreparedDocument preparedDocument = (PreparedDocument)documentsIt.next(); 83 AttributesImpl attrs = new AttributesImpl (); 84 attrs.addAttribute("", "id", "id", "CDATA", String.valueOf(preparedDocument.getId())); 85 VariantKey documentKey = preparedDocument.getDocumentKey(); 86 attrs.addAttribute("", "documentId", "documentId", "CDATA", String.valueOf(documentKey.getDocumentId())); 87 attrs.addAttribute("", "branchId", "branchId", "CDATA", String.valueOf(documentKey.getBranchId())); 88 attrs.addAttribute("", "languageId", "languageId", "CDATA", String.valueOf(documentKey.getLanguageId())); 89 90 contentHandler.startElement(PublisherImpl.NAMESPACE, "preparedDocument", "p:preparedDocument", attrs); 91 preparedDocument.getSaxBuffer().toSAX(contentHandler); 92 contentHandler.endElement(PublisherImpl.NAMESPACE, "preparedDocument", "p:preparedDocument"); 93 } 94 95 contentHandler.endElement(PublisherImpl.NAMESPACE, "preparedDocuments", "p:preparedDocuments"); 96 } 97 98 public VariantKey getNavigationDoc() { 99 return navigationDoc; 100 } 101 102 public String getPubReqSet() { 103 return pubReqSet; 104 } 105 } 106 | Popular Tags |