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

COVERAGE SUMMARY FOR SOURCE FILE [BucketLoggingHandler.java]

nameclass, %method, %block, %line, %
BucketLoggingHandler.java100% (1/1)100% (5/5)78%  (132/169)81%  (26/32)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BucketLoggingHandler100% (1/1)100% (5/5)78%  (132/169)81%  (26/32)
endElement (String, String, String): void 100% (1/1)72%  (90/125)76%  (16/21)
getResult (): BucketLogging 100% (1/1)87%  (13/15)67%  (2/3)
BucketLoggingHandler (): void 100% (1/1)100% (11/11)100% (3/3)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
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;
24import java.util.Set;
25 
26import org.jclouds.http.functions.ParseSax;
27import org.jclouds.s3.domain.BucketLogging;
28import org.jclouds.s3.domain.AccessControlList.CanonicalUserGrantee;
29import org.jclouds.s3.domain.AccessControlList.EmailAddressGrantee;
30import org.jclouds.s3.domain.AccessControlList.Grant;
31import org.jclouds.s3.domain.AccessControlList.Grantee;
32import org.jclouds.s3.domain.AccessControlList.GroupGrantee;
33import org.xml.sax.Attributes;
34 
35import com.google.common.collect.Sets;
36 
37/**
38 * Parses the following XML document:
39 * <p/>
40 * BucketLoggingStatus xmlns="http://s3.amazonaws.com/doc/2006-03-01/"
41 * 
42 * @author Adrian Cole
43 * @see <a href="http://docs.amazonwebservices.com/AmazonS3/latest/index.html?ServerLogs.html"/>
44 */
45public class BucketLoggingHandler extends ParseSax.HandlerWithResult<BucketLogging> {
46   private Set<Grant> targetGrants = Sets.newHashSet();
47   private StringBuilder currentText = new StringBuilder();
48 
49   public BucketLogging getResult() {
50      if (targetBucket == null)
51         return null;
52      return new BucketLogging(targetBucket, targetPrefix, targetGrants);
53   }
54 
55   private String currentId;
56   private String currentDisplayName;
57   private String currentGranteeType;
58   private String currentPermission;
59   private Grantee currentGrantee;
60 
61   private String targetBucket;
62   private String targetPrefix;
63 
64   public void startElement(String uri, String name, String qName, Attributes attrs) {
65      if (qName.equals("Grantee")) {
66         currentGranteeType = attrs.getValue("xsi:type");
67      }
68   }
69 
70   public void endElement(String uri, String name, String qName) {
71      if (qName.equals("TargetBucket")) {
72         this.targetBucket = currentOrNull(currentText);
73      } else if (qName.equals("TargetPrefix")) {
74         this.targetPrefix = currentOrNull(currentText);
75      } else if (qName.equals("Grantee")) {
76         if ("AmazonCustomerByEmail".equals(currentGranteeType)) {
77            currentGrantee = new EmailAddressGrantee(currentId);
78         } else if ("CanonicalUser".equals(currentGranteeType)) {
79            currentGrantee = new CanonicalUserGrantee(currentId, currentDisplayName);
80         } else if ("Group".equals(currentGranteeType)) {
81            currentGrantee = new GroupGrantee(URI.create(currentId));
82         }
83      } else if (qName.equals("Grant")) {
84         targetGrants.add(new Grant(currentGrantee, currentPermission));
85      } else if (qName.equals("ID") || qName.equals("EmailAddress") || qName.equals("URI")) {
86         currentId = currentOrNull(currentText);
87      } else if (qName.equals("DisplayName")) {
88         currentDisplayName = currentOrNull(currentText);
89      } else if (qName.equals("Permission")) {
90         currentPermission = currentOrNull(currentText);
91      }
92      currentText = new StringBuilder();
93   }
94 
95   public void characters(char ch[], int start, int length) {
96      currentText.append(ch, start, length);
97   }
98}

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