Program: 24563
Project: 24563
Buggy source:
/** 
 * Load the list of data providers from XML file
 * @param file2Read
 * @return List of data providers
 * @throws DocumentException
 * @throws IOException
 */
@Override public List<DataProvider> loadDataProvidersFromFile(File file2Read,File repositoryPath) throws DocumentException, IOException, ParseException {
  List<DataProvider> dataProvidersLoaded=new ArrayList<DataProvider>();
  SAXReader reader=new SAXReader();
  Document document=reader.read(file2Read);
  if (configuration != null && configuration.getCurrentServerOAIUrl() != null) {
    ExternalServiceUtil.replaceAllExternalServices(document,configuration.getCurrentServerOAIUrl());
    XmlUtil.writePrettyPrint(dataProvidersFile,document);
  }
  if (!document.getRootElement().elements("String_Node_Str").isEmpty()) {
    for (    Element currentDataProviderElement : (List<Element>)document.getRootElement().elements("String_Node_Str")) {
      String providerId=currentDataProviderElement.attributeValue("String_Node_Str");
      String providerName=currentDataProviderElement.elementText("String_Node_Str");
      String providerCountry=currentDataProviderElement.elementText("String_Node_Str");
      String providerDescription=currentDataProviderElement.elementText("String_Node_Str");
      HashMap<String,DataSourceContainer> dataSourceContainers=new HashMap<String,DataSourceContainer>();
      DataProvider provider=new DataProvider(providerId,providerName,providerCountry,providerDescription,dataSourceContainers,null,null,null);
      for (      Element currentDataSourceElement : (List<Element>)currentDataProviderElement.elements("String_Node_Str")) {
        String id=currentDataSourceElement.attributeValue("String_Node_Str");
        String description=currentDataSourceElement.elementText("String_Node_Str");
        String metadataFormat=currentDataSourceElement.attributeValue("String_Node_Str");
        String schema=currentDataSourceElement.attributeValue("String_Node_Str");
        String namespace=currentDataSourceElement.attributeValue("String_Node_Str");
        String lastIngest=currentDataSourceElement.attributeValue("String_Node_Str");
        String sample=currentDataSourceElement.attributeValue("String_Node_Str");
        String status=currentDataSourceElement.attributeValue("String_Node_Str");
        String isSampleStr=currentDataSourceElement.attributeValue("String_Node_Str");
        if (isSampleStr == null)         isSampleStr="String_Node_Str";
        boolean isSample=Boolean.valueOf(isSampleStr);
        if (namespace == null) {
          namespace=MetadataTransformationManager.getNamespace(metadataFormat);
        }
        if (schema == null) {
          schema=MetadataTransformationManager.getSchema(metadataFormat);
        }
        Element recordIdPolicyNode=currentDataSourceElement.element("String_Node_Str");
        String recordIdPolicyClass=recordIdPolicyNode.attributeValue("String_Node_Str");
        RecordIdPolicy recordIdPolicy=null;
        if (recordIdPolicyClass.equals(IdGeneratedRecordIdPolicy.class.getSimpleName())) {
          recordIdPolicy=new IdGeneratedRecordIdPolicy();
        }
 else         if (recordIdPolicyClass.equals(IdProvidedRecordIdPolicy.class.getSimpleName())) {
          recordIdPolicy=new IdProvidedRecordIdPolicy();
        }
 else         if (recordIdPolicyClass.equals(IdExtractedRecordIdPolicy.class.getSimpleName())) {
          String identifierXpath=recordIdPolicyNode.element("String_Node_Str").getText();
          Map<String,String> namespaces=new TreeMap<String,String>();
          Element namespacesElement=recordIdPolicyNode.element("String_Node_Str");
          if (namespacesElement != null) {
            List<Element> namespaceElement=namespacesElement.elements("String_Node_Str");
            for (            Element currentNamespace : namespaceElement) {
              namespaces.put(currentNamespace.elementText("String_Node_Str"),currentNamespace.elementText("String_Node_Str"));
            }
          }
          recordIdPolicy=new IdExtractedRecordIdPolicy(identifierXpath,namespaces);
        }
 else {
          throw new RuntimeException("String_Node_Str" + recordIdPolicyClass);
        }
        Map<String,MetadataTransformation> metadataTransformations=new HashMap<String,MetadataTransformation>();
        for (        Element metadataTransformationElement : (List<Element>)currentDataSourceElement.element("String_Node_Str").elements("String_Node_Str")) {
          String transformationId=metadataTransformationElement.getText();
          MetadataTransformation metadataTransformation=metadataTransformationManager.loadMetadataTransformation(transformationId);
          if (metadataTransformation != null)           metadataTransformations.put(metadataTransformation.getId(),metadataTransformation);
        }
        DataSource dataSource=null;
        DataSource existDataSource=getDataSource(id);
        if (existDataSource != null) {
          int i=0;
          while (true) {
            if (getDataSourceContainer(id + i) == null) {
              id=(id + i);
              break;
            }
            i++;
          }
        }
        String dataSourceType=currentDataSourceElement.attribute("String_Node_Str").getText();
        if (dataSourceType.equals("String_Node_Str")) {
          String oaiSource=currentDataSourceElement.elementText("String_Node_Str");
          String oaiSet=(currentDataSourceElement.element("String_Node_Str") != null ? currentDataSourceElement.elementText("String_Node_Str") : null);
          dataSource=new OaiDataSource(provider,id,description,schema,namespace,metadataFormat,oaiSource,oaiSet,new IdProvidedRecordIdPolicy(),metadataTransformations);
        }
 else         if (dataSourceType.equals("String_Node_Str")) {
          dataSource=new SruRecordUpdateDataSource(provider,id,description,schema,namespace,metadataFormat,recordIdPolicy,metadataTransformations);
        }
 else         if (dataSourceType.equals("String_Node_Str")) {
          String sourcesDirPath=currentDataSourceElement.elementText("String_Node_Str");
          String extractStrategyString=currentDataSourceElement.elementText("String_Node_Str");
          Element currentRetrieveStrategy=currentDataSourceElement.element("String_Node_Str");
          String retrieveStrategyString=null;
          if (currentRetrieveStrategy != null) {
            retrieveStrategyString=currentRetrieveStrategy.attributeValue("String_Node_Str");
          }
          FileRetrieveStrategy retrieveStrategy;
          if (retrieveStrategyString != null && retrieveStrategyString.equals(FtpFileRetrieveStrategy.class.getName())) {
            String server=currentRetrieveStrategy.elementText("String_Node_Str");
            String user=currentRetrieveStrategy.elementText("String_Node_Str");
            String password=currentRetrieveStrategy.elementText("String_Node_Str");
            String idType;
            if (user != null && password != null) {
              idType=FtpFileRetrieveStrategy.NORMAL;
            }
 else {
              idType=FtpFileRetrieveStrategy.ANONYMOUS;
            }
            String ftpPath=currentRetrieveStrategy.elementText("String_Node_Str");
            retrieveStrategy=new FtpFileRetrieveStrategy(server,user,password,idType,ftpPath);
          }
 else           if (retrieveStrategyString != null && retrieveStrategyString.equals(HttpFileRetrieveStrategy.class.getName())) {
            String url=currentRetrieveStrategy.elementText("String_Node_Str");
            retrieveStrategy=new HttpFileRetrieveStrategy(url);
          }
 else {
            retrieveStrategy=new FolderFileRetrieveStrategy();
          }
          CharacterEncoding characterEncoding=null;
          String recordXPath=null;
          Map<String,String> namespaces=null;
          FileExtractStrategy extractStrategy=null;
          if (extractStrategyString.equals(Iso2709FileExtractStrategy.class.getSimpleName())) {
            characterEncoding=CharacterEncoding.get(currentDataSourceElement.attributeValue("String_Node_Str"));
            String isoImplementationClass=currentDataSourceElement.attributeValue("String_Node_Str");
            extractStrategy=new Iso2709FileExtractStrategy(isoImplementationClass);
          }
 else           if (extractStrategyString.equals(MarcXchangeFileExtractStrategy.class.getSimpleName())) {
            extractStrategy=new MarcXchangeFileExtractStrategy();
          }
 else           if (extractStrategyString.equals(SimpleFileExtractStrategy.class.getSimpleName())) {
            extractStrategy=new SimpleFileExtractStrategy();
            Element splitRecordsElement=currentDataSourceElement.element("String_Node_Str");
            if (splitRecordsElement != null) {
              recordXPath=splitRecordsElement.elementText("String_Node_Str");
              namespaces=new TreeMap<String,String>();
              Element namespacesElement=splitRecordsElement.element("String_Node_Str");
              if (namespacesElement != null) {
                List<Element> namespaceElement=namespacesElement.elements("String_Node_Str");
                for (                Element currentNamespace : namespaceElement) {
                  namespaces.put(currentNamespace.elementText("String_Node_Str"),currentNamespace.elementText("String_Node_Str"));
                }
              }
            }
          }
          dataSource=new DirectoryImporterDataSource(provider,id,description,schema,namespace,metadataFormat,extractStrategy,retrieveStrategy,characterEncoding,sourcesDirPath,recordIdPolicy,metadataTransformations,recordXPath,namespaces);
        }
 else         if (dataSourceType.equals("String_Node_Str")) {
          Element targetElement=currentDataSourceElement.element("String_Node_Str");
          String targetAddress=targetElement.elementText("String_Node_Str");
          int targetPort=Integer.parseInt(targetElement.elementText("String_Node_Str"));
          String targetDatabase=targetElement.elementText("String_Node_Str");
          String targetUser=targetElement.elementText("String_Node_Str");
          String targetPassword=targetElement.elementText("String_Node_Str");
          String targetRecordSyntax=targetElement.elementText("String_Node_Str");
          CharacterEncoding targetCharacterEncoding=CharacterEncoding.get(targetElement.elementText("String_Node_Str"));
          Target target=new Target(targetAddress,targetPort,targetDatabase,targetUser,targetPassword,targetCharacterEncoding,targetRecordSyntax);
          Harvester harvestMethod=null;
          String harvestMethodString=currentDataSourceElement.elementText("String_Node_Str");
          if (harvestMethodString.equals(TimestampHarvester.class.getSimpleName())) {
            String timestampString=currentDataSourceElement.elementText("String_Node_Str");
            try {
              Date earliestTimestamp=DateUtil.string2Date(timestampString,"String_Node_Str");
              harvestMethod=new TimestampHarvester(target,earliestTimestamp);
            }
 catch (            ParseException e) {
              log.error("String_Node_Str" + timestampString,e);
              break;
            }
          }
 else           if (harvestMethodString.equals(IdListHarvester.class.getSimpleName())) {
            String filePath=currentDataSourceElement.elementText("String_Node_Str");
            File idListFile=new File(filePath);
            harvestMethod=new IdListHarvester(target,idListFile);
          }
 else           if (harvestMethodString.equals(IdSequenceHarvester.class.getSimpleName())) {
            String maximumIdString=currentDataSourceElement.elementText("String_Node_Str");
            Long maximumId=(maximumIdString != null && !maximumIdString.isEmpty() ? Long.valueOf(maximumIdString) : null);
            harvestMethod=new IdSequenceHarvester(target,maximumId);
          }
          dataSource=new DataSourceZ3950(provider,id,description,schema,namespace,harvestMethod,recordIdPolicy,metadataTransformations);
        }
 else {
          throw new RuntimeException("String_Node_Str" + dataSourceType + "String_Node_Str");
        }
        parseOldTasks(dataSource);
        boolean removeSynFile=false;
        if (dataSource != null) {
          if (status != null && !file2Read.getParentFile().getName().equals("String_Node_Str")) {
            if (status.equals(DataSource.StatusDS.OK.toString())) {
              dataSource.setStatus(DataSource.StatusDS.OK);
            }
 else             if (status.equals(DataSource.StatusDS.ERROR.toString())) {
              dataSource.setStatus(DataSource.StatusDS.ERROR);
            }
 else             if (status.equals(DataSource.StatusDS.WARNING.toString())) {
              dataSource.setStatus(DataSource.StatusDS.WARNING);
            }
 else             if (status.equals(DataSource.StatusDS.RUNNING.toString())) {
              dataSource.setStatus(DataSource.StatusDS.RUNNING);
            }
 else             if (status.equals(DataSource.StatusDS.CANCELED.toString())) {
              dataSource.setStatus(DataSource.StatusDS.CANCELED);
            }
 else             if (status.equals(DataSource.StatusDS.PRE_PROCESS_ERROR.toString())) {
              dataSource.setStatus(DataSource.StatusDS.PRE_PROCESS_ERROR);
            }
 else             if (status.equals(DataSource.StatusDS.POST_PROCESS_ERROR.toString())) {
              dataSource.setStatus(DataSource.StatusDS.POST_PROCESS_ERROR);
            }
          }
          if (lastIngest == null && !file2Read.getParentFile().getName().equals("String_Node_Str")) {
            lastIngest=dataSource.getSynchronizationDate(new File(new File(repositoryPath,id),"String_Node_Str"));
            removeSynFile=true;
          }
 else           if (file2Read.getParentFile().getName().equals("String_Node_Str")) {
            lastIngest="String_Node_Str";
          }
          if (lastIngest != null && !lastIngest.equals("String_Node_Str")) {
            try {
              dataSource.setLastUpdate(DateUtil.string2Date(lastIngest,TimeUtil.LONG_DATE_FORMAT));
            }
 catch (            ParseException e) {
              dataSource.setLastUpdate(DateUtil.string2Date(lastIngest,TimeUtil.SHORT_DATE_FORMAT));
            }
          }
          if (sample == null) {
            sample=String.valueOf(dataSource.getSampleNumber(new File(new File(repositoryPath,id),"String_Node_Str")));
            removeSynFile=true;
          }
          if (!sample.equals("String_Node_Str") && !file2Read.getParentFile().getName().equals("String_Node_Str")) {
            dataSource.setMaxRecord4Sample(Integer.valueOf(sample));
          }
          if (removeSynFile) {
            File dataSourceSyncDate=new File(new File(repositoryPath,id),"String_Node_Str");
            if (dataSourceSyncDate.exists()) {
              boolean result=dataSourceSyncDate.delete();
              if (result)               log.info("String_Node_Str" + id);
 else               log.error("String_Node_Str" + id);
            }
          }
          String marcFormat=currentDataSourceElement.attributeValue("String_Node_Str");
          if (marcFormat != null && !marcFormat.isEmpty())           dataSource.setMarcFormat(marcFormat);
          List servicesList=currentDataSourceElement.selectNodes("String_Node_Str");
          String executeType=currentDataSourceElement.valueOf("String_Node_Str");
          if (executeType != null && !executeType.isEmpty())           dataSource.setExternalServicesRunType(ExternalServiceStates.ContainerType.valueOf(executeType));
          for (          Object node : servicesList) {
            Node n=(Node)node;
            String serviceId=n.valueOf("String_Node_Str");
            String serviceType=n.valueOf("String_Node_Str");
            String enabled=n.valueOf("String_Node_Str");
            boolean isEnabled=Boolean.valueOf((enabled == null || enabled.isEmpty()) ? "String_Node_Str" : enabled);
            String serviceUri=n.valueOf("String_Node_Str");
            String serviceStatusUri=n.valueOf("String_Node_Str");
            String externalResultsUri=n.valueOf("String_Node_Str");
            String serviceName=n.valueOf("String_Node_Str");
            String externalServiceType=n.valueOf("String_Node_Str");
            if (externalServiceType == null || externalServiceType.isEmpty())             externalServiceType=ExternalServiceType.MONITORED.name();
            ExternalRestService externalRestService;
            if (externalServiceType.equals(ExternalServiceType.NO_MONITOR.name())) {
              externalRestService=new ExternalServiceNoMonitor(serviceId,serviceName,serviceUri,dataSource);
            }
 else {
              externalRestService=new ExternalRestService(serviceId,serviceName,serviceUri,serviceStatusUri,serviceType,ExternalServiceType.valueOf(externalServiceType));
            }
            externalRestService.setEnabled(isEnabled);
            if (externalResultsUri != null && !externalResultsUri.isEmpty())             externalRestService.setExternalResultsUri(externalResultsUri);
            List parametersList=n.selectNodes("String_Node_Str");
            for (            Object nodeP : parametersList) {
              Node parameterNode=(Node)nodeP;
              String parameterName=parameterNode.valueOf("String_Node_Str");
              String parameterValue=parameterNode.valueOf("String_Node_Str");
              String parameterType=parameterNode.valueOf("String_Node_Str");
              boolean parameterRequired=Boolean.parseBoolean(parameterNode.valueOf("String_Node_Str"));
              String exampleStr=parameterNode.valueOf("String_Node_Str");
              String semanticsStr=parameterNode.valueOf("String_Node_Str");
              ServiceParameter serviceParameter=new ServiceParameter(parameterName,parameterType,parameterRequired,exampleStr,semanticsStr);
              serviceParameter.setValue(parameterValue);
              externalRestService.getServiceParameters().add(serviceParameter);
            }
            dataSource.getExternalRestServices().add(externalRestService);
          }
          loadDataSourceTags(currentDataSourceElement,dataSource);
          if (currentDataSourceElement.elementText("String_Node_Str") != null && !currentDataSourceElement.elementText("String_Node_Str").isEmpty())           dataSource.setExportDir(currentDataSourceElement.elementText("String_Node_Str"));
 else {
            File newExportDir=new File(repositoryPath.getAbsolutePath() + File.separator + dataSource.getId()+ File.separator+ "String_Node_Str");
            dataSource.setExportDir(newExportDir.getAbsolutePath());
          }
          boolean exists=metadataSchemaManager.schemaExists(metadataFormat);
          if (!exists) {
            List<MetadataSchemaVersion> metadataSchemaVersions=new ArrayList<MetadataSchemaVersion>();
            metadataSchemaVersions.add(new MetadataSchemaVersion(1.0,schema));
            metadataSchemaManager.saveMetadataSchema(null,metadataFormat,null,namespace,null,null,metadataSchemaVersions,true);
          }
          dataSource.setIsSample(isSample);
          dataSourceContainers.put(dataSource.getId(),new LightDataSourceContainer(dataSource));
        }
      }
      if (getDataProvider(provider.getId()) != null) {
        provider.setId(DataProvider.generateId(provider.getName()));
      }
      dataProvidersLoaded.add(provider);
    }
  }
  if (dataProviders != null && dataProviders.size() > 0) {
    for (    DataProvider dataProviderLoaded : dataProvidersLoaded) {
      try {
        ConfigSingleton.getRepoxContextUtil().getRepoxManager().getAccessPointsManager().initialize(dataProviderLoaded.getDataSourceContainers());
      }
 catch (      SQLException e) {
        e.printStackTrace();
      }
      dataProviders.add(dataProviderLoaded);
    }
  }
 else {
    dataProviders=dataProvidersLoaded;
  }
  saveData();
  return dataProvidersLoaded;
}

Fixed version (ground truth):
/** 
 * Load the list of data providers from XML file
 * @param file2Read
 * @return List of data providers
 * @throws DocumentException
 * @throws IOException
 */
@Override public List<DataProvider> loadDataProvidersFromFile(File file2Read,File repositoryPath) throws DocumentException, IOException, ParseException {
  List<DataProvider> dataProvidersLoaded=new ArrayList<DataProvider>();
  SAXReader reader=new SAXReader();
  Document document=reader.read(file2Read);
  if (configuration != null && configuration.getCurrentServerOAIUrl() != null) {
    ExternalServiceUtil.replaceAllExternalServices(document,configuration.getCurrentServerOAIUrl());
    XmlUtil.writePrettyPrint(dataProvidersFile,document);
  }
  if (!document.getRootElement().elements("String_Node_Str").isEmpty()) {
    for (    Element currentDataProviderElement : (List<Element>)document.getRootElement().elements("String_Node_Str")) {
      String providerId=currentDataProviderElement.attributeValue("String_Node_Str");
      String providerName=currentDataProviderElement.elementText("String_Node_Str");
      String providerCountry=currentDataProviderElement.elementText("String_Node_Str");
      String providerDescription=currentDataProviderElement.elementText("String_Node_Str");
      HashMap<String,DataSourceContainer> dataSourceContainers=new HashMap<String,DataSourceContainer>();
      DataProvider provider=new DataProvider(providerId,providerName,providerCountry,providerDescription,dataSourceContainers,null,null,null,null);
      for (      Element currentDataSourceElement : (List<Element>)currentDataProviderElement.elements("String_Node_Str")) {
        String id=currentDataSourceElement.attributeValue("String_Node_Str");
        String description=currentDataSourceElement.elementText("String_Node_Str");
        String metadataFormat=currentDataSourceElement.attributeValue("String_Node_Str");
        String schema=currentDataSourceElement.attributeValue("String_Node_Str");
        String namespace=currentDataSourceElement.attributeValue("String_Node_Str");
        String lastIngest=currentDataSourceElement.attributeValue("String_Node_Str");
        String sample=currentDataSourceElement.attributeValue("String_Node_Str");
        String status=currentDataSourceElement.attributeValue("String_Node_Str");
        String isSampleStr=currentDataSourceElement.attributeValue("String_Node_Str");
        if (isSampleStr == null)         isSampleStr="String_Node_Str";
        boolean isSample=Boolean.valueOf(isSampleStr);
        if (namespace == null) {
          namespace=MetadataTransformationManager.getNamespace(metadataFormat);
        }
        if (schema == null) {
          schema=MetadataTransformationManager.getSchema(metadataFormat);
        }
        Element recordIdPolicyNode=currentDataSourceElement.element("String_Node_Str");
        String recordIdPolicyClass=recordIdPolicyNode.attributeValue("String_Node_Str");
        RecordIdPolicy recordIdPolicy=null;
        if (recordIdPolicyClass.equals(IdGeneratedRecordIdPolicy.class.getSimpleName())) {
          recordIdPolicy=new IdGeneratedRecordIdPolicy();
        }
 else         if (recordIdPolicyClass.equals(IdProvidedRecordIdPolicy.class.getSimpleName())) {
          recordIdPolicy=new IdProvidedRecordIdPolicy();
        }
 else         if (recordIdPolicyClass.equals(IdExtractedRecordIdPolicy.class.getSimpleName())) {
          String identifierXpath=recordIdPolicyNode.element("String_Node_Str").getText();
          Map<String,String> namespaces=new TreeMap<String,String>();
          Element namespacesElement=recordIdPolicyNode.element("String_Node_Str");
          if (namespacesElement != null) {
            List<Element> namespaceElement=namespacesElement.elements("String_Node_Str");
            for (            Element currentNamespace : namespaceElement) {
              namespaces.put(currentNamespace.elementText("String_Node_Str"),currentNamespace.elementText("String_Node_Str"));
            }
          }
          recordIdPolicy=new IdExtractedRecordIdPolicy(identifierXpath,namespaces);
        }
 else {
          throw new RuntimeException("String_Node_Str" + recordIdPolicyClass);
        }
        Map<String,MetadataTransformation> metadataTransformations=new HashMap<String,MetadataTransformation>();
        for (        Element metadataTransformationElement : (List<Element>)currentDataSourceElement.element("String_Node_Str").elements("String_Node_Str")) {
          String transformationId=metadataTransformationElement.getText();
          MetadataTransformation metadataTransformation=metadataTransformationManager.loadMetadataTransformation(transformationId);
          if (metadataTransformation != null)           metadataTransformations.put(metadataTransformation.getId(),metadataTransformation);
        }
        DataSource dataSource=null;
        DataSource existDataSource=getDataSource(id);
        if (existDataSource != null) {
          int i=0;
          while (true) {
            if (getDataSourceContainer(id + i) == null) {
              id=(id + i);
              break;
            }
            i++;
          }
        }
        String dataSourceType=currentDataSourceElement.attribute("String_Node_Str").getText();
        if (dataSourceType.equals("String_Node_Str")) {
          String oaiSource=currentDataSourceElement.elementText("String_Node_Str");
          String oaiSet=(currentDataSourceElement.element("String_Node_Str") != null ? currentDataSourceElement.elementText("String_Node_Str") : null);
          dataSource=new OaiDataSource(provider,id,description,schema,namespace,metadataFormat,oaiSource,oaiSet,new IdProvidedRecordIdPolicy(),metadataTransformations);
        }
 else         if (dataSourceType.equals("String_Node_Str")) {
          dataSource=new SruRecordUpdateDataSource(provider,id,description,schema,namespace,metadataFormat,recordIdPolicy,metadataTransformations);
        }
 else         if (dataSourceType.equals("String_Node_Str")) {
          String sourcesDirPath=currentDataSourceElement.elementText("String_Node_Str");
          String extractStrategyString=currentDataSourceElement.elementText("String_Node_Str");
          Element currentRetrieveStrategy=currentDataSourceElement.element("String_Node_Str");
          String retrieveStrategyString=null;
          if (currentRetrieveStrategy != null) {
            retrieveStrategyString=currentRetrieveStrategy.attributeValue("String_Node_Str");
          }
          FileRetrieveStrategy retrieveStrategy;
          if (retrieveStrategyString != null && retrieveStrategyString.equals(FtpFileRetrieveStrategy.class.getName())) {
            String server=currentRetrieveStrategy.elementText("String_Node_Str");
            String user=currentRetrieveStrategy.elementText("String_Node_Str");
            String password=currentRetrieveStrategy.elementText("String_Node_Str");
            String idType;
            if (user != null && password != null) {
              idType=FtpFileRetrieveStrategy.NORMAL;
            }
 else {
              idType=FtpFileRetrieveStrategy.ANONYMOUS;
            }
            String ftpPath=currentRetrieveStrategy.elementText("String_Node_Str");
            retrieveStrategy=new FtpFileRetrieveStrategy(server,user,password,idType,ftpPath);
          }
 else           if (retrieveStrategyString != null && retrieveStrategyString.equals(HttpFileRetrieveStrategy.class.getName())) {
            String url=currentRetrieveStrategy.elementText("String_Node_Str");
            retrieveStrategy=new HttpFileRetrieveStrategy(url);
          }
 else {
            retrieveStrategy=new FolderFileRetrieveStrategy();
          }
          CharacterEncoding characterEncoding=null;
          String recordXPath=null;
          Map<String,String> namespaces=null;
          FileExtractStrategy extractStrategy=null;
          if (extractStrategyString.equals(Iso2709FileExtractStrategy.class.getSimpleName())) {
            characterEncoding=CharacterEncoding.get(currentDataSourceElement.attributeValue("String_Node_Str"));
            String isoImplementationClass=currentDataSourceElement.attributeValue("String_Node_Str");
            extractStrategy=new Iso2709FileExtractStrategy(isoImplementationClass);
          }
 else           if (extractStrategyString.equals(MarcXchangeFileExtractStrategy.class.getSimpleName())) {
            extractStrategy=new MarcXchangeFileExtractStrategy();
          }
 else           if (extractStrategyString.equals(SimpleFileExtractStrategy.class.getSimpleName())) {
            extractStrategy=new SimpleFileExtractStrategy();
            Element splitRecordsElement=currentDataSourceElement.element("String_Node_Str");
            if (splitRecordsElement != null) {
              recordXPath=splitRecordsElement.elementText("String_Node_Str");
              namespaces=new TreeMap<String,String>();
              Element namespacesElement=splitRecordsElement.element("String_Node_Str");
              if (namespacesElement != null) {
                List<Element> namespaceElement=namespacesElement.elements("String_Node_Str");
                for (                Element currentNamespace : namespaceElement) {
                  namespaces.put(currentNamespace.elementText("String_Node_Str"),currentNamespace.elementText("String_Node_Str"));
                }
              }
            }
          }
          dataSource=new DirectoryImporterDataSource(provider,id,description,schema,namespace,metadataFormat,extractStrategy,retrieveStrategy,characterEncoding,sourcesDirPath,recordIdPolicy,metadataTransformations,recordXPath,namespaces);
        }
 else         if (dataSourceType.equals("String_Node_Str")) {
          Element targetElement=currentDataSourceElement.element("String_Node_Str");
          String targetAddress=targetElement.elementText("String_Node_Str");
          int targetPort=Integer.parseInt(targetElement.elementText("String_Node_Str"));
          String targetDatabase=targetElement.elementText("String_Node_Str");
          String targetUser=targetElement.elementText("String_Node_Str");
          String targetPassword=targetElement.elementText("String_Node_Str");
          String targetRecordSyntax=targetElement.elementText("String_Node_Str");
          CharacterEncoding targetCharacterEncoding=CharacterEncoding.get(targetElement.elementText("String_Node_Str"));
          Target target=new Target(targetAddress,targetPort,targetDatabase,targetUser,targetPassword,targetCharacterEncoding,targetRecordSyntax);
          Harvester harvestMethod=null;
          String harvestMethodString=currentDataSourceElement.elementText("String_Node_Str");
          if (harvestMethodString.equals(TimestampHarvester.class.getSimpleName())) {
            String timestampString=currentDataSourceElement.elementText("String_Node_Str");
            try {
              Date earliestTimestamp=DateUtil.string2Date(timestampString,"String_Node_Str");
              harvestMethod=new TimestampHarvester(target,earliestTimestamp);
            }
 catch (            ParseException e) {
              log.error("String_Node_Str" + timestampString,e);
              break;
            }
          }
 else           if (harvestMethodString.equals(IdListHarvester.class.getSimpleName())) {
            String filePath=currentDataSourceElement.elementText("String_Node_Str");
            File idListFile=new File(filePath);
            harvestMethod=new IdListHarvester(target,idListFile);
          }
 else           if (harvestMethodString.equals(IdSequenceHarvester.class.getSimpleName())) {
            String maximumIdString=currentDataSourceElement.elementText("String_Node_Str");
            Long maximumId=(maximumIdString != null && !maximumIdString.isEmpty() ? Long.valueOf(maximumIdString) : null);
            harvestMethod=new IdSequenceHarvester(target,maximumId);
          }
          dataSource=new DataSourceZ3950(provider,id,description,schema,namespace,harvestMethod,recordIdPolicy,metadataTransformations);
        }
 else {
          throw new RuntimeException("String_Node_Str" + dataSourceType + "String_Node_Str");
        }
        parseOldTasks(dataSource);
        boolean removeSynFile=false;
        if (dataSource != null) {
          if (status != null && !file2Read.getParentFile().getName().equals("String_Node_Str")) {
            if (status.equals(DataSource.StatusDS.OK.toString())) {
              dataSource.setStatus(DataSource.StatusDS.OK);
            }
 else             if (status.equals(DataSource.StatusDS.ERROR.toString())) {
              dataSource.setStatus(DataSource.StatusDS.ERROR);
            }
 else             if (status.equals(DataSource.StatusDS.WARNING.toString())) {
              dataSource.setStatus(DataSource.StatusDS.WARNING);
            }
 else             if (status.equals(DataSource.StatusDS.RUNNING.toString())) {
              dataSource.setStatus(DataSource.StatusDS.RUNNING);
            }
 else             if (status.equals(DataSource.StatusDS.CANCELED.toString())) {
              dataSource.setStatus(DataSource.StatusDS.CANCELED);
            }
 else             if (status.equals(DataSource.StatusDS.PRE_PROCESS_ERROR.toString())) {
              dataSource.setStatus(DataSource.StatusDS.PRE_PROCESS_ERROR);
            }
 else             if (status.equals(DataSource.StatusDS.POST_PROCESS_ERROR.toString())) {
              dataSource.setStatus(DataSource.StatusDS.POST_PROCESS_ERROR);
            }
          }
          if (lastIngest == null && !file2Read.getParentFile().getName().equals("String_Node_Str")) {
            lastIngest=dataSource.getSynchronizationDate(new File(new File(repositoryPath,id),"String_Node_Str"));
            removeSynFile=true;
          }
 else           if (file2Read.getParentFile().getName().equals("String_Node_Str")) {
            lastIngest="String_Node_Str";
          }
          if (lastIngest != null && !lastIngest.equals("String_Node_Str")) {
            try {
              dataSource.setLastUpdate(DateUtil.string2Date(lastIngest,TimeUtil.LONG_DATE_FORMAT));
            }
 catch (            ParseException e) {
              dataSource.setLastUpdate(DateUtil.string2Date(lastIngest,TimeUtil.SHORT_DATE_FORMAT));
            }
          }
          if (sample == null) {
            sample=String.valueOf(dataSource.getSampleNumber(new File(new File(repositoryPath,id),"String_Node_Str")));
            removeSynFile=true;
          }
          if (!sample.equals("String_Node_Str") && !file2Read.getParentFile().getName().equals("String_Node_Str")) {
            dataSource.setMaxRecord4Sample(Integer.valueOf(sample));
          }
          if (removeSynFile) {
            File dataSourceSyncDate=new File(new File(repositoryPath,id),"String_Node_Str");
            if (dataSourceSyncDate.exists()) {
              boolean result=dataSourceSyncDate.delete();
              if (result)               log.info("String_Node_Str" + id);
 else               log.error("String_Node_Str" + id);
            }
          }
          String marcFormat=currentDataSourceElement.attributeValue("String_Node_Str");
          if (marcFormat != null && !marcFormat.isEmpty())           dataSource.setMarcFormat(marcFormat);
          List servicesList=currentDataSourceElement.selectNodes("String_Node_Str");
          String executeType=currentDataSourceElement.valueOf("String_Node_Str");
          if (executeType != null && !executeType.isEmpty())           dataSource.setExternalServicesRunType(ExternalServiceStates.ContainerType.valueOf(executeType));
          for (          Object node : servicesList) {
            Node n=(Node)node;
            String serviceId=n.valueOf("String_Node_Str");
            String serviceType=n.valueOf("String_Node_Str");
            String enabled=n.valueOf("String_Node_Str");
            boolean isEnabled=Boolean.valueOf((enabled == null || enabled.isEmpty()) ? "String_Node_Str" : enabled);
            String serviceUri=n.valueOf("String_Node_Str");
            String serviceStatusUri=n.valueOf("String_Node_Str");
            String externalResultsUri=n.valueOf("String_Node_Str");
            String serviceName=n.valueOf("String_Node_Str");
            String externalServiceType=n.valueOf("String_Node_Str");
            if (externalServiceType == null || externalServiceType.isEmpty())             externalServiceType=ExternalServiceType.MONITORED.name();
            ExternalRestService externalRestService;
            if (externalServiceType.equals(ExternalServiceType.NO_MONITOR.name())) {
              externalRestService=new ExternalServiceNoMonitor(serviceId,serviceName,serviceUri,dataSource);
            }
 else {
              externalRestService=new ExternalRestService(serviceId,serviceName,serviceUri,serviceStatusUri,serviceType,ExternalServiceType.valueOf(externalServiceType));
            }
            externalRestService.setEnabled(isEnabled);
            if (externalResultsUri != null && !externalResultsUri.isEmpty())             externalRestService.setExternalResultsUri(externalResultsUri);
            List parametersList=n.selectNodes("String_Node_Str");
            for (            Object nodeP : parametersList) {
              Node parameterNode=(Node)nodeP;
              String parameterName=parameterNode.valueOf("String_Node_Str");
              String parameterValue=parameterNode.valueOf("String_Node_Str");
              String parameterType=parameterNode.valueOf("String_Node_Str");
              boolean parameterRequired=Boolean.parseBoolean(parameterNode.valueOf("String_Node_Str"));
              String exampleStr=parameterNode.valueOf("String_Node_Str");
              String semanticsStr=parameterNode.valueOf("String_Node_Str");
              ServiceParameter serviceParameter=new ServiceParameter(parameterName,parameterType,parameterRequired,exampleStr,semanticsStr);
              serviceParameter.setValue(parameterValue);
              externalRestService.getServiceParameters().add(serviceParameter);
            }
            dataSource.getExternalRestServices().add(externalRestService);
          }
          loadDataSourceTags(currentDataSourceElement,dataSource);
          if (currentDataSourceElement.elementText("String_Node_Str") != null && !currentDataSourceElement.elementText("String_Node_Str").isEmpty())           dataSource.setExportDir(currentDataSourceElement.elementText("String_Node_Str"));
 else {
            File newExportDir=new File(repositoryPath.getAbsolutePath() + File.separator + dataSource.getId()+ File.separator+ "String_Node_Str");
            dataSource.setExportDir(newExportDir.getAbsolutePath());
          }
          boolean exists=metadataSchemaManager.schemaExists(metadataFormat);
          if (!exists) {
            List<MetadataSchemaVersion> metadataSchemaVersions=new ArrayList<MetadataSchemaVersion>();
            metadataSchemaVersions.add(new MetadataSchemaVersion(1.0,schema));
            metadataSchemaManager.saveMetadataSchema(null,metadataFormat,null,namespace,null,null,metadataSchemaVersions,true);
          }
          dataSource.setIsSample(isSample);
          dataSourceContainers.put(dataSource.getId(),new LightDataSourceContainer(dataSource));
        }
      }
      if (getDataProvider(provider.getId()) != null) {
        provider.setId(DataProvider.generateId(provider.getName()));
      }
      dataProvidersLoaded.add(provider);
    }
  }
  if (dataProviders != null && dataProviders.size() > 0) {
    for (    DataProvider dataProviderLoaded : dataProvidersLoaded) {
      try {
        ConfigSingleton.getRepoxContextUtil().getRepoxManager().getAccessPointsManager().initialize(dataProviderLoaded.getDataSourceContainers());
      }
 catch (      SQLException e) {
        e.printStackTrace();
      }
      dataProviders.add(dataProviderLoaded);
    }
  }
 else {
    dataProviders=dataProvidersLoaded;
  }
  saveData();
  return dataProvidersLoaded;
}