KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/report/AclPrincipalPropSetReport.java,v 1.7 2004/08/05 15:44:57 unico Exp $
3  * $Revision: 1.7 $
4  * $Date: 2004/08/05 15:44:57 $
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.Enumeration JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.apache.slide.common.NamespaceAccessToken;
31 import org.apache.slide.common.PropertyParseException;
32 import org.apache.slide.common.RequestedProperties;
33 import org.apache.slide.common.RequestedPropertiesImpl;
34 import org.apache.slide.common.ServiceAccessException;
35 import org.apache.slide.common.SlideException;
36 import org.apache.slide.common.SlideToken;
37 import org.apache.slide.content.NodeProperty;
38 import org.apache.slide.content.NodeRevisionDescriptor;
39 import org.apache.slide.content.NodeRevisionDescriptors;
40 import org.apache.slide.content.NodeRevisionNumber;
41 import org.apache.slide.security.NodePermission;
42 import org.apache.slide.structure.SubjectNode;
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.jdom.Element;
49
50
51 /**
52  * DAV:acl-principal-prop-set report worker.
53  *
54  */

55 public class AclPrincipalPropSetReport extends AbstractReport implements AclConstants {
56     
57     private RequestedProperties requestedProperties = null;
58     
59     /**
60      * Constructor
61      *
62      * @param slideToken a SlideToken
63      * @param token a NamespaceAccessToken
64      * @param config a WebdavServletConfig
65      * @param serverUrl a String
66      * @param contextPath a String
67      */

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

80     public void init(String JavaDoc resourcePath, Element aclPrincipalPropSetElm) throws PreconditionViolationException {
81         if (aclPrincipalPropSetElm.getChildren().size() == 0) {
82             throw new PreconditionViolationException(
83                 new ViolatedPrecondition("at-least-one-child-element",
84                                          WebdavStatus.SC_BAD_REQUEST,
85                                          "DAV:acl-principal-prop-set element must have at least one child"),
86                 resourcePath
87             );
88         }
89         List JavaDoc propElmL = aclPrincipalPropSetElm.getChildren(E_PROP, DNSP);
90         if (propElmL.size() > 1) {
91             throw new PreconditionViolationException(
92                 new ViolatedPrecondition("at-most-one-prop-element",
93                                          WebdavStatus.SC_BAD_REQUEST,
94                                          "DAV:acl-principal-prop-set element must have at most one DAV:prop child"),
95                 resourcePath
96             );
97         }
98         
99         if (propElmL.size() == 1) {
100             Element propElm = (Element)propElmL.get(0);
101             try {
102                 this.requestedProperties = new RequestedPropertiesImpl(propElm);
103             }
104             catch (PropertyParseException e) {
105                 throw new PreconditionViolationException(
106                     new ViolatedPrecondition("invalid-prop",
107                                              WebdavStatus.SC_BAD_REQUEST,
108                                              e.getMessage()),
109                     resourcePath
110                 );
111             }
112         }
113     }
114     
115     /**
116      * Execute report and add results to given multistatus element
117      *
118      * @param resourcePath a String
119      * @param multistatusElm an Element
120      * @param depth an int
121      *
122      * @throws SlideException
123      * @throws IOException
124      */

125     public void execute(String JavaDoc resourcePath, Element multistatusElm, int depth) throws SlideException, IOException JavaDoc {
126         NodeRevisionDescriptors nrds = content.retrieve(slideToken, resourcePath);
127         NodeRevisionDescriptor nrd = content.retrieve(slideToken, nrds);
128         Enumeration JavaDoc permissions = security.enumeratePermissions(slideToken, resourcePath, true);
129         while (permissions != null && permissions.hasMoreElements()) {
130             NodePermission p = (NodePermission)permissions.nextElement();
131             SubjectNode principalNode = SubjectNode.getSubjectNode(p.getSubjectUri());
132             String JavaDoc principalPath = getPrincipalPath(principalNode, nrd);
133             if (principalPath != null) {
134                 multistatusElm.addContent(getResponseElement(slideToken, principalPath, new NodeRevisionNumber(), requestedProperties));
135             }
136         }
137     }
138     
139     private String JavaDoc getPrincipalPath(SubjectNode principalNode, NodeRevisionDescriptor nrd) throws SlideException {
140         if (principalNode.equals(SubjectNode.ALL)
141             || principalNode.equals(SubjectNode.SELF)
142             || principalNode.equals(SubjectNode.AUTHENTICATED)
143             || principalNode.equals(SubjectNode.UNAUTHENTICATED)
144            ) {
145             return null;
146         }
147         else if (principalNode.equals(SubjectNode.OWNER)) {
148             NodeProperty ownerProp = nrd.getProperty(P_OWNER);
149             if (ownerProp != null) {
150                 return token.getNamespaceConfig().getUsersPath()+"/"+ownerProp.getValue();
151             }
152             else {
153                 return null;
154             }
155         }
156         else {
157             return principalNode.getUri();
158         }
159     }
160     
161     /**
162      * Method checkPreconditions
163      * @param resourcePath a String
164      * @param depth an int
165      * @throws PreconditionViolationException
166      * @throws ServiceAccessException
167      */

168     public void checkPreconditions(String JavaDoc resourcePath, int depth) throws PreconditionViolationException, ServiceAccessException {
169         if (depth != 0) {
170             throw new PreconditionViolationException(
171                 new ViolatedPrecondition("depth-must-be-zero",
172                                          WebdavStatus.SC_BAD_REQUEST,
173                                          "This report is only defined for depth=0."),
174                 resourcePath
175             );
176         }
177     }
178 }
179
Popular Tags