Commit c8caea35 authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ added template helper

parent 64107db2
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
package org.etsi.mts.tdl.ui.wizard;

import java.io.File;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.osgi.framework.Bundle;

public class TemplateHelper {
	enum Libraries {
		Standard, HTTP 
	}
	public static String getLibrary(String name) {
		String library = "";
		try {
			System.out.println("Get standard library...");
			String absolutePath = Path.of("templates/"+name+".tdltx").toFile().getAbsolutePath();
			System.out.println("  Path: " + absolutePath);
			String source = "templates/"+name+".tdltx";
			URI uri = new File(source).toURI();
			if (Platform.isRunning()) {
				System.out.println("Running as plugin...");
				Bundle bundle = Platform.getBundle("org.etsi.mts.tdl.tx.ui");
				URL url = bundle.getEntry(source);
				uri = url.toURI();
				uri = FileLocator.resolve(url).toURI();
			} else {
				System.out.println("Get from class localtion...");
				String binPath = TemplateContent.class.getClass().getProtectionDomain().getCodeSource()
						.getLocation().getPath();
				String projectPath = new File(binPath).getParent();
				uri = new File(((projectPath + "/") + source)).toURI();
			}
//			System.out.println(uri);
			library = Files.readString(Path.of(uri));
		} catch (Throwable _e) {
			throw Exceptions.sneakyThrow(_e);
		}
		return library;
	}

}