1 11 package org.eclipse.pde.internal.core.util; 12 13 import java.util.StringTokenizer ; 14 15 import org.eclipse.osgi.util.NLS; 16 import org.eclipse.pde.core.plugin.IFragment; 17 import org.eclipse.pde.core.plugin.IFragmentModel; 18 import org.eclipse.pde.core.plugin.IPluginBase; 19 import org.eclipse.pde.core.plugin.IPluginExtension; 20 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 21 import org.eclipse.pde.core.plugin.IPluginModelBase; 22 import org.eclipse.pde.internal.core.text.plugin.PluginExtensionPointNode; 23 24 public class IdUtil { 25 public static boolean isValidCompositeID(String name) { 26 if (name.length() <= 0) { 27 return false; 28 } 29 for (int i = 0; i < name.length(); i++) { 30 char c = name.charAt(i); 31 if ((c < 'A' || 'Z' < c) && (c < 'a' || 'z' < c) 32 && (c < '0' || '9' < c) && c != '_') { 33 if (i == 0 || i == name.length() - 1 || c != '.') { 34 return false; 35 } 36 } 37 } 38 return true; 39 } 40 41 public static boolean isValidSimpleID(String name) { 42 if (name.length() <= 0) { 43 return false; 44 } 45 for (int i = 0; i < name.length(); i++) { 46 char c = name.charAt(i); 47 if ((c < 'A' || 'Z' < c) && (c < 'a' || 'z' < c) 48 && (c < '0' || '9' < c) && c != '_') { 49 return false; 50 } 51 } 52 return true; 53 } 54 55 public static String getValidId(String projectName) { 56 return projectName.replaceAll("[^a-zA-Z0-9\\._]", "_"); } 58 59 63 public static String getValidName(String id, String nameFieldQualifier) { 64 StringTokenizer tok = new StringTokenizer (id, "."); while (tok.hasMoreTokens()) { 66 String token = tok.nextToken(); 67 if (!tok.hasMoreTokens()) { 68 String name = Character.toUpperCase(token.charAt(0)) 69 + ((token.length() > 1) ? token.substring(1) : ""); return NLS.bind(nameFieldQualifier, name); 71 } 72 } 73 return ""; } 75 76 public static String getValidProvider(String id) { 77 StringTokenizer tok = new StringTokenizer (id, "."); int count = tok.countTokens(); 79 if (count > 2 && tok.nextToken().equals("com")) return tok.nextToken().toUpperCase(); 81 return ""; } 83 84 public static String getFullId(IPluginExtension extension) { 85 String id = extension.getId(); 86 IPluginBase plugin = extension.getPluginBase(); 87 if ("3.2".equals(plugin.getSchemaVersion())) { if (id.indexOf('.') > 0) 89 return id; 90 } 91 92 if (plugin instanceof IFragment) 93 return ((IFragment) plugin).getPluginId() + '.' + id; 94 return plugin.getId() + '.' + id; 95 } 96 97 102 public static String getFullId(IPluginExtensionPoint point, 103 IPluginModelBase model) { 104 105 if ((point instanceof PluginExtensionPointNode) && 106 (model != null)) { 107 String pointId = point.getId(); 108 if ("3.2".equals(model.getPluginBase().getSchemaVersion()) && pointId.indexOf('.') > 0) return pointId; 110 String id = null; 111 if (model instanceof IFragmentModel) { 112 IFragment fragment = ((IFragmentModel)model).getFragment(); 113 if (fragment != null) 114 id = fragment.getPluginId(); 115 } 116 if (id == null) 117 id = model.getPluginBase().getId(); 118 return id + '.' + pointId; 119 } 120 return point.getFullId(); 121 } 122 123 public static boolean isInterestingExtensionPoint(String point) { 124 return "org.eclipse.pde.core.source".equals(point) || "org.eclipse.core.runtime.products".equals(point) || "org.eclipse.pde.core.javadoc".equals(point) || "org.eclipse.ui.intro".equals(point); } 129 } 130 | Popular Tags |