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 java.text.DateFormat;
19: import java.util.Date;
20:
21: import org.apache.xmlbeans.XmlCursor;
22: import org.outerj.daisy.publisher.serverimpl.DummyLexicalHandler;
23: import org.outerj.daisy.repository.Document;
24: import org.outerj.daisy.repository.Repository;
25: import org.outerj.daisy.repository.RepositoryException;
26: import org.outerj.daisy.repository.Version;
27: import org.outerj.daisy.repository.user.UserManager;
28: import org.outerj.daisy.repository.variant.VariantManager;
29: import org.outerj.daisy.xmlutil.StripDocumentHandler;
30: import org.outerx.daisy.x10.VersionDocument;
31: import org.xml.sax.ContentHandler;
32:
33: public class ShallowAnnotatedVersionRequest extends AbstractRequest
34: implements Request {
35: public ShallowAnnotatedVersionRequest(LocationInfo locationInfo) {
36: super (locationInfo);
37: }
38:
39: public void processInt(ContentHandler contentHandler,
40: PublisherContext publisherContext) throws Exception {
41: Document document = publisherContext.getDocument();
42: Version version = publisherContext.getVersion();
43: if (version != null) {
44:
45: VersionDocument versionXml = version.getShallowXml();
46: Version liveVersion = document.getLiveVersion();
47: long liveVersionId = liveVersion != null ? liveVersion
48: .getId() : -1;
49: annotateVersion(versionXml.getVersion(), liveVersionId,
50: publisherContext);
51: versionXml.save(new StripDocumentHandler(contentHandler),
52: new DummyLexicalHandler());
53: }
54: }
55:
56: private void annotateVersion(VersionDocument.Version versionXml,
57: long liveVersionId, PublisherContext publisherContext)
58: throws RepositoryException {
59: DateFormat dateFormat = publisherContext.getTimestampFormat();
60: Repository repository = publisherContext.getRepository();
61: UserManager userManager = repository.getUserManager();
62: VariantManager variantManager = repository.getVariantManager();
63:
64: long creatorId = versionXml.getCreator();
65: Date created = versionXml.getCreated().getTime();
66: Date lastModified = versionXml.getLastModified().getTime();
67: long lastModifierId = versionXml.getLastModifier();
68: boolean isLiveVersion = (versionXml.getId() == liveVersionId);
69:
70: XmlCursor cursor = versionXml.newCursor();
71: cursor.toNextToken();
72: cursor.insertAttributeWithValue("createdFormatted", dateFormat
73: .format(created));
74: cursor.insertAttributeWithValue("creatorDisplayName",
75: userManager.getUserDisplayName(creatorId));
76: cursor.insertAttributeWithValue("lastModifiedFormatted",
77: dateFormat.format(lastModified));
78: cursor.insertAttributeWithValue("lastModifierDisplayName",
79: userManager.getUserDisplayName(lastModifierId));
80: if (versionXml.isSetSyncedWithLanguageId()
81: && versionXml.getSyncedWithLanguageId() != -1)
82: cursor.insertAttributeWithValue("syncedWithLanguage",
83: variantManager
84: .getLanguage(
85: versionXml
86: .getSyncedWithLanguageId(),
87: false).getName());
88: if (isLiveVersion)
89: cursor.insertAttributeWithValue("live", "true");
90: cursor.dispose();
91:
92: String updatedName = publisherContext
93: .resolveVariables(versionXml.getDocumentName());
94: if (updatedName != null)
95: versionXml.setDocumentName(updatedName);
96: }
97: }
|