aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1685094 - /aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/SimpleNamespaceHandlerSet.java
Date Fri, 12 Jun 2015 14:40:59 GMT
Author: sergeyb
Date: Fri Jun 12 14:40:59 2015
New Revision: 1685094

URL: http://svn.apache.org/r1685094
Log:
[ARIES-1334] Updating SimpleNamespaceHandlerSet to do the best effort at resolving relative
schema references such as xsd:include

Modified:
    aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/SimpleNamespaceHandlerSet.java

Modified: aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/SimpleNamespaceHandlerSet.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/SimpleNamespaceHandlerSet.java?rev=1685094&r1=1685093&r2=1685094&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/SimpleNamespaceHandlerSet.java
(original)
+++ aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/SimpleNamespaceHandlerSet.java
Fri Jun 12 14:40:59 2015
@@ -18,21 +18,30 @@
  */
 package org.apache.aries.blueprint.container;
 
-import org.apache.aries.blueprint.NamespaceHandler;
-import org.apache.aries.blueprint.ext.impl.ExtNamespaceHandler;
-import org.apache.aries.blueprint.parser.NamespaceHandlerSet;
-import org.xml.sax.SAXException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import javax.xml.XMLConstants;
 import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URL;
-import java.util.*;
+
+import org.apache.aries.blueprint.NamespaceHandler;
+import org.apache.aries.blueprint.ext.impl.ExtNamespaceHandler;
+import org.apache.aries.blueprint.parser.NamespaceHandlerSet;
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSResourceResolver;
+import org.xml.sax.SAXException;
 
 public class SimpleNamespaceHandlerSet implements NamespaceHandlerSet {
 
@@ -81,6 +90,25 @@ public class SimpleNamespaceHandlerSet i
                     schemaSources.add(new StreamSource(is));
                 }
                 SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+                schemaFactory.setResourceResolver(new LSResourceResolver() {
+                    
+                    public LSInput resolveResource(String type, String namespace, String
publicId,
+                                                   String systemId, String baseURI) {
+                        try {
+                            if (systemId != null && !URI.create(systemId).isAbsolute())
{
+                                URI namespaceURI = URI.create(namespace);
+                                if (namespaces.containsKey(namespaceURI)) {
+                                    URI systemIdUri = namespaces.get(namespaceURI).toURI().resolve(systemId);
+                                    InputStream resourceStream = systemIdUri.toURL().openStream();
+                                    return new LSInputImpl(publicId, systemId, resourceStream);
+                                }
+                            }
+                        } catch (Exception ex) {
+                            // ignore
+                        }
+                        return null;
+                    }
+                });
                 schema = schemaFactory.newSchema(schemaSources.toArray(new Source[schemaSources.size()]));
             } finally {
                 for (InputStream is : streams) {
@@ -103,4 +131,93 @@ public class SimpleNamespaceHandlerSet i
         schema = null;
     }
 
+    private static class LSInputImpl implements LSInput {
+
+        protected String fPublicId;
+
+        protected String fSystemId;
+
+        protected String fBaseSystemId;
+
+        protected InputStream fByteStream;
+
+        protected Reader fCharStream;
+
+        protected String fData;
+
+        protected String fEncoding;
+
+        protected boolean fCertifiedText;
+
+        LSInputImpl(String publicId, String systemId, InputStream byteStream) {
+            fPublicId = publicId;
+            fSystemId = systemId;
+            fByteStream = byteStream;
+        }
+
+        public InputStream getByteStream() {
+            return fByteStream;
+        }
+
+        public void setByteStream(InputStream byteStream) {
+            fByteStream = byteStream;
+        }
+
+        public Reader getCharacterStream() {
+            return fCharStream;
+        }
+
+        public void setCharacterStream(Reader characterStream) {
+            fCharStream = characterStream;
+        }
+
+        public String getStringData() {
+            return fData;
+        }
+
+        public void setStringData(String stringData) {
+            fData = stringData;
+        }
+
+        public String getEncoding() {
+            return fEncoding;
+        }
+
+        public void setEncoding(String encoding) {
+            fEncoding = encoding;
+        }
+
+        public String getPublicId() {
+            return fPublicId;
+        }
+
+        public void setPublicId(String publicId) {
+            fPublicId = publicId;
+        }
+
+        public String getSystemId() {
+            return fSystemId;
+        }
+
+        public void setSystemId(String systemId) {
+            fSystemId = systemId;
+        }
+
+        public String getBaseURI() {
+            return fBaseSystemId;
+        }
+
+        public void setBaseURI(String baseURI) {
+            fBaseSystemId = baseURI;
+        }
+
+        public boolean getCertifiedText() {
+            return fCertifiedText;
+        }
+
+        public void setCertifiedText(boolean certifiedText) {
+            fCertifiedText = certifiedText;
+        }
+
+    }
 }



Mime
View raw message