1 11 12 package org.eclipse.pde.internal.ui.templates; 13 14 import java.net.MalformedURLException ; 15 import java.net.URL ; 16 import java.util.ArrayList ; 17 import java.util.Locale ; 18 import java.util.ResourceBundle ; 19 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.IProgressMonitor; 22 import org.eclipse.core.runtime.Platform; 23 import org.eclipse.pde.ui.templates.OptionTemplateSection; 24 import org.osgi.framework.Bundle; 25 26 public abstract class PDETemplateSection extends OptionTemplateSection { 27 28 public static final String KEY_PRODUCT_BRANDING = "productBranding"; public static final String KEY_PRODUCT_NAME = "productName"; 31 public static final String VALUE_PRODUCT_ID = "product"; public static final String VALUE_PRODUCT_NAME = "RCP Product"; public static final String VALUE_PERSPECTIVE_NAME = "RCP Perspective"; public static final String VALUE_APPLICATION_ID = "application"; 36 protected ResourceBundle getPluginResourceBundle() { 37 Bundle bundle = Platform.getBundle(Activator.getPluginId()); 38 return Platform.getResourceBundle(bundle); 39 } 40 41 protected URL getInstallURL() { 42 return Activator.getDefault().getInstallURL(); 43 } 44 45 public URL getTemplateLocation() { 46 try { 47 String [] candidates = getDirectoryCandidates(); 48 for (int i = 0; i < candidates.length; i++) { 49 if (Activator.getDefault().getBundle().getEntry(candidates[i]) != null) { 50 URL candidate = new URL (getInstallURL(), candidates[i]); 51 return candidate; 52 } 53 } 54 } catch (MalformedURLException e) { 55 } 56 return null; 57 } 58 59 private String [] getDirectoryCandidates() { 60 double version = getTargetVersion(); 61 ArrayList result = new ArrayList (); 62 if (version >= 3.3) 63 result.add("templates_3.3" + "/" + getSectionId() + "/"); if (version >= 3.2) 65 result.add("templates_3.2" + "/" + getSectionId() + "/"); if (version >= 3.1) 67 result.add("templates_3.1" + "/" + getSectionId() + "/"); if (version >= 3.0) 69 result.add("templates_3.0" + "/" + getSectionId() + "/"); return (String [])result.toArray(new String [result.size()]); 71 } 72 73 76 public String [] getNewFiles() { 77 return new String [0]; 78 } 79 80 protected String getFormattedPackageName(String id){ 81 StringBuffer buffer = new StringBuffer (); 82 for (int i = 0; i < id.length(); i++) { 83 char ch = id.charAt(i); 84 if (buffer.length() == 0) { 85 if (Character.isJavaIdentifierStart(ch)) 86 buffer.append(Character.toLowerCase(ch)); 87 } else { 88 if (Character.isJavaIdentifierPart(ch) || ch == '.') 89 buffer.append(ch); 90 } 91 } 92 return buffer.toString().toLowerCase(Locale.ENGLISH); 93 } 94 95 protected void generateFiles(IProgressMonitor monitor) throws CoreException { 96 super.generateFiles(monitor); 97 if (copyBrandingDirectory()) { 99 super.generateFiles(monitor, Activator.getDefault().getBundle().getEntry("branding/")); } 101 } 102 103 protected boolean copyBrandingDirectory() { 104 return getBooleanOption(KEY_PRODUCT_BRANDING); 105 } 106 107 protected void createBrandingOptions() { 108 addOption(KEY_PRODUCT_BRANDING, PDETemplateMessages.HelloRCPTemplate_productBranding, false, 0); 109 } 110 111 112 } 113 | Popular Tags |