Bug 491556 - [Welcome] Provide theme-specific mechanism to influence path resolution

Add support for resolving theme-specific files.  When resolving a
file path, the Intro first checks for a file under a path with the
theme-id.  For example, resolving 'intro-eclipse.png' ->
'org.eclipse.ui.intro.universal.solstice/intro-eclipse.png'.

Change-Id: I8f558a4c264fb459efe0dbaeed7f92aaa980fb09
diff --git a/org.eclipse.ui.intro.universal/src/org/eclipse/ui/internal/intro/universal/UniversalIntroConfigurer.java b/org.eclipse.ui.intro.universal/src/org/eclipse/ui/internal/intro/universal/UniversalIntroConfigurer.java
index 941eaa2..06bfddc 100644
--- a/org.eclipse.ui.intro.universal/src/org/eclipse/ui/internal/intro/universal/UniversalIntroConfigurer.java
+++ b/org.eclipse.ui.intro.universal/src/org/eclipse/ui/internal/intro/universal/UniversalIntroConfigurer.java
@@ -29,6 +29,7 @@
 import org.eclipse.help.internal.util.SequenceResolver;
 import org.eclipse.jface.action.Action;
 import org.eclipse.ui.internal.intro.impl.model.ExtensionMap;
+import org.eclipse.ui.internal.intro.impl.model.IntroTheme;
 import org.eclipse.ui.internal.intro.universal.contentdetect.ContentDetector;
 import org.eclipse.ui.internal.intro.universal.util.ImageUtil;
 import org.eclipse.ui.internal.intro.universal.util.PreferenceArbiter;
@@ -177,27 +178,56 @@
 	}
 
 	private String resolveVariable(Bundle bundle, String value) {
-		if (value != null) {
-			String path = null;
-			if (value.startsWith("intro:")) { //$NON-NLS-1$
-				bundle = UniversalIntroPlugin.getDefault().getBundle();
-				path = value.substring(6);
-			} else if (value.startsWith("product:")) { //$NON-NLS-1$
-				path = value.substring(8);
-			} else
-				return value;
-			try {
-				URL url = bundle.getEntry(path);
-				if (url != null) {
-					URL localURL = FileLocator.toFileURL(url);
-					return localURL.toString();
-				}
-			} catch (IOException e) {
-				// just use the value as-is
-				return value;
-			}
+		if (value == null) {
+			return null;
 		}
-		return null;
+		if (value.startsWith("intro:")) { //$NON-NLS-1$
+			bundle = UniversalIntroPlugin.getDefault().getBundle();
+			return resolveFile(bundle, value.substring(6));
+		} else if (value.startsWith("product:")) { //$NON-NLS-1$
+			return resolveFile(bundle, value.substring(8));
+		}
+		return value;
+	}
+
+	private String resolveFile(Bundle bundle, String path) {
+		String prefixedPath = getThemePrefixedPath(path);
+		try {
+			URL url = null;
+			if (prefixedPath != null) {
+				url = bundle.getEntry(prefixedPath);
+			}
+			if (url == null) {
+				url = bundle.getEntry(path);
+			}
+			if (url != null) {
+				URL localURL = FileLocator.toFileURL(url);
+				return localURL.toString();
+			}
+		} catch (IOException e) {
+		}
+		// just use the value as-is
+		return path;
+	}
+
+	/**
+	 * Prefix the file component of the given path with the theme's id. For
+	 * example, with theme <code>org.eclipse.ui.intro.universal.solstice</code>:
+	 * <ul>
+	 * <li>foo &rarr; org.eclipse.ui.intro.universal.solstice/foo
+	 * </ul>
+	 * 
+	 * @param path
+	 *            the path
+	 * @return same path with a prefixed theme directory component
+	 */
+	private String getThemePrefixedPath(String path) {
+		String prefix = themeProperties != null ? themeProperties.get(IntroTheme.ATT_ID) : null;
+		prefix = prefix == null ? "" : prefix.trim(); //$NON-NLS-1$
+		if (prefix.length() == 0) {
+			return null;
+		}
+		return prefix + Path.SEPARATOR + path;
 	}
 
 	private String getProductProperty(IProduct product, String variableName) {
diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroTheme.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroTheme.java
index a71080e..b5a1ea8 100644
--- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroTheme.java
+++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroTheme.java
@@ -21,6 +21,7 @@
 
 
 public class IntroTheme extends AbstractIntroIdElement {
+	private static final String ATT_NAME = "name"; //$NON-NLS-1$
 	private static final String ATT_PATH = "path"; //$NON-NLS-1$
 	private String name;
 	private String path;
@@ -29,7 +30,7 @@
 	
 	public IntroTheme(IConfigurationElement element) {
 		super(element);
-		name = element.getAttribute(name);
+		name = element.getAttribute(ATT_NAME);
 		path = element.getAttribute(ATT_PATH);
 		path = BundleUtil.getResolvedResourceLocation(path, getBundle());
 		scalable = "true".equals(element.getAttribute(FontSelection.ATT_SCALABLE)); //$NON-NLS-1$
@@ -76,5 +77,7 @@
 			if (name!=null && value!=null)
 				properties.put(name, value);
 		}
+		// Put the theme id in the properties too
+		properties.put(ATT_ID, getId());
 	}
 }