예제 #1
0
  private void processImports(final Document document, final WroModel model) {
    final NodeList importsList = document.getElementsByTagName(TAG_IMPORT);
    LOG.debug("number of imports: {}", importsList.getLength());
    for (int i = 0; i < importsList.getLength(); i++) {
      final Element element = (Element) importsList.item(i);
      final String name = element.getTextContent();
      LOG.debug("processing import: {}", name);
      LOG.debug("processImports#uriLocatorFactory: {}", uriLocatorFactory);
      final XmlModelFactory importedModelFactory =
          new XmlModelFactory() {
            @Override
            protected InputStream getModelResourceAsStream() throws IOException {
              LOG.debug("build model from import: {}", name);
              LOG.debug("uriLocatorFactory: {}", uriLocatorFactory);
              return uriLocatorFactory.locate(name);
            };
          };
      // pass the reference of the uriLocatorFactory to the anonymously created factory.
      importedModelFactory.uriLocatorFactory = this.uriLocatorFactory;
      if (processedImports.contains(name)) {
        final String message = "Recursive import detected: " + name;
        LOG.error(message);
        throw new RecursiveGroupDefinitionException(message);
      }

      processedImports.add(name);
      importedModelFactory.processedImports.addAll(this.processedImports);
      model.merge(importedModelFactory.create());
    }
  }