Search in sources :

Example 1 with AcsFileFinder

use of alma.acs.makesupport.AcsFileFinder in project ACS by ACS-Community.

the class XmlSeeker method getXmls.

/**
         * Get an Arraylist with the XMLs on the added dirs that conforms with the xsd filename.
         * @param xsd the filename of the xsd to seek inside the XML files
         * @return the XMLs list */
public ArrayList getXmls(String xsd) {
    File[] fileArr;
    ArrayList<File> files = new ArrayList<File>();
    File[] dirArr = new File[dirs.size()];
    dirs.toArray(dirArr);
    AcsFileFinder fileFinder = new AcsFileFinder(dirArr, this, null);
    fileArr = fileFinder.getAllFiles();
    for (int i = 0; i < fileArr.length; i++) {
        DOMParser dp;
        dp = new DOMParser();
        try {
            dp.parse(fileArr[i].getAbsolutePath());
        } catch (Exception e) {
            e.printStackTrace();
        }
        Document doc = dp.getDocument();
        // Hack to support both Errors and Logs 
        // TODO: Please do this thing in a generic way
        Node typeNode = doc.getElementsByTagName("Type").item(0);
        // Type node may not even exist
        if (typeNode != null) {
            NamedNodeMap atributes = typeNode.getAttributes();
            Node schema = atributes.getNamedItem("xsi:schemaLocation");
            if (schema.getNodeValue().contentEquals(xsd))
                files.add(fileArr[i]);
        }
    }
    return (files);
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) DOMParser(org.apache.xerces.parsers.DOMParser) Document(org.w3c.dom.Document) File(java.io.File) AcsFileFinder(alma.acs.makesupport.AcsFileFinder)

Aggregations

AcsFileFinder (alma.acs.makesupport.AcsFileFinder)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 DOMParser (org.apache.xerces.parsers.DOMParser)1 Document (org.w3c.dom.Document)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1