001 /** 002 * Copyright 2005-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.krad.datadictionary.validation.constraint; 017 018 import org.kuali.rice.core.api.config.property.ConfigurationService; 019 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 020 import org.kuali.rice.krad.service.KRADServiceLocator; 021 import org.kuali.rice.krad.uif.UifConstants; 022 023 import java.util.ArrayList; 024 import java.util.List; 025 026 /** 027 * Parent abstract class that allows additional characters to be allowed in child constraint 028 * character sets, see AlphaNumericPatternConstraint, among others for example. 029 * 030 * By setting an allow flag to true you are allowing that character as a valid character in the set. 031 * AllowAll set to true will allow all characters which have a flag to be allowed in the set. 032 * 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 */ 035 public abstract class AllowCharacterConstraint extends ValidCharactersPatternConstraint { 036 protected boolean allowWhitespace = false; 037 protected boolean omitNewline = false; 038 protected boolean allowUnderscore = false; 039 protected boolean allowPeriod = false; 040 protected boolean allowParenthesis = false; 041 protected boolean allowDollar = false; 042 protected boolean allowForwardSlash = false; 043 protected boolean allowDoubleQuote = false; 044 protected boolean allowApostrophe = false; 045 protected boolean allowComma = false; 046 protected boolean allowColon = false; 047 protected boolean allowSemiColon = false; 048 protected boolean allowQuestionMark = false; 049 protected boolean allowExclaimation = false; 050 protected boolean allowDash = false; 051 protected boolean allowPlus = false; 052 protected boolean allowEquals = false; 053 protected boolean allowAsterisk = false; 054 protected boolean allowAtSign = false; 055 protected boolean allowPercent = false; 056 protected boolean allowPound = false; 057 protected boolean allowGreaterThan = false; 058 protected boolean allowLessThan = false; 059 protected boolean allowBrackets = false; 060 protected boolean allowAmpersand = false; 061 protected boolean allowCurlyBraces = false; 062 protected boolean allowBackslash = false; 063 protected boolean allowAll = false; 064 065 /** 066 * @return the allowWhitespace 067 */ 068 @BeanTagAttribute(name = "allowWhitespace") 069 public boolean isAllowWhitespace() { 070 return this.allowWhitespace; 071 } 072 073 /** 074 * @param allowWhitespace the allowWhitespace to set 075 */ 076 public void setAllowWhitespace(boolean allowWhitespace) { 077 this.allowWhitespace = allowWhitespace; 078 } 079 080 /** 081 * @return the allowUnderscore 082 */ 083 @BeanTagAttribute(name = "allowUnderscore") 084 public boolean isAllowUnderscore() { 085 return this.allowUnderscore; 086 } 087 088 /** 089 * @param allowUnderscore the allowUnderscore to set 090 */ 091 public void setAllowUnderscore(boolean allowUnderscore) { 092 this.allowUnderscore = allowUnderscore; 093 } 094 095 /** 096 * @return the allowPeriod 097 */ 098 @BeanTagAttribute(name = "allowPeriod") 099 public boolean isAllowPeriod() { 100 return this.allowPeriod; 101 } 102 103 /** 104 * @param allowPeriod the allowPeriod to set 105 */ 106 public void setAllowPeriod(boolean allowPeriod) { 107 this.allowPeriod = allowPeriod; 108 } 109 110 /** 111 * @return the allowParenthesis 112 */ 113 @BeanTagAttribute(name = "allowParenthesis") 114 public boolean isAllowParenthesis() { 115 return this.allowParenthesis; 116 } 117 118 /** 119 * @param allowParenthesis the allowParenthesis to set 120 */ 121 public void setAllowParenthesis(boolean allowParenthesis) { 122 this.allowParenthesis = allowParenthesis; 123 } 124 125 /** 126 * @return the allowDollar 127 */ 128 @BeanTagAttribute(name = "allowDollar") 129 public boolean isAllowDollar() { 130 return this.allowDollar; 131 } 132 133 /** 134 * @param allowDollar the allowDollar to set 135 */ 136 public void setAllowDollar(boolean allowDollar) { 137 this.allowDollar = allowDollar; 138 } 139 140 /** 141 * @return the allowForwardSlash 142 */ 143 @BeanTagAttribute(name = "allowForwardSlash") 144 public boolean isAllowForwardSlash() { 145 return this.allowForwardSlash; 146 } 147 148 /** 149 * @param allowForwardSlash the allowForwardSlash to set 150 */ 151 public void setAllowForwardSlash(boolean allowForwardSlash) { 152 this.allowForwardSlash = allowForwardSlash; 153 } 154 155 /** 156 * @return the allowDoubleQuote 157 */ 158 @BeanTagAttribute(name = "allowDoubleQuote") 159 public boolean isAllowDoubleQuote() { 160 return this.allowDoubleQuote; 161 } 162 163 /** 164 * @param allowDoubleQuote the allowDoubleQuote to set 165 */ 166 public void setAllowDoubleQuote(boolean allowDoubleQuote) { 167 this.allowDoubleQuote = allowDoubleQuote; 168 } 169 170 /** 171 * @return the allowApostrophe 172 */ 173 @BeanTagAttribute(name = "allowApostrophe") 174 public boolean isAllowApostrophe() { 175 return this.allowApostrophe; 176 } 177 178 /** 179 * @param allowApostrophe the allowApostrophe to set 180 */ 181 public void setAllowApostrophe(boolean allowApostrophe) { 182 this.allowApostrophe = allowApostrophe; 183 } 184 185 /** 186 * @return the allowComma 187 */ 188 @BeanTagAttribute(name = "allowComma") 189 public boolean isAllowComma() { 190 return this.allowComma; 191 } 192 193 /** 194 * @param allowComma the allowComma to set 195 */ 196 public void setAllowComma(boolean allowComma) { 197 this.allowComma = allowComma; 198 } 199 200 /** 201 * @return the allowColon 202 */ 203 @BeanTagAttribute(name = "allowColon") 204 public boolean isAllowColon() { 205 return this.allowColon; 206 } 207 208 /** 209 * @param allowColon the allowColon to set 210 */ 211 public void setAllowColon(boolean allowColon) { 212 this.allowColon = allowColon; 213 } 214 215 /** 216 * @return the allowSemiColon 217 */ 218 @BeanTagAttribute(name = "allowSemiColon") 219 public boolean isAllowSemiColon() { 220 return this.allowSemiColon; 221 } 222 223 /** 224 * @param allowSemiColon the allowSemiColon to set 225 */ 226 public void setAllowSemiColon(boolean allowSemiColon) { 227 this.allowSemiColon = allowSemiColon; 228 } 229 230 /** 231 * @return the allowQuestionMark 232 */ 233 @BeanTagAttribute(name = "allowQuestionMark") 234 public boolean isAllowQuestionMark() { 235 return this.allowQuestionMark; 236 } 237 238 /** 239 * @param allowQuestionMark the allowQuestionMark to set 240 */ 241 public void setAllowQuestionMark(boolean allowQuestionMark) { 242 this.allowQuestionMark = allowQuestionMark; 243 } 244 245 /** 246 * @return the allowExclaimation 247 */ 248 @BeanTagAttribute(name = "allowExclaimation") 249 public boolean isAllowExclaimation() { 250 return this.allowExclaimation; 251 } 252 253 /** 254 * @param allowExclaimation the allowExclaimation to set 255 */ 256 public void setAllowExclaimation(boolean allowExclaimation) { 257 this.allowExclaimation = allowExclaimation; 258 } 259 260 /** 261 * @return the allowDash 262 */ 263 @BeanTagAttribute(name = "allowDash") 264 public boolean isAllowDash() { 265 return this.allowDash; 266 } 267 268 /** 269 * @param allowDash the allowDash to set 270 */ 271 public void setAllowDash(boolean allowDash) { 272 this.allowDash = allowDash; 273 } 274 275 /** 276 * @return the allowPlus 277 */ 278 @BeanTagAttribute(name = "allowPlus") 279 public boolean isAllowPlus() { 280 return this.allowPlus; 281 } 282 283 /** 284 * @param allowPlus the allowPlus to set 285 */ 286 public void setAllowPlus(boolean allowPlus) { 287 this.allowPlus = allowPlus; 288 } 289 290 /** 291 * @return the allowEquals 292 */ 293 @BeanTagAttribute(name = "allowEquals") 294 public boolean isAllowEquals() { 295 return this.allowEquals; 296 } 297 298 /** 299 * @param allowEquals the allowEquals to set 300 */ 301 public void setAllowEquals(boolean allowEquals) { 302 this.allowEquals = allowEquals; 303 } 304 305 /** 306 * @return the allowAsterisk 307 */ 308 @BeanTagAttribute(name = "allowAsterisk") 309 public boolean isAllowAsterisk() { 310 return this.allowAsterisk; 311 } 312 313 /** 314 * @param allowAsterisk the allowAsterisk to set 315 */ 316 public void setAllowAsterisk(boolean allowAsterisk) { 317 this.allowAsterisk = allowAsterisk; 318 } 319 320 /** 321 * @return the allowAtSign 322 */ 323 @BeanTagAttribute(name = "allowAtSign") 324 public boolean isAllowAtSign() { 325 return this.allowAtSign; 326 } 327 328 /** 329 * @param allowAtSign the allowAtSign to set 330 */ 331 public void setAllowAtSign(boolean allowAtSign) { 332 this.allowAtSign = allowAtSign; 333 } 334 335 /** 336 * @return the allowPercent 337 */ 338 @BeanTagAttribute(name = "allowPercent") 339 public boolean isAllowPercent() { 340 return this.allowPercent; 341 } 342 343 /** 344 * @param allowPercent the allowPercent to set 345 */ 346 public void setAllowPercent(boolean allowPercent) { 347 this.allowPercent = allowPercent; 348 } 349 350 /** 351 * @return the allowPound 352 */ 353 @BeanTagAttribute(name = "allowPound") 354 public boolean isAllowPound() { 355 return this.allowPound; 356 } 357 358 /** 359 * @param allowPound the allowPound to set 360 */ 361 public void setAllowPound(boolean allowPound) { 362 this.allowPound = allowPound; 363 } 364 365 @BeanTagAttribute(name = "allowGreaterThan") 366 public boolean isAllowGreaterThan() { 367 return allowGreaterThan; 368 } 369 370 public void setAllowGreaterThan(boolean allowGreaterThan) { 371 this.allowGreaterThan = allowGreaterThan; 372 } 373 374 @BeanTagAttribute(name = "allowLessThan") 375 public boolean isAllowLessThan() { 376 return allowLessThan; 377 } 378 379 public void setAllowLessThan(boolean allowLessThan) { 380 this.allowLessThan = allowLessThan; 381 } 382 383 @BeanTagAttribute(name = "allowBrackets") 384 public boolean isAllowBrackets() { 385 return allowBrackets; 386 } 387 388 public void setAllowBrackets(boolean allowBrackets) { 389 this.allowBrackets = allowBrackets; 390 } 391 392 @BeanTagAttribute(name = "allowAmpersand") 393 public boolean isAllowAmpersand() { 394 return allowAmpersand; 395 } 396 397 public void setAllowAmpersand(boolean allowAmpersand) { 398 this.allowAmpersand = allowAmpersand; 399 } 400 401 @BeanTagAttribute(name = "allowCurlyBraces") 402 public boolean isAllowCurlyBraces() { 403 return allowCurlyBraces; 404 } 405 406 public void setAllowCurlyBraces(boolean allowCurlyBraces) { 407 this.allowCurlyBraces = allowCurlyBraces; 408 } 409 410 @BeanTagAttribute(name = "allowBackslash") 411 public boolean isAllowBackslash() { 412 return allowBackslash; 413 } 414 415 public void setAllowBackslash(boolean allowBackslash) { 416 this.allowBackslash = allowBackslash; 417 } 418 419 /** 420 * If true, this constraint will allow all symbols that have flags for them. Equivalent to 421 * setting each flag to true separately. 422 * 423 * @return the allowAll 424 */ 425 @BeanTagAttribute(name = "allowAll") 426 public boolean isAllowAll() { 427 return this.allowAll; 428 } 429 430 /** 431 * @param allowAll the allowAll to set 432 */ 433 public void setAllowAll(boolean allowAll) { 434 this.allowAll = allowAll; 435 } 436 437 @BeanTagAttribute(name = "omitNewline") 438 public boolean isOmitNewline() { 439 return omitNewline; 440 } 441 442 /** 443 * When set to true, omit new line characters from the set of valid characters. This flag 444 * will only have an effect if the allowWhitespace flag is true, otherwise all whitespace 445 * including new lines characters are omitted. 446 * 447 * @param omitNewline 448 */ 449 public void setOmitNewline(boolean omitNewline) { 450 this.omitNewline = omitNewline; 451 } 452 453 /** 454 * This method returns the allowed set of characters allowed by this constraint, based on the 455 * flags set. This string is intended to be placed within the or set of a regex, ie between the 456 * [ ] symbols 457 * 458 * @return 459 */ 460 protected String getAllowedCharacterRegex() { 461 StringBuilder regexString = new StringBuilder(""); 462 if (allowWhitespace || allowAll) { 463 regexString.append("\\t\\v\\040"); 464 if (!omitNewline) { 465 regexString.append("\\f\\r\\n"); 466 } 467 } 468 if (allowUnderscore || allowAll) { 469 regexString.append("_"); 470 } 471 if (allowPeriod || allowAll) { 472 regexString.append("."); 473 } 474 if (allowParenthesis || allowAll) { 475 regexString.append("("); 476 regexString.append(")"); 477 } 478 if (allowDollar || allowAll) { 479 regexString.append("$"); 480 } 481 if (allowForwardSlash || allowAll) { 482 regexString.append("/"); 483 } 484 if (allowDoubleQuote || allowAll) { 485 regexString.append("\\\""); 486 } 487 if (allowApostrophe || allowAll) { 488 regexString.append("'"); 489 } 490 if (allowComma || allowAll) { 491 regexString.append(","); 492 } 493 if (allowColon || allowAll) { 494 regexString.append(":"); 495 } 496 if (allowSemiColon || allowAll) { 497 regexString.append(";"); 498 } 499 if (allowQuestionMark || allowAll) { 500 regexString.append("?"); 501 } 502 if (allowExclaimation || allowAll) { 503 regexString.append("!"); 504 } 505 if (allowDash || allowAll) { 506 regexString.append("\\-"); 507 } 508 if (allowPlus || allowAll) { 509 regexString.append("+"); 510 } 511 if (allowEquals || allowAll) { 512 regexString.append("="); 513 } 514 if (allowAsterisk || allowAll) { 515 regexString.append("*"); 516 } 517 if (allowAtSign || allowAll) { 518 regexString.append("@"); 519 } 520 if (allowPercent || allowAll) { 521 regexString.append("%"); 522 } 523 if (allowPound || allowAll) { 524 regexString.append("#"); 525 } 526 if (allowLessThan || allowAll) { 527 regexString.append("\\0074"); 528 } 529 if (allowGreaterThan || allowAll) { 530 regexString.append("\\0076"); 531 } 532 if (allowAmpersand || allowAll) { 533 regexString.append("\\0046"); 534 } 535 if (allowBackslash || allowAll) { 536 regexString.append("\\0134"); 537 } 538 if (allowCurlyBraces || allowAll) { 539 regexString.append("\\0173\\0175"); 540 } 541 if (allowBrackets || allowAll) { 542 regexString.append("\\0133\\0135"); 543 } 544 return regexString.toString(); 545 } 546 547 /** 548 * Generates a comma separated string of the allowed set of characters, for the {0} parameter to 549 * be used within its validation message 550 * 551 * @return the validationMessageParams 552 */ 553 public List<String> getValidationMessageParams() { 554 if (validationMessageParams == null) { 555 validationMessageParams = new ArrayList<String>(); 556 ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService(); 557 StringBuilder paramString = new StringBuilder(""); 558 559 if (allowWhitespace || allowAll) { 560 paramString.append(", " + configService.getPropertyValueAsString( 561 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "whitespace")); 562 if (!omitNewline) { 563 paramString.append(", " + configService.getPropertyValueAsString( 564 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "newline")); 565 } 566 } 567 if (allowUnderscore || allowAll) { 568 paramString.append(", " + configService.getPropertyValueAsString( 569 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "underscore")); 570 } 571 if (allowPeriod || allowAll) { 572 paramString.append(", " + configService.getPropertyValueAsString( 573 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "period")); 574 } 575 if (allowParenthesis || allowAll) { 576 paramString.append(", " + configService.getPropertyValueAsString( 577 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "parenthesis")); 578 } 579 if (allowDollar || allowAll) { 580 paramString.append(", " + configService.getPropertyValueAsString( 581 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "dollar")); 582 } 583 if (allowForwardSlash || allowAll) { 584 paramString.append(", " + configService.getPropertyValueAsString( 585 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "forwardSlash")); 586 } 587 if (allowDoubleQuote || allowAll) { 588 paramString.append(", " + configService.getPropertyValueAsString( 589 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "doubleQuote")); 590 } 591 if (allowApostrophe || allowAll) { 592 paramString.append(", " + configService.getPropertyValueAsString( 593 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "apostrophe")); 594 } 595 if (allowComma || allowAll) { 596 paramString.append(", " + configService.getPropertyValueAsString( 597 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "comma")); 598 } 599 if (allowColon || allowAll) { 600 paramString.append(", " + configService.getPropertyValueAsString( 601 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "colon")); 602 } 603 if (allowSemiColon || allowAll) { 604 paramString.append(", " + configService.getPropertyValueAsString( 605 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "semiColon")); 606 } 607 if (allowQuestionMark || allowAll) { 608 paramString.append(", " + configService.getPropertyValueAsString( 609 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "questionMark")); 610 } 611 if (allowExclaimation || allowAll) { 612 paramString.append(", " + configService.getPropertyValueAsString( 613 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "exclaimation")); 614 } 615 if (allowDash || allowAll) { 616 paramString.append(", " + configService.getPropertyValueAsString( 617 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "dash")); 618 } 619 if (allowPlus || allowAll) { 620 paramString.append(", " + configService.getPropertyValueAsString( 621 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "plus")); 622 } 623 if (allowEquals || allowAll) { 624 paramString.append(", " + configService.getPropertyValueAsString( 625 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "equals")); 626 } 627 if (allowAsterisk || allowAll) { 628 paramString.append(", " + configService.getPropertyValueAsString( 629 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "asterisk")); 630 } 631 if (allowAtSign || allowAll) { 632 paramString.append(", " + configService.getPropertyValueAsString( 633 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "atSign")); 634 } 635 if (allowPercent || allowAll) { 636 paramString.append(", " + configService.getPropertyValueAsString( 637 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "percent")); 638 } 639 if (allowPound || allowAll) { 640 paramString.append(", " + configService.getPropertyValueAsString( 641 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "pound")); 642 } 643 if (allowLessThan || allowAll) { 644 paramString.append(", " + configService.getPropertyValueAsString( 645 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "lessThan")); 646 } 647 if (allowGreaterThan || allowAll) { 648 paramString.append(", " + configService.getPropertyValueAsString( 649 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "greaterThan")); 650 } 651 if (allowAmpersand || allowAll) { 652 paramString.append(", " + configService.getPropertyValueAsString( 653 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "ampersand")); 654 } 655 if (allowBackslash || allowAll) { 656 paramString.append(", " + configService.getPropertyValueAsString( 657 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "backslash")); 658 } 659 if (allowCurlyBraces || allowAll) { 660 paramString.append(", " + configService.getPropertyValueAsString( 661 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "curlyBraces")); 662 } 663 if (allowBrackets || allowAll) { 664 paramString.append(", " + configService.getPropertyValueAsString( 665 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "brackets")); 666 } 667 668 validationMessageParams.add(paramString.toString()); 669 } 670 return this.validationMessageParams; 671 } 672 673 }