/**
* Copyright (C) 2008-2010, Squale Project - http://www.squale.org
*
* This file is part of Squale.
*
* Squale is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* Squale is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Squale. If not, see <http://www.gnu.org/licenses/>.
*/
package org.squale.squalix.tools.sourcecodeanalyser;
import java.io.InputStream;
import org.apache.commons.digester.Digester;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.squale.squalecommon.util.xml.XmlImport;
import org.squale.squalix.configurationmanager.ConfigUtility;
import org.squale.squalix.core.exception.ConfigurationException;
/**
* Configuration pour la r�cup�ration des sources via une arborescence de fichiers. La configuration associ�e est
* d�finie dans un fichier XML (<code>sourcecodeanalyser-config.xml</code>), celui-ci est lu par cette classe.
*/
public class SourceCodeAnalyserConfig
extends XmlImport
{
/**
* Logger.
*/
private static final Log LOGGER = LogFactory.getLog( SourceCodeAnalyserConfig.class );
/** R�pertoire racine */
private String mRootDirectory;
/**
* Constructeur par d�faut
*/
public SourceCodeAnalyserConfig()
{
super( LOGGER );
}
/**
* @return le r�pertoire racine
*/
public String getRootDirectory()
{
return mRootDirectory;
}
/**
* @param pRootDirectory le r�pertoire racine
*/
public void setRootDirectory( String pRootDirectory )
{
// On ajoute �ventuellement un / � la fin si il n'est
// pas d�j� pr�sent
String newRootDirectory = pRootDirectory;
if ( !newRootDirectory.endsWith( "/" ) )
{
newRootDirectory += "/";
}
mRootDirectory = ConfigUtility.filterStringWithSystemProps( newRootDirectory );
}
/**
* Lecture du fichier de configuration
*
* @param pStream flux
* @throws ConfigurationException si erreur
*/
public void parse( InputStream pStream )
throws ConfigurationException
{
StringBuffer errors = new StringBuffer();
Digester digester =
preSetupDigester( "-//SourceCodeAnalyser Configuration DTD //EN",
"/config/sourcecodeanalyser-config-1.0.dtd", errors );
// Traitement du r�pertoire racine
digester.addCallMethod( "sourcecodeanalyser-configuration/rootPath", "setRootDirectory", 1,
new Class[] { String.class } );
digester.addCallParam( "sourcecodeanalyser-configuration/rootPath", 0 );
digester.push( this );
// Appel du parser
parse( digester, pStream, errors );
if ( errors.length() > 0 )
{
throw new ConfigurationException( SourceCodeAnalyserMessages.getString( "exception.configuration",
new Object[] { errors.toString() } ) );
}
}
}