001/** 002 * Copyright 2005-2015 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 */ 016package org.kuali.rice.krad.datadictionary.validation.constraint; 017 018import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 019import org.kuali.rice.krad.messages.MessageService; 020import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 021import org.kuali.rice.krad.uif.UifConstants; 022 023import java.util.ArrayList; 024import 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 */ 035public 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 regular expression for matching allowed characters 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 557 MessageService messageService = KRADServiceLocatorWeb.getMessageService(); 558 559 StringBuilder paramString = new StringBuilder(""); 560 if (allowWhitespace || allowAll) { 561 paramString.append(", " + messageService.getMessageText( 562 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "whitespace")); 563 if (!omitNewline) { 564 paramString.append(", " + messageService.getMessageText( 565 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "newline")); 566 } 567 } 568 if (allowUnderscore || allowAll) { 569 paramString.append(", " + messageService.getMessageText( 570 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "underscore")); 571 } 572 if (allowPeriod || allowAll) { 573 paramString.append(", " + messageService.getMessageText( 574 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "period")); 575 } 576 if (allowParenthesis || allowAll) { 577 paramString.append(", " + messageService.getMessageText( 578 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "parenthesis")); 579 } 580 if (allowDollar || allowAll) { 581 paramString.append(", " + messageService.getMessageText( 582 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "dollar")); 583 } 584 if (allowForwardSlash || allowAll) { 585 paramString.append(", " + messageService.getMessageText( 586 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "forwardSlash")); 587 } 588 if (allowDoubleQuote || allowAll) { 589 paramString.append(", " + messageService.getMessageText( 590 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "doubleQuote")); 591 } 592 if (allowApostrophe || allowAll) { 593 paramString.append(", " + messageService.getMessageText( 594 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "apostrophe")); 595 } 596 if (allowComma || allowAll) { 597 paramString.append(", " + messageService.getMessageText( 598 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "comma")); 599 } 600 if (allowColon || allowAll) { 601 paramString.append(", " + messageService.getMessageText( 602 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "colon")); 603 } 604 if (allowSemiColon || allowAll) { 605 paramString.append(", " + messageService.getMessageText( 606 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "semiColon")); 607 } 608 if (allowQuestionMark || allowAll) { 609 paramString.append(", " + messageService.getMessageText( 610 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "questionMark")); 611 } 612 if (allowExclaimation || allowAll) { 613 paramString.append(", " + messageService.getMessageText( 614 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "exclaimation")); 615 } 616 if (allowDash || allowAll) { 617 paramString.append(", " + messageService.getMessageText( 618 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "dash")); 619 } 620 if (allowPlus || allowAll) { 621 paramString.append(", " + messageService.getMessageText( 622 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "plus")); 623 } 624 if (allowEquals || allowAll) { 625 paramString.append(", " + messageService.getMessageText( 626 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "equals")); 627 } 628 if (allowAsterisk || allowAll) { 629 paramString.append(", " + messageService.getMessageText( 630 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "asterisk")); 631 } 632 if (allowAtSign || allowAll) { 633 paramString.append(", " + messageService.getMessageText( 634 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "atSign")); 635 } 636 if (allowPercent || allowAll) { 637 paramString.append(", " + messageService.getMessageText( 638 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "percent")); 639 } 640 if (allowPound || allowAll) { 641 paramString.append(", " + messageService.getMessageText( 642 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "pound")); 643 } 644 if (allowLessThan || allowAll) { 645 paramString.append(", " + messageService.getMessageText( 646 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "lessThan")); 647 } 648 if (allowGreaterThan || allowAll) { 649 paramString.append(", " + messageService.getMessageText( 650 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "greaterThan")); 651 } 652 if (allowAmpersand || allowAll) { 653 paramString.append(", " + messageService.getMessageText( 654 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "ampersand")); 655 } 656 if (allowBackslash || allowAll) { 657 paramString.append(", " + messageService.getMessageText( 658 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "backslash")); 659 } 660 if (allowCurlyBraces || allowAll) { 661 paramString.append(", " + messageService.getMessageText( 662 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "curlyBraces")); 663 } 664 if (allowBrackets || allowAll) { 665 paramString.append(", " + messageService.getMessageText( 666 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "brackets")); 667 } 668 669 validationMessageParams.add(paramString.toString()); 670 } 671 return this.validationMessageParams; 672 } 673 674}