01: package org.compass.core.converter.xsem;
02:
03: import org.compass.core.config.CompassConfigurable;
04: import org.compass.core.config.CompassEnvironment;
05: import org.compass.core.config.CompassSettings;
06: import org.compass.core.config.ConfigurationException;
07: import org.compass.core.util.ClassUtils;
08:
09: /**
10: * A set of utilities for {@link XmlContentConverter}.
11: *
12: * @author kimchy
13: */
14: public abstract class XmlContentConverterUtils {
15:
16: /**
17: * Creates a new {@link XmlContentConverter} based on the given settings.
18: */
19: public static XmlContentConverter createXmlContentConverter(
20: CompassSettings settings) throws ConfigurationException {
21: String type = settings
22: .getSetting(CompassEnvironment.Converter.XmlContent.TYPE);
23: if (type == null) {
24: throw new ConfigurationException(
25: "xmlContent type configuration can not be found, please set it in the configuration settings");
26: }
27: XmlContentConverter xmlContentConverter = null;
28: try {
29: xmlContentConverter = (XmlContentConverter) ClassUtils
30: .forName(type, settings.getClassLoader())
31: .newInstance();
32: } catch (Exception e) {
33: throw new ConfigurationException(
34: "Failed to create xmlContent [" + type + "]", e);
35: }
36: if (xmlContentConverter instanceof CompassConfigurable) {
37: ((CompassConfigurable) xmlContentConverter)
38: .configure(settings);
39: }
40: if (xmlContentConverter instanceof SupportsXmlContentWrapper) {
41: String wrapper = settings
42: .getSetting(
43: CompassEnvironment.Converter.XmlContent.WRAPPER,
44: CompassEnvironment.Converter.XmlContent.WRAPPER_PROTOTYPE);
45: if (!((SupportsXmlContentWrapper) xmlContentConverter)
46: .supports(wrapper)) {
47: throw new SupportsXmlContentWrapper.NotSupportedXmlContentWrapperException(
48: xmlContentConverter, wrapper);
49: }
50: }
51: return xmlContentConverter;
52: }
53: }
|