1 11 12 package org.eclipse.pde.internal.ui.wizards.templates; 13 14 import java.net.MalformedURLException ; 15 import java.net.URL ; 16 import java.util.Locale ; 17 import java.util.ResourceBundle ; 18 19 import org.eclipse.core.runtime.Platform; 20 import org.eclipse.pde.core.plugin.IPluginBase; 21 import org.eclipse.pde.internal.core.TargetPlatform; 22 import org.eclipse.pde.internal.core.plugin.PluginBase; 23 import org.eclipse.pde.internal.ui.PDEPlugin; 24 import org.eclipse.pde.ui.templates.OptionTemplateSection; 25 import org.osgi.framework.Bundle; 26 27 public abstract class PDETemplateSection extends OptionTemplateSection { 28 29 protected ResourceBundle getPluginResourceBundle() { 30 Bundle bundle = Platform.getBundle(PDEPlugin.getPluginId()); 31 return Platform.getResourceBundle(bundle); 32 } 33 34 protected URL getInstallURL() { 35 return PDEPlugin.getDefault().getInstallURL(); 36 } 37 38 public URL getTemplateLocation() { 39 try { 40 String [] candidates = getDirectoryCandidates(); 41 for (int i = 0; i < candidates.length; i++) { 42 if (PDEPlugin.getDefault().getBundle().getEntry(candidates[i]) != null) { 43 URL candidate = new URL (getInstallURL(), candidates[i]); 44 return candidate; 45 } 46 } 47 } catch (MalformedURLException e) { 48 } 49 return null; 50 } 51 52 private String [] getDirectoryCandidates() { 53 String version = getVersion(model.getPluginBase()); 54 if ("3.0".equals(version)) return new String [] { "templates_3.0" + "/" + getSectionId() + "/" }; if ("3.1".equals(version) || "3.2".equals(version)) return new String [] { 58 "templates_3.2" + "/" + getSectionId() + "/", "templates_3.1" + "/" + getSectionId() + "/", "templates_3.0" + "/" + getSectionId() + "/" }; return new String [] { "templates" + "/" + getSectionId() + "/" }; } 63 64 private String getVersion(IPluginBase plugin) { 65 if (plugin instanceof PluginBase) 67 return ((PluginBase)plugin).getTargetVersion(); 68 return TargetPlatform.getTargetVersionString(); 69 } 70 71 74 public String [] getNewFiles() { 75 return new String [0]; 76 } 77 78 protected String getFormattedPackageName(String id){ 79 StringBuffer buffer = new StringBuffer (); 80 for (int i = 0; i < id.length(); i++) { 81 char ch = id.charAt(i); 82 if (buffer.length() == 0) { 83 if (Character.isJavaIdentifierStart(ch)) 84 buffer.append(Character.toLowerCase(ch)); 85 } else { 86 if (Character.isJavaIdentifierPart(ch) || ch == '.') 87 buffer.append(ch); 88 } 89 } 90 return buffer.toString().toLowerCase(Locale.ENGLISH); 91 } 92 } 93 | Popular Tags |