1 16 package org.outerj.daisy.publisher.serverimpl.requestmodel; 17 18 import org.xml.sax.ContentHandler ; 19 import org.outerx.daisy.x10.CommentsDocument; 20 import org.outerx.daisy.x10.CommentDocument; 21 import org.outerj.daisy.repository.comment.CommentVisibility; 22 import org.outerj.daisy.repository.RepositoryException; 23 import org.outerj.daisy.repository.Document; 24 import org.outerj.daisy.repository.Version; 25 import org.outerj.daisy.repository.Repository; 26 import org.outerj.daisy.repository.variant.VariantManager; 27 import org.outerj.daisy.repository.user.UserManager; 28 import org.outerj.daisy.publisher.serverimpl.StripDocumentHandler; 29 import org.outerj.daisy.publisher.serverimpl.InsertBreaksInCommentsHandler; 30 import org.outerj.daisy.publisher.serverimpl.DummyLexicalHandler; 31 import org.apache.xmlbeans.XmlCursor; 32 33 import java.text.DateFormat ; 34 35 public class MyCommentsRequest implements Request { 36 public void process(ContentHandler contentHandler, PublisherContext publisherContext) throws Exception { 37 Repository repository = publisherContext.getRepository(); 38 CommentsDocument commentsDocument = repository.getCommentManager().getComments(CommentVisibility.PRIVATE).getXml(); 39 annotateMyComments(commentsDocument.getComments().getCommentArray(), publisherContext); 40 commentsDocument.save(new StripDocumentHandler(new InsertBreaksInCommentsHandler(contentHandler)), new DummyLexicalHandler()); 41 } 42 43 public void annotateMyComments(CommentDocument.Comment[] commentsXml, PublisherContext publisherContext) throws RepositoryException { 44 Repository repository = publisherContext.getRepository(); 45 DateFormat dateFormat = publisherContext.getTimestampFormat(); 46 UserManager userManager = repository.getUserManager(); 47 VariantManager variantManager = repository.getVariantManager(); 48 49 50 for (int i = 0; i < commentsXml.length; i++) { 51 CommentDocument.Comment commentXml = commentsXml[i]; 52 Document document = repository.getDocument(commentXml.getDocumentId(), commentXml.getBranchId(), commentXml.getLanguageId(), false); 53 54 String documentName; 55 Version liveVersion = document.getLiveVersion(); 56 if (liveVersion != null) 57 documentName = liveVersion.getDocumentName(); 58 else 59 documentName = document.getName(); 60 String branch = variantManager.getBranch(commentXml.getBranchId(), false).getName(); 61 String language = variantManager.getLanguage(commentXml.getLanguageId(), false).getName(); 62 String createdByDisplayName = userManager.getUserDisplayName(commentXml.getCreatedBy()); 63 String createdOnFormatted = dateFormat.format(commentXml.getCreatedOn().getTime()); 64 65 XmlCursor cursor = commentXml.newCursor(); 66 cursor.toNextToken(); 67 cursor.insertAttributeWithValue("createdOnFormatted", createdOnFormatted); 68 cursor.insertAttributeWithValue("createdByDisplayName", createdByDisplayName); 69 cursor.insertAttributeWithValue("documentName", documentName); 70 cursor.insertAttributeWithValue("branch", branch); 71 cursor.insertAttributeWithValue("language", language); 72 cursor.dispose(); 73 74 } 75 } 76 } 77 | Popular Tags |