| 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 | */ |
| 19 | package org.jclouds.azureblob.predicates.validators; |
| 20 | |
| 21 | import javax.inject.Inject; |
| 22 | |
| 23 | import org.jclouds.predicates.validators.DnsNameValidator; |
| 24 | |
| 25 | import com.google.inject.Singleton; |
| 26 | |
| 27 | /** |
| 28 | * Validates name for Azure container. The complete requirements are listed at: |
| 29 | * http://weblogs.asp.net |
| 30 | * /vblasberg/archive/2009/02/17/azure-details-and-limitations-blobs-tables-and-queues.aspx |
| 31 | * |
| 32 | * @see org.jclouds.rest.InputParamValidator |
| 33 | * @see org.jclouds.predicates.Validator |
| 34 | * |
| 35 | * @author Oleksiy Yarmula |
| 36 | */ |
| 37 | @Singleton |
| 38 | public class ContainerNameValidator extends DnsNameValidator { |
| 39 | |
| 40 | @Inject |
| 41 | ContainerNameValidator() { |
| 42 | super(3,63); |
| 43 | } |
| 44 | |
| 45 | public void validate(String containerName) { |
| 46 | super.validate(containerName); |
| 47 | if (containerName.contains("--")) |
| 48 | throw exception(containerName, "Every dash must be followed by letter or number"); |
| 49 | if (containerName.endsWith("-")) |
| 50 | throw exception(containerName, "Shouldn't end with a dash"); |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | protected IllegalArgumentException exception(String containerName, String reason) { |
| 55 | return new IllegalArgumentException( |
| 56 | String |
| 57 | .format( |
| 58 | "Object '%s' doesn't match Azure container naming convention. " |
| 59 | + "Reason: %s. For more info, please refer to http://weblogs.asp.net/vblasberg/archive/2009/02/17/" |
| 60 | + "azure-details-and-limitations-blobs-tables-and-queues.aspx.", |
| 61 | containerName, reason)); |
| 62 | } |
| 63 | |
| 64 | } |