Skip to main content
summaryrefslogtreecommitdiffstats
blob: dbae02ba7d402488cc67f9ebe2a853b610e8fea7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package org.eclipse.xpand3.util;

import java.io.InputStream;

public class Xpand3FileUtil {

	public static final String CHECK_EXTENSION = ".chk";
	public static final String XPAND_EXTENSION = ".xpt";
	public static final String XTEND_EXTENSION = ".ext";

	public static final String[] SUPPORTED_EXTENSIONS = new String[] {
			XTEND_EXTENSION, XPAND_EXTENSION, CHECK_EXTENSION };

	public static InputStream getXpand3FileAsStream(String xpandFileName,
			Object context) {
		if (xpandFileName == null || "".equals(xpandFileName)) {
			return null;
		}
		xpandFileName = xpandFileName.replace(SyntaxConstants.NS_DELIM, "/");
		Loader classLoader = LoaderFactory.getClassLoader(context);
		InputStream resourceAsStream = classLoader
				.getResourceAsStream(xpandFileName);
		int index = 0;
		while (resourceAsStream == null && index < SUPPORTED_EXTENSIONS.length) {
			resourceAsStream = classLoader.getResourceAsStream(xpandFileName
					+ SUPPORTED_EXTENSIONS[index++]);
		}
		return resourceAsStream;
	}
}

Back to the top