You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2002/04/08 13:51:25 UTC

cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method ReportMethod.java

juergen     02/04/08 04:51:25

  Modified:    src/webdav/server/org/apache/slide/webdav/method
                        ReportMethod.java
  Log:
  added principal-match Report (Eckehard)
  
  Revision  Changes    Path
  1.14      +244 -10   jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/ReportMethod.java
  
  Index: ReportMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/ReportMethod.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ReportMethod.java	5 Apr 2002 05:45:10 -0000	1.13
  +++ ReportMethod.java	8 Apr 2002 11:51:25 -0000	1.14
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/ReportMethod.java,v 1.13 2002/04/05 05:45:10 juergen Exp $
  - * $Revision: 1.13 $
  - * $Date: 2002/04/05 05:45:10 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/ReportMethod.java,v 1.14 2002/04/08 11:51:25 juergen Exp $
  + * $Revision: 1.14 $
  + * $Date: 2002/04/08 11:51:25 $
    *
    * ====================================================================
    *
  @@ -82,7 +82,10 @@
   import javax.servlet.http.HttpServletResponse;
   
   import javax.xml.parsers.ParserConfigurationException ;
  +import javax.xml.parsers.DocumentBuilderFactory;
  +import javax.xml.parsers.DocumentBuilder;
   
  +import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
   
   import org.apache.util.WebdavStatus;
  @@ -139,6 +142,14 @@
   import org.apache.slide.webdav.util.resourcekind.VersionControlled;
   import org.apache.slide.webdav.util.resourcekind.CheckedOutVersionControlled;
   import org.apache.slide.webdav.util.resourcekind.CheckedInVersionControlled;
  +import org.apache.slide.webdav.util.WebdavConstants;
  +
  +import org.apache.slide.search.SearchQuery;
  +import org.apache.slide.search.SearchQueryResult;
  +import org.apache.slide.search.Search;
  +import org.apache.slide.search.RequestedResource;
  +import org.apache.slide.lock.LockTokenNotFoundException;
  +import org.apache.slide.authenticate.CredentialsToken;
   
   import org.jdom.Element;
   import org.jdom.Document;
  @@ -153,7 +164,7 @@
   /**
    * An implementation of the DeltaV <code>REPORT</code> method.
    *
  - * @version $Revision: 1.13 $
  + * @version $Revision: 1.14 $
    *
    * @author <a href="mailto:ralf.stuckert@softwareag.com">Ralf Stuckert</a>
    */
  @@ -229,6 +240,12 @@
       protected String requestedReport = null;
       
       /**
  +     * The <code>&lt;principalProperty&gt;</code> element of an
  +     * <code>principal-match</code> report request.
  +     */
  +    protected Element principalProperty = null;
  +    
  +    /**
        * The <code>&lt;expand-property&gt;</code> element of an
        * <code>expand-property</code> report request.
        */
  @@ -298,7 +315,11 @@
               }
               else if (element.getName().equalsIgnoreCase(R_ACL_PRINCIPAL_PROPS)){
                   requestedReport = R_ACL_PRINCIPAL_PROPS;
  -                parseACLPrincipalRequest(element);
  +                parseACLRequest(element);
  +            }
  +            else if (element.getName().equalsIgnoreCase(R_PRINCIPAL_MATCH)){
  +                requestedReport = R_PRINCIPAL_MATCH;
  +                parsePrincipalMatchRequest(element);
               }
               else if (element.getName().equalsIgnoreCase(R_LOCATE_BY_HISTORY)){
                   requestedReport = R_LOCATE_BY_HISTORY;
  @@ -366,14 +387,14 @@
       /**
        * Parses the <code>&lt;acl-principal&gt;</code> request.
        *
  -     * @param      aclPrincipalElement  the <code>&lt;acl-principal&gt;</code>
  +     * @param      aclElement  the <code>&lt;acl&gt;</code>
        *                                 Element.
        *
        * @throws     WebdavException if parsing fails for any reason.
        */
  -    protected void parseACLPrincipalRequest(Element aclPrincipalElement) throws WebdavException {
  +    protected void parseACLRequest(Element aclElement) throws WebdavException {
           
  -        List childrenList = aclPrincipalElement.getChildren();
  +        List childrenList = aclElement.getChildren();
           if (childrenList.size() == 0) {
               throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
           }
  @@ -389,6 +410,49 @@
       }
       
       /**
  +     * Parses the <code>&lt;acl-principal&gt;</code> request.
  +     *
  +     * @param      aclElement  the <code>&lt;acl&gt;</code>
  +     *                                 Element.
  +     *
  +     * @throws     WebdavException if parsing fails for any reason.
  +     */
  +    protected void parsePrincipalMatchRequest(Element aclElement) throws WebdavException {
  +        
  +        List childrenList = aclElement.getChildren();
  +        Iterator childListIter = null;
  +        if (childrenList.size() == 0) {
  +            throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +        }
  +        
  +        childListIter = childrenList.iterator();
  +        
  +        while (childListIter.hasNext()) {
  +            Element element = (Element)childListIter.next();
  +            
  +            if ((E_PRINCIPAL_PROPERTY.equals(element.getName())) && (principalProperty == null)) {
  +                List props = element.getChildren();
  +                if (props.size() != 1) {
  +                    throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +                }
  +                principalProperty = (Element) props.get(0);
  +            }
  +            else if ((E_SELF.equals(element.getName())) && (principalProperty == null)) {
  +                principalProperty = element;
  +            }
  +            else if ((E_ALLPROP.equals(element.getName()) || E_PROP.equals(element.getName())) && (requestedProperties == null)) {
  +                requestedProperties = new RequestedPropertiesImpl(element);
  +            }
  +            else {
  +                throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +            }
  +        }
  +        if (principalProperty == null) {
  +            throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +        }
  +    }
  +    
  +    /**
        * Parses the <code>&lt;expand-property&gt;</code> request.
        *
        * @param      expandPropertyElement  the <code>&lt;expand-property&gt;</code>
  @@ -470,6 +534,9 @@
               else if (R_ACL_PRINCIPAL_PROPS.equals(requestedReport)) {
                   executeAclPrincipalReport(requestUri, multistatusElement, getDepth());
               }
  +            else if (R_PRINCIPAL_MATCH.equals(requestedReport)) {
  +                executeAclMatchReport(requestUri, multistatusElement, getDepth());
  +            }
               else if (R_LOCATE_BY_HISTORY.equals(requestedReport)) {
                   executeLocateByHistoryReport(requestUri, multistatusElement, getDepth());
               }
  @@ -710,7 +777,7 @@
       }
       
       /**
  -     * Executes a requested <code>acl-principal</code> report.
  +     * Executes a requested <code>acl-principal-prop</code> report.
        *
        * @param      requestUri     the URI of the requested resource.
        * @param      parentElement  the parent Element to append the
  @@ -742,7 +809,7 @@
           
           // create virtuel ACL property object
           Element aclproperty = new Element(E_PROPERTY,DEFAULT_NAMESPACE);
  -        aclproperty.setAttribute(PARAM_NAME,P_ACL);
  +        aclproperty.addAttribute(PARAM_NAME,P_ACL);
           Element prop = new Element(E_PROP,DEFAULT_NAMESPACE);
           prop.addContent(aclproperty);
           RequestedPropertiesImpl reqProperties = new RequestedPropertiesImpl(prop);
  @@ -833,6 +900,173 @@
               String principalUrl = ((String)principalIter.next()).substring(token.getNamespaceConfig().toString().length()+1);
               Element response = getResponseElement(principalUrl, revisionDescriptors, revisionNumber, slideToken, principalUrl, requestedProperties);
               parentElement.addContent((Element) response);
  +        }
  +    }
  +    
  +    /**
  +     * Executes a requested <code>acl-match</code> report.
  +     *
  +     * @param      requestUri     the URI of the requested resource.
  +     * @param      parentElement  the parent Element to append the
  +     *                            &lt;response&gt;</code> to.
  +     *
  +     * @throws     WebdavException
  +     * @throws     ObjectLockedException
  +     * @throws     RevisionDescriptorNotFoundException
  +     * @throws     ServiceAccessException
  +     * @throws     LinkedObjectNotFoundException
  +     * @throws     AccessDeniedException
  +     * @throws     ObjectNotFoundException
  +     * @throws     JDOMException
  +     */
  +    protected void executeAclMatchReport(String requestUri, Element parentElement, int depth) throws WebdavException, ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, JDOMException {
  +        
  +        List propstatList = null;
  +        String currentUri = null;
  +        String userID = null;
  +        String userpath = token.getNamespaceConfig().getUsersPath();
  +        String searchDocument = null;
  +        org.w3c.dom.Document parseDoc = null;
  +        org.w3c.dom.Element rootElement = null;
  +        org.w3c.dom.NodeList nl = null;
  +        org.w3c.dom.Element queryElement = null;
  +        int maxDepth = 0;
  +        SearchQuery searchQuery = null;
  +        Search searchHelper  = null;
  +        String grammarNamespace = null;
  +        SearchQueryResult queryResult = null;
  +        PropertyRetriever retriever = null;
  +        List propList = null;
  +        char seperator = '/';
  +        boolean self = false;
  +        
  +        // check if self or principal-property is searched
  +        if ((principalProperty.getName()).equalsIgnoreCase("self")) {
  +            self = true;
  +        }
  +        
  +        // get current user
  +        CredentialsToken crdToken = slideToken.getCredentialsToken();
  +        if (crdToken != null) userID = crdToken.getPublicCredentials();
  +        if (userID != null) {
  +            if (!(userpath.endsWith("/"))) userpath = userpath + "/";
  +        }
  +        String currentUser = new String (userpath + userID);
  +        
  +        // get matched user
  +        currentUri = requestUri;
  +        
  +        
  +        if (self) {
  +            // build query for self
  +            searchDocument = C_MATCH_REPORT_SEARCH1 + C_MATCH_REPORT_ALLPROP +
  +                C_MATCH_REPORT_SEARCH2 + currentUri + C_MATCH_REPORT_SEARCH_SELF;
  +        } else {
  +            searchDocument = C_MATCH_REPORT_SEARCH1 + C_MATCH_REPORT_ALLPROP +
  +                C_MATCH_REPORT_SEARCH2 + currentUri + C_MATCH_REPORT_SEARCH_PROP1;
  +        }
  +        
  +        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  +        factory.setNamespaceAware(true);
  +        
  +        try {
  +            DocumentBuilder builder = factory.newDocumentBuilder();
  +            parseDoc = builder.parse(new InputSource(new StringReader(searchDocument)));
  +        } catch (Exception e) {
  +            resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +            throw new WebdavException(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +        }
  +        
  +        rootElement = parseDoc.getDocumentElement();
  +        nl = rootElement.getChildNodes();
  +        for (int i = 0; i < nl.getLength(); i++) {
  +            if (nl.item (i) instanceof org.w3c.dom.Element)
  +                queryElement = (org.w3c.dom.Element)nl.item(i);
  +        }
  +        
  +        // get search depth
  +        if (self) {
  +            for (int i = 0; i < currentUser.length(); i++) {
  +                if (currentUser.charAt(i) == seperator) {
  +                    maxDepth++;
  +                }
  +            }
  +        } else {
  +            maxDepth = depth;
  +        }
  +        
  +        // create search query for principals
  +        grammarNamespace = queryElement.getNamespaceURI();
  +        searchHelper = token.getSearchHelper();
  +        try {
  +            searchQuery = searchHelper.createSearchQuery
  +                (grammarNamespace, queryElement, slideToken, maxDepth);
  +        } catch (BadQueryException e) {
  +            resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  +            throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +        }
  +        
  +        // Search for Principals
  +        queryResult = searchHelper.search (slideToken, searchQuery);
  +        retriever = new PropertyRetrieverImpl(token, slideToken);
  +        
  +        org.jdom.Namespace namespace = org.jdom.Namespace.getNamespace ("D", "DAV:");
  +        
  +        Iterator it = queryResult.iterator();
  +        String serverURL = "http://" + req.getServerName()+ ":" + req.getServerPort();
  +        
  +        while (it.hasNext()) {
  +            String uri = null;
  +            RequestedResource resource = (RequestedResource)it.next();
  +            String currentUrl = resource.getHref();
  +            uri = resource.getHref();
  +            if (!self) {
  +                try {
  +                    uri = (String) resource.getThisValue("owner");
  +                    if (uri != null) {
  +                        if (!(userpath.endsWith("/"))) userpath = userpath + "/";
  +                        uri = new String (userpath + uri);
  +                    } else {
  +                        uri = new String (userpath);
  +                    }
  +                } catch (Exception e) {}
  +            }
  +
  +            // remove not matching principals
  +            if ((uri != null)) {
  +                if (currentUser.startsWith(uri)) {
  +                    org.jdom.Element responseElement =
  +                        new org.jdom.Element (WebdavConstants.E_RESPONSE, namespace);
  +                    
  +                    parentElement.addContent (responseElement);
  +                    org.jdom.Element hrefElement =
  +                        new org.jdom.Element (WebdavConstants.E_HREF, namespace);
  +                    
  +                    
  +                    hrefElement.addContent(currentUrl);
  +                    responseElement.addContent (hrefElement);
  +                    
  +                    // get properties, if any defined
  +                    if (requestedProperties != null) {
  +                        try {
  +                            propList = retriever.getPropertiesOfObject (requestedProperties,
  +                                                                        currentUrl,
  +                                                                        req.getContextPath(),
  +                                                                        serverURL,
  +                                                                        true);
  +                            
  +                        } catch (LockTokenNotFoundException e) {
  +                            resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                            throw new WebdavException(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                        }
  +                        
  +                        Iterator iterator = propList.iterator();
  +                        while (iterator.hasNext()) {
  +                            responseElement.addContent((org.jdom.Element)iterator.next());
  +                        }
  +                    }
  +                }
  +            }
           }
       }
       
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>