All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.milyn.GenericReaderConfigurator Maven / Gradle / Ivy

There is a newer version: 1.7.1
Show newest version
/*
	Milyn - Copyright (C) 2006

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License (version 2.1) as published by the Free Software
	Foundation.

	This library 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 Lesser General Public License for more details:
	http://www.gnu.org/licenses/lgpl.txt
*/
package org.milyn;

import org.xml.sax.XMLReader;
import org.milyn.delivery.AbstractParser;
import org.milyn.ReaderConfigurator;
import org.milyn.cdr.SmooksResourceConfiguration;

import java.util.*;

/**
 * Generic reader configurator.
 * 

* Specific reader implementations can define specialized configurators. * * @author [email protected] */ public class GenericReaderConfigurator implements ReaderConfigurator { private Class readerClass; private Properties parameters = new Properties(); private List featuresOn = new ArrayList(); private List featuresOff = new ArrayList(); private String targetProfile; public GenericReaderConfigurator() { } public GenericReaderConfigurator(Class readerClass) { this.readerClass = readerClass; } public Properties getParameters() { return parameters; } public GenericReaderConfigurator setParameters(Properties parameters) { this.parameters = parameters; return this; } public GenericReaderConfigurator setFeature(String feature, boolean on) { if(on) { featuresOn.add(feature); } else { featuresOff.add(feature); } return this; } public GenericReaderConfigurator setTargetProfile(String targetProfile) { this.targetProfile = targetProfile; return this; } public SmooksResourceConfiguration toConfig() { SmooksResourceConfiguration smooksConfig = new SmooksResourceConfiguration(); if(readerClass != null) { smooksConfig.setResource(readerClass.getName()); } if(targetProfile != null) { smooksConfig.setTargetProfile(targetProfile); } // Add the parameters... Set> entries = parameters.entrySet(); for (Map.Entry entry : entries) { smooksConfig.setParameter((String)entry.getKey(), (String)entry.getValue()); } // Add the "on" features... for(String featureOn : featuresOn) { smooksConfig.setParameter(AbstractParser.FEATURE_ON, featureOn); } // Add the "off" features... for(String featureOff : featuresOff) { smooksConfig.setParameter(AbstractParser.FEATURE_OFF, featureOff); } return smooksConfig; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy