001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.lenya.cms.cocoon.acting;
020:
021: import java.io.File;
022: import java.util.Map;
023:
024: import org.apache.avalon.framework.parameters.Parameters;
025: import org.apache.cocoon.acting.ServiceableAction;
026: import org.apache.cocoon.environment.ObjectModelHelper;
027: import org.apache.cocoon.environment.Redirector;
028: import org.apache.cocoon.environment.Request;
029: import org.apache.cocoon.environment.Session;
030: import org.apache.cocoon.environment.SourceResolver;
031: import org.apache.lenya.ac.AccessControlException;
032: import org.apache.lenya.ac.Identity;
033: import org.apache.lenya.ac.User;
034: import org.apache.lenya.cms.publication.Document;
035: import org.apache.lenya.cms.publication.DocumentFactory;
036: import org.apache.lenya.cms.publication.DocumentUtil;
037: import org.apache.lenya.cms.publication.PageEnvelope;
038: import org.apache.lenya.cms.publication.PageEnvelopeFactory;
039: import org.apache.lenya.cms.publication.Publication;
040: import org.apache.lenya.cms.publication.PublicationUtil;
041: import org.apache.lenya.cms.rc.RCEnvironment;
042: import org.apache.lenya.cms.repository.Node;
043: import org.apache.lenya.cms.repository.RepositoryUtil;
044:
045: /**
046: * Revision controller action.
047: *
048: * @version $Id: RevisionControllerAction.java 487290 2006-12-14 18:18:35Z
049: * andreas $
050: */
051: public class RevisionControllerAction extends ServiceableAction {
052:
053: private String rcmlDirectory = null;
054: private String backupDirectory = null;
055: private String username = null;
056: private Node node = null;
057:
058: /**
059: * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector,
060: * org.apache.cocoon.environment.SourceResolver, java.util.Map,
061: * java.lang.String, org.apache.avalon.framework.parameters.Parameters)
062: */
063: public Map act(Redirector redirector, SourceResolver resolver,
064: Map objectModel, String src, Parameters parameters)
065: throws Exception {
066: // Get request object
067: Request request = ObjectModelHelper.getRequest(objectModel);
068:
069: if (request == null) {
070: getLogger().error(".act(): No request object");
071:
072: return null;
073: }
074:
075: PageEnvelope envelope = null;
076: Publication publication;
077:
078: try {
079: publication = PublicationUtil.getPublication(this .manager,
080: request);
081: } catch (Exception e) {
082: throw new AccessControlException(e);
083: }
084: org.apache.lenya.cms.repository.Session repoSession = RepositoryUtil
085: .getSession(this .manager, request);
086:
087: DocumentFactory factory = DocumentUtil.createDocumentFactory(
088: this .manager, repoSession);
089: Document document = null;
090:
091: try {
092: publication = PublicationUtil.getPublication(this .manager,
093: objectModel);
094: envelope = PageEnvelopeFactory.getInstance()
095: .getPageEnvelope(factory, objectModel, publication);
096: document = envelope.getDocument();
097: } catch (Exception e) {
098: getLogger().error("Resolving page envelope failed: ", e);
099: throw e;
100: }
101:
102: // get Parameters for RC
103: String publicationPath = publication.getDirectory()
104: .getCanonicalPath();
105: RCEnvironment rcEnvironment = RCEnvironment.getInstance(
106: publication.getServletContext().getCanonicalPath(),
107: getLogger());
108: this .rcmlDirectory = rcEnvironment.getRCMLDirectory();
109: this .rcmlDirectory = publicationPath + File.separator
110: + this .rcmlDirectory;
111: this .backupDirectory = rcEnvironment.getBackupDirectory();
112: this .backupDirectory = publicationPath + File.separator
113: + this .backupDirectory;
114:
115: // Get session
116: Session session = request.getSession(false);
117:
118: if (session == null) {
119: getLogger().error(".act(): No session object");
120:
121: return null;
122: }
123:
124: Identity identity = (Identity) session
125: .getAttribute(Identity.class.getName());
126: getLogger().debug(".act(): Identity: " + identity);
127:
128: // FIXME: hack because of the uri for the editor bitflux. The filename
129: // cannot be get from
130: // the page-envelope
131:
132: String documentid = document.getPath();
133: int bx = documentid.lastIndexOf("-bxe");
134:
135: if (bx > 0) {
136: String language = document.getLanguage();
137:
138: int l = documentid.length();
139: int bxLength = "-bxe".length();
140: int lang = documentid.lastIndexOf("_", bx);
141: int langLength = bx - lang;
142:
143: if (bx > 0 && bx + bxLength <= l) {
144: documentid = documentid.substring(0, bx)
145: + documentid.substring(bx + bxLength, l);
146:
147: if (lang > 0 && langLength + lang < l) {
148: language = documentid.substring(lang + 1, lang
149: + langLength);
150: documentid = documentid.substring(0, lang)
151: + documentid.substring(lang + langLength, l
152: - bxLength);
153: }
154: }
155:
156: Document srcDoc = factory.get(publication, document
157: .getArea(), documentid, language);
158: this .node = srcDoc.getRepositoryNode();
159:
160: } else {
161: this .node = document.getRepositoryNode();
162: }
163:
164: this .username = null;
165:
166: if (identity != null) {
167: User user = identity.getUser();
168: if (user != null) {
169: this .username = user.getId();
170: }
171: } else {
172: getLogger().error(".act(): No identity yet");
173: }
174:
175: getLogger().debug(".act(): Username: " + this .username);
176:
177: return null;
178: }
179:
180: /**
181: * Get the node.
182: * @return the node
183: */
184: protected Node getNode() {
185: return this .node;
186: }
187:
188: /**
189: * Get the user name.
190: * @return the user name
191: */
192: protected String getUsername() {
193: return this.username;
194: }
195:
196: }
|