1 20 package org.apache.directory.ldapstudio.aciitemeditor.sourceeditor; 21 22 23 import java.util.ArrayList ; 24 import java.util.List ; 25 26 import org.eclipse.jface.text.rules.IRule; 27 import org.eclipse.jface.text.rules.IToken; 28 import org.eclipse.jface.text.rules.IWhitespaceDetector; 29 import org.eclipse.jface.text.rules.IWordDetector; 30 import org.eclipse.jface.text.rules.RuleBasedScanner; 31 import org.eclipse.jface.text.rules.SingleLineRule; 32 import org.eclipse.jface.text.rules.Token; 33 import org.eclipse.jface.text.rules.WhitespaceRule; 34 import org.eclipse.jface.text.rules.WordRule; 35 36 37 43 public class ACICodeScanner extends RuleBasedScanner 44 { 45 46 public static final String identificationTagPartition = "identificationTag"; 48 49 public static final String precedencePartition = "precedence"; 51 52 public static final String authenticationLevelPartition = "authenticationLevel"; 54 55 public static final String [] itemOrUserFirstSectionPartition = new String [] 56 { "itemOrUserFirst", "itemFirst", "userFirst" }; 58 59 public static final String [] userSection = new String [] 60 { "userClasses", "userPermissions" }; 62 63 public static final String [] aciKeywords = new String [] 64 { "protectedItems", "itemPermissions", "entry", "allUserAttributeTypes", "attributeType", "allAttributeValues", "allUserAttributeTypesAndValues", "attributeValue", "selfValue", "rangeOfValues", "maxValueCount", "maxImmSub", "restrictedBy", "classes", "grantsAndDenials", "allUsers", "thisEntry", "name", "userGroup", "subtree", "type", "valuesIn", "none", "simple", "strong" }; 90 91 public static final String [] aciGrantValues = new String [] 92 { "grantAdd", "grantDiscloseOnError", "grantRead", "grantRemove", "grantBrowse", "grantExport", "grantImport", "grantModify", "grantRename", "grantReturnDN", "grantCompare", "grantFilterMatch", "grantInvoke", }; 106 107 public static final String [] aciDenyValues = new String [] 108 { "denyAdd", "denyDiscloseOnError", "denyRead", "denyRemove", "denyBrowse", "denyExport", "denyImport", "denyModify", "denyRename", "denyReturnDN", "denyCompare", "denyFilterMatch", "denyInvoke" }; 122 123 129 public ACICodeScanner( ACITextAttributeProvider provider ) 130 { 131 List <IRule> rules = new ArrayList <IRule>(); 132 133 IToken keyword = new Token( provider.getAttribute( ACITextAttributeProvider.KEYWORD_ATTRIBUTE ) ); 134 IToken undefined = new Token( provider.getAttribute( ACITextAttributeProvider.DEFAULT_ATTRIBUTE ) ); 135 IToken string = new Token( provider.getAttribute( ACITextAttributeProvider.STRING_ATTRIBUTE ) ); 136 IToken grantValue = new Token( provider.getAttribute( ACITextAttributeProvider.GRANT_VALUE ) ); 137 IToken denyValue = new Token( provider.getAttribute( ACITextAttributeProvider.DENY_VALUE ) ); 138 IToken identification = new Token( provider.getAttribute( ACITextAttributeProvider.IDENTIFICATION_ATTRIBUTE ) ); 139 IToken precedence = new Token( provider.getAttribute( ACITextAttributeProvider.PRECEDENCE_ATTRIBUTE ) ); 140 IToken authenticationLevel = new Token( provider 141 .getAttribute( ACITextAttributeProvider.AUTHENTICATIONLEVEL_ATTRIBUTE ) ); 142 IToken itemOrUserFirst = new Token( provider.getAttribute( ACITextAttributeProvider.ITEMORUSERFIRST_ATTRIBUTE ) ); 143 IToken user = new Token( provider.getAttribute( ACITextAttributeProvider.USER_ATTRIBUTE ) ); 144 145 rules.add( new SingleLineRule( "\"", "\"", string, '\0', true ) ); rules.add( new SingleLineRule( "'", "'", string, '\0', true ) ); rules.add( new WhitespaceRule( new IWhitespaceDetector() 150 { 151 157 public boolean isWhitespace( char c ) 158 { 159 return Character.isWhitespace( c ); 160 } 161 } ) ); 162 163 WordRule wr = new WordRule( new AciWordDetector(), undefined ); 165 166 for ( int i = 0; i < aciKeywords.length; ++i ) 168 { 169 wr.addWord( aciKeywords[i], keyword ); 170 } 171 172 for ( int i = 0; i < aciGrantValues.length; ++i ) 174 { 175 wr.addWord( aciGrantValues[i], grantValue ); 176 } 177 178 for ( int i = 0; i < aciDenyValues.length; ++i ) 180 { 181 wr.addWord( aciDenyValues[i], denyValue ); 182 } 183 184 for ( int i = 0; i < itemOrUserFirstSectionPartition.length; ++i ) 186 { 187 wr.addWord( itemOrUserFirstSectionPartition[i], itemOrUserFirst ); 188 } 189 190 for ( int i = 0; i < userSection.length; ++i ) 192 { 193 wr.addWord( userSection[i], user ); 194 } 195 196 wr.addWord( identificationTagPartition, identification ); 197 198 wr.addWord( precedencePartition, precedence ); 199 200 wr.addWord( authenticationLevelPartition, authenticationLevel ); 201 202 rules.add( wr ); 203 204 IRule[] param = new IRule[rules.size()]; 206 rules.toArray( param ); 207 setRules( param ); 208 } 209 210 216 static class AciWordDetector implements IWordDetector 217 { 218 221 public boolean isWordPart( char c ) 222 { 223 return ( Character.isLetterOrDigit( c ) || c == '_' || c == '$' || c == '#' || c == '@' || c == '~' 224 || c == '.' || c == '?' ); 225 } 226 227 228 231 public boolean isWordStart( char c ) 232 { 233 return ( Character.isLetter( c ) || c == '.' || c == '_' || c == '?' || c == '$' ); 234 } 235 } 236 } 237 | Popular Tags |