Author: nicolas
Date: Wed Feb 20 07:29:52 2008
New Revision: 629505
URL: http://svn.apache.org/viewvc?rev=629505&view=rev
Log:
use Xalan extension to invoke custom XpathFunction
Added:
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java
(with props)
maven/archiva/branches/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunctionTest.java
(with props)
Modified:
maven/archiva/branches/springy/archiva-base/archiva-common/pom.xml
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReader.java
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl
Modified: maven/archiva/branches/springy/archiva-base/archiva-common/pom.xml
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-common/pom.xml?rev=629505&r1=629504&r2=629505&view=diff
==============================================================================
--- maven/archiva/branches/springy/archiva-base/archiva-common/pom.xml
(original)
+++ maven/archiva/branches/springy/archiva-base/archiva-common/pom.xml Wed Feb
20 07:29:52 2008
@@ -57,6 +57,11 @@
<version>2.5.1</version>
</dependency>
<dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <version>2.7.0</version>
+ </dependency>
+ <dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
Added:
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java?rev=629505&view=auto
==============================================================================
---
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java
(added)
+++
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java
Wed Feb 20 07:29:52 2008
@@ -0,0 +1,90 @@
+package org.apache.maven.archiva.common.spring;
+
+/*
+ * 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.
+ */
+
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathFunction;
+import javax.xml.xpath.XPathFunctionException;
+import javax.xml.xpath.XPathFunctionResolver;
+
+/**
+ * XPathFunction to convert plexus property-name to Spring propertyName.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Nicolas De Loof</a>
+ * @since 1.1
+ */
+public class CamelCaseXpathFunction
+ implements XPathFunction, XPathFunctionResolver
+{
+
+ private static final QName name = new QName(
"http://plexus.codehaus.org/", "camelCase" );
+
+ /**
+ * [EMAIL PROTECTED]
+ *
+ * @see
javax.xml.xpath.XPathFunctionResolver#resolveFunction(javax.xml.namespace.QName,
+ * int)
+ */
+ public XPathFunction resolveFunction( QName functionName, int arity )
+ {
+ if ( name.equals( functionName.getLocalPart() ) && arity >= 1 )
+ {
+ return new CamelCaseXpathFunction();
+ }
+ return null;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ *
+ * @see javax.xml.xpath.XPathFunction#evaluate(java.util.List)
+ */
+ public Object evaluate( List args )
+ throws XPathFunctionException
+ {
+ return toCamelCase( (String) args.get( 0 ) );
+ }
+
+ public static String toCamelCase( String string )
+ {
+ StringBuilder camelCase = new StringBuilder();
+ boolean first = true;
+
+ StringTokenizer tokenizer = new StringTokenizer( string.toLowerCase(),
"-" );
+ while ( tokenizer.hasMoreTokens() )
+ {
+ String token = tokenizer.nextToken();
+ if ( first )
+ {
+ camelCase.append( token.charAt( 0 ) );
+ first = false;
+ }
+ else
+ {
+ camelCase.append( Character.toUpperCase( token.charAt( 0 ) ) );
+ }
+ camelCase.append( token.substring( 1, token.length() ) );
+ }
+ return camelCase.toString();
+ }
+}
Propchange:
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReader.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReader.java?rev=629505&r1=629504&r2=629505&view=diff
==============================================================================
---
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReader.java
(original)
+++
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusBeanDefinitionDocumentReader.java
Wed Feb 20 07:29:52 2008
@@ -60,6 +60,8 @@
DOMResult transResult = new DOMResult();
+ // FIXME : uses Xalan extension. need either to force Xalan as
Transformer or
+ // register a XpathFunctionResolver (how ?)
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer( xsltSource );
t.transform( xmlSource, transResult );
Modified:
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl?rev=629505&r1=629504&r2=629505&view=diff
==============================================================================
---
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl
(original)
+++
maven/archiva/branches/springy/archiva-base/archiva-common/src/main/resources/org/apache/maven/archiva/common/spring/plexus2spring.xsl
Wed Feb 20 07:29:52 2008
@@ -1,6 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
<xsl:stylesheet
- version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+
xmlns:plexus="org.apache.maven.archiva.common.spring.CamelCaseXpathFunction">
+<!--
+ use xalan extension mecanism to call static methods
+ @see http://www.ibm.com/developerworks/library/x-xalanextensions.html
+ -->
<xsl:output method="xml" indent="yes"
doctype-public="-//SPRING//DTD BEAN 2.0//EN"
@@ -50,7 +74,7 @@
<xsl:for-each select="configuration/*">
<property>
<xsl:attribute name="name">
- <xsl:value-of select="name(.)" />
+ <xsl:value-of select="plexus:toCamelCase( name(.) )" />
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="." />
Added:
maven/archiva/branches/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunctionTest.java
URL:
http://svn.apache.org/viewvc/maven/archiva/branches/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunctionTest.java?rev=629505&view=auto
==============================================================================
---
maven/archiva/branches/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunctionTest.java
(added)
+++
maven/archiva/branches/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunctionTest.java
Wed Feb 20 07:29:52 2008
@@ -0,0 +1,28 @@
+package org.apache.maven.archiva.common.spring;
+
+import java.util.Arrays;
+
+import javax.xml.xpath.XPathFunction;
+
+import junit.framework.TestCase;
+
+/**
+ * @author ndeloof
+ *
+ */
+public class CamelCaseXpathFunctionTest
+ extends TestCase
+{
+
+ private XPathFunction function = new CamelCaseXpathFunction();
+
+ /**
+ * Test method for [EMAIL PROTECTED]
org.apache.maven.archiva.common.spring.CamelCaseXpathFunction#toCamelCase(java.lang.String)}.
+ */
+ public void testToCamelCase()
+ throws Exception
+ {
+ assertEquals( "aCamelCaseProperty", function.evaluate( Arrays.asList(
new String[] { "a-camel-case-property" } ) ) );
+ }
+
+}
Propchange:
maven/archiva/branches/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunctionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/archiva/branches/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunctionTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
maven/archiva/branches/springy/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/spring/CamelCaseXpathFunctionTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain