Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.jet/plugin.properties1
-rw-r--r--plugins/org.eclipse.jet/plugin.xml6
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/PluginProjectMonitor.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TransformDataFactory.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/EntityResolverFactory.java194
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/Messages.java39
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/XMLDOMLoader.java119
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/messages.properties2
8 files changed, 363 insertions, 2 deletions
diff --git a/plugins/org.eclipse.jet/plugin.properties b/plugins/org.eclipse.jet/plugin.properties
index 3b95455..7ed43ca 100644
--- a/plugins/org.eclipse.jet/plugin.properties
+++ b/plugins/org.eclipse.jet/plugin.properties
@@ -53,3 +53,4 @@ extpoint.modelInspectors.name = Model Inspectors
extensions.modelLoaders.emf.name = EMF Model Loader
extensions.modelLoaders.emfxml.name = EMF-based loader for XML documents
extensions.modelLoaders.resource.name = Eclipse Resource Loader
+extensions.modelLoaders.xml.name = XML Document Loader (XML DOM)
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index 2e2523f..7bc3c23 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -1051,6 +1051,12 @@ if 'length' is specified, convert only the specified number of characters, other
dynamicTypes="false"
id="resource"
name="%extensions.modelLoaders.resource.name"/>
+ <loader
+ class="org.eclipse.jet.internal.runtime.model.XMLDOMLoader"
+ dynamicTypes="false"
+ id="xml"
+ name="%extensions.modelLoaders.xml.name">
+ </loader>
</extension>
<extension
point="org.eclipse.jet.modelInspectors">
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/PluginProjectMonitor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/PluginProjectMonitor.java
index a7c9eb3..2531a9f 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/PluginProjectMonitor.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/PluginProjectMonitor.java
@@ -205,7 +205,7 @@ public class PluginProjectMonitor implements IResourceChangeListener
if(hasPluginManifest(project)) {
if(DEBUG)System.out.println(" has plugin.xml"); //$NON-NLS-1$
URL extensionsURL = new URL(projectURL, "plugin.xml"); //$NON-NLS-1$
- pluginDocumentRoot = JETActivatorWrapper.INSTANCE.getLoaderManager().getLoader(extensionsURL.toExternalForm(), null, "xml").load(extensionsURL); //$NON-NLS-1$
+ pluginDocumentRoot = JETActivatorWrapper.INSTANCE.getLoaderManager().getLoader(extensionsURL.toExternalForm(), "org.eclipse.jet.xml", "xml").load(extensionsURL); //$NON-NLS-1$ //$NON-NLS-2$
}
for (Iterator i = listeners.iterator(); i.hasNext();)
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TransformDataFactory.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TransformDataFactory.java
index 78d00d6..30681c3 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TransformDataFactory.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/TransformDataFactory.java
@@ -137,7 +137,7 @@ public class TransformDataFactory
try
{
URL extensionsURL = new URL(pluginURL, "plugin.xml"); //$NON-NLS-1$
- Object resource = JETActivatorWrapper.INSTANCE.getLoaderManager().getLoader(extensionsURL.toExternalForm(), null, null).load(extensionsURL);
+ Object resource = JETActivatorWrapper.INSTANCE.getLoaderManager().getLoader(extensionsURL.toExternalForm(), "org.eclipse.jet.xml", null).load(extensionsURL); //$NON-NLS-1$
initXPathExpressions();
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
new file mode 100644
index 0000000..5f20867
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/EntityResolverFactory.java
@@ -0,0 +1,194 @@
+/*******************************************************************************
+ * 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
+ * /
+ *******************************************************************************/
+
+package org.eclipse.jet.internal.runtime.model;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jet.internal.InternalJET2Platform;
+import org.eclipse.osgi.util.NLS;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * Factory for constructing EntityResolver instances for XML and EMF modeling
+ * loading
+ * <p>
+ * NOTE: This code depends on internals of the WebTools project. There are no guarantees that future versions
+ * of WebTools project will support his. This dependency is implemented using reflection
+ * so that future breakage of dependencies will permit the code to continue working, albeit
+ * with reduced functionality.
+ * </p>
+ *
+ */
+public final class EntityResolverFactory {
+ private static final class URIResolverPluginClassProxy {
+
+ private static final String WST_URIRESOLVER_PLUGIN_CLASS = "org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin"; //$NON-NLS-1$
+ private static final String WST_URIRESOLVER_PLUGIN_ID = "org.eclipse.wst.common.uriresolver"; //$NON-NLS-1$
+ private final Class pluginClass;
+ private final Method createResolverMethod;
+
+ public URIResolverPluginClassProxy() throws BundleException,
+ ClassNotFoundException, SecurityException,
+ NoSuchMethodException {
+ Bundle bundle = Platform.getBundle(WST_URIRESOLVER_PLUGIN_ID);
+ if (bundle == null) {
+ throw new BundleException(NLS.bind(Messages.EntityResolverFactory_BundleNotResolved, WST_URIRESOLVER_PLUGIN_ID));
+ }
+
+ pluginClass = bundle.loadClass(WST_URIRESOLVER_PLUGIN_CLASS);
+ createResolverMethod = pluginClass.getMethod("createResolver", //$NON-NLS-1$
+ new Class[0]);
+ }
+
+ public URIResolverProxy createResolver() throws SecurityException,
+ NoSuchMethodException, IllegalArgumentException,
+ IllegalAccessException, InvocationTargetException {
+ Object result = createResolverMethod.invoke(null, new Object[0]);
+
+ return new URIResolverProxy(result);
+ }
+ }
+
+ private static final class URIResolverProxy {
+
+ private final Object uriResolver;
+ private final Method resolveMethod;
+ private final Method resolvePhysicalLocationMethod;
+
+ public URIResolverProxy(Object uriResolver) throws SecurityException,
+ NoSuchMethodException {
+ this.uriResolver = uriResolver;
+ Class resolverClass = uriResolver.getClass();
+
+ resolveMethod = resolverClass.getMethod("resolve", new Class[] { //$NON-NLS-1$
+ String.class, String.class, String.class });
+ resolvePhysicalLocationMethod = resolverClass.getMethod(
+ "resolvePhysicalLocation", new Class[] { String.class, //$NON-NLS-1$
+ String.class, String.class });
+ }
+
+ private String invokeResolveMethod(Method method, String baseLocation,
+ String publicId, String systemId) {
+ try {
+ Object result = method.invoke(uriResolver, new Object[] {
+ baseLocation, publicId, systemId });
+ return (String) result;
+ } catch (IllegalArgumentException e) {
+ // ignore;
+ } catch (IllegalAccessException e) {
+ // ignore;
+ } catch (InvocationTargetException e) {
+ // ignore;
+ }
+ return null;
+ }
+
+ public String resolve(String baseLocation, String publicId,
+ String systemId) {
+ return invokeResolveMethod(resolveMethod, baseLocation, publicId,
+ systemId);
+ }
+
+ public String resolvePhysicalLocation(String baseLocation,
+ String publicId, String systemId) {
+ return invokeResolveMethod(resolvePhysicalLocationMethod,
+ baseLocation, publicId, systemId);
+ }
+ }
+
+ private static final class WSTEntityResolver extends DefaultEntityResolver implements EntityResolver {
+
+ private final String baseLocation;
+ private final URIResolverProxy uriResolver;
+
+ public WSTEntityResolver(String baseLocation,
+ URIResolverProxy uriResolver) {
+ this.baseLocation = baseLocation;
+ this.uriResolver = uriResolver;
+ }
+
+ public InputSource resolveEntity(String publicId, String systemId)
+ throws SAXException, IOException {
+
+ final String resolvedURI = uriResolver.resolve(baseLocation,
+ publicId, systemId);
+ return super.resolveEntity(publicId, resolvedURI);
+ }
+
+ }
+
+ public static class DefaultEntityResolver implements EntityResolver {
+ public InputSource resolveEntity(String publicId, String systemId)
+ throws SAXException, IOException {
+
+ final URL systemURL = new URL(systemId);
+ InputStream stream;
+ try {
+ stream = systemURL.openStream();
+ } catch (FileNotFoundException e) {
+ // the default FNF exception is doesn't explain much, use a better one.
+ throw new FileNotFoundException(
+ NLS.bind(
+ Messages.EntityResolverFactory_FileNotFound,
+ publicId, systemId));
+ }
+ return new InputSource(stream);
+ }
+
+ }
+
+ private static boolean initialized = false;
+ private static URIResolverProxy uriResolver;
+
+ public static EntityResolver getEntityResolver(String baseLocation) {
+ initURIResolver();
+
+ return uriResolver != null ? new WSTEntityResolver(baseLocation,
+ uriResolver) : new DefaultEntityResolver();
+ }
+
+ private static void initURIResolver() {
+ if (!initialized) {
+ initialized = true;
+ try {
+ uriResolver = new URIResolverPluginClassProxy()
+ .createResolver();
+ } catch (SecurityException e) {
+ InternalJET2Platform.logError("Error initializing access to WST URIResolver", e); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ InternalJET2Platform.logError("Error initializing access to WST URIResolver", e); //$NON-NLS-1$
+ } catch (NoSuchMethodException e) {
+ InternalJET2Platform.logError("Error initializing access to WST URIResolver", e); //$NON-NLS-1$
+ } catch (IllegalAccessException e) {
+ InternalJET2Platform.logError("Error initializing access to WST URIResolver", e); //$NON-NLS-1$
+ } catch (InvocationTargetException e) {
+ InternalJET2Platform.logError("Error initializing access to WST URIResolver", e); //$NON-NLS-1$
+ } catch (BundleException e) {
+ // ignore, this indicates the WST bundle not present.
+ } catch (ClassNotFoundException e) {
+ InternalJET2Platform.logError("Error initializing access to WST URIResolver", e); //$NON-NLS-1$
+ }
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/Messages.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/Messages.java
new file mode 100644
index 0000000..4661b65
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/Messages.java
@@ -0,0 +1,39 @@
+/**
+ * <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: Messages.java,v 1.1 2008/04/23 01:16:17 pelder Exp $
+ */
+package org.eclipse.jet.internal.runtime.model;
+
+
+import org.eclipse.osgi.util.NLS;
+
+
+public class Messages extends NLS
+{
+ private static final String BUNDLE_NAME = "org.eclipse.jet.internal.runtime.model.messages"; //$NON-NLS-1$
+
+ public static String EntityResolverFactory_BundleNotResolved;
+
+ public static String EntityResolverFactory_FileNotFound;
+ static
+ {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages()
+ {
+ }
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/XMLDOMLoader.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/XMLDOMLoader.java
new file mode 100644
index 0000000..5358fb9
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/XMLDOMLoader.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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
+ * /
+ *******************************************************************************/
+package org.eclipse.jet.internal.runtime.model;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.net.URL;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.jet.runtime.model.IModelLoader;
+import org.w3c.dom.Document;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * Implement a JET Loader that loads XML documents as XML DOM, and resolves any XML Entities using the
+ * Web Tools projects URI Resolver capabilities and UI.
+ *
+ */
+public class XMLDOMLoader implements IModelLoader {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jet.runtime.model.IModelLoader#canLoad(java.lang.String)
+ */
+ public boolean canLoad(String kind) {
+ // will attempt to load anything...
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jet.runtime.model.IModelLoader#load(java.net.URL)
+ */
+ public Object load(URL modelUrl) throws IOException {
+ InputStream inputStream = modelUrl.openStream();
+ InputSource inputSource = new InputSource(inputStream);
+
+ Document document = parse(inputSource, modelUrl.toExternalForm());
+ return document;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jet.runtime.model.IModelLoader#load(java.net.URL,
+ * java.lang.String)
+ */
+ public Object load(URL modelUrl, String kind) throws IOException {
+ // ignore the kind ...
+ return load(modelUrl);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jet.runtime.model.IModelLoader#loadFromString(java.lang.String,
+ * java.lang.String)
+ */
+ public Object loadFromString(String serializedModel, String kind)
+ throws IOException {
+ InputSource inputSource = new InputSource(new StringReader(
+ serializedModel));
+ return parse(inputSource, null);
+ }
+
+ /**
+ * @param inputSource
+ * @param baseLocation TODO
+ * @return
+ * @throws ParserConfigurationException
+ * @throws SAXException
+ * @throws IOException
+ */
+ private Document parse(InputSource inputSource, final String baseLocation) throws IOException {
+ try {
+ DocumentBuilderFactory builderFactory = DocumentBuilderFactory
+ .newInstance();
+ builderFactory.setNamespaceAware(true);
+
+ DocumentBuilder builder = builderFactory.newDocumentBuilder();
+
+ // install an entity resolver to handle resolution of external DOCTYPE, and ENTITY references
+ EntityResolver entityResolver = EntityResolverFactory.getEntityResolver(baseLocation);
+ if(entityResolver != null) {
+ builder.setEntityResolver(entityResolver);
+ }
+
+ Document document = builder.parse(inputSource);
+ return document;
+ } catch (ParserConfigurationException e) {
+ IOException ioex = new IOException();
+ ioex.initCause(e);
+ throw ioex;
+ } catch (SAXException e) {
+ IOException ioex = new IOException();
+ ioex.initCause(e);
+ throw ioex;
+ }
+ }
+
+
+}
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
new file mode 100644
index 0000000..b8307b8
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/messages.properties
@@ -0,0 +1,2 @@
+EntityResolverFactory_BundleNotResolved=Bundle {0} not resolved
+EntityResolverFactory_FileNotFound=Reference to DOCTYPE with public ID ''{0}'' failed. Unable to open {1}

Back to the top