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: package org.apache.lenya.cms.usecases.webdav;
019:
020: import java.text.SimpleDateFormat;
021: import java.util.Vector;
022:
023: import org.apache.lenya.cms.publication.Document;
024: import org.apache.lenya.cms.publication.Publication;
025: import org.apache.lenya.cms.publication.PublicationException;
026: import org.apache.lenya.cms.publication.PublicationUtil;
027: import org.apache.lenya.cms.publication.URLInformation;
028: import org.apache.lenya.cms.repository.Node;
029: import org.apache.lenya.cms.site.usecases.SiteUsecase;
030:
031: /**
032: * Usecase to display the overview tab in the site area for a document.
033: *
034: */
035: public class FilePropfind extends SiteUsecase {
036:
037: protected static final String DOCUMENT = "document";
038: protected static final String DOCUMENTS = "documents";
039: protected static final String SOURCEURL = "sourceURL";
040: protected static final String DATEFORMAT = "dateFormat";
041: protected static final String RC = "rc";
042:
043: /**
044: * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
045: */
046: protected void initParameters() {
047: super .initParameters();
048:
049: Vector docs = new Vector();
050: Vector checkedOut = new Vector();
051:
052: String request = getSourceURL();
053:
054: try {
055:
056: Document doc = getTargetDocument(false);
057: docs.add(doc);
058:
059: Node node = doc.getRepositoryNode();
060: if (node.isCheckedOut()) {
061: checkedOut.add(node.getCheckoutUserId());
062: } else {
063: checkedOut.add(null);
064: }
065:
066: setParameter(DOCUMENTS, docs);
067: setParameter(RC, checkedOut);
068: setParameter(SOURCEURL, request);
069: SimpleDateFormat format = new SimpleDateFormat(
070: "EEE, d MMM yyyy HH:mm:ss zzz");
071: setParameter(DATEFORMAT, format);
072:
073: } catch (Exception e) {
074: throw new RuntimeException(e);
075: }
076: }
077:
078: /**
079: * @return The area without the "info-" prefix.
080: */
081: public String getArea() {
082: URLInformation info = new URLInformation(getSourceURL());
083: return info.getArea();
084: }
085:
086: /**
087: * Returns the document to be redirected to after the usecase has been completed. If the
088: * parameter <code>success</code> is false, the source document is returned (override this
089: * method to change this behaviour).
090: * @param success If the usecase was successfully completed.
091: * @return A document.
092: */
093: protected Document getTargetDocument(boolean success) {
094: Document document = (Document) getParameter(TARGET_DOCUMENT);
095: if (document == null) {
096: document = getSourceDocument();
097: }
098: return document;
099: }
100:
101: private Publication publication;
102:
103: /**
104: * Access to the current publication. Use this when the publication is not yet known in the
105: * usecase: e.g. when creating a global asset. When adding a resource or a child to a document,
106: * access the publication via that document's interface instead.
107: *
108: * @return the publication in which the use-case is being executed
109: */
110: protected Publication getPublication() {
111: if (this .publication == null) {
112: try {
113: this .publication = PublicationUtil
114: .getPublicationFromUrl(this .manager,
115: getDocumentFactory(), getSourceURL());
116: } catch (PublicationException e) {
117: throw new RuntimeException(e);
118: }
119: }
120: return this.publication;
121: }
122:
123: }
|