org.milyn.GenericReaderConfigurator Maven / Gradle / Ivy
/*
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 extends XMLReader> 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