1 10 package org.mmbase.applications.editwizard; 11 12 import org.mmbase.bridge.Cloud; 13 import java.util.*; 14 import org.mmbase.applications.dove.Dove; 15 import org.mmbase.util.logging.*; 16 import org.mmbase.util.Casting; 17 import org.w3c.dom.*; 18 19 20 37 public class WizardDatabaseConnector { 38 39 private static final Logger log = Logging.getLoggerInstance(WizardDatabaseConnector.class); 41 42 int didcounter=1; 43 private Cloud userCloud = null; 44 45 48 public WizardDatabaseConnector(){ 49 } 50 51 56 public void setUserInfo(Cloud cloud) { 57 userCloud=cloud; 58 } 59 60 65 public void tagDataNodes(Document data) { 66 didcounter = 1; 67 tagDataNode(data.getDocumentElement()); 68 } 69 70 74 public void tagDataNode(Node node) { 75 NodeList nodes = Utils.selectNodeList(node, ".|.//*"); 76 didcounter = Utils.tagNodeList(nodes, "did", "d", didcounter); 77 82 convertBooleanToInt(node); 83 } 84 85 94 95 Collection loadRelations(Node object, String objectNumber, Node loadAction) throws WizardException { 96 NodeList allRelations = Utils.selectNodeList(loadAction, ".//relation"); 98 99 if (log.isDebugEnabled()) { 100 log.debug("All relations " + Utils.getXML(allRelations) + " adding to " + Utils.getXML(object)); 101 } 102 for (int i = 0; i < allRelations.getLength(); i++) { 104 Node relation = allRelations.item(i); 105 NodeList objects = Utils.selectNodeList(relation, "object"); 107 if (objects.getLength() == 0) { 108 relation.appendChild(relation.getOwnerDocument().createElement("object")); 109 } 110 } 111 NodeList relations = Utils.selectNodeList(loadAction, "relation"); 113 if (relations.getLength() > 0) { 115 return getRelations(object, objectNumber, relations); 116 } else { 117 return new ArrayList(); 118 } 119 120 } 121 122 131 public Document load(Node schema, String objectNumber) throws WizardException { 132 Document data = Utils.parseXML("<data />"); 134 135 log.debug("Loading: " + objectNumber); 137 138 NodeList fieldstoload = Utils.selectNodeList(schema, "action[@type='load']/field"); 140 Node object=null; 141 if (fieldstoload == null || fieldstoload.getLength() == 0) { 142 object = getData(data.getDocumentElement(), objectNumber); 143 } else { 144 object = getData(data.getDocumentElement(), objectNumber, fieldstoload); 145 } 146 147 Node loadAction = Utils.selectSingleNode(schema, "action[@type='load']"); 149 if (loadAction != null) { 150 loadRelations(object, objectNumber, loadAction); 151 } 152 tagDataNodes(data); 153 return data; 154 } 155 156 157 164 public Node getConstraints(String objecttype) throws WizardException { 165 ConnectorCommand cmd = new ConnectorCommandGetConstraints(objecttype); 167 fireCommand(cmd); 168 169 if (!cmd.hasError()) { 170 Node result = cmd.getResponseXML().getFirstChild().cloneNode(true); 172 return result; 173 } else { 174 throw new WizardException("Could not obtain constraints for " + objecttype + " : " + cmd.getError()); 175 } 176 } 177 178 184 public Node getList(Node query) throws WizardException { 185 ConnectorCommand cmd = new ConnectorCommandGetList(query); 187 fireCommand(cmd); 188 189 if (!cmd.hasError()) { 190 if (log.isDebugEnabled()) log.debug(Utils.getSerializedXML(cmd.getResponseXML())); 192 Node result = cmd.getResponseXML().cloneNode(true); 193 return result; 194 } else { 195 throw new WizardException("Could not get list : " + cmd.getError()); 196 } 197 } 198 199 207 public Node getData(Node targetNode, String objectnumber) throws WizardException { 208 return getData(targetNode, objectnumber, null); 209 } 210 211 220 public Node getData(Node targetNode, String objectnumber, NodeList restrictions) throws WizardException { 221 Node objectNode = getDataNode(targetNode.getOwnerDocument(), objectnumber, restrictions); 223 targetNode.appendChild(objectNode); 225 return objectNode; 226 } 227 228 237 public Node getDataNode(Document document, String objectnumber, NodeList restrictions) throws WizardException { 238 ConnectorCommandGetData cmd = new ConnectorCommandGetData(objectnumber, restrictions); 240 fireCommand(cmd); 241 242 if (!cmd.hasError()) { 243 Node objectNode = Utils.selectSingleNode(cmd.getResponseXML(), "/*/object[@number='" + objectnumber + "']"); 245 if (document != null ) { 247 objectNode = document.importNode(objectNode.cloneNode(true),true); 249 tagDataNode(objectNode); 250 } 251 return objectNode; 252 } else { 253 throw new WizardException("Could not obtain object " + objectnumber + " : " + cmd.getError()); 254 } 255 } 256 257 264 public void getRelations(Node targetNode, String objectnumber) throws WizardException { 265 getRelations(targetNode, objectnumber, null); 266 } 267 268 276 public Collection getRelations(Node targetNode, String objectNumber, NodeList queryRelations) throws WizardException { 277 278 ConnectorCommandGetRelations cmd = new ConnectorCommandGetRelations(objectNumber, queryRelations); 280 fireCommand(cmd); 281 if (!cmd.hasError()) { 282 NodeList relations = Utils.selectNodeList(cmd.getResponseXML(), "/*/object/relation"); 283 for (int i = 0; i < relations.getLength(); i++) { 284 tagDataNode(relations.item(i)); 285 } 286 return Utils.appendNodeList(relations, targetNode); 287 } else { 289 throw new WizardException("Could not ontain relations for " + objectNumber + " : " + cmd.getError()); 290 } 291 292 } 293 294 302 public Node getNew(Node targetNode, String objecttype) throws WizardException { 303 ConnectorCommandGetNew cmd = new ConnectorCommandGetNew(objecttype); 305 fireCommand(cmd); 306 307 if (!cmd.hasError()) { 308 if (targetNode == null) { 309 throw new WizardException("No targetNode found"); 310 } 311 Node objectNode = targetNode.getOwnerDocument().importNode(Utils.selectSingleNode(cmd.getResponseXML(), "/*/object[@type='"+objecttype+"']").cloneNode(true), true); 312 tagDataNode(objectNode); 313 targetNode.appendChild(objectNode); 314 return objectNode; 315 } else { 316 throw new WizardException("Could not create new object of type " + objecttype + " : " + cmd.getError()); 317 } 318 } 319 320 332 public Node getNewRelation(Node targetNode, String role, 333 String sourceObjectNumber, String sourceType, 334 String destinationObjectNumber, String destinationType, String createDir) throws WizardException { 335 ConnectorCommandGetNewRelation cmd = new ConnectorCommandGetNewRelation(role, sourceObjectNumber, sourceType, destinationObjectNumber, destinationType, createDir); 337 fireCommand(cmd); 338 339 if (!cmd.hasError()) { 340 Node objectNode = targetNode.getOwnerDocument().importNode(Utils.selectSingleNode(cmd.getResponseXML(), "/*/relation").cloneNode(true), true); 341 tagDataNode(objectNode); 342 targetNode.appendChild(objectNode); 343 return objectNode; 344 } else { 345 throw new WizardException("Could not create new relation, role=" + role + 346 ", source=" + sourceObjectNumber + " (" + sourceType + ")" + 347 ", destination=" + destinationObjectNumber + " ("+destinationType+")" + 348 " : " + cmd.getError()); 349 } 350 } 351 352 362 private void fillObjectFields(Document data, Node targetParentNode, Node objectDef, 363 Node objectNode, Map params, int createorder) throws WizardException { 364 NodeList fields = Utils.selectNodeList(objectDef, "field"); 366 for (int i=0; i<fields.getLength(); i++) { 367 Node field = fields.item(i); 368 String fieldname = Utils.getAttribute(field, "name"); 369 Node datafield = Utils.selectSingleNode(objectNode, "field[@name='"+fieldname+"']"); 371 if (datafield==null) { 372 String type = Utils.getAttribute(objectDef, "type"); 374 throw new WizardException("field " + fieldname + " does not exist in '" + type + "'"); 375 } 376 String value = Utils.getText(field); 377 378 params.put("pos",createorder+""); 381 Node parent = data.getDocumentElement(); 382 if (log.isDebugEnabled()) log.debug("parent="+parent.toString()); 383 value = Utils.transformAttribute(parent,value,false,params); 384 params.remove("pos"); 385 if (value == null) { 386 value = ""; 387 } 388 if (datafield != null) { 389 Utils.storeText(datafield, value, params); } else { 392 Node newfield = targetParentNode.getOwnerDocument().importNode(field.cloneNode(true), true); 394 objectNode.appendChild(newfield); 395 Utils.storeText(newfield, value, params); } 397 } 398 } 399 400 409 public Node createObject(Document data, Node targetParentNode, Node objectDef, Map params) throws WizardException { 410 return createObject(data, targetParentNode, objectDef, params, 1); 411 } 412 413 445 public Node createObject(Document data, Node targetParentNode, Node objectDef, Map params, int createorder) throws WizardException { 446 447 String context = (String )params.get("context"); 448 449 if (objectDef == null) throw new WizardException("No 'objectDef' given"); 451 String nodeName = objectDef.getNodeName(); 452 453 455 if (nodeName.equals("action")) { 456 NodeList objectdefs = Utils.selectNodeList(objectDef, "object|relation"); 457 Node firstobject = null; 458 for (int i=0; i < objectdefs.getLength(); i++) { 459 firstobject = createObject(data, targetParentNode, objectdefs.item(i), params); 460 } 461 log.debug("This is an action"); return firstobject; 463 } 464 465 NodeList relations; 466 Node objectNode; 467 468 if (nodeName.equals("relation")) { 469 objectNode = targetParentNode; 471 if (objectNode == null) { 472 throw new WizardException("Could not find a parent node for relation " + Utils.stringFormatted(objectDef)); 473 } 474 relations = Utils.selectNodeList(objectDef, "."); 475 } else if (nodeName.equals("object")) { 476 String objectType = Utils.getAttribute(objectDef, "type"); 477 if (objectType.equals("")) throw new WizardException("No 'type' attribute used in " + Utils.stringFormatted(objectDef)); 478 if (log.isDebugEnabled()) log.debug("Create object of type " + objectType); 479 objectNode = getNew(targetParentNode, objectType); 481 if (context!=null && !context.equals("")) { 482 Utils.setAttribute(objectNode, "context", context); 483 } 484 fillObjectFields(data,targetParentNode,objectDef,objectNode,params,createorder); 485 relations = Utils.selectNodeList(objectDef, "relation"); 486 } else { 487 throw new WizardException("Can only create with 'action' 'object' or 'relation' nodes"); 488 } 489 490 491 Node lastCreatedRelation = null; 493 494 for (int i=0; i < relations.getLength(); i++) { 495 Node relation = relations.item(i); 496 String role = Utils.getAttribute(relation, "role", "related"); 498 String snumber = Utils.getAttribute(objectNode, "number"); 499 String stype = Utils.getAttribute(objectNode, "type"); 500 String dnumber = Utils.getAttribute(relation, "destination", null); 503 dnumber=Utils.transformAttribute(data.getDocumentElement(), dnumber, false, params); 504 String dtype = ""; 505 506 String createDir = Utils.getAttribute(relation, Dove.ELM_CREATEDIR, "either"); 507 Node inside_object = null; 508 Node inside_objectdef = Utils.selectSingleNode(relation, "object"); 509 if (dnumber != null) { 510 try { 514 inside_object = getDataNode(targetParentNode.getOwnerDocument(), dnumber, null); 515 } catch (Exception e) { 516 throw new WizardException("Could not load object (" + dnumber + "). Message: " + Logging.stackTrace(e)); 517 } 518 Utils.setAttribute(inside_object, "already-exists", "true"); 520 dtype = Utils.getAttribute(inside_object, "type", ""); 522 } else { 523 dtype=Utils.getAttribute(relation, "destinationtype", ""); 525 if (dtype.equals("")) { 527 if (inside_objectdef!=null) { 528 dtype = Utils.getAttribute(inside_objectdef, "type"); 529 } 530 } 531 } 532 533 Node relationNode = getNewRelation(objectNode, role, snumber, stype, dnumber, dtype,createDir); 534 if (context!=null && !context.equals("")) { 535 Utils.setAttribute(relationNode, "context", context); 536 } 537 fillObjectFields(data,targetParentNode,relation,relationNode,params,createorder); 538 539 tagDataNode(relationNode); 540 lastCreatedRelation = relationNode; 541 542 if (inside_object==null) { 543 if (inside_objectdef==null) { 545 inside_object=data.createElement("object"); 548 ((Element)inside_object).setAttribute("number",""); 549 ((Element)inside_object).setAttribute("type",Utils.getAttribute(relation, "destinationtype", "")); 550 ((Element)inside_object).setAttribute("disposable","true"); 551 } else { 552 inside_object = createObject(data,relationNode, inside_objectdef, params); 553 dnumber = Utils.getAttribute(inside_object, "number"); 554 ((Element)relationNode).setAttribute("destination",dnumber); 555 } 556 } 557 relationNode.appendChild(inside_object); 558 } 559 if (nodeName.equals("relation")) { 560 return lastCreatedRelation; 561 } else { 562 return objectNode; 563 } 564 } 565 566 572 private Element sendCommand(Element cmd, Map binaries) throws WizardException { 573 Dove dove = new Dove(Utils.emptyDocument()); 574 Element results = dove.executeRequest(cmd, userCloud, binaries); 575 NodeList errors = Utils.selectNodeList(results, ".//error"); 576 if (errors.getLength() > 0){ 577 StringBuffer errorMessage = new StringBuffer ("Errors received from MMBase Dove servlet: "); 578 for (int i = 0; i < errors.getLength(); i++){ 579 errorMessage.append(Utils.getText(errors.item(i))).append("\n"); 580 } 581 throw new WizardException(errorMessage.toString()); 582 } 583 return results; 584 } 585 586 590 private Document fireCommand(ConnectorCommand command) throws WizardException { 591 List tmp = new Vector(); 592 tmp.add(command); 593 return fireCommandList(tmp); 594 } 595 596 600 private Document fireCommandList(List commands) throws WizardException { 601 Document req = Utils.parseXML("<request/>"); 604 Element docel = req.getDocumentElement(); 605 606 Iterator i = commands.iterator(); 607 while (i.hasNext()) { 608 ConnectorCommand cmd = (ConnectorCommand) i.next(); 609 docel.appendChild(req.importNode(cmd.getCommandXML().getDocumentElement().cloneNode(true), true)); 610 } 611 612 String res=""; 613 614 Element results=sendCommand(docel,null); 615 616 Document response = Utils.emptyDocument(); 617 response.appendChild(response.importNode(results,true)); 618 619 i = commands.iterator(); 621 while (i.hasNext()) { 622 ConnectorCommand cmd = (ConnectorCommand) i.next(); 623 624 Node resp = Utils.selectSingleNode(response, "/*/"+cmd.getName() +"[@id]"); 626 if (resp!=null) { 627 cmd.setResponse(resp); 629 } else { 630 log.error("Could NOT store response "+cmd.getId()+" in a ConnectorCommand"); 631 log.error(cmd.getResponseXML()); 632 } 633 } 634 return response; 635 } 636 637 645 public Element put(Document originalData, Document newData, Map binaries) throws WizardException { 646 Node putcmd =getPutData(originalData, newData); 647 return sendCommand(putcmd.getOwnerDocument().getDocumentElement(), binaries); 648 } 649 650 657 protected void convertIntToDateTime(Node rootNode) { 658 NodeList nodes = Utils.selectNodeList(rootNode, ".//field[@type='datetime']"); 660 for (int i = 0; i < nodes.getLength(); i++) { 661 Node node = nodes.item(i); 662 String value = Utils.getText(node); 663 if (!"".equals(value)) { 664 value = Casting.toString(Casting.toDate(value)); 665 Utils.storeText(node, value); 666 } 667 } 668 } 669 670 677 protected void convertIntToBoolean(Node rootNode) { 678 NodeList nodes = Utils.selectNodeList(rootNode, ".//field[@type='boolean']"); 680 for (int i = 0; i < nodes.getLength(); i++) { 681 Node node = nodes.item(i); 682 String value = Utils.getText(node); 683 if (!"".equals(value)) { 684 int boolAsInt = Casting.toInt(value); 685 value = Casting.toString(Boolean.valueOf(boolAsInt > 0)); 686 Utils.storeText(node, value); 687 } 688 } 689 } 690 691 698 protected void convertDateTimeToInt(Node rootNode) { 699 NodeList nodes = Utils.selectNodeList(rootNode, ".//field[@type='datetime']"); 701 for (int i = 0; i < nodes.getLength(); i++) { 702 Node node = nodes.item(i); 703 String value = Utils.getText(node); 704 if (!"".equals(value)) { 705 long time = Casting.toDate(value).getTime(); 706 value = time == -1 ? "-1" : "" + time / 1000; 707 Utils.storeText(node, value); 708 } 709 } 710 } 711 712 719 protected void convertBooleanToInt(Node rootNode) { 720 NodeList nodes = Utils.selectNodeList(rootNode, ".//field[@type='boolean']"); 722 for (int i = 0; i < nodes.getLength(); i++) { 723 Node node = nodes.item(i); 724 String value = Utils.getText(node); 725 if (!"".equals(value)) { 726 if (Casting.toBoolean(value)) { 727 value = "1"; 728 } else { 729 value = "0"; 730 } 731 Utils.storeText(node, value); 732 } 733 } 734 } 735 736 743 public Node getPutData(Document originalData, Document newData) throws WizardException { 744 Document workDoc = Utils.emptyDocument(); 745 workDoc.appendChild(workDoc.importNode(newData.getDocumentElement().cloneNode(true), true)); 746 747 Node workRoot = workDoc.getDocumentElement(); 748 749 Document req = Utils.parseXML("<request><put id=\"put\"><original/><new/></put></request>"); 751 752 Node reqorig = Utils.selectSingleNode(req, "/request/put/original"); 753 Node reqnew = Utils.selectSingleNode(req, "/request/put/new"); 754 755 NodeList disposables = Utils.selectNodeList(workRoot, ".//*[@disposable or @destination='-']"); 758 for (int i=0; i<disposables.getLength(); i++) { 759 Node disp = disposables.item(i); 760 disp.getParentNode().removeChild(disp); 761 } 762 763 makeFlat(originalData, reqorig, ".//object", "field"); 765 makeFlat(originalData, reqorig, ".//relation", "field"); 766 767 makeFlat(workRoot, reqnew, ".//object", "field"); 769 makeFlat(workRoot, reqnew, ".//relation", "field"); 770 771 777 convertIntToBoolean(reqorig); 778 convertIntToBoolean(reqnew); 779 780 NodeList nodes = Utils.selectNodeList(reqnew, ".//relation|.//object[not(@disposable)]"); 782 for (int i=0; i<nodes.getLength(); i++) { 783 Node node = nodes.item(i); 784 String nodename = node.getNodeName(); 785 786 String did = Utils.getAttribute(node, "did", ""); 787 Node orignode = Utils.selectSingleNode(reqorig, ".//*[@did='"+did+"' and not(@already-exists)]"); 788 789 if (orignode!=null) { 792 if (nodename.equals("relation")) { 794 String destination = Utils.getAttribute(node,"destination", ""); 795 String olddestination = Utils.getAttribute(orignode,"destination", ""); 796 if (!destination.equals(olddestination) && !destination.equals("")) { 797 Utils.setAttribute(node, "status", "changed"); 799 Utils.setAttribute(node, "olddestination", olddestination); 801 } else { 802 boolean valueschanged = checkRelationFieldsChanged(orignode, node); 805 806 if (valueschanged) { 807 Utils.setAttribute(node,"status", "fieldschangedonly"); 810 } else { 811 node.getParentNode().removeChild(node); 814 orignode.getParentNode().removeChild(orignode); 815 } 816 } 817 } 818 if (nodename.equals("object")) { 819 boolean different = isDifferent(node, orignode); 822 if (!different) { 823 node.getParentNode().removeChild(node); 825 Utils.setAttribute(orignode, "repository", "true"); 826 } else { 827 NodeList fields=Utils.selectNodeList(node,"field"); 829 for (int j=0; j<fields.getLength(); j++) { 830 Node origfield = Utils.selectSingleNode(orignode, "field[@name='"+Utils.getAttribute(fields.item(j), "name")+"']"); 831 if (origfield!=null) { 832 if (!isDifferent(fields.item(j), origfield)) { 833 fields.item(j).getParentNode().removeChild(fields.item(j)); 835 origfield.getParentNode().removeChild(origfield); 836 } 837 } 838 } 839 Utils.setAttribute(orignode, "repository", "false"); 840 } 841 } 842 } else { 843 String already_exists = Utils.getAttribute(node, "already-exists", "false"); 848 if (!already_exists.equals("true")) { 849 Utils.setAttribute(node, "status", "new"); 851 852 NodeList fields=Utils.selectNodeList(node,"field"); 856 for (int j=0; j<fields.getLength(); j++) { 857 if ("".equals(Utils.getText(fields.item(j)))) { 862 fields.item(j).getParentNode().removeChild(fields.item(j)); 863 } 864 } 865 866 } else { 867 node.getParentNode().removeChild(node); 869 } 870 } 871 } 872 873 NodeList repnodes = Utils.selectNodeList(reqorig, ".//relation[@repository='true']|.//object[@repository='true']"); 875 for (int i=0; i<repnodes.getLength(); i++) { 876 Node repnode = repnodes.item(i); 877 repnode.getParentNode().removeChild(repnode); 878 } 879 880 NodeList orignodes = Utils.selectNodeList(reqorig, ".//relation|.//object"); 882 for (int i=0; i<orignodes.getLength(); i++) { 883 Node orignode = orignodes.item(i); 884 String nodenumber = Utils.getAttribute(orignode, "number", ""); 885 Node node = Utils.selectSingleNode(reqnew, ".//*[@number='"+nodenumber+"']"); 886 if (node==null) { 887 Node newnode = req.createElement(orignode.getNodeName()); 890 Utils.copyAllAttributes(orignode, newnode); 891 Utils.setAttribute(newnode, "status", "delete"); 892 reqnew.appendChild(newnode); 893 } 894 } 895 896 NodeList rels = Utils.selectNodeList(req, "//new/relation[@status='changed']"); 902 for (int i=0; i<rels.getLength(); i++) { 903 Node rel = rels.item(i); 904 Node newrel = rel.cloneNode(true); 905 906 Utils.setAttribute(rel, "destination", Utils.getAttribute(rel, "olddestination", "")); 908 rel.getAttributes().removeNamedItem("olddestination"); 909 Utils.setAttribute(rel, "status", "delete"); 910 911 newrel.getAttributes().removeNamedItem("number"); 913 newrel.getAttributes().removeNamedItem("olddestination"); 914 Utils.setAttribute(newrel, "status", "new"); 915 String role = Utils.getAttribute(newrel, "role", "related"); 916 Utils.setAttribute(newrel, "role", role); 917 918 NodeList flds = Utils.selectNodeList(rel, "field"); 920 Utils.appendNodeList(flds,rel); 921 922 rel.getParentNode().appendChild(newrel); 924 } 925 926 rels = Utils.selectNodeList(req, "//new/relation[@status='fieldschangedonly']"); 931 for (int i=0; i<rels.getLength(); i++) { 932 Node rel = rels.item(i); 933 String number = Utils.getAttribute(rel,"number",""); 934 Node origrel = Utils.selectSingleNode(req, "//original/relation[@number='"+number+"']"); 935 if (!number.equals("") && origrel!=null) { 936 convertRelationIntoObject(origrel); 938 convertRelationIntoObject(rel); 939 } 940 } 941 return req.getDocumentElement(); 942 } 943 944 951 public void makeFlat(Node sourcenode, Node targetParentNode, String xpath, String allowedChildrenXpath) { 952 NodeList list = Utils.selectNodeList(sourcenode, xpath); 953 for (int i=0; i<list.getLength(); i++) { 954 Node item = list.item(i); 955 Node newnode = targetParentNode.getOwnerDocument().importNode(item, false); 956 targetParentNode.appendChild(newnode); 957 cloneOneDeep(item, newnode, allowedChildrenXpath); 958 } 959 } 960 961 968 public void cloneOneDeep(Node sourcenode, Node targetParentNode, String allowedChildrenXpath) { 969 NodeList list = Utils.selectNodeList(sourcenode, allowedChildrenXpath); 970 Utils.appendNodeList(list, targetParentNode); 971 } 972 973 980 public boolean isDifferent(Node node1, Node node2) { 981 boolean res = false; 983 if (node1.getChildNodes().getLength() != node2.getChildNodes().getLength()) { 984 return true; 986 } 987 if (node1.getNodeType() != node2.getNodeType()) { 989 return true; 990 } 991 if ((node1.getNodeType() == Node.TEXT_NODE) || (node1.getNodeType() == Node.CDATA_SECTION_NODE)) { 992 String s1 = node1.getNodeValue(); 993 String s2 = node2.getNodeValue(); 994 if (!s1.equals(s2)) return true; 995 } 996 NodeList kids = node1.getChildNodes(); 998 NodeList kids2 = node2.getChildNodes(); 999 1000 for (int i=0; i<kids.getLength(); i++) { 1001 if (isDifferent(kids.item(i), kids2.item(i))) { 1002 return true; 1003 } 1004 } 1005 return false; 1006 } 1007 1008 1016 private boolean checkRelationFieldsChanged(Node origrel, Node rel) throws WizardException{ 1017 NodeList origflds = Utils.selectNodeList(origrel, "field"); 1018 NodeList newflds = Utils.selectNodeList(rel, "field"); 1019 Document tmp = Utils.parseXML("<tmp><n1><r/></n1><n2><r/></n2></tmp>"); 1020 1021 Node n1 = Utils.selectSingleNode(tmp, "/tmp/n1/r"); 1022 Node n2 = Utils.selectSingleNode(tmp, "/tmp/n2/r"); 1023 1024 Utils.appendNodeList(origflds,n1); 1025 Utils.appendNodeList(newflds,n2); 1026 1027 return isDifferent(n1,n2); 1028 } 1029 1030 1036 private void convertRelationIntoObject(Node rel) { 1037 1038 Node obj = rel.getOwnerDocument().createElement("object"); 1039 1040 List except = new Vector(); 1042 except.add("destination"); 1043 except.add("source"); 1044 except.add("role"); 1045 except.add("status"); Utils.copyAllAttributes(rel, obj, except); 1047 1048 NodeList flds = Utils.selectNodeList(rel, "field"); 1050 1051 Utils.appendNodeList(flds, obj); 1052 1053 rel.getParentNode().replaceChild(obj, rel); 1055 } 1056} 1057 | Popular Tags |