Adding an EntityResolver for the apache namespace

This will look for xsd files and other xml entities on the classpath if
they are in the http://geode.incubator.apache.org/schema namespace.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/abe9d47d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/abe9d47d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/abe9d47d

Branch: refs/heads/develop
Commit: abe9d47d502e1f3db0f032ecb06bd6f771330668
Parents: 58ddc22
Author: Dan Smith <[email protected]>
Authored: Tue Oct 6 15:54:55 2015 -0700
Committer: Dan Smith <[email protected]>
Committed: Wed Oct 7 09:26:32 2015 -0700

----------------------------------------------------------------------
 .../cache/xmlcache/DefaultEntityResolver2.java  |  2 +-
 .../cache/xmlcache/GeodeEntityResolver.java     | 49 ++++++++++++++++++++
 .../cache/xmlcache/PivotalEntityResolver.java   |  2 +-
 .../services/org.xml.sax.ext.EntityResolver2    |  1 +
 4 files changed, 52 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/abe9d47d/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/DefaultEntityResolver2.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/DefaultEntityResolver2.java
 
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/DefaultEntityResolver2.java
index 7e7135f..169f214 100644
--- 
a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/DefaultEntityResolver2.java
+++ 
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/DefaultEntityResolver2.java
@@ -50,7 +50,7 @@ abstract public class DefaultEntityResolver2 implements 
EntityResolver2 {
    * @return InputSource if resource found, otherwise null.
    * @since 8.1
    */
-  protected final InputSource getClassPathIntputSource(final String publicId, 
final String systemId, final String path) {
+  protected final InputSource getClassPathInputSource(final String publicId, 
final String systemId, final String path) {
     final InputStream stream = 
ClassPathLoader.getLatest().getResourceAsStream(getClass(), path);
     if (null == stream) {
       return null;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/abe9d47d/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/GeodeEntityResolver.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/GeodeEntityResolver.java
 
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/GeodeEntityResolver.java
new file mode 100644
index 0000000..e331867
--- /dev/null
+++ 
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/GeodeEntityResolver.java
@@ -0,0 +1,49 @@
+/*=========================================================================
+ * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
+ * This product is protected by U.S. and international copyright
+ * and intellectual property laws. Pivotal products are covered by
+ * more patents listed at http://www.pivotal.io/patents.
+ *=========================================================================
+ */
+
+package com.gemstone.gemfire.internal.cache.xmlcache;
+
+import java.io.IOException;
+import java.util.ServiceLoader;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.EntityResolver2;
+
+/**
+ * Resolves entities for XSDs or DTDs with SYSTEM IDs rooted at
+ * http://www.pivotal.io/xml/ns from the classpath at
+ * /META-INF/schemas/schema.pivotal.io/.
+ * 
+ * Loaded by {@link ServiceLoader} on {@link EntityResolver2} class. See file
+ * <code>META-INF/services/org.xml.sax.ext.EntityResolver2</code>
+ * 
+ * @author [email protected]
+ * 
+ * @since 8.1
+ */
+public final class GeodeEntityResolver extends DefaultEntityResolver2 {
+
+  private static final String SYSTEM_ID_ROOT = 
"http://geode.incubator.apache.org/schema";;
+
+  private static final String CLASSPATH_ROOT = 
"/META-INF/schemas/geode.incubator.apache.org/";
+
+  @Override
+  public InputSource resolveEntity(final String name, final String publicId, 
final String baseURI, final String systemId) throws SAXException, IOException {
+    if (null == systemId) {
+      return null;
+    }
+
+    if (systemId.startsWith(SYSTEM_ID_ROOT)) {
+      return getClassPathInputSource(publicId, systemId, CLASSPATH_ROOT + 
systemId.substring(SYSTEM_ID_ROOT.length()));
+    }
+
+    return null;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/abe9d47d/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/PivotalEntityResolver.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/PivotalEntityResolver.java
 
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/PivotalEntityResolver.java
index 27e2764..81ef91b 100644
--- 
a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/PivotalEntityResolver.java
+++ 
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/xmlcache/PivotalEntityResolver.java
@@ -40,7 +40,7 @@ public final class PivotalEntityResolver extends 
DefaultEntityResolver2 {
     }
 
     if (systemId.startsWith(SYSTEM_ID_ROOT)) {
-      return getClassPathIntputSource(publicId, systemId, CLASSPATH_ROOT + 
systemId.substring(SYSTEM_ID_ROOT.length()));
+      return getClassPathInputSource(publicId, systemId, CLASSPATH_ROOT + 
systemId.substring(SYSTEM_ID_ROOT.length()));
     }
 
     return null;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/abe9d47d/gemfire-core/src/main/resources/META-INF/services/org.xml.sax.ext.EntityResolver2
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/main/resources/META-INF/services/org.xml.sax.ext.EntityResolver2
 
b/gemfire-core/src/main/resources/META-INF/services/org.xml.sax.ext.EntityResolver2
index 5901ec1..53face5 100644
--- 
a/gemfire-core/src/main/resources/META-INF/services/org.xml.sax.ext.EntityResolver2
+++ 
b/gemfire-core/src/main/resources/META-INF/services/org.xml.sax.ext.EntityResolver2
@@ -1 +1,2 @@
 com.gemstone.gemfire.internal.cache.xmlcache.PivotalEntityResolver
+com.gemstone.gemfire.internal.cache.xmlcache.GeodeEntityResolver

Reply via email to