Changed to use file url rather than plugin url
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/resolver/ResolverExtension.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/resolver/ResolverExtension.java
index 5ea79d1..9c8ceac 100644
--- a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/resolver/ResolverExtension.java
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/resolver/ResolverExtension.java
@@ -13,12 +13,15 @@
package org.eclipse.wst.xsl.core.resolver;
import java.io.IOException;
+import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverExtension;
import org.eclipse.wst.sse.core.StructuredModelManager;
@@ -35,84 +38,117 @@
/**
* TODO: Javadoc
+ *
* @author Jesper Steen Moeller
- *
+ *
*/
-public class ResolverExtension implements URIResolverExtension {
-
+public class ResolverExtension implements URIResolverExtension
+{
private static final Double DEFAULT_XSLT_VERSION = 1.0;
-
- private static final String SCHEMA_BASE_URI = "platform:/plugin/" + XSLCorePlugin.PLUGIN_ID + "/xslt-schemas"; //$NON-NLS-1$ //$NON-NLS-2$
- private static final String XSLT_1_0_PATH = SCHEMA_BASE_URI + "/xslt-1.0.xsd"; //$NON-NLS-1$
- private static final String XSLT_2_0_PATH = SCHEMA_BASE_URI + "/xslt-2.0.xsd"; //$NON-NLS-1$
-
private static final String XSLT_STYLESHEET = "stylesheet"; //$NON-NLS-1$
private static final String XSLT_TEMPLATE = "template"; //$NON-NLS-1$
private static final String XSLT_VERSION = "version"; //$NON-NLS-1$
-
- /**
- * TODO: Add Javadoc
- */
- public ResolverExtension() {
- }
- public String resolve(IFile file, String baseLocation, String publicId,
- String systemId) {
+ private boolean initialised;
+ private String xslt_1_0_fileURL;
+ private String xslt_2_0_fileURL;
+
+ public String resolve(IFile file, String baseLocation, String publicId, String systemId)
+ {
// Is someone looking for "our" schema?
- if (! XSLCore.XSL_NAMESPACE_URI.equals(publicId)) {
+ if (!XSLCore.XSL_NAMESPACE_URI.equals(publicId))
+ {
// Not this time, return right away
return null;
}
String version = null;
-
- if (file != null)
+
+ if (file != null)
version = peekVersionAttributeFromSSE(file);
if (version == null)
version = peekVersionFromFile(file, baseLocation);
-
+
if (version == null)
return null;
-
+
Double versionNumber = null;
- try {
+ try
+ {
versionNumber = Double.valueOf(version);
- } catch (Throwable t) {
+ }
+ catch (Throwable t)
+ {
// Not interested
}
-
- if (versionNumber == null) {
+
+ if (versionNumber == null)
+ {
versionNumber = DEFAULT_XSLT_VERSION;
}
-
+
// We carelessly ditch the fraction part
int intVersion = versionNumber.intValue();
- if (intVersion == 1) {
- return XSLT_1_0_PATH;
- } else if (intVersion == 2) {
- return XSLT_2_0_PATH;
+ checkInitialised();
+ if (intVersion == 1)
+ {
+ return xslt_1_0_fileURL;
}
- else return null;
+ else if (intVersion == 2)
+ {
+ return xslt_2_0_fileURL;
+ }
+ else
+ return null;
}
- private String peekVersionFromFile(IFile file, String baseLocation) {
+ private void checkInitialised()
+ {
+ if (!initialised)
+ {
+ initialised = true;
+ try
+ {
+ URL pluginURL = FileLocator.find(XSLCorePlugin.getDefault().getBundle(), new Path("/xslt-schemas/xslt-1.0.xsd"), null);
+ xslt_1_0_fileURL = FileLocator.toFileURL(pluginURL).toExternalForm();
+ pluginURL = FileLocator.find(XSLCorePlugin.getDefault().getBundle(), new Path("/xslt-schemas/xslt-2.0.xsd"), null);
+ xslt_2_0_fileURL = FileLocator.toFileURL(pluginURL).toExternalForm();
+ }
+ catch (IOException e)
+ {
+ XSLCorePlugin.log(e);
+ }
+ }
+ }
+
+ private String peekVersionFromFile(IFile file, String baseLocation)
+ {
XSLVersionHandler handler = new XSLVersionHandler();
- try {
+ try
+ {
handler.parseContents(file != null ? createInputSource(file) : createInputSource(baseLocation));
- } catch (SAXException se) {
+ }
+ catch (SAXException se)
+ {
XSLCorePlugin.log(se);
// drop through, since this is almost to be expected
- } catch (IOException ioe) {
+ }
+ catch (IOException ioe)
+ {
XSLCorePlugin.log(new CoreException(XSLCorePlugin.newErrorStatus("Can't parse XSL document", ioe))); //$NON-NLS-1$
// drop through, since this is not really a show-stopper
- } catch (ParserConfigurationException pce) {
+ }
+ catch (ParserConfigurationException pce)
+ {
// some bad thing happened - force this describer to be disabled
String message = Messages.XSLCorePlugin_parserConfiguration;
XSLCorePlugin.log(new Status(IStatus.ERROR, XSLCorePlugin.PLUGIN_ID, 0, message, pce));
throw new RuntimeException(message);
// drop through, since this is not really a show-stopper
- } catch (CoreException ce) {
+ }
+ catch (CoreException ce)
+ {
XSLCorePlugin.log(ce);
// drop through, since this is not really a show-stopper
}
@@ -121,37 +157,48 @@
return versionX;
}
- private String peekVersionAttributeFromSSE(IFile file) {
+ private String peekVersionAttributeFromSSE(IFile file)
+ {
IModelManager manager = StructuredModelManager.getModelManager();
- if (manager != null) {
+ if (manager != null)
+ {
String id = manager.calculateId(file);
IStructuredModel model = manager.getExistingModelForRead(id);
- try {
- if (model instanceof IDOMModel) {
- Document doc = ((IDOMModel)model).getDocument();
- if (doc != null && doc.getDocumentElement() != null) {
+ try
+ {
+ if (model instanceof IDOMModel)
+ {
+ Document doc = ((IDOMModel) model).getDocument();
+ if (doc != null && doc.getDocumentElement() != null)
+ {
Element documentElement = doc.getDocumentElement();
- if (XSLT_STYLESHEET.equals(documentElement.getLocalName()) ||
- XSLT_TEMPLATE.equals(documentElement.getLocalName())) {
+ if (XSLT_STYLESHEET.equals(documentElement.getLocalName()) || XSLT_TEMPLATE.equals(documentElement.getLocalName()))
+ {
return documentElement.getAttribute(XSLT_VERSION);
- } else return ""; //$NON-NLS-1$
+ }
+ else
+ return ""; //$NON-NLS-1$
}
}
- } finally {
+ }
+ finally
+ {
// bug 225304
- if (model!=null)
+ if (model != null)
model.releaseFromRead();
}
}
return null;
}
- private InputSource createInputSource(String systemId) throws CoreException {
+ private InputSource createInputSource(String systemId) throws CoreException
+ {
return new InputSource(systemId);
}
- private InputSource createInputSource(IFile file) throws CoreException {
+ private InputSource createInputSource(IFile file) throws CoreException
+ {
InputSource src = new InputSource(file.getContents());
src.setSystemId(file.getLocationURI().toString());
return src;