package net.sourceforge.schematronep;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
import javax.xml.transform.stream.StreamSource;


import org.eclipse.core.resources.IFile;

public class CustomURIResolver implements URIResolver
{
	URIResolver parent = null;
	IFile base = null;
	public CustomURIResolver(URIResolver aParent, IFile aBase)
	{
		this.parent = aParent;
		this.base = aBase;
	}
	
	public void setBase(IFile aBase)
	{
		this.base = aBase;
	}
	
	public Source resolve(String path, String arg1) throws TransformerException
	{
		File f = resolve(path);
		
		if (f != null)
		{
			try
			{
				return new StreamSource(new FileInputStream(f));
			}
			catch (FileNotFoundException fnfe)
			{
				fnfe.printStackTrace();
			}
		}
		
		return parent.resolve(path, arg1);
	}
	
	public File resolve(String path)
	{
		if (path.startsWith("/") == false && path.indexOf(":") == -1)
		{
			Log.debug("Relative folder is: " + base.getParent().getLocation());
			String folder = base.getParent().getLocation().toString();
			
			File file = new File(folder, path);
			
			if (file.exists())
			{
				return file;
			}
		}
		return null;
	}

}

@@ -297,16 +297,79 @@
 ource;%0A%0A
+import net.sourceforge.schematronep.builder.SchematronBuilder;%0A
 %0Aimport 
@@ -764,16 +764,279 @@
 tion%0A%09%7B%0A
+%09%09if (SchematronBuilder.getSkeletonFileName().equals(path))%0A%09%09%7B%0A%09%09%09ClassLoader loader = SchematronPlugin.getDefault().getDescriptor().getPluginClassLoader();%0A%0A%09%09%09return new StreamSource(loader.getResourceAsStream(%22net/sourceforge/schematronep/xsl/%22 + path));%0A%09%09%7D%0A
 %09%09File f

Add support for internal resources so schematron-message.xsl can import iso_schematron_skeleton.xsl