1 package org.apache.maven.archiva.common.spring;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import java.util.List;
23 import java.util.StringTokenizer;
25 import javax.xml.namespace.QName;
26 import javax.xml.xpath.XPathFunction;
27 import javax.xml.xpath.XPathFunctionException;
28 import javax.xml.xpath.XPathFunctionResolver;
31 * XPathFunction to convert plexus property-name to Spring propertyName.
33 * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
36 public class CamelCaseXpathFunction
37 implements XPathFunction, XPathFunctionResolver
40 private static final QName name = new QName( "http://plexus.codehaus.org/", "camelCase" );
45 * @see javax.xml.xpath.XPathFunctionResolver#resolveFunction(javax.xml.namespace.QName,
48 public XPathFunction resolveFunction( QName functionName, int arity )
50 if ( name.equals( functionName.getLocalPart() ) && arity >= 1 )
52 return new CamelCaseXpathFunction();
60 * @see javax.xml.xpath.XPathFunction#evaluate(java.util.List)
62 public Object evaluate( List args )
63 throws XPathFunctionException
65 return toCamelCase( (String) args.get( 0 ) );
68 public static String toCamelCase( String string )
70 StringBuilder camelCase = new StringBuilder();
73 StringTokenizer tokenizer = new StringTokenizer( string.toLowerCase(), "-" );
74 while ( tokenizer.hasMoreTokens() )
76 String token = tokenizer.nextToken();
79 camelCase.append( token.charAt( 0 ) );
84 camelCase.append( Character.toUpperCase( token.charAt( 0 ) ) );
86 camelCase.append( token.substring( 1, token.length() ) );
88 return camelCase.toString();