1 6 7 package com.quikj.application.web.talk.jspbeans; 8 9 import java.io.*; 10 import java.util.*; 11 import java.net.*; 12 13 import javax.xml.parsers.*; 15 import org.xml.sax.*; 16 import org.w3c.dom.*; 17 18 22 public class ContactCenterCustomerProperty 23 { 24 public ContactCenterCustomerProperty(String path, String customer) 25 throws FileNotFoundException, IOException, SAXException, AceException, ParserConfigurationException 26 { 27 this.customer = customer; 28 29 file = new File(path + "/aceapp/data/customer", 31 customer + ".xml"); 32 33 if (file.exists() == false) 34 { 35 throw new AceException("File " + file.getAbsolutePath() + " does not exist"); 36 } 37 38 loadPropertyFromFile(); 39 } 40 41 private void setupDefaultValues() 42 { 43 validatorObject = null; 44 45 pagesParams = new HashMap(); 46 47 userParams = new HashMap(); 48 49 active = true; 50 51 checkOperatorAvailability = false; 52 53 oosEmail = null; 54 55 accessType = "unrestricted"; 56 57 authenticatorClassName = null; 58 59 authenticatorParams = new HashMap(); 60 61 operator = null; 62 63 language = "English"; 64 65 clientType = "JAVA"; 66 67 locale = "en_US"; 68 } 69 70 private void loadPropertyFromFile() 71 throws FileNotFoundException, IOException, SAXParseException, SAXException, AceException, ParserConfigurationException 72 { 73 URL url = file.toURL(); 75 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 76 77 dbf.setValidating(true); 79 dbf.setIgnoringComments(true); 80 dbf.setIgnoringElementContentWhitespace(true); 81 dbf.setCoalescing(true); 82 dbf.setNamespaceAware(true); 83 84 DocumentBuilder doc_builder = dbf.newDocumentBuilder(); 86 87 doc_builder.setErrorHandler(new org.xml.sax.ErrorHandler () 88 { 89 public void fatalError(SAXParseException e) 91 throws SAXException 92 { 93 } 94 95 public void error(SAXParseException e) 97 throws SAXParseException 98 { 99 throw e; 100 } 101 102 public void warning(SAXParseException e) 104 throws SAXParseException 105 { 106 throw e; 107 } 108 109 } 110 111 ); 112 113 Document doc = doc_builder.parse(new InputSource(url.toString())); 115 if (doc.getNodeType() != Node.DOCUMENT_NODE) 116 { 117 throw new AceException("Document does not begin with an XML node"); 118 } 119 120 setupDefaultValues(); 121 122 Node root_element; 125 boolean root_found = false; 126 for (root_element = doc.getFirstChild(); 127 root_element != null; 128 root_element = root_element.getNextSibling()) 129 { 130 if (root_element.getNodeType() == Node.ELEMENT_NODE) 131 { 132 if (root_element.getNodeName().equals("talk-config") == false) 133 { 134 throw new AceException("Root node name " 135 + root_element.getNodeName() 136 + " must be " 137 + "talk-config"); 138 139 } 140 141 root_found = true; 142 break; 143 144 } 145 147 } 148 149 if (root_found == false) 150 { 151 throw new AceException("Root node " 152 + "talk-config" 153 + " not found"); 154 155 } 156 157 Node ele_node; 159 for (ele_node = root_element.getFirstChild(); 160 ele_node != null; 161 ele_node = ele_node.getNextSibling()) 162 { 163 if (ele_node.getNodeType() == Node.ELEMENT_NODE) 164 { 165 String node_name = ele_node.getNodeName(); 166 if (node_name.equals( "pages" ) == true) 167 { 168 processPagesParams( ele_node ); 169 } 170 else if (node_name.equals( "service-params" ) == true) 171 { 172 processServiceParams( ele_node ); 173 } 174 else if (node_name.equals( "user-params" ) == true) 175 { 176 processUserParams(ele_node); 177 } 178 else if (node_name.equals("access" ) == true) 179 { 180 processAccessParams( ele_node ); 181 } 182 184 } 185 186 } 187 188 lastLoaded = (new Date()).getTime(); 189 190 } 191 192 private void processPagesParams(Node node) 193 throws AceException 194 { 195 NamedNodeMap attribs = node.getAttributes(); 196 int length = attribs.getLength(); 197 198 for (int i = 0; i < length; i++) 199 { 200 Node attr = attribs.item(i); 201 if (attr.getNodeName().equals("language") == true) 202 { 203 setLanguage(attr.getNodeValue()); 204 } 205 } 207 208 Node ele_node; 209 for (ele_node = node.getFirstChild(); 210 ele_node != null; 211 ele_node = ele_node.getNextSibling()) 212 { 213 if (ele_node.getNodeType() == Node.ELEMENT_NODE) 214 { 215 if (ele_node.getNodeName().equals("page-param") == true) 216 { 217 attribs = ele_node.getAttributes(); 218 length = attribs.getLength(); 219 if (length < 2) 220 221 { 222 throw new AceException("Node does not have sufficient attributes"); 224 225 } 227 String name = null; 228 String value = null; 229 230 for (int i = 0; i < length; i++) 231 { 232 Node attr = attribs.item(i); 233 if (attr.getNodeName().equals("name") == true) 234 { 235 name = attr.getNodeValue(); 236 } 237 else if (attr.getNodeName().equals("value") == true) 238 { 239 value = attr.getNodeValue(); 240 } 241 } 244 if ((name == null) || (value == null)) 245 { 246 throw new AceException("The name/value is missing for a page-param element"); 247 } 248 249 pagesParams.put(name, value); 250 251 } 252 } 254 } 256 } 257 258 private void processUserParams(Node node) 259 throws AceException 260 { 261 Node ele_node; 262 for (ele_node = node.getFirstChild(); 263 ele_node != null; 264 ele_node = ele_node.getNextSibling()) 265 { 266 if (ele_node.getNodeType() == Node.ELEMENT_NODE) 267 { 268 if (ele_node.getNodeName().equals("user-param") == true) 269 { 270 NamedNodeMap attribs = ele_node.getAttributes(); 271 int length = attribs.getLength(); 272 if (length < 2) 273 274 { 275 throw new AceException("Node does not have sufficient attributes"); 277 278 } 280 String name = null; 281 String value = null; 282 283 for (int i = 0; i < length; i++) 284 { 285 Node attr = attribs.item(i); 286 if (attr.getNodeName().equals("name") == true) 287 { 288 name = attr.getNodeValue(); 289 } 290 else if (attr.getNodeName().equals("value") == true) 291 { 292 value = attr.getNodeValue(); 293 } 294 } 297 if ((name == null) || (value == null)) 298 { 299 throw new AceException("The name/value is missing for a user-param element"); 300 } 301 302 userParams.put(name, value); 303 304 } 305 } 307 } 309 } 310 311 private void processServiceParams(Node node) 312 throws AceException 313 { 314 NamedNodeMap attribs = node.getAttributes(); 316 int length = attribs.getLength(); 317 318 for (int i = 0; i < length; i++) 319 { 320 Node attr = attribs.item(i); 321 if (attr.getNodeName().equals("active") == true) 322 { 323 String value = attr.getNodeValue(); 324 if (value.equalsIgnoreCase("yes") == true) 325 { 326 active = true; 327 } 328 else if (value.equalsIgnoreCase("no") == true) 329 { 330 active = false; 331 } 332 else 333 { 334 throw new AceException("The active attribute can only have values \"yes\" or \"no\""); 335 } 336 } 337 else if (attr.getNodeName().equals("operator") == true) 338 { 339 operator = attr.getNodeValue(); 340 } 341 else if (attr.getNodeName().equals("checkOperatorAvailability") == true) 342 { 343 String value = attr.getNodeValue(); 344 if (value.equalsIgnoreCase("yes") == true) 345 { 346 checkOperatorAvailability = true; 347 } 348 else if (value.equalsIgnoreCase("no") == true) 349 { 350 checkOperatorAvailability = false; 351 } 352 else 353 { 354 throw new AceException("The checkOperatorAvailability attribute can only have values \"yes\" or \"no\""); 355 } 356 } 357 else if (attr.getNodeName().equals("email") == true) 358 { 359 String val = attr.getNodeValue(); 360 if (val.length() > 0) 361 { 362 oosEmail = val; 363 } 364 } 365 else if (attr.getNodeName().equals("clientType") == true) 366 { 367 String val = attr.getNodeValue(); 368 if (val.length() > 0) 369 { 370 clientType = val; 371 } 372 } 373 } 374 } 375 376 377 private void processAccessParams(Node node) 378 throws AceException 379 { 380 NamedNodeMap attribs = node.getAttributes(); 381 int length = attribs.getLength(); 382 383 if (length < 1) 384 { 385 throw new AceException("access does not have sufficient attributes"); 387 } 388 389 for (int i = 0; i < length; i++) 390 { 391 Node attr = attribs.item(i); 392 if (attr.getNodeName().equals("type") == true) 393 { 394 accessType = attr.getNodeValue(); 395 } 396 397 } 398 399 if (accessType == null) 400 { 401 throw new AceException("The type attribute is missing for the \"access\" element"); 402 } 403 404 if (accessType.equals("unrestricted") == true) 405 { 406 return; 407 } 408 409 Node ele_node; 412 for (ele_node = node.getFirstChild(); 413 ele_node != null; 414 ele_node = ele_node.getNextSibling()) 415 { 416 if (ele_node.getNodeType() == Node.ELEMENT_NODE) 417 { 418 String node_name = ele_node.getNodeName(); 419 if (node_name.equals("authenticator") == true) 420 { 421 processAuthenticatorParams(ele_node); 423 break; 424 } 425 } 426 } 427 428 try 430 { 431 Class cl = Class.forName(authenticatorClassName); 432 Class [] interfaces = cl.getInterfaces(); 433 boolean iface_implemented = false; 434 for (int i = 0; i < interfaces.length; i++) 435 { 436 if (interfaces[i].getName().equals("com.quikj.application.web.talk.jspbeans.ContactCenterAuthenticatorInterface") 437 == true) 438 { 439 iface_implemented = true; 440 break; 441 } 442 } 443 444 if (iface_implemented == false) 445 { 446 throw new AceException("Class " + authenticatorClassName 447 + " does not implement the proper interface"); 448 } 449 450 validatorObject = (ContactCenterAuthenticatorInterface)cl.newInstance(); 451 452 Iterator iter = authenticatorParams.keySet().iterator(); 453 while (iter.hasNext() == true) 454 { 455 String name = (String )iter.next(); 456 String value = (String )authenticatorParams.get(name); 457 validatorObject.setParam(name, value); 458 } 459 460 String error = validatorObject.init(); 461 if (error != null) 462 { 463 throw new AceException("Authenticator initialization failed: " + error); 464 } 465 } 466 catch (Exception ex) 467 { 468 throw new AceException(ex.getClass().getName() + ": " + ex.getMessage()); 469 } 470 471 } 472 473 private void processAuthenticatorParams(Node node) 474 throws AceException 475 { 476 NamedNodeMap attribs = node.getAttributes(); 477 int length = attribs.getLength(); 478 479 if (length < 1) 480 { 481 throw new AceException("Node db does not have sufficient attributes"); 483 } 484 485 for (int i = 0; i < length; i++) 486 { 487 Node attr = attribs.item(i); 488 if (attr.getNodeName().equals("className") == true) 489 { 490 authenticatorClassName = attr.getNodeValue(); 491 } 492 493 } 494 495 Node ele_node; 496 for (ele_node = node.getFirstChild(); 497 ele_node != null; 498 ele_node = ele_node.getNextSibling()) 499 { 500 if (ele_node.getNodeType() == Node.ELEMENT_NODE) 501 { 502 String node_name = ele_node.getNodeName(); 503 if (node_name.equals("authenticator-param") == true) 504 { 505 processAuthenticatorAttributes(ele_node); 507 } 508 } 509 } 510 511 if (authenticatorClassName == null) 512 { 513 throw new AceException("Authenticator className has not been specified"); 514 } 515 } 516 517 private void processAuthenticatorAttributes(Node node) 518 throws AceException 519 { 520 NamedNodeMap attribs = node.getAttributes(); 521 int length = attribs.getLength(); 522 523 if (length < 2) 524 { 525 throw new AceException("Node param does not have sufficient attributes"); 527 } 529 String name = null; 530 String value = null; 531 for (int i = 0; i < length; i++) 532 { 533 Node attr = attribs.item(i); 534 if (attr.getNodeName().equals("name") == true) 535 { 536 name = attr.getNodeValue(); 537 } 538 else if (attr.getNodeName().equals("value") == true) 539 { 540 value = attr.getNodeValue(); 541 } 542 } 543 544 if ((name == null) || (value == null)) 545 { 546 throw new AceException("node param does not contain either or both the name/value attributes"); 547 } 548 549 authenticatorParams.put(name, value); 550 } 551 552 public void updateConfiguration() 553 throws FileNotFoundException, IOException, SAXParseException, SAXException, AceException, ParserConfigurationException 554 { 555 if (file == null) 556 { 557 return; 558 } 559 560 long mod = file.lastModified(); 561 if (mod > lastLoaded) 562 { 563 loadPropertyFromFile(); 564 } 565 } 566 567 568 572 public ContactCenterAuthenticatorInterface getValidatorObject() 573 { 574 return this.validatorObject; 575 } 576 577 581 public String getCustomer() 582 { 583 return this.customer; 584 } 585 586 590 public void setCustomer(String customer) 591 { 592 } 593 594 598 public HashMap getPagesParams() 599 { 600 return this.pagesParams; 601 } 602 603 607 public void setPagesParams(HashMap pagesParams) 608 { 609 } 610 611 615 public HashMap getUserParams() 616 { 617 return this.userParams; 618 } 619 620 624 public void setUserParams(HashMap userParams) 625 { 626 this.userParams = userParams; 627 } 628 629 633 public boolean isActive() 634 { 635 return this.active; 636 } 637 638 642 public void setActive(boolean active) 643 { 644 this.active = active; 645 } 646 647 651 public boolean isCheckOperatorAvailability() 652 { 653 return this.checkOperatorAvailability; 654 } 655 656 660 public void setCheckOperatorAvailability(boolean checkOperatorAvailability) 661 { 662 this.checkOperatorAvailability = checkOperatorAvailability; 663 } 664 665 669 public String getOosEmail() 670 { 671 return this.oosEmail; 672 } 673 674 678 public void setOosEmail(String oosEmail) 679 { 680 this.oosEmail = oosEmail; 681 } 682 683 687 public String getAccessType() 688 { 689 return this.accessType; 690 } 691 692 696 public void setAccessType(String accessType) 697 { 698 this.accessType = accessType; 699 } 700 701 705 public String getAuthenticatorClassName() 706 { 707 return this.authenticatorClassName; 708 } 709 710 714 public void setAuthenticatorClassName(String authenticatorClassName) 715 { 716 this.authenticatorClassName = authenticatorClassName; 717 } 718 719 723 public HashMap getAuthenticatorParams() 724 { 725 return this.authenticatorParams; 726 } 727 728 732 public void setAuthenticatorParams(HashMap authenticatorParams) 733 { 734 this.authenticatorParams = authenticatorParams; 735 } 736 737 741 public String getOperator() 742 { 743 return this.operator; 744 } 745 746 750 public void setOperator(String operator) 751 { 752 this.operator = operator; 753 } 754 755 759 public String getLanguage() 760 { 761 return this.language; 762 } 763 764 768 public void setLanguage(String language) 769 { 770 if (language != null) 771 { 772 if (language.equals("English") == true) 773 { 774 setLocale("en_US"); 775 } 776 else if (language.equals("French") == true) 777 { 778 setLocale("fr_FR"); 779 } 780 else if (language.equals("German") == true) 781 { 782 setLocale("de_DE"); 783 } 784 else if (language.equals("Spanish") == true) 785 { 786 setLocale("es_ES"); 787 } 788 else if (language.equals("Dutch") == true) 789 { 790 setLocale("nl_BE"); 791 } 792 else if (language.equals("Italian") == true) 793 { 794 setLocale("it_IT"); 795 } 796 } 797 798 this.language = language; 799 } 800 801 805 public String getClientType() 806 { 807 return this.clientType; 808 } 809 810 814 public void setClientType(String clientType) 815 { 816 this.clientType = clientType; 817 } 818 819 823 public String getLocale() 824 { 825 return this.locale; 826 } 827 828 832 public void setLocale(String locale) 833 { 834 this.locale = locale; 835 } 836 837 private long lastLoaded = 0L; 838 private File file; 839 840 841 private ContactCenterAuthenticatorInterface validatorObject; 842 843 844 private String customer; 845 846 847 private HashMap pagesParams = new HashMap(); 848 849 850 private HashMap userParams = new HashMap(); 851 852 853 private boolean active = true; 854 855 856 private boolean checkOperatorAvailability = false; 857 858 859 private String oosEmail; 860 861 862 private String accessType; 863 864 865 private String authenticatorClassName; 866 867 868 private HashMap authenticatorParams = new HashMap(); 869 870 871 private String operator; 872 873 874 private String language; 875 876 877 private String clientType; 878 879 880 private String locale; 881 882 } | Popular Tags |