KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2002-2006 Jahia Ltd
3  *
4  * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (JCDDL),
5  * Version 1.0 (the "License"), or (at your option) any later version; you may
6  * not use this file except in compliance with the License. You should have
7  * received a copy of the License along with this program; if not, you may obtain
8  * a copy of the License at
9  *
10  * http://www.jahia.org/license/
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
/*
18  * $Header$
19  * $Revision: 207589 $
20  * $Date: 2004-08-05 16:47:24 +0200 (Thu, 05 Aug 2004) $
21  *
22  * ====================================================================
23  *
24  * Copyright 1999-2002 The Apache Software Foundation
25  *
26  * Licensed under the Apache License, Version 2.0 (the "License");
27  * you may not use this file except in compliance with the License.
28  * You may obtain a copy of the License at
29  *
30  * http://www.apache.org/licenses/LICENSE-2.0
31  *
32  * Unless required by applicable law or agreed to in writing, software
33  * distributed under the License is distributed on an "AS IS" BASIS,
34  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35  * See the License for the specific language governing permissions and
36  * limitations under the License.
37  *
38  */

39
40 package org.apache.slide.webdav.method.report;
41
42 import org.apache.slide.common.*;
43 import org.apache.slide.webdav.WebdavServletConfig;
44 import org.apache.slide.webdav.util.AclConstants;
45 import org.apache.slide.webdav.util.PreconditionViolationException;
46 import org.apache.slide.webdav.util.ViolatedPrecondition;
47 import org.apache.slide.webdav.util.WebdavStatus;
48 import org.apache.slide.webdav.util.resourcekind.PrincipalImpl;
49 import org.jdom.Element;
50
51 import java.io.IOException JavaDoc;
52 import java.util.Iterator JavaDoc;
53
54
55 /**
56  * DAV:principal-search-property-set report worker.
57  *
58  */

59 public class PrincipalSearchPropertySetReport extends AbstractReport implements AclConstants {
60
61     /**
62      * Constructor
63      *
64      * @param slideToken a SlideToken
65      * @param token a NamespaceAccessToken
66      * @param config a WebdavServletConfig
67      * @param serverUrl a String
68      * @param contextPath a String
69      */

70     public PrincipalSearchPropertySetReport(SlideToken slideToken, NamespaceAccessToken token, WebdavServletConfig config, String JavaDoc slideContextPath) {
71         super(slideToken, token, config, slideContextPath);
72     }
73
74     /**
75      * Initialize report worker with specified report element
76      *
77      * @param resourcePath a String
78      * @param principalSearchPropertySetElm an Element
79      *
80      * @throws PreconditionViolationException
81      */

82     public void init(String JavaDoc resourcePath, Element principalSearchPropertySetElm) throws PreconditionViolationException {
83         if (principalSearchPropertySetElm.getChildren().size() > 0) {
84             throw new PreconditionViolationException(
85                 new ViolatedPrecondition("empty-principal-search-property-set-element",
86                                          WebdavStatus.SC_BAD_REQUEST,
87                                          "DAV:principal-search-property-set element must be empty"),
88                 resourcePath
89             );
90         }
91     }
92
93     /**
94      * Execute report and add results to given multistatus element
95      *
96      * @param resourcePath a String
97      * @param principalSearchPropertySetElm an Element
98      * @param depth an int
99      *
100      * @throws SlideException
101      * @throws IOException
102      */

103     public void execute(String JavaDoc resourcePath, Element principalSearchPropertySetElm, int depth) throws SlideException, IOException JavaDoc {
104         Iterator JavaDoc props = retriever.getAllPropertyNames(PrincipalImpl.getInstance())
105             .getRequestedProperties();
106         while (props.hasNext()) {
107             RequestedProperty p = (RequestedProperty)props.next();
108             Element principalSearchPropertyElm = new Element(E_PRINCIPAL_SEARCH_PROPERTY, DNSP);
109             Element propElm = new Element("prop", DNSP);
110             principalSearchPropertyElm.addContent(propElm);
111             propElm.addContent(new Element(p.getName(), p.getNamespace()));
112             Element descriptionElm = new Element("description", DNSP);
113             principalSearchPropertyElm.addContent(descriptionElm);
114             descriptionElm.setText(p.getName());
115             principalSearchPropertySetElm.addContent(principalSearchPropertyElm);
116         }
117     }
118
119     /**
120      * Method checkPreconditions
121      * @param resourcePath a String
122      * @param depth an int
123      * @throws PreconditionViolationException
124      * @throws ServiceAccessException
125      */

126     public void checkPreconditions(String JavaDoc resourcePath, int depth) throws PreconditionViolationException, ServiceAccessException {
127         if (depth != 0) {
128             throw new PreconditionViolationException(
129                 new ViolatedPrecondition("depth-must-be-zero",
130                                          WebdavStatus.SC_BAD_REQUEST,
131                                          "This report is only defined for depth=0."),
132                 resourcePath
133             );
134         }
135         UriPath resourcepath = new UriPath(resourcePath);
136         NamespaceConfig namespaceConfig = token.getNamespaceConfig();
137         UriPath userspath = namespaceConfig.getUsersPath() != null
138             ? new UriPath(namespaceConfig.getUsersPath())
139             : null;
140         UriPath groupspath = namespaceConfig.getGroupsPath() != null
141             ? new UriPath(namespaceConfig.getGroupsPath())
142             : null;
143         UriPath rolespath = namespaceConfig.getRolesPath() != null
144             ? new UriPath(namespaceConfig.getRolesPath())
145             : null;
146         if (!resourcepath.equals(userspath) &&
147             !resourcepath.equals(groupspath) &&
148             !resourcepath.equals(rolespath)) {
149             throw new PreconditionViolationException(
150                 new ViolatedPrecondition("valid-request-uri",
151                                          WebdavStatus.SC_BAD_REQUEST,
152                                          "This report is only defined for one of the collections identified in the value of the DAV:principal-collection-set property."),
153                 resourcePath
154             );
155         }
156     }
157 }
158
Popular Tags