mirror of https://github.com/apache/archiva.git
Revised ConfigurationManager to use ConfigurationXpp3Reader instead of dom4j for parsing the xml config file.
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@414748 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1e5e969496
commit
d9310c161f
|
@ -54,11 +54,13 @@ public class BaseAction
|
|||
|
||||
private Map parameters;
|
||||
|
||||
public Map getParameters() {
|
||||
public Map getParameters()
|
||||
{
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(Map parameters) {
|
||||
public void setParameters( Map parameters )
|
||||
{
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,21 @@
|
|||
package org.apache.maven.repository.manager.web.action;
|
||||
|
||||
/*
|
||||
* Copyright 2006 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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 com.opensymphony.xwork.Action;
|
||||
import com.opensymphony.webwork.interceptor.ParameterAware;
|
||||
|
||||
|
@ -8,10 +24,8 @@ import java.util.HashMap;
|
|||
|
||||
import org.apache.maven.repository.manager.web.utils.ConfigurationManager;
|
||||
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
|
||||
*
|
||||
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.IndexConfigurationAction"
|
||||
*/
|
||||
public class IndexConfigurationAction
|
||||
|
@ -24,18 +38,20 @@ public class IndexConfigurationAction
|
|||
*/
|
||||
private ConfigurationManager configManager;
|
||||
|
||||
public Map getParameters() {
|
||||
public Map getParameters()
|
||||
{
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(Map parameters) {
|
||||
public void setParameters( Map parameters )
|
||||
{
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that is executed when the action is invoked.
|
||||
*
|
||||
* @return a String that specifies where to go to next
|
||||
* @return a String that specifies where to go to next
|
||||
* @throws Exception
|
||||
*/
|
||||
public String execute()
|
||||
|
@ -48,7 +64,7 @@ public class IndexConfigurationAction
|
|||
{
|
||||
String[] discoverSnapshots = (String[]) parameters.get( ConfigurationManager.DISCOVER_SNAPSHOTS );
|
||||
String[] minimalIndexPath = (String[]) parameters.get( ConfigurationManager.MIN_INDEXPATH );
|
||||
if( minimalIndexPath != null && minimalIndexPath.length == 1 && minimalIndexPath[0] != null )
|
||||
if ( minimalIndexPath != null && minimalIndexPath.length == 1 && minimalIndexPath[0] != null )
|
||||
{
|
||||
map.put( ConfigurationManager.MIN_INDEXPATH, minimalIndexPath[0] );
|
||||
}
|
||||
|
@ -56,9 +72,9 @@ public class IndexConfigurationAction
|
|||
map.put( ConfigurationManager.INDEXPATH, indexPath[0] );
|
||||
map.put( ConfigurationManager.DISCOVER_SNAPSHOTS, discoverSnapshots[0] );
|
||||
|
||||
String[] blacklistPatterns = ( String[] ) parameters.get( ConfigurationManager.DISCOVERY_BLACKLIST_PATTERNS );
|
||||
if( blacklistPatterns != null && blacklistPatterns.length == 1 && blacklistPatterns[0] != null )
|
||||
{
|
||||
String[] blacklistPatterns = (String[]) parameters.get( ConfigurationManager.DISCOVERY_BLACKLIST_PATTERNS );
|
||||
if ( blacklistPatterns != null && blacklistPatterns.length == 1 && blacklistPatterns[0] != null )
|
||||
{
|
||||
map.put( ConfigurationManager.DISCOVERY_BLACKLIST_PATTERNS, blacklistPatterns[0] );
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +1,40 @@
|
|||
package org.apache.maven.repository.manager.web.utils;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.SAXReader;
|
||||
/*
|
||||
* Copyright 2006 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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 org.apache.maven.repository.configuration.Configuration;
|
||||
import org.apache.maven.repository.configuration.io.xpp3.ConfigurationXpp3Writer;
|
||||
import org.apache.maven.repository.configuration.io.xpp3.ConfigurationXpp3Reader;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.io.Reader;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URL;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* This class updates the configuration in plexus.xml
|
||||
* This class updates/sets the configuration values in the mrm-admin-config.xml file used
|
||||
* for discovery and indexing.
|
||||
*
|
||||
* @plexus.component role="org.apache.maven.repository.manager.web.utils.ConfigurationManager"
|
||||
*/
|
||||
|
@ -43,17 +60,14 @@ public class ConfigurationManager
|
|||
|
||||
public static final String DISCOVERY_BLACKLIST_PATTERNS = "discoveryBlacklistPatterns";
|
||||
|
||||
|
||||
private Configuration config;
|
||||
|
||||
private File plexusDescriptor;
|
||||
|
||||
private Document document;
|
||||
|
||||
/**
|
||||
* Method for updating the configuration in plexus.xml
|
||||
* Method for updating the configuration in mrm-admin-config.xml
|
||||
*
|
||||
* @param map contains the fields and the values to be updated in the configuration
|
||||
* @param map contains the fields and the values to be updated in the configuration
|
||||
*/
|
||||
public void updateConfiguration( Map map )
|
||||
throws IOException
|
||||
|
@ -62,54 +76,44 @@ public class ConfigurationManager
|
|||
|
||||
try
|
||||
{
|
||||
document = readXmlDocument( file );
|
||||
config = readXmlDocument( file );
|
||||
}
|
||||
catch ( DocumentException de )
|
||||
catch ( XmlPullParserException de )
|
||||
{
|
||||
de.printStackTrace();
|
||||
}
|
||||
|
||||
Element rootElement = document.getRootElement();
|
||||
for( Iterator iter2 = rootElement.elementIterator(); iter2.hasNext(); )
|
||||
{
|
||||
Element field = (Element) iter2.next();
|
||||
if( !map.containsKey( field.getName() ) )
|
||||
{
|
||||
map.put( field.getName(), field.getData() );
|
||||
}
|
||||
}
|
||||
|
||||
for( Iterator iter = map.entrySet().iterator();iter.hasNext(); )
|
||||
for ( Iterator iter = map.entrySet().iterator(); iter.hasNext(); )
|
||||
{
|
||||
Map.Entry entry = (Map.Entry) iter.next();
|
||||
String name = (String) entry.getKey();
|
||||
String value = ( String ) entry.getValue();
|
||||
String value = (String) entry.getValue();
|
||||
|
||||
if( name.equals( DISCOVERY_CRON_EXPRESSION ) )
|
||||
if ( name.equals( DISCOVERY_CRON_EXPRESSION ) )
|
||||
{
|
||||
config.setDiscoveryCronExpression( value );
|
||||
}
|
||||
if( name.equals( REPOSITORY_LAYOUT ) )
|
||||
if ( name.equals( REPOSITORY_LAYOUT ) )
|
||||
{
|
||||
config.setRepositoryLayout( value );
|
||||
}
|
||||
if( name.equals( DISCOVER_SNAPSHOTS ) )
|
||||
if ( name.equals( DISCOVER_SNAPSHOTS ) )
|
||||
{
|
||||
config.setDiscoverSnapshots( Boolean.getBoolean( value ) );
|
||||
}
|
||||
if( name.equals( REPOSITORY_DIRECTORY ) )
|
||||
if ( name.equals( REPOSITORY_DIRECTORY ) )
|
||||
{
|
||||
config.setRepositoryDirectory( value );
|
||||
}
|
||||
if( name.equals( INDEXPATH ) )
|
||||
if ( name.equals( INDEXPATH ) )
|
||||
{
|
||||
config.setIndexPath( value );
|
||||
}
|
||||
if( name.equals( MIN_INDEXPATH ) )
|
||||
if ( name.equals( MIN_INDEXPATH ) )
|
||||
{
|
||||
config.setMinimalIndexPath( value );
|
||||
}
|
||||
if( name.equals( DISCOVERY_BLACKLIST_PATTERNS ) )
|
||||
if ( name.equals( DISCOVERY_BLACKLIST_PATTERNS ) )
|
||||
{
|
||||
config.setDiscoveryBlackListPatterns( value );
|
||||
}
|
||||
|
@ -119,7 +123,7 @@ public class ConfigurationManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Method that gets the properties set in the index-config.xml for the configuration fields
|
||||
* Method that gets the properties set in the mrm-admin-config.xml for the configuration fields
|
||||
* used in the schedule, indexing and discovery
|
||||
*
|
||||
* @return a Map that contains the elements in the properties of the configuration object
|
||||
|
@ -131,7 +135,7 @@ public class ConfigurationManager
|
|||
File file = getConfigFile();
|
||||
config = new Configuration();
|
||||
|
||||
if( !file.exists() )
|
||||
if ( !file.exists() )
|
||||
{
|
||||
writeXmlDocument( getConfigFile() );
|
||||
}
|
||||
|
@ -139,54 +143,11 @@ public class ConfigurationManager
|
|||
{
|
||||
try
|
||||
{
|
||||
document = readXmlDocument( file );
|
||||
config = readXmlDocument( file );
|
||||
}
|
||||
catch ( DocumentException de )
|
||||
catch ( XmlPullParserException xe )
|
||||
{
|
||||
de.printStackTrace();
|
||||
}
|
||||
|
||||
map = new HashMap();
|
||||
Element rootElement = document.getRootElement();
|
||||
for( Iterator iter2 = rootElement.elementIterator(); iter2.hasNext(); )
|
||||
{
|
||||
Element field = (Element) iter2.next();
|
||||
map.put( field.getName(), field.getData() );
|
||||
}
|
||||
|
||||
if( map.get( DISCOVERY_CRON_EXPRESSION ) != null && !"".equals( map.get( DISCOVERY_CRON_EXPRESSION ) ) )
|
||||
{
|
||||
config.setDiscoveryCronExpression( ( String ) map.get( DISCOVERY_CRON_EXPRESSION ) );
|
||||
}
|
||||
|
||||
if( map.get( REPOSITORY_LAYOUT ) != null && !"".equals( map.get( REPOSITORY_LAYOUT ) ) )
|
||||
{
|
||||
config.setRepositoryLayout( (String ) map.get( REPOSITORY_LAYOUT ) );
|
||||
}
|
||||
|
||||
if( map.get( DISCOVER_SNAPSHOTS ) != null && !"".equals( map.get( DISCOVER_SNAPSHOTS ) ) )
|
||||
{
|
||||
config.setDiscoverSnapshots( ( ( Boolean ) map.get( DISCOVER_SNAPSHOTS ) ).booleanValue() );
|
||||
}
|
||||
|
||||
if( map.get( REPOSITORY_DIRECTORY ) != null && !"".equals( map.get( REPOSITORY_DIRECTORY ) ) )
|
||||
{
|
||||
config.setRepositoryDirectory( ( String ) map.get( REPOSITORY_DIRECTORY ) );
|
||||
}
|
||||
|
||||
if( map.get( INDEXPATH ) != null && !"".equals( map.get( INDEXPATH ) ) )
|
||||
{
|
||||
config.setIndexPath( ( String ) map.get( INDEXPATH ) );
|
||||
}
|
||||
|
||||
if( map.get( MIN_INDEXPATH ) != null && !"".equals( map.get( MIN_INDEXPATH ) ) )
|
||||
{
|
||||
config.setMinimalIndexPath( ( String ) map.get( MIN_INDEXPATH ) );
|
||||
}
|
||||
|
||||
if( map.get( DISCOVERY_BLACKLIST_PATTERNS ) != null && !"".equals( map.get( DISCOVERY_BLACKLIST_PATTERNS ) ) )
|
||||
{
|
||||
config.setDiscoveryBlackListPatterns( ( String ) map.get( DISCOVERY_BLACKLIST_PATTERNS ) );
|
||||
xe.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,66 +155,28 @@ public class ConfigurationManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Method that reads the xml file and puts it in a Document object
|
||||
* Method that reads the xml file and returns a Configuration object
|
||||
*
|
||||
* @param file the xml file to be read
|
||||
* @return a Document object that represents the contents of the xml file
|
||||
* @throws DocumentException
|
||||
* @param file the xml file to be read
|
||||
* @return a Document object that represents the contents of the xml file
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
* @throws XmlPullParserException
|
||||
*/
|
||||
protected Document readXmlDocument( File file )
|
||||
throws DocumentException
|
||||
protected Configuration readXmlDocument( File file )
|
||||
throws IOException, XmlPullParserException
|
||||
{
|
||||
SAXReader reader = new SAXReader();
|
||||
if ( file.exists() )
|
||||
{
|
||||
return reader.read( file );
|
||||
}
|
||||
ConfigurationXpp3Reader configReader = new ConfigurationXpp3Reader();
|
||||
Reader reader = new FileReader( file );
|
||||
Configuration config = configReader.read( reader );
|
||||
|
||||
return null;
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for removing the specified element from the document
|
||||
* Method for writing the configuration into the xml file
|
||||
*
|
||||
* @param element
|
||||
* @param name
|
||||
*/
|
||||
protected void removeElement( Element element, String name )
|
||||
{
|
||||
for( Iterator children = element.elementIterator(); children.hasNext(); )
|
||||
{
|
||||
Element child = (Element) children.next();
|
||||
if( child.getName().equals( name ) )
|
||||
{
|
||||
element.remove( child );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Element addElement( Element element, String name )
|
||||
{
|
||||
return element.addElement( name );
|
||||
}
|
||||
|
||||
protected void setElementValue( Element element, String value )
|
||||
{
|
||||
element.setText( value );
|
||||
}
|
||||
|
||||
protected Element addAndSetElement( Element element, String elementName, String elementValue )
|
||||
{
|
||||
Element retElement = addElement( element, elementName );
|
||||
|
||||
setElementValue( retElement, elementValue );
|
||||
|
||||
return retElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for writing the document object into its corresponding
|
||||
* xml file.
|
||||
*
|
||||
* @param file the file where the document will be written to
|
||||
* @param file the file where the document will be written to
|
||||
*/
|
||||
protected void writeXmlDocument( File file )
|
||||
throws IOException
|
||||
|
@ -264,7 +187,7 @@ public class ConfigurationManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Method that returns the index-config.xml file
|
||||
* Method that returns the mrm-admin-config.xml file
|
||||
*
|
||||
* @return a File that references the plexus.xml
|
||||
*/
|
||||
|
@ -272,7 +195,7 @@ public class ConfigurationManager
|
|||
{
|
||||
URL indexConfigXml = getClass().getClassLoader().getResource( "../" + INDEX_CONFIG_FILE );
|
||||
|
||||
if( indexConfigXml != null )
|
||||
if ( indexConfigXml != null )
|
||||
{
|
||||
plexusDescriptor = new File( indexConfigXml.getFile() );
|
||||
}
|
||||
|
@ -283,14 +206,10 @@ public class ConfigurationManager
|
|||
int lastIndex = path.lastIndexOf( '/' );
|
||||
path = path.substring( 0, lastIndex + 1 );
|
||||
path = path + INDEX_CONFIG_FILE;
|
||||
plexusDescriptor = new File ( path );
|
||||
plexusDescriptor = new File( path );
|
||||
}
|
||||
|
||||
return plexusDescriptor;
|
||||
}
|
||||
|
||||
protected Document getDocument()
|
||||
{
|
||||
return document;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<b>INDEX CONFIGURATION:</b>
|
||||
</p>
|
||||
|
||||
<form action="configureIndex.action" method="get">
|
||||
<form action="configureIndex.action" method="post">
|
||||
Index Path: <input type="text" name="indexPath" value="<ww:property value="parameters.indexPath"/>"/>
|
||||
<br>
|
||||
Minimal Index Path: <input type="text" name="minimalIndexPath" value="<ww:property value="parameters.minimalIndexPath"/>"/>
|
||||
|
|
Loading…
Reference in New Issue