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

COVERAGE SUMMARY FOR SOURCE FILE [BucketNameValidator.java]

nameclass, %method, %block, %line, %
BucketNameValidator.java100% (1/1)75%  (3/4)54%  (37/68)67%  (8/12)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BucketNameValidator100% (1/1)75%  (3/4)54%  (37/68)67%  (8/12)
exception (String, String): IllegalArgumentException 0%   (0/1)0%   (0/16)0%   (0/1)
validate (String): void 100% (1/1)61%  (23/38)62%  (5/8)
BucketNameValidator (): void 100% (1/1)100% (5/5)100% (2/2)
getAcceptableRange (): CharMatcher 100% (1/1)100% (9/9)100% (1/1)

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.predicates.validators;
20 
21import static com.google.common.base.CharMatcher.is;
22 
23import javax.inject.Inject;
24 
25import org.jclouds.predicates.validators.DnsNameValidator;
26 
27import com.google.common.base.CharMatcher;
28import com.google.inject.Singleton;
29 
30/**
31 * Validates name for S3 buckets. The complete requirements are listed at:
32 * http://docs.amazonwebservices.com/AmazonS3/latest/index.html?BucketRestrictions.html
33 * 
34 * @see org.jclouds.rest.InputParamValidator
35 * @see org.jclouds.predicates.Validator
36 * 
37 * @author Adrian Cole
38 */
39@Singleton
40public class BucketNameValidator extends DnsNameValidator {
41 
42   @Inject
43   BucketNameValidator() {
44      super(3, 63);
45   }
46 
47   public void validate(String containerName) {
48      super.validate(containerName);
49      if (containerName.indexOf("..") != -1)
50         throw exception(containerName, "Bucket names cannot contain two, adjacent periods");
51      if (containerName.endsWith("-"))
52         throw exception(containerName, "Bucket names should not end with a dash");
53 
54      if (containerName.indexOf("-.") != -1 || containerName.indexOf(".-") != -1)
55         throw exception(
56                  containerName,
57                  "Bucket names cannot contain dashes next to periods (e.g., \"my-.bucket.com\" and \"my.-bucket\" are invalid)");
58   }
59 
60   @Override
61   protected IllegalArgumentException exception(String containerName, String reason) {
62      return new IllegalArgumentException(
63               String
64                        .format(
65                                 "Object '%s' doesn't match S3 bucket virtual host naming convention. "
66                                          + "Reason: %s. For more info, please refer to http://docs.amazonwebservices.com/AmazonS3/latest/index.html?BucketRestrictions.html.",
67                                 containerName, reason));
68   }
69 
70   /**
71    * Amazon also permits periods in the dns name.
72    * It also permits underscores, although they aren't recommended.
73    */
74   @Override
75   protected CharMatcher getAcceptableRange() {
76      return super.getAcceptableRange().or(is('.')).or(is('_'));
77   }
78}

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