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

org.yangcentral.yangkit.parser.CapabilityParser Maven / Gradle / Ivy

There is a newer version: 1.4.5
Show newest version
package org.yangcentral.yangkit.parser;

import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class CapabilityParser {
   private String capabilityFile;

   public CapabilityParser(String capabilityFile) {
      this.capabilityFile = capabilityFile;
   }

   List parse() throws DocumentException {
      List capabilities = new ArrayList<>();
      SAXReader reader = new SAXReader();
      Document capabilitiesDoc = reader.read(new File(this.capabilityFile));
      Element root = capabilitiesDoc.getRootElement();
      Element capabilitiesElement = root.element("capabilities");

      for (Element element: capabilitiesElement.elements()) {
         String text = element.getTextTrim();
         if (text.contains("module=")) {
            ModuleSupportCapability capability = new ModuleSupportCapability(URI.create(text));
            capability.parse(text);
            capabilities.add(capability);
         } else {
            Capability capability = new Capability(URI.create(text));
            capabilities.add(capability);
         }
      }

      return capabilities;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy