KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > publisher > serverimpl > requestmodel > MyCommentsRequest


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.publisher.serverimpl.requestmodel;
17
18 import org.xml.sax.ContentHandler JavaDoc;
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 JavaDoc;
34
35 public class MyCommentsRequest implements Request {
36     public void process(ContentHandler JavaDoc contentHandler, PublisherContext publisherContext) throws Exception JavaDoc {
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 JavaDoc 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 JavaDoc documentName;
55             Version liveVersion = document.getLiveVersion();
56             if (liveVersion != null)
57                 documentName = liveVersion.getDocumentName();
58             else
59                 documentName = document.getName();
60             String JavaDoc branch = variantManager.getBranch(commentXml.getBranchId(), false).getName();
61             String JavaDoc language = variantManager.getLanguage(commentXml.getLanguageId(), false).getName();
62             String JavaDoc createdByDisplayName = userManager.getUserDisplayName(commentXml.getCreatedBy());
63             String JavaDoc 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