KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > webdav > method > report > AbstractReport


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/report/AbstractReport.java,v 1.9 2004/08/05 14:43:34 dflorey Exp $
3  * $Revision: 1.9 $
4  * $Date: 2004/08/05 14:43:34 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.webdav.method.report;
25
26 import java.io.IOException JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.apache.slide.common.NamespaceAccessToken;
31 import org.apache.slide.common.RequestedProperties;
32 import org.apache.slide.common.ServiceAccessException;
33 import org.apache.slide.common.SlideException;
34 import org.apache.slide.common.SlideToken;
35 import org.apache.slide.content.Content;
36 import org.apache.slide.content.NodeRevisionNumber;
37 import org.apache.slide.content.NodeProperty.NamespaceCache;
38 import org.apache.slide.search.Search;
39 import org.apache.slide.security.Security;
40 import org.apache.slide.structure.Structure;
41 import org.apache.slide.webdav.WebdavServletConfig;
42 import org.apache.slide.webdav.util.AclConstants;
43 import org.apache.slide.webdav.util.DeltavConstants;
44 import org.apache.slide.webdav.util.PreconditionViolationException;
45 import org.apache.slide.webdav.util.PropertyRetriever;
46 import org.apache.slide.webdav.util.PropertyRetrieverImpl;
47 import org.apache.slide.webdav.util.WebdavStatus;
48 import org.apache.slide.webdav.util.WebdavUtils;
49 import org.jdom.Element;
50 import org.jdom.Namespace;
51
52
53 /**
54  * Abstract report worker.
55  *
56  */

57 public abstract class AbstractReport implements DeltavConstants, AclConstants {
58     
59     protected static final Namespace DNSP = NamespaceCache.DEFAULT_NAMESPACE;
60     protected static final String JavaDoc HTTP_VERSION = "HTTP/1.1";
61     
62     protected SlideToken slideToken;
63     protected NamespaceAccessToken token;
64     protected WebdavServletConfig config;
65     protected String JavaDoc slideContextPath;
66     protected Structure structure;
67     protected Content content;
68     protected Security security;
69     protected Search search;
70     protected PropertyRetriever retriever;
71     
72     /**
73      * Constructor
74      *
75      * @param slideToken a SlideToken
76      * @param token a NamespaceAccessToken
77      * @param resourcePath a String
78      * @param config a WebdavServletConfig
79      * @param servletPath a String, the result of HttpRequest.getServletPath()
80      * @param contextPath a String , the result of HttpRequest.getContextPath()
81      */

82     public AbstractReport(SlideToken slideToken, NamespaceAccessToken token, WebdavServletConfig config, String JavaDoc slideContextPath) {
83         this.slideToken = slideToken;
84         this.token = token;
85         this.config = config;
86         this.slideContextPath = slideContextPath;
87         this.structure = token.getStructureHelper();
88         this.content = token.getContentHelper();
89         this.security = token.getSecurityHelper();
90         this.search = token.getSearchHelper();
91         this.retriever = new PropertyRetrieverImpl(token, slideToken, config);
92     }
93     
94     /**
95      * Initialize report worker with specified report element
96      *
97      * @param resourcePath a String
98      * @param reportElm an Element
99      *
100      * @throws PreconditionViolationException
101      */

102     public abstract void init(String JavaDoc resourcePath, Element reportElm) throws PreconditionViolationException;
103     
104     /**
105      * Execute report and add results to given multistatus element
106      *
107      * @param resourcePath a String
108      * @param multistatusElm an Element
109      * @param depth an int
110      *
111      * @throws SlideException
112      * @throws IOException
113      *
114      */

115     public abstract void execute(String JavaDoc resourcePath, Element multistatusElm, int depth) throws SlideException, IOException JavaDoc;
116     
117     /**
118      * Method checkPreconditions
119      * @param resourcePath a String
120      * @param depth an int
121      * @throws PreconditionViolationException
122      * @throws ServiceAccessException
123      */

124     public void checkPreconditions(String JavaDoc resourcePath, int depth) throws PreconditionViolationException, ServiceAccessException {
125         // no preconditions
126
}
127     
128     protected Element getResponseElement(SlideToken slideToken, String JavaDoc resourcePath, NodeRevisionNumber revisionNumber, RequestedProperties requestedProperties) {
129         
130         Element responseElm = new Element(E_RESPONSE, DNSP);
131         Element hrefElm = new Element(E_HREF, DNSP);
132
133         String JavaDoc absUri = WebdavUtils.getAbsolutePath (resourcePath, slideContextPath, config);
134         hrefElm.setText (absUri);
135         responseElm.addContent(hrefElm);
136         
137         try {
138             List JavaDoc propstatList = retriever.getPropertiesOfObject(requestedProperties,
139                                                                 resourcePath,
140                                                                 revisionNumber,
141                                                                 slideContextPath,
142                                                                 true);
143             Iterator JavaDoc iterator = propstatList.iterator();
144             while (iterator.hasNext()) {
145                 responseElm.addContent((Element)iterator.next());
146             }
147         }
148         catch (Exception JavaDoc e) {
149             responseElm = getErrorResponse(resourcePath, WebdavUtils.getErrorCode(e), null);
150         }
151         return responseElm;
152     }
153     
154     protected Element getErrorResponse(String JavaDoc resourcePath, int statusCode, String JavaDoc condition) {
155         
156         Element responseElm = new Element(E_RESPONSE, DNSP);
157         
158         Element hrefElm = new Element(E_HREF, DNSP);
159         hrefElm.setText(WebdavUtils.getAbsolutePath (resourcePath, slideContextPath, config));
160         responseElm.addContent(hrefElm);
161         Element propStatElm = new Element(E_PROPSTAT, DNSP);
162         responseElm.addContent(propStatElm);
163         
164         Element statusElm = new Element(E_STATUS, DNSP);
165         statusElm.setText(HTTP_VERSION+" "+statusCode+" "+WebdavStatus.getStatusText(statusCode));
166         propStatElm.addContent(statusElm);
167         
168         if (condition != null) {
169             Element responseDescriptiont = new Element(E_RESPONSEDESCRIPTION, DNSP);
170             Element errorElm = new Element(E_ERROR, DNSP);
171             responseDescriptiont.addContent(errorElm);
172             Element conditionElm = new Element(condition, DNSP);
173             errorElm.addContent(conditionElm);
174             propStatElm.addContent(responseDescriptiont);
175         }
176         return responseElm;
177     }
178 }
179
180
Popular Tags