[bug 258937] Imports should be able to Access Files over the net
https://bugs.eclipse.org/bugs/show_bug.cgi?id=258937
diff --git a/bundles/org.eclipse.wst.xsl.core/.classpath b/bundles/org.eclipse.wst.xsl.core/.classpath
index 39659ed..5e0b5d0 100644
--- a/bundles/org.eclipse.wst.xsl.core/.classpath
+++ b/bundles/org.eclipse.wst.xsl.core/.classpath
@@ -5,6 +5,9 @@
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
<accessrules>
<accessrule kind="accessible" pattern="*org/eclipse/wst/xsl/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/wst/xml/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/wst/validation/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/wst/sse/**"/>
</accessrules>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/XSLCorePlugin.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/XSLCorePlugin.java
index ef42029..9334dab 100644
--- a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/XSLCorePlugin.java
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/XSLCorePlugin.java
@@ -18,6 +18,9 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
+import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog;
+import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
@@ -128,5 +131,5 @@
*/
public static IStatus newErrorStatus(String message, Throwable exception) {
return new Status(IStatus.ERROR, PLUGIN_ID, message, exception);
- }
+ }
}
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/util/XMLCatalog.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/util/XMLCatalog.java
new file mode 100644
index 0000000..8d5f575
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/util/XMLCatalog.java
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Standards for Technology in Automotive Retail 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:
+ * David Carver (STAR) - bug 258937 - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsl.core.internal.util;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
+import org.eclipse.wst.xml.core.internal.catalog.CatalogSet;
+import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog;
+import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog;
+
+/**
+ * This class provides convience methods for reading from the WTP
+ * XML Catalog implementation.
+ *
+ * @since 1.1
+ */
+public class XMLCatalog {
+ private CatalogSet catalogSet = new CatalogSet();
+
+ protected ICatalog systemCatalog;
+
+ protected ICatalog userCatalog;
+
+ protected ICatalog defaultCatalog;
+
+ public XMLCatalog() {
+ initXMLCatalog();
+ }
+
+ private void initXMLCatalog() {
+ defaultCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog();
+ INextCatalog[] nextCatalogs = defaultCatalog.getNextCatalogs();
+ for (int i = 0; i < nextCatalogs.length; i++)
+ {
+ INextCatalog catalog = nextCatalogs[i];
+ ICatalog referencedCatalog = catalog.getReferencedCatalog();
+ if (referencedCatalog != null)
+ {
+ if (XMLCorePlugin.SYSTEM_CATALOG_ID
+ .equals(referencedCatalog.getId()))
+ {
+ systemCatalog = referencedCatalog;
+ } else if (XMLCorePlugin.USER_CATALOG_ID
+ .equals(referencedCatalog.getId()))
+ {
+ userCatalog = referencedCatalog;
+ }
+ }
+ }
+ }
+
+ /**
+ * Checks if the provided uri string exists in the catalog.
+ * @param uri
+ * @return true if it exists, false if not.
+ */
+ public boolean exists(String uri) {
+ try {
+ if (defaultCatalog.resolveURI(uri) != null ||
+ systemCatalog.resolveURI(uri) != null ||
+ userCatalog.resolveURI(uri) != null) {
+ return true;
+ }
+ } catch (IOException ex) {
+
+ }
+ return false;
+ }
+
+
+ public ICatalog getSystemCatalog() {
+ return systemCatalog;
+ }
+
+ public ICatalog getUserCatalog() {
+ return userCatalog;
+ }
+
+ public ICatalog getDefaultCatalog() {
+ return defaultCatalog;
+ }
+
+ protected static String makeAbsolute(String baseLocation, String location)
+ {
+ URL local = null;
+ location = location.replace('\\', '/');
+ try
+ {
+ URL baseURL = new URL(baseLocation);
+ local = new URL(baseURL, location);
+ } catch (MalformedURLException e)
+ {
+ }
+
+ if (local != null)
+ {
+ return local.toString();
+ } else
+ {
+ return location;
+ }
+ }
+
+}
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/XSLValidator.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/XSLValidator.java
index c8d552b..9cb855a 100644
--- a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/XSLValidator.java
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/XSLValidator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Chase Technology Ltd - http://www.chasetechnology.co.uk
+ * Copyright (c) 2007, 2009 Chase Technology Ltd - http://www.chasetechnology.co.uk
* 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
@@ -9,6 +9,7 @@
* Doug Satchwell (Chase Technology Ltd) - initial API and implementation
* David Carver (STAR) - bug 230072 - Project level specific validation
* - bug 226245 - XPath 2.0 validation for XSLT
+ * - bug 258937 - XML Catalog support for includes/imports
*******************************************************************************/
package org.eclipse.wst.xsl.core.internal.validation;
@@ -36,6 +37,7 @@
import org.eclipse.wst.xsl.core.internal.Messages;
import org.eclipse.wst.xsl.core.internal.XSLCorePlugin;
import org.eclipse.wst.xsl.core.internal.util.Debug;
+import org.eclipse.wst.xsl.core.internal.util.XMLCatalog;
import org.eclipse.wst.xsl.core.model.CallTemplate;
import org.eclipse.wst.xsl.core.model.Include;
import org.eclipse.wst.xsl.core.model.Parameter;
@@ -204,10 +206,17 @@
if (includedFile == null || !includedFile.exists())
{ // included file does not exist
XSLAttribute att = include.getAttribute("href"); //$NON-NLS-1$
- if (att != null)
- createMarker(report, att, getPreference(ValidationPreferences.MISSING_INCLUDE), Messages.XSLValidator_4 + include.getHref());
- else
- createMarker(report, include, getPreference(ValidationPreferences.NAME_ATTRIBUTE_EMPTY), Messages.XSLValidator_23 );
+ if (att != null) {
+ XMLCatalog catalog = new XMLCatalog();
+ if (!catalog.exists(att.getValue())) {
+ // Do we want to try and get the file?
+ // If we do then there might be performance issues
+ createMarker(report, att, getPreference(ValidationPreferences.MISSING_INCLUDE), Messages.XSLValidator_4 + include.getHref());
+ }
+ }
+ else {
+ createMarker(report, include, getPreference(ValidationPreferences.NAME_ATTRIBUTE_EMPTY), Messages.XSLValidator_23 );
+ }
}
else if (includedFile.equals(include.getStylesheet().getFile()))
{ // stylesheet including itself!
@@ -220,7 +229,13 @@
IFile includedFile = include.getHrefAsFile();
if (includedFile == null || !includedFile.exists())
{ // included file does not exist
- createMarker(report, include.getAttribute("href"), getPreference(ValidationPreferences.MISSING_INCLUDE), Messages.XSLValidator_8 + include.getHref()); //$NON-NLS-1$
+ XSLAttribute att = include.getAttribute("href"); //$NON-NLS-1$
+ if (att != null) {
+ XMLCatalog catalog = new XMLCatalog();
+ if (!catalog.exists(att.getValue())) {
+ createMarker(report, att, getPreference(ValidationPreferences.MISSING_INCLUDE), Messages.XSLValidator_4 + include.getHref());
+ }
+ }
}
else if (includedFile.equals(include.getStylesheet().getFile()))
{ // stylesheet including itself!
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/eclipse/Validator.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/eclipse/Validator.java
index 3db07ad..64a9281 100644
--- a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/eclipse/Validator.java
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/eclipse/Validator.java
@@ -17,7 +17,6 @@
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.HashMap;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -96,28 +95,8 @@
@Override
public ValidationReport validate(final String uri, InputStream inputstream, NestedValidatorContext context)
{
- ValidationReport valreport = new ValidationReport(){
-
- public String getFileURI()
- {
- return uri;
- }
-
- @SuppressWarnings("unchecked")
- public HashMap getNestedMessages()
- {
- return new HashMap();
- }
-
- public ValidationMessage[] getValidationMessages()
- {
- return new ValidationMessage[0];
- }
-
- public boolean isValid()
- {
- return true;
- }};
+ ValidationReport valreport = new XSLValidationReport(uri);
+
try
{
String encUri = URIEncoder.encode(uri);
diff --git a/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/eclipse/XSLValidationReport.java b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/eclipse/XSLValidationReport.java
new file mode 100644
index 0000000..ea88aaf
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsl.core/src/org/eclipse/wst/xsl/core/internal/validation/eclipse/XSLValidationReport.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2009 Chase Technology Ltd - http://www.chasetechnology.co.uk
+ * 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:
+ * Doug Satchwell (Chase Technology Ltd) - initial API and implementation
+ * David Carver - refactored to it's own class instead of an inline override.
+ ********************************************************************************/
+
+package org.eclipse.wst.xsl.core.internal.validation.eclipse;
+
+import java.util.HashMap;
+
+import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage;
+import org.eclipse.wst.xml.core.internal.validation.core.ValidationReport;
+
+public class XSLValidationReport implements ValidationReport {
+ private String uri;
+
+ public XSLValidationReport(String uri) {
+ this.uri = uri;
+ }
+
+ public String getFileURI()
+ {
+ return uri;
+ }
+
+ @SuppressWarnings("unchecked")
+ public HashMap getNestedMessages()
+ {
+ return new HashMap();
+ }
+
+ public ValidationMessage[] getValidationMessages()
+ {
+ return new ValidationMessage[0];
+ }
+
+ public boolean isValid()
+ {
+ return true;
+ }
+}