Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2008-04-23 14:57:35 -0400
committerpelder2008-04-23 14:57:35 -0400
commit30276594947d97bdf923ee7283c6099d30a5c751 (patch)
treed689d4d998f6d275d774f84e7837b71d0a0f15e3
parent59bbd1ea030b8cb8641403d0f83e189168284ef8 (diff)
downloadorg.eclipse.jet-30276594947d97bdf923ee7283c6099d30a5c751.tar.gz
org.eclipse.jet-30276594947d97bdf923ee7283c6099d30a5c751.tar.xz
org.eclipse.jet-30276594947d97bdf923ee7283c6099d30a5c751.zip
[195847] Load referenced DTDs in XML documents using the WST XML Catalog
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/EMFXMLModelLoader.java22
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/EntityResolverFactory.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/MyGenericXMLResourceFactoryImpl.java86
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/messages.properties2
4 files changed, 107 insertions, 5 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/EMFXMLModelLoader.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/EMFXMLModelLoader.java
index a48d3d7..82d9ce1 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/EMFXMLModelLoader.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/EMFXMLModelLoader.java
@@ -32,7 +32,6 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
import org.eclipse.emf.ecore.util.ExtendedMetaData;
import org.eclipse.emf.ecore.xmi.XMLResource;
-import org.eclipse.emf.ecore.xmi.impl.GenericXMLResourceFactoryImpl;
import org.eclipse.jet.runtime.model.IModelLoader;
/**
@@ -107,7 +106,6 @@ public class EMFXMLModelLoader implements IModelLoader
{
Map options = new HashMap();
options.put(XMLResource.OPTION_EXTENDED_META_DATA, new MyExtendedMetaData(resourceSet.getPackageRegistry()));
-
return options;
}
@@ -117,9 +115,27 @@ public class EMFXMLModelLoader implements IModelLoader
private ResourceSet getResourceSet()
{
ResourceSet resourceSet = new ResourceSetImpl();
+ // The following code could replace MyGenericXMLResourceFactoryImpl once the following conditions are met:
+ // 1) JET depends on EMF 2.4 or later
+ // 2) EMF implements code in XMLHandler.resolveEntity(String,String) to set publicId and baseLocation
+// resourceSet.setURIConverter(new ExtensibleURIConverterImpl(){
+// public InputStream createInputStream(URI uri, Map options) throws IOException
+// {
+// if(options != null && options.containsKey("publicId") && options.containsKey("baseLocation")) {
+// final URIResolverProxy resolver = EntityResolverFactory.getURIResolver();
+// if(resolver != null) {
+// final String publicId = (String)options.get("publicId");
+// final String baseLocation = (String)options.get("baseLocation");
+// final String systemId = resolver.resolve(baseLocation, publicId, uri.toString());
+// return super.createInputStream(URI.createURI(systemId));
+// }
+// }
+// return super.createInputStream(uri, options);
+// }
+// });
// register the generic XML resource factory...
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(XML_TYPE,
- new GenericXMLResourceFactoryImpl());
+ new MyGenericXMLResourceFactoryImpl());
return resourceSet;
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/EntityResolverFactory.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/EntityResolverFactory.java
index 5f20867..ee11d20 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/EntityResolverFactory.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/EntityResolverFactory.java
@@ -137,7 +137,7 @@ public final class EntityResolverFactory {
}
- public static class DefaultEntityResolver implements EntityResolver {
+ private static class DefaultEntityResolver implements EntityResolver {
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/MyGenericXMLResourceFactoryImpl.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/MyGenericXMLResourceFactoryImpl.java
new file mode 100644
index 0000000..40558c3
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/MyGenericXMLResourceFactoryImpl.java
@@ -0,0 +1,86 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: MyGenericXMLResourceFactoryImpl.java,v 1.1 2008/04/23 18:57:35 pelder Exp $
+ */
+package org.eclipse.jet.internal.runtime.model;
+
+import java.io.IOException;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xmi.XMLLoad;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.emf.ecore.xmi.impl.GenericXMLResourceFactoryImpl;
+import org.eclipse.emf.ecore.xmi.impl.SAXXMLHandler;
+import org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Override of {@link GenericXMLResourceFactoryImpl} that installs a JET customized
+ * {@link EntityResolver}.
+ */
+public class MyGenericXMLResourceFactoryImpl extends GenericXMLResourceFactoryImpl
+{
+
+ /* (non-Javadoc)
+ * @see org.eclipse.emf.ecore.xmi.impl.GenericXMLResourceFactoryImpl#createResource(org.eclipse.emf.common.util.URI)
+ */
+ public Resource createResource(URI uri)
+ {
+ // get our entity resolver...
+ final EntityResolver entityResolver = EntityResolverFactory.getEntityResolver(uri.toString());
+
+ // Create a customized XMLResourceImpl that uses it.
+ final XMLResource actualResource = new XMLResourceImpl(uri) {
+ protected XMLLoad createXMLLoad()
+ {
+ return new XMLLoadImpl(createXMLHelper()) {
+
+ protected DefaultHandler makeDefaultHandler()
+ {
+ return new SAXXMLHandler(resource,helper,options) {
+ public InputSource resolveEntity(String publicId, String systemId) throws SAXException
+ {
+
+ try
+ {
+ return entityResolver.resolveEntity(publicId, systemId);
+ }
+ catch (IOException e)
+ {
+ throw new SAXException(e);
+ }
+ }
+ };
+ }
+
+ };
+ }
+ };
+
+ // Copy properties of the XMLResource as created by the super class
+ final XMLResource protoResource = (XMLResource)super.createResource(uri);
+ actualResource.setEncoding(protoResource.getEncoding());
+ actualResource.getDefaultLoadOptions().putAll(protoResource.getDefaultLoadOptions());
+ actualResource.getDefaultSaveOptions().putAll(protoResource.getDefaultSaveOptions());
+
+ return actualResource;
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/messages.properties b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/messages.properties
index b8307b8..0dce6cd 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/messages.properties
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/messages.properties
@@ -1,2 +1,2 @@
EntityResolverFactory_BundleNotResolved=Bundle {0} not resolved
-EntityResolverFactory_FileNotFound=Reference to DOCTYPE with public ID ''{0}'' failed. Unable to open {1}
+EntityResolverFactory_FileNotFound=Reference to public ID ''{0}'' could not be resolved. Unable to open ''{1}''

Back to the top