EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.s3.xml]

COVERAGE SUMMARY FOR SOURCE FILE [AccessControlListHandler.java]

nameclass, %method, %block, %line, %
AccessControlListHandler.java100% (1/1)100% (5/5)95%  (147/155)97%  (30/31)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AccessControlListHandler100% (1/1)100% (5/5)95%  (147/155)97%  (30/31)
endElement (String, String, String): void 100% (1/1)93%  (113/121)95%  (20/21)
AccessControlListHandler (): void 100% (1/1)100% (13/13)100% (4/4)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
getResult (): AccessControlList 100% (1/1)100% (3/3)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (10/10)100% (3/3)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.s3.xml;
20 
21import static org.jclouds.util.SaxUtils.currentOrNull;
22 
23import java.net.URI;
24 
25import org.jclouds.http.functions.ParseSax;
26import org.jclouds.s3.domain.AccessControlList;
27import org.jclouds.s3.domain.CanonicalUser;
28import org.jclouds.s3.domain.AccessControlList.CanonicalUserGrantee;
29import org.jclouds.s3.domain.AccessControlList.EmailAddressGrantee;
30import org.jclouds.s3.domain.AccessControlList.Grantee;
31import org.jclouds.s3.domain.AccessControlList.GroupGrantee;
32import org.xml.sax.Attributes;
33 
34/**
35 * Parses the following XML document:
36 * <p/>
37 * AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/"
38 * 
39 * @author James Murty
40 * @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAccessPolicy.html"/>
41 */
42public class AccessControlListHandler extends ParseSax.HandlerWithResult<AccessControlList> {
43   private AccessControlList acl = new AccessControlList();
44   private StringBuilder currentText = new StringBuilder();
45 
46   public AccessControlListHandler() {
47   }
48 
49   public AccessControlList getResult() {
50      return acl;
51   }
52 
53   private String currentId;
54   private String currentDisplayName;
55   private String currentGranteeType;
56   private String currentPermission;
57   private Grantee currentGrantee;
58 
59   public void startElement(String uri, String name, String qName, Attributes attrs) {
60      if (qName.equals("Grantee")) {
61         currentGranteeType = attrs.getValue("xsi:type");
62      }
63   }
64 
65   public void endElement(String uri, String name, String qName) {
66      if (qName.equals("Owner")) {
67         CanonicalUser owner = new CanonicalUser(currentId);
68         owner.setDisplayName(currentDisplayName);
69         acl.setOwner(owner);
70      } else if (qName.equals("Grantee")) {
71         if ("AmazonCustomerByEmail".equals(currentGranteeType)) {
72            currentGrantee = new EmailAddressGrantee(currentId);
73         } else if ("CanonicalUser".equals(currentGranteeType)) {
74            currentGrantee = new CanonicalUserGrantee(currentId, currentDisplayName);
75         } else if ("Group".equals(currentGranteeType)) {
76            currentGrantee = new GroupGrantee(URI.create(currentId));
77         }
78      } else if (qName.equals("Grant")) {
79         acl.addPermission(currentGrantee, currentPermission);
80      }
81 
82      else if (qName.equals("ID") || qName.equals("EmailAddress") || qName.equals("URI")) {
83         currentId = currentOrNull(currentText);
84      } else if (qName.equals("DisplayName")) {
85         currentDisplayName = currentOrNull(currentText);
86      } else if (qName.equals("Permission")) {
87         currentPermission = currentOrNull(currentText);
88      }
89      currentText = new StringBuilder();
90   }
91 
92   public void characters(char ch[], int start, int length) {
93      currentText.append(ch, start, length);
94   }
95}

[all classes][org.jclouds.s3.xml]
EMMA 2.0.5312 (C) Vladimir Roubtsov