コード例 #1
0
 private SchemaAtom add(final String targetNamespaceIn, final URL url, final XsltX xsltX)
     throws IOException {
   SchemaAtom schemaAtom = null;
   logger.finest(url.toExternalForm());
   final String catalogURL = URLCodec.toExternalForm(urlCatalog);
   final String initialURL = URLCodec.toExternalForm(url);
   final String uri = ((catalogURL == null) ? initialURL : initialURL.replace(catalogURL, ""));
   final String protocol = url.getProtocol();
   final boolean isLocal =
       (("file".equals(protocol)) || ("jar".equals(protocol))); // i18n internal
   final boolean isLoaded = schemaAtoms.containsKey(uri);
   if (isLocal && (!isLoaded)) {
     // get schema content
     byte[] bytesXsd = StreamU.read(url);
     // optional transform
     if (xsltX != null) {
       bytesXsd = xsltX.transform(bytesXsd);
     }
     logger.finest(UTF8Codec.toString(bytesXsd));
     // default XSLT for XSD
     final URL urlAugmentXSLT = new URL(initialURL.replace(".xsd", ".xslt"));
     final byte[] xslt = StreamU.readSafe(urlAugmentXSLT);
     if (xslt != null) {
       final XsltX xsltAugment = new XsltX(xslt);
       bytesXsd = xsltAugment.transform(bytesXsd);
     }
     // load into DOM
     final Document document = DocumentU.toDocument(bytesXsd);
     final Element element = document.getDocumentElement();
     final String targetNamespace =
         ElementU.getAttribute(element, XsdU.TARGET_NAMESPACE, XsdU.NS_URI_NULL);
     if ((targetNamespaceIn != null) && (!targetNamespaceIn.equals(targetNamespace))) {
       logger.warning(String.format("%s != %s", targetNamespaceIn, targetNamespace));
     }
     // register content
     final XsdAtom xsdAtom = atomFactory.create(element, null);
     final QName name = QNameU.getQName(targetNamespace, element.getLocalName(), null);
     schemaAtom = new SchemaAtom(url, name, xsdAtom);
     schemaAtoms.put(uri, schemaAtom);
     // schemaAtoms.put(targetNamespace, schemaAtom);  // why this? (duplicate)
     // import dependencies
     doImport(url, xsdAtom, xsltX);
     doInclude(url, xsdAtom, xsltX);
   }
   return schemaAtom;
 }
コード例 #2
0
 private void doInclude(final URL url, final XsdAtom xsdAtom, final XsltX xsltX)
     throws IOException {
   final Collection<Element> children = ElementU.getChildren(xsdAtom.getElement(), XsdU.INCLUDE);
   for (final Element child : children) {
     final String schemaLocation = ElementU.getAttribute(child, XsdU.SCHEMA_LOCATION);
     final URL urlInclude = URLCodec.resolve(url, schemaLocation);
     add(null, urlInclude, xsltX);
   }
 }
コード例 #3
0
 private void doImport(final URL url, final XsdAtom xsdAtom, final XsltX xsltX)
     throws IOException {
   final Collection<Element> children = ElementU.getChildren(xsdAtom.getElement(), XsdU.IMPORT);
   for (final Element child : children) {
     final String namespace = ElementU.getAttribute(child, XsdU.NAMESPACE);
     final String schemaLocation = ElementU.getAttribute(child, XsdU.SCHEMA_LOCATION);
     final URL urlImport = URLCodec.resolve(url, schemaLocation);
     add(namespace, urlImport, xsltX);
   }
 }