begin_unit|revision:0.9.5;language:Java;cregit-version:0.0.1
begin_comment
comment|/**  * Licensed to the Apache Software Foundation (ASF) under one  * or more contributor license agreements.  See the NOTICE file  * distributed with this work for additional information  * regarding copyright ownership.  The ASF licenses this file  * to you under the Apache License, Version 2.0 (the  * "License"); you may not use this file except in compliance  * with the License.  You may obtain a copy of the License at  *  *     http://www.apache.org/licenses/LICENSE-2.0  *  * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License.  */
end_comment

begin_package
DECL|package|org.apache.hadoop.hdfs.web
package|package
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hdfs
operator|.
name|web
package|;
end_package

begin_import
import|import
name|java
operator|.
name|net
operator|.
name|URI
import|;
end_import

begin_import
import|import
name|java
operator|.
name|util
operator|.
name|List
import|;
end_import

begin_import
import|import
name|java
operator|.
name|util
operator|.
name|Map
import|;
end_import

begin_import
import|import
name|javax
operator|.
name|ws
operator|.
name|rs
operator|.
name|core
operator|.
name|MultivaluedMap
import|;
end_import

begin_import
import|import
name|javax
operator|.
name|ws
operator|.
name|rs
operator|.
name|core
operator|.
name|UriBuilder
import|;
end_import

begin_import
import|import
name|com
operator|.
name|sun
operator|.
name|jersey
operator|.
name|spi
operator|.
name|container
operator|.
name|ContainerRequest
import|;
end_import

begin_import
import|import
name|com
operator|.
name|sun
operator|.
name|jersey
operator|.
name|spi
operator|.
name|container
operator|.
name|ContainerRequestFilter
import|;
end_import

begin_import
import|import
name|com
operator|.
name|sun
operator|.
name|jersey
operator|.
name|spi
operator|.
name|container
operator|.
name|ContainerResponseFilter
import|;
end_import

begin_import
import|import
name|com
operator|.
name|sun
operator|.
name|jersey
operator|.
name|spi
operator|.
name|container
operator|.
name|ResourceFilter
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|util
operator|.
name|StringUtils
import|;
end_import

begin_comment
comment|/**  * A filter to change parameter names to lower cases  * so that parameter names are considered as case insensitive.  */
end_comment

begin_class
DECL|class|ParamFilter
specifier|public
class|class
name|ParamFilter
implements|implements
name|ResourceFilter
block|{
DECL|field|LOWER_CASE
specifier|private
specifier|static
specifier|final
name|ContainerRequestFilter
name|LOWER_CASE
init|=
operator|new
name|ContainerRequestFilter
argument_list|()
block|{
annotation|@
name|Override
specifier|public
name|ContainerRequest
name|filter
parameter_list|(
specifier|final
name|ContainerRequest
name|request
parameter_list|)
block|{
specifier|final
name|MultivaluedMap
argument_list|<
name|String
argument_list|,
name|String
argument_list|>
name|parameters
init|=
name|request
operator|.
name|getQueryParameters
argument_list|()
decl_stmt|;
if|if
condition|(
name|containsUpperCase
argument_list|(
name|parameters
operator|.
name|keySet
argument_list|()
argument_list|)
condition|)
block|{
comment|//rebuild URI
specifier|final
name|URI
name|lower
init|=
name|rebuildQuery
argument_list|(
name|request
operator|.
name|getRequestUri
argument_list|()
argument_list|,
name|parameters
argument_list|)
decl_stmt|;
name|request
operator|.
name|setUris
argument_list|(
name|request
operator|.
name|getBaseUri
argument_list|()
argument_list|,
name|lower
argument_list|)
expr_stmt|;
block|}
return|return
name|request
return|;
block|}
block|}
decl_stmt|;
annotation|@
name|Override
DECL|method|getRequestFilter ()
specifier|public
name|ContainerRequestFilter
name|getRequestFilter
parameter_list|()
block|{
return|return
name|LOWER_CASE
return|;
block|}
annotation|@
name|Override
DECL|method|getResponseFilter ()
specifier|public
name|ContainerResponseFilter
name|getResponseFilter
parameter_list|()
block|{
return|return
literal|null
return|;
block|}
comment|/** Do the strings contain upper case letters? */
DECL|method|containsUpperCase (final Iterable<String> strings)
specifier|static
name|boolean
name|containsUpperCase
parameter_list|(
specifier|final
name|Iterable
argument_list|<
name|String
argument_list|>
name|strings
parameter_list|)
block|{
for|for
control|(
name|String
name|s
range|:
name|strings
control|)
block|{
for|for
control|(
name|int
name|i
init|=
literal|0
init|;
name|i
operator|<
name|s
operator|.
name|length
argument_list|()
condition|;
name|i
operator|++
control|)
block|{
if|if
condition|(
name|Character
operator|.
name|isUpperCase
argument_list|(
name|s
operator|.
name|charAt
argument_list|(
name|i
argument_list|)
argument_list|)
condition|)
block|{
return|return
literal|true
return|;
block|}
block|}
block|}
return|return
literal|false
return|;
block|}
comment|/** Rebuild the URI query with lower case parameter names. */
DECL|method|rebuildQuery (final URI uri, final MultivaluedMap<String, String> parameters)
specifier|private
specifier|static
name|URI
name|rebuildQuery
parameter_list|(
specifier|final
name|URI
name|uri
parameter_list|,
specifier|final
name|MultivaluedMap
argument_list|<
name|String
argument_list|,
name|String
argument_list|>
name|parameters
parameter_list|)
block|{
name|UriBuilder
name|b
init|=
name|UriBuilder
operator|.
name|fromUri
argument_list|(
name|uri
argument_list|)
operator|.
name|replaceQuery
argument_list|(
literal|""
argument_list|)
decl_stmt|;
for|for
control|(
name|Map
operator|.
name|Entry
argument_list|<
name|String
argument_list|,
name|List
argument_list|<
name|String
argument_list|>
argument_list|>
name|e
range|:
name|parameters
operator|.
name|entrySet
argument_list|()
control|)
block|{
specifier|final
name|String
name|key
init|=
name|StringUtils
operator|.
name|toLowerCase
argument_list|(
name|e
operator|.
name|getKey
argument_list|()
argument_list|)
decl_stmt|;
for|for
control|(
name|String
name|v
range|:
name|e
operator|.
name|getValue
argument_list|()
control|)
block|{
name|b
operator|=
name|b
operator|.
name|queryParam
argument_list|(
name|key
argument_list|,
name|v
argument_list|)
expr_stmt|;
block|}
block|}
return|return
name|b
operator|.
name|build
argument_list|()
return|;
block|}
block|}
end_class

end_unit

