Search in sources :

Example 1 with XMLConfigurationProvider

use of org.walkmod.conf.providers.XMLConfigurationProvider in project walkmod-core by walkmod.

the class AbstractXMLConfigurationAction method execute.

@Override
public void execute() throws Exception {
    File file = new File(provider.getConfigFileName());
    if (!file.exists()) {
        provider.createConfig();
        provider.init(new ConfigurationImpl());
    } else {
        provider.init(new ConfigurationImpl());
    }
    if (recursive) {
        Document document = provider.getDocument();
        Element rootElement = document.getDocumentElement();
        NodeList children = rootElement.getChildNodes();
        int childSize = children.getLength();
        boolean containsModules = false;
        for (int i = 0; i < childSize; i++) {
            Node childNode = children.item(i);
            if (childNode instanceof Element) {
                Element child = (Element) childNode;
                final String nodeName = child.getNodeName();
                if ("modules".equals(nodeName)) {
                    containsModules = true;
                    NodeList moduleNodeList = child.getChildNodes();
                    int max = moduleNodeList.getLength();
                    for (int j = 0; j < max; j++) {
                        String cfg = provider.getConfigFileName();
                        if (cfg != null) {
                            File auxFile = new File(cfg).getCanonicalFile().getParentFile();
                            File moduleFileDir = new File(auxFile, moduleNodeList.item(j).getTextContent());
                            XMLConfigurationProvider aux = new XMLConfigurationProvider(moduleFileDir.getAbsolutePath() + File.separator + "walkmod.xml", false);
                            AbstractXMLConfigurationAction ct = clone(aux, recursive);
                            ct.execute();
                        }
                    }
                }
            }
        }
        if (!containsModules) {
            doAction();
        }
    } else {
        doAction();
    }
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) XMLConfigurationProvider(org.walkmod.conf.providers.XMLConfigurationProvider) Document(org.w3c.dom.Document) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl)

Aggregations

File (java.io.File)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 ConfigurationImpl (org.walkmod.conf.entities.impl.ConfigurationImpl)1 XMLConfigurationProvider (org.walkmod.conf.providers.XMLConfigurationProvider)1