Search in sources :

Example 1 with XMLEntityResolver

use of org.apache.xerces.xni.parser.XMLEntityResolver in project intellij-community by JetBrains.

the class ModelGen method loadModel.

public void loadModel(final File... modelRoots) throws Exception {
    XMLEntityResolver resolver = new XMLEntityResolver() {

        public XMLInputSource resolveEntity(XMLResourceIdentifier xmlResourceIdentifier) throws XNIException, IOException {
            String esid = xmlResourceIdentifier.getExpandedSystemId();
            if (esid == null) {
                final String location = schemaLocationMap.get(xmlResourceIdentifier.getNamespace());
                if (location != null) {
                    esid = location;
                } else {
                    return null;
                }
            }
            // Util.log("resolving "+esid);
            File f = null;
            for (File root : modelRoots) {
                if (root == null)
                    continue;
                if (root.isDirectory()) {
                    final String fileName = esid.substring(esid.lastIndexOf('/') + 1);
                    f = new File(root, fileName);
                } else {
                    f = root;
                }
            }
            if (f == null || !f.exists()) {
                Util.logerr("unable to resolve: " + esid);
                return null;
            }
            esid = f.getPath();
            return new XMLInputSource(null, esid, null);
        }
    };
    ArrayList<File> files = new ArrayList<>();
    for (File root : modelRoots) {
        ContainerUtil.addAll(files, root.listFiles());
    }
    loader.loadModel(model, files, resolver);
    Util.log(model.jtMap.size() + " java types loaded");
}
Also used : XMLResourceIdentifier(org.apache.xerces.xni.XMLResourceIdentifier) XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource) ArrayList(java.util.ArrayList) XMLEntityResolver(org.apache.xerces.xni.parser.XMLEntityResolver) File(java.io.File)

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)1 XMLResourceIdentifier (org.apache.xerces.xni.XMLResourceIdentifier)1 XMLEntityResolver (org.apache.xerces.xni.parser.XMLEntityResolver)1 XMLInputSource (org.apache.xerces.xni.parser.XMLInputSource)1