1 11 package org.eclipse.ui.internal.cheatsheets.registry; 12 13 import org.eclipse.core.runtime.*; 14 import org.eclipse.ui.internal.cheatsheets.*; 15 16 30 public abstract class RegistryReader { 31 protected static final String TAG_DESCRIPTION = "description"; 33 36 RegistryReader() { 37 } 38 39 45 String getDescription(IConfigurationElement config) { 46 IConfigurationElement[] children = config.getChildren(TAG_DESCRIPTION); 47 if (children.length >= 1) { 48 return children[0].getValue(); 49 } 50 return ICheatSheetResource.EMPTY_STRING; 51 } 52 53 57 private void logError(IConfigurationElement element, String text) { 58 IExtension extension = element.getDeclaringExtension(); 59 StringBuffer buf = new StringBuffer (); 60 buf.append("Plugin " + extension.getContributor().getName() + ", extension " + extension.getExtensionPointUniqueIdentifier()); buf.append("\n" + text); 63 IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, buf.toString(), null); 64 CheatSheetPlugin.getPlugin().getLog().log(status); 65 } 66 67 70 void logMissingAttribute(IConfigurationElement element, String attributeName) { 71 logError(element, "Required attribute '" + attributeName + "' not defined"); } 73 74 77 private void logUnknownElement(IConfigurationElement element) { 78 logError(element, "Unknown extension tag found: " + element.getName()); } 80 81 86 private IExtension[] orderExtensions(IExtension[] extensions) { 87 Sorter sorter = new Sorter() { 92 public boolean compare(Object extension1, Object extension2) { 93 String s1 = ((IExtension) extension1).getContributor().getName().toUpperCase(); 94 String s2 = ((IExtension) extension2).getContributor().getName().toUpperCase(); 95 return s2.compareTo(s1) > 0; 97 } 98 }; 99 100 Object [] sorted = sorter.sort(extensions); 101 IExtension[] sortedExtension = new IExtension[sorted.length]; 102 System.arraycopy(sorted, 0, sortedExtension, 0, sorted.length); 103 return sortedExtension; 104 } 105 106 115 abstract boolean readElement(IConfigurationElement element); 116 117 122 void readElementChildren(IConfigurationElement element) { 123 readElements(element.getChildren()); 124 } 125 126 132 private void readElements(IConfigurationElement[] elements) { 133 for (int i = 0; i < elements.length; i++) { 134 if (!readElement(elements[i])) 135 logUnknownElement(elements[i]); 136 } 137 } 138 139 143 private void readExtension(IExtension extension) { 144 readElements(extension.getConfigurationElements()); 145 } 146 147 151 void readRegistry(IExtensionRegistry registry, String pluginId, String extensionPoint) { 152 IExtensionPoint point = registry.getExtensionPoint(pluginId, extensionPoint); 153 if (point != null) { 154 IExtension[] extensions = point.getExtensions(); 155 extensions = orderExtensions(extensions); 156 for (int i = 0; i < extensions.length; i++) 157 readExtension(extensions[i]); 158 } 159 } 160 } 161 | Popular Tags |