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

org.milyn.GenericReaderConfigurator Maven / Gradle / Ivy

The newest version!
/*
	Milyn - Copyright (C) 2006 - 2010

	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 List toConfig() { SmooksResourceConfiguration smooksConfig = new SmooksResourceConfiguration(); smooksConfig.setSelector(AbstractParser.ORG_XML_SAX_DRIVER); 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); } List configList = new ArrayList(); configList.add(smooksConfig); return configList; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy