Search in sources :

Example 6 with ConfigurationException

use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.

the class PluginsConfigurationProvider method lookUpDocument.

private Document lookUpDocument() {
    Document doc = null;
    URL url = null;
    if (configuration == null) {
        throw new ConfigurationException("Missing default values configuration");
    }
    File f = new File(fileName);
    if (f.exists()) {
        try {
            url = f.toURI().toURL();
        } catch (MalformedURLException e) {
            throw new ConfigurationException("Unable to load " + fileName, e);
        }
    }
    if (url == null) {
        url = configuration.getClassLoader().getResource(fileName);
    }
    InputStream is = null;
    if (url == null) {
        if (errorIfMissing) {
            throw new ConfigurationException("Could not open files of the name " + fileName);
        } else {
            LOG.info("Unable to locate default values configuration of the name " + f.getName() + ", skipping");
            return doc;
        }
    }
    try {
        is = url.openStream();
        InputSource in = new InputSource(is);
        in.setSystemId(url.toString());
        doc = DomHelper.parse(in, dtdMappings);
    } catch (Exception e) {
        throw new ConfigurationException("Unable to load " + fileName, e);
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            LOG.error("Unable to close input stream", e);
        }
    }
    if (doc != null) {
        LOG.debug("Default Walkmod plugins configuration parsed");
    }
    return doc;
}
Also used : MalformedURLException(java.net.MalformedURLException) InputSource(org.xml.sax.InputSource) ConfigurationException(org.walkmod.conf.ConfigurationException) InputStream(java.io.InputStream) IOException(java.io.IOException) Document(org.w3c.dom.Document) File(java.io.File) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ConfigurationException(org.walkmod.conf.ConfigurationException)

Example 7 with ConfigurationException

use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.

the class XMLConfigurationProvider method loadPlugins.

private void loadPlugins() {
    Element rootElement = document.getDocumentElement();
    NodeList children = rootElement.getChildNodes();
    int childSize = children.getLength();
    for (int i = 0; i < childSize; i++) {
        Node childNode = children.item(i);
        if ("plugins".equals(childNode.getNodeName())) {
            Element child = (Element) childNode;
            Collection<PluginConfig> plugins = new LinkedList<PluginConfig>();
            configuration.setPlugins(plugins);
            NodeList pluginNodes = child.getChildNodes();
            int pluginSize = pluginNodes.getLength();
            for (int j = 0; j < pluginSize; j++) {
                Node pluginNode = pluginNodes.item(j);
                if ("plugin".equals(pluginNode.getNodeName())) {
                    Element pluginElement = (Element) pluginNode;
                    PluginConfig pc = new PluginConfigImpl();
                    String groupId = pluginElement.getAttribute("groupId");
                    String artifactId = pluginElement.getAttribute("artifactId");
                    String version = pluginElement.getAttribute("version");
                    if (groupId == null) {
                        throw new ConfigurationException("Invalid plugin definition. A groupId is necessary.");
                    }
                    if (artifactId == null) {
                        throw new ConfigurationException("Invalid plugin definition. A artifactId is necessary.");
                    }
                    if (version == null) {
                        throw new ConfigurationException("Invalid plugin definition. A version is necessary.");
                    }
                    pc.setGroupId(groupId);
                    pc.setArtifactId(artifactId);
                    pc.setVersion(version);
                    plugins.add(pc);
                }
            }
        }
    }
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) ConfigurationException(org.walkmod.conf.ConfigurationException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) PluginConfigImpl(org.walkmod.conf.entities.impl.PluginConfigImpl) LinkedList(java.util.LinkedList)

Example 8 with ConfigurationException

use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.

the class XMLConfigurationProvider method loadDocument.

/**
 * Load the XML configuration on memory as a DOM structure with SAX.
 * Additional information about elements location is added. Non valid DTDs
 * or XML structures are detected.
 *
 * @param file
 *            XML configuration
 * @return XML tree
 */
private Document loadDocument(String file) {
    Document doc = null;
    URL url = null;
    File f = new File(file);
    if (f.exists()) {
        try {
            url = f.toURI().toURL();
        } catch (MalformedURLException e) {
            throw new ConfigurationException("Unable to load " + file, e);
        }
    }
    if (url == null) {
        url = ClassLoader.getSystemResource(file);
    }
    InputStream is = null;
    if (url == null) {
        if (errorIfMissing) {
            throw new ConfigurationException("Could not open files of the name " + file);
        } else {
            LOG.info("Unable to locate configuration files of the name " + file + ", skipping");
            return doc;
        }
    }
    try {
        is = url.openStream();
        InputSource in = new InputSource(is);
        in.setSystemId(url.toString());
        doc = DomHelper.parse(in, dtdMappings);
    } catch (Exception e) {
        throw new ConfigurationException("Unable to load " + file, e);
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            LOG.error("Unable to close input stream", e);
        }
    }
    if (doc != null) {
        LOG.debug("Wallmod configuration parsed");
    }
    return doc;
}
Also used : MalformedURLException(java.net.MalformedURLException) InputSource(org.xml.sax.InputSource) ConfigurationException(org.walkmod.conf.ConfigurationException) InputStream(java.io.InputStream) IOException(java.io.IOException) Document(org.w3c.dom.Document) File(java.io.File) URL(java.net.URL) JSONException(com.alibaba.fastjson.JSONException) TransformerException(javax.xml.transform.TransformerException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ConfigurationException(org.walkmod.conf.ConfigurationException)

Example 9 with ConfigurationException

use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.

the class XMLConfigurationProvider method getTransformationItems.

public List<TransformationConfig> getTransformationItems(Element element, boolean exceptionsEnabled) {
    List<TransformationConfig> transformationConfigs = new LinkedList<TransformationConfig>();
    NodeList transfNodes = element.getChildNodes();
    for (int j = 0; j < transfNodes.getLength(); j++) {
        element = (Element) transfNodes.item(j);
        if ("transformation".equals(element.getNodeName())) {
            TransformationConfig tc = new TransformationConfigImpl();
            String name = element.getAttribute("name");
            String visitor = element.getAttribute("type");
            String isMergeable = element.getAttribute("isMergeable");
            String mergePolicy = element.getAttribute("merge-policy");
            if ("".equals(visitor)) {
                throw new ConfigurationException("Invalid transformation definition: A " + "type attribute must be specified");
            }
            if ("".equals(name)) {
                name = null;
            }
            tc.setName(name);
            tc.setType(visitor);
            tc.setParameters(getParams(element));
            if (isMergeable != null && !("".equals(isMergeable))) {
                tc.isMergeable(Boolean.parseBoolean(isMergeable));
            }
            if (!"".equals(mergePolicy.trim())) {
                tc.isMergeable(true);
                tc.setMergePolicy(mergePolicy);
            }
            transformationConfigs.add(tc);
        }
    }
    return transformationConfigs;
}
Also used : TransformationConfigImpl(org.walkmod.conf.entities.impl.TransformationConfigImpl) ConfigurationException(org.walkmod.conf.ConfigurationException) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) NodeList(org.w3c.dom.NodeList) LinkedList(java.util.LinkedList)

Example 10 with ConfigurationException

use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.

the class DynamicModulesConfigurationProvider method load.

@Override
public void load() throws ConfigurationException {
    DummyConfigurationProvider dummy = new DummyConfigurationProvider();
    dummy.init(configuration);
    try {
        configuration.runInitializers(dummy);
    } catch (Exception e) {
        throw new ConfigurationException("Error running initializers", e);
    }
    List<String> modules = configuration.getModules();
    if (modules != null && !modules.isEmpty()) {
        configuration.getChainConfigs().clear();
    }
}
Also used : DummyConfigurationProvider(org.walkmod.conf.DummyConfigurationProvider) ConfigurationException(org.walkmod.conf.ConfigurationException) ConfigurationException(org.walkmod.conf.ConfigurationException)

Aggregations

ConfigurationException (org.walkmod.conf.ConfigurationException)15 File (java.io.File)7 LinkedList (java.util.LinkedList)7 NodeList (org.w3c.dom.NodeList)6 IOException (java.io.IOException)5 URL (java.net.URL)5 Element (org.w3c.dom.Element)5 Node (org.w3c.dom.Node)5 PluginConfig (org.walkmod.conf.entities.PluginConfig)4 InputStream (java.io.InputStream)3 MalformedURLException (java.net.MalformedURLException)3 Document (org.w3c.dom.Document)3 WalkerConfig (org.walkmod.conf.entities.WalkerConfig)3 PluginConfigImpl (org.walkmod.conf.entities.impl.PluginConfigImpl)3 InputSource (org.xml.sax.InputSource)3 ChainConfig (org.walkmod.conf.entities.ChainConfig)2 ChainConfigImpl (org.walkmod.conf.entities.impl.ChainConfigImpl)2 ParserConfigImpl (org.walkmod.conf.entities.impl.ParserConfigImpl)2 WalkerConfigImpl (org.walkmod.conf.entities.impl.WalkerConfigImpl)2 JSONException (com.alibaba.fastjson.JSONException)1