1 11 12 package org.eclipse.ui.internal.navigator.extensions; 13 14 import java.util.HashSet ; 15 import java.util.Iterator ; 16 import java.util.Set ; 17 import java.util.regex.Pattern ; 18 19 import org.eclipse.core.runtime.Assert; 20 import org.eclipse.core.runtime.IConfigurationElement; 21 import org.eclipse.osgi.util.NLS; 22 import org.eclipse.ui.internal.navigator.CommonNavigatorMessages; 23 import org.eclipse.ui.internal.navigator.NavigatorPlugin; 24 25 class Binding { 26 27 private final Set rootPatterns = new HashSet (); 28 29 private final Set includePatterns = new HashSet (); 30 31 private final Set excludePatterns = new HashSet (); 32 33 private final String TAG_EXTENSION; 34 35 protected Binding(String tagExtension) { 36 TAG_EXTENSION = tagExtension; 37 } 38 39 44 boolean isVisibleExtension(String anExtensionId) { 45 Pattern pattern = null; 46 for (Iterator itr = includePatterns.iterator(); itr.hasNext();) { 47 pattern = (Pattern ) itr.next(); 48 if (pattern.matcher(anExtensionId).matches()) { 49 return true; 50 } 51 } 52 53 for (Iterator itr = excludePatterns.iterator(); itr.hasNext();) { 54 pattern = (Pattern ) itr.next(); 55 if (pattern.matcher(anExtensionId).matches()) { 56 return false; 57 } 58 } 59 return false; 60 } 61 62 67 boolean isRootExtension(String anExtensionId) { 68 if (rootPatterns.size() == 0) { 69 return false; 70 } 71 Pattern pattern = null; 72 for (Iterator itr = rootPatterns.iterator(); itr.hasNext();) { 73 pattern = (Pattern ) itr.next(); 74 if (pattern.matcher(anExtensionId).matches()) { 75 return true; 76 } 77 } 78 return false; 79 } 80 81 86 boolean hasOverriddenRootExtensions() { 87 return rootPatterns.size() > 0; 88 } 89 90 void consumeIncludes(IConfigurationElement element, boolean toRespectRoots) { 91 92 Assert.isTrue(NavigatorViewerDescriptor.TAG_INCLUDES.equals(element 93 .getName())); 94 IConfigurationElement[] contentExtensionPatterns = element 95 .getChildren(TAG_EXTENSION); 96 String isRootString = null; 97 boolean isRoot = false; 98 String patternString = null; 99 Pattern compiledPattern = null; 100 for (int i = 0; i < contentExtensionPatterns.length; i++) { 101 if (toRespectRoots) { 102 isRootString = contentExtensionPatterns[i] 103 .getAttribute(NavigatorViewerDescriptor.ATT_IS_ROOT); 104 isRoot = (isRootString != null) ? Boolean.valueOf( 105 isRootString.trim()).booleanValue() : false; 106 } 107 108 patternString = contentExtensionPatterns[i] 109 .getAttribute(NavigatorViewerDescriptor.ATT_PATTERN); 110 if (patternString == null) { 111 NavigatorPlugin 112 .logError( 113 0, 114 NLS 115 .bind( 116 CommonNavigatorMessages.Attribute_Missing_Warning, 117 new Object [] { 118 NavigatorViewerDescriptor.ATT_PATTERN, 119 element 120 .getDeclaringExtension() 121 .getUniqueIdentifier(), 122 element 123 .getDeclaringExtension() 124 .getNamespace() }), 125 null); 126 } else { 127 compiledPattern = Pattern.compile(patternString); 128 includePatterns.add(compiledPattern); 129 if (toRespectRoots && isRoot) { 130 rootPatterns.add(compiledPattern); 131 } 132 } 133 } 134 135 } 136 137 void consumeExcludes(IConfigurationElement element) { 138 Assert.isTrue(NavigatorViewerDescriptor.TAG_EXCLUDES.equals(element 139 .getName())); 140 IConfigurationElement[] contentExtensionPatterns = element 141 .getChildren(TAG_EXTENSION); 142 String patternString = null; 143 Pattern compiledPattern = null; 144 for (int i = 0; i < contentExtensionPatterns.length; i++) { 145 146 patternString = contentExtensionPatterns[i] 147 .getAttribute(NavigatorViewerDescriptor.ATT_PATTERN); 148 if (patternString == null) { 149 NavigatorPlugin 150 .logError( 151 0, 152 NLS 153 .bind( 154 CommonNavigatorMessages.Attribute_Missing_Warning, 155 new Object [] { 156 NavigatorViewerDescriptor.ATT_PATTERN, 157 element 158 .getDeclaringExtension() 159 .getUniqueIdentifier(), 160 element 161 .getDeclaringExtension() 162 .getNamespace() }), 163 null); 164 } else { 165 compiledPattern = Pattern.compile(patternString); 166 excludePatterns.add(compiledPattern); 167 } 168 } 169 170 } 171 } | Popular Tags |