01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
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.xmlutil.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: import java.util.List;
35:
36: public class MyCommentsRequest extends AbstractRequest implements
37: Request {
38: public MyCommentsRequest(LocationInfo locationInfo) {
39: super (locationInfo);
40: }
41:
42: public void processInt(ContentHandler contentHandler,
43: PublisherContext publisherContext) throws Exception {
44: Repository repository = publisherContext.getRepository();
45: CommentsDocument commentsDocument = repository
46: .getCommentManager().getComments(
47: CommentVisibility.PRIVATE).getXml();
48: annotateMyComments(commentsDocument.getComments()
49: .getCommentList(), publisherContext);
50: commentsDocument.save(new StripDocumentHandler(
51: new InsertBreaksInCommentsHandler(contentHandler)),
52: new DummyLexicalHandler());
53: }
54:
55: public void annotateMyComments(
56: List<CommentDocument.Comment> commentsXml,
57: PublisherContext publisherContext)
58: throws RepositoryException {
59: Repository repository = publisherContext.getRepository();
60: DateFormat dateFormat = publisherContext.getTimestampFormat();
61: UserManager userManager = repository.getUserManager();
62: VariantManager variantManager = repository.getVariantManager();
63:
64: for (CommentDocument.Comment commentXml : commentsXml) {
65: Document document = repository.getDocument(commentXml
66: .getDocumentId(), commentXml.getBranchId(),
67: commentXml.getLanguageId(), false);
68:
69: String documentName;
70: Version liveVersion = document.getLiveVersion();
71: if (liveVersion != null)
72: documentName = liveVersion.getDocumentName();
73: else
74: documentName = document.getName();
75: String branch = variantManager.getBranch(
76: commentXml.getBranchId(), false).getName();
77: String language = variantManager.getLanguage(
78: commentXml.getLanguageId(), false).getName();
79: String createdByDisplayName = userManager
80: .getUserDisplayName(commentXml.getCreatedBy());
81: String createdOnFormatted = dateFormat.format(commentXml
82: .getCreatedOn().getTime());
83:
84: XmlCursor cursor = commentXml.newCursor();
85: cursor.toNextToken();
86: cursor.insertAttributeWithValue("createdOnFormatted",
87: createdOnFormatted);
88: cursor.insertAttributeWithValue("createdByDisplayName",
89: createdByDisplayName);
90: cursor.insertAttributeWithValue("documentName",
91: documentName);
92: cursor.insertAttributeWithValue("branch", branch);
93: cursor.insertAttributeWithValue("language", language);
94: cursor.dispose();
95:
96: }
97: }
98: }
|