* under the License.
*/
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.smartcardio.ATR;
+
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
+import org.springframework.util.xml.DomUtils;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
{
private Element root;
- private String name;
-
/**
*
*/
- public DomPlexusConfiguration( String name, Element root )
+ public DomPlexusConfiguration( Element root )
{
- this.name = name;
this.root = root;
}
public String getAttribute( String paramName )
throws PlexusConfigurationException
{
- // TODO Auto-generated method stub
- return null;
+ return root.getAttribute( paramName );
}
/**
*/
public String getAttribute( String name, String defaultValue )
{
- // TODO Auto-generated method stub
- return null;
+ String attribute = root.getAttribute( name );
+ if ( attribute == null )
+ {
+ attribute = defaultValue;
+ }
+ return attribute;
}
/**
*/
public String[] getAttributeNames()
{
- // TODO Auto-generated method stub
- return null;
+ NamedNodeMap attributes = root.getAttributes();
+ String[] names = new String[attributes.getLength()];
+ for ( int i = 0; i < names.length; i++ )
+ {
+ names[i] = attributes.item( i ).getLocalName();
+ }
+ return names;
}
/**
*/
public PlexusConfiguration getChild( String child )
{
- // TODO Auto-generated method stub
+ Element e = DomUtils.getChildElementByTagName( root, child );
+ if (e != null)
+ {
+ return new DomPlexusConfiguration( e );
+ }
return null;
}
*/
public PlexusConfiguration getChild( int i )
{
- // TODO Auto-generated method stub
+ NodeList childs = root.getChildNodes();
+ for ( int j = 0; j < childs.getLength(); j++ )
+ {
+ Node child = childs.item( j );
+ if ( child.getNodeType() == Node.ELEMENT_NODE )
+ {
+ if (i-- == 0)
+ {
+ return new DomPlexusConfiguration( (Element) child );
+ }
+ }
+ }
return null;
}
*/
public PlexusConfiguration getChild( String child, boolean createChild )
{
- // TODO Auto-generated method stub
- return null;
+ PlexusConfiguration config = getChild( child );
+ if (config == null && createChild )
+ {
+ // Creating a new child requires a Document
+ throw new UnsupportedOperationException( "Not implemented" );
+ }
+ return config;
}
/**
*/
public int getChildCount()
{
- // TODO Auto-generated method stub
- return 0;
+ int count = 0;
+ NodeList childs = root.getChildNodes();
+ for ( int i = 0; i < childs.getLength(); i++ )
+ {
+ Node child = childs.item( i );
+ if ( child.getNodeType() == Node.ELEMENT_NODE )
+ {
+ count++;
+ }
+ }
+ return count;
}
/**
*/
public PlexusConfiguration[] getChildren()
{
- // TODO Auto-generated method stub
- return null;
+ int count = getChildCount();
+ PlexusConfiguration[] children = new PlexusConfiguration[count];
+ for ( int i = 0; i < children.length; i++ )
+ {
+ children[i] = getChild( i );
+ }
+ return children;
}
/**
*/
public PlexusConfiguration[] getChildren( String name )
{
- // TODO Auto-generated method stub
- return null;
+ throw new UnsupportedOperationException( "Not implemented" );
}
/**
*/
public String getName()
{
- // TODO Auto-generated method stub
- return null;
+ return root.getNodeName();
}
/**
public String getValue()
throws PlexusConfigurationException
{
- // TODO Auto-generated method stub
- return null;
+ return root.getNodeValue();
}
/**
*/
public String getValue( String defaultValue )
{
- // TODO Auto-generated method stub
- return null;
+ String value = root.getTextContent();
+ if ( value == null )
+ {
+ value = defaultValue;
+ }
+ return value;
}
}
--- /dev/null
+package org.codehaus.plexus.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.beans.PropertyEditorSupport;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.commons.lang.StringUtils;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.springframework.beans.PropertyEditorRegistrar;
+import org.springframework.beans.PropertyEditorRegistry;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class PlexusConfigurationPropertyEditor
+ extends PropertyEditorSupport
+ implements PropertyEditorRegistrar
+{
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.springframework.beans.PropertyEditorRegistrar#registerCustomEditors(org.springframework.beans.PropertyEditorRegistry)
+ */
+ public void registerCustomEditors( PropertyEditorRegistry registry )
+ {
+ registry.registerCustomEditor( PlexusConfiguration.class, this );
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
+ */
+ public void setAsText( String text )
+ throws IllegalArgumentException
+ {
+ if (StringUtils.isBlank( text ))
+ {
+ setValue( null );
+ return;
+ }
+ try
+ {
+ Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( text ) );
+ XmlPlexusConfiguration configuration = new XmlPlexusConfiguration( dom );
+ setValue( configuration );
+ }
+ catch ( Exception e )
+ {
+ throw new IllegalArgumentException( "Failed to convert to Plexus XML configuration", e );
+ }
+ }
+
+}