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.Date;
022: import java.util.Vector;
023:
024: import org.apache.avalon.framework.service.ServiceSelector;
025: import org.apache.lenya.cms.publication.Document;
026: import org.apache.lenya.cms.publication.Publication;
027: import org.apache.lenya.cms.publication.PublicationException;
028: import org.apache.lenya.cms.publication.PublicationUtil;
029: import org.apache.lenya.cms.repository.Node;
030: import org.apache.lenya.cms.site.SiteManager;
031: import org.apache.lenya.cms.site.usecases.SiteUsecase;
032:
033: /**
034: * Usecase to provide WebDAV propfind support for a document.
035: *
036: */
037: public class Propfind extends SiteUsecase {
038:
039: protected static final String DOCUMENT = "document";
040: protected static final String DOCUMENTS = "documents";
041: protected static final String SOURCEURL = "sourceURL";
042: protected static final String DATEFORMAT = "dateFormat";
043: protected static final String RC = "rc";
044:
045: /**
046: * Ctor.
047: */
048: public Propfind() {
049: super ();
050: }
051:
052: /**
053: * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
054: */
055: protected void initParameters() {
056: super .initParameters();
057:
058: Publication _publication = this .getPublication();
059:
060: ServiceSelector siteManagerSelector = null;
061: SiteManager siteManager = null;
062: Vector docs = new Vector();
063: Vector checkedOut = new Vector();
064:
065: String request = getSourceURL();
066: if (request.endsWith(".html"))
067: request = request.substring(0, request.indexOf(".html"));
068: if (!request.endsWith("/"))
069: request = request + "/";
070: if (request.indexOf("webdav") > -1) {
071: request = request.replaceFirst("webdav", "authoring");
072: }
073: try {
074:
075: siteManagerSelector = (ServiceSelector) this .manager
076: .lookup(SiteManager.ROLE + "Selector");
077: siteManager = (SiteManager) siteManagerSelector
078: .select(_publication.getSiteManagerHint());
079: Document[] documents = siteManager.getDocuments(
080: getDocumentFactory(), _publication,
081: Publication.AUTHORING_AREA);
082:
083: for (int i = 0; i < documents.length; i++) {
084: String test = documents[i].getCanonicalWebappURL()
085: .replaceFirst("/[^/]*.html", "");
086: if (!test.endsWith("/"))
087: test = test + "/";
088: if (test.equals(request)) {
089: docs.add(documents[i]);
090:
091: Node node = documents[i].getRepositoryNode();
092: if (node.isCheckedOut()) {
093: checkedOut.add(node.getCheckoutUserId());
094: } else {
095: checkedOut.add(null);
096: }
097: }
098: }
099:
100: setParameter(DOCUMENTS, docs);
101: setParameter(RC, checkedOut);
102: setParameter(SOURCEURL, request);
103: SimpleDateFormat format = new SimpleDateFormat(
104: "EEE, d MMM yyyy HH:mm:ss zzz");
105: setParameter(DATEFORMAT, format);
106: Date rootModDate = new Date();
107: setParameter("rootModDate", rootModDate);
108: String defaultLang = _publication.getDefaultLanguage();
109: setParameter("defaultLang", defaultLang);
110:
111: } catch (Exception e) {
112: throw new RuntimeException(e);
113: } finally {
114: if (siteManagerSelector != null) {
115: if (siteManager != null) {
116: siteManagerSelector.release(siteManager);
117: }
118: this .manager.release(siteManagerSelector);
119: }
120: }
121: }
122:
123: /**
124: * @return The area without the "info-" prefix.
125: */
126: public String getArea() {
127: return Publication.AUTHORING_AREA;
128: }
129:
130: private Publication publication;
131:
132: /**
133: * Access to the current publication. Use this when the publication is not yet known in the
134: * usecase: e.g. when creating a global asset. When adding a resource or a child to a document,
135: * access the publication via that document's interface instead.
136: *
137: * @return the publication in which the use-case is being executed
138: */
139: protected Publication getPublication() {
140: if (this .publication == null) {
141: try {
142: this .publication = PublicationUtil
143: .getPublicationFromUrl(this .manager,
144: getDocumentFactory(), getSourceURL());
145: } catch (PublicationException e) {
146: throw new RuntimeException(e);
147: }
148: }
149: return this.publication;
150: }
151:
152: }
|