Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java @ 464:70df44021a9f
Next step of changing the concept how to use the user interface. Adapted namespaces and replaced FISArtifact with a ProxyArtifact.
gnv-artifacts/trunk@525 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Sat, 09 Jan 2010 17:55:45 +0000 |
parents | 3ddc22aab764 |
children | b7bb66440cc8 |
comparison
equal
deleted
inserted
replaced
463:07672838fa5f | 464:70df44021a9f |
---|---|
19 import org.w3c.dom.Element; | 19 import org.w3c.dom.Element; |
20 import org.w3c.dom.Node; | 20 import org.w3c.dom.Node; |
21 import org.w3c.dom.NodeList; | 21 import org.w3c.dom.NodeList; |
22 | 22 |
23 import de.intevation.artifactdatabase.Config; | 23 import de.intevation.artifactdatabase.Config; |
24 import de.intevation.artifactdatabase.XMLUtils; | |
25 import de.intevation.artifacts.ArtifactNamespaceContext; | |
24 import de.intevation.artifacts.CallMeta; | 26 import de.intevation.artifacts.CallMeta; |
25 import de.intevation.gnv.artifacts.GNVArtifactBase; | 27 import de.intevation.gnv.artifacts.GNVArtifactBase; |
26 import de.intevation.gnv.artifacts.cache.CacheFactory; | 28 import de.intevation.gnv.artifacts.cache.CacheFactory; |
27 import de.intevation.gnv.artifacts.ressource.RessourceFactory; | 29 import de.intevation.gnv.artifacts.ressource.RessourceFactory; |
28 import de.intevation.gnv.geobackend.base.Result; | 30 import de.intevation.gnv.geobackend.base.Result; |
35 import de.intevation.gnv.state.describedata.MinMaxDescribeData; | 37 import de.intevation.gnv.state.describedata.MinMaxDescribeData; |
36 import de.intevation.gnv.state.describedata.NamedArrayList; | 38 import de.intevation.gnv.state.describedata.NamedArrayList; |
37 import de.intevation.gnv.state.describedata.NamedCollection; | 39 import de.intevation.gnv.state.describedata.NamedCollection; |
38 import de.intevation.gnv.state.describedata.SingleValueDescribeData; | 40 import de.intevation.gnv.state.describedata.SingleValueDescribeData; |
39 import de.intevation.gnv.state.exception.StateException; | 41 import de.intevation.gnv.state.exception.StateException; |
40 import de.intevation.gnv.utils.ArtifactXMLUtilities; | |
41 import de.intevation.gnv.utils.InputValidator; | 42 import de.intevation.gnv.utils.InputValidator; |
42 | 43 |
43 /** | 44 /** |
44 * @author Tim Englich <tim.englich@intevation.de> | 45 * @author Tim Englich <tim.englich@intevation.de> |
45 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> | 46 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> |
517 */ | 518 */ |
518 public void describe(Document document, Node rootNode, CallMeta callMeta,String uuid) { | 519 public void describe(Document document, Node rootNode, CallMeta callMeta,String uuid) { |
519 log.debug("StateBase.describe"); | 520 log.debug("StateBase.describe"); |
520 Collection<Object> descibeData = this.getDescibeData(uuid); | 521 Collection<Object> descibeData = this.getDescibeData(uuid); |
521 if (descibeData != null) { | 522 if (descibeData != null) { |
522 ArtifactXMLUtilities xmlutilities = new ArtifactXMLUtilities(); | |
523 Iterator<Object> it = descibeData.iterator(); | 523 Iterator<Object> it = descibeData.iterator(); |
524 Node staticNode = xmlutilities.createArtifactElement(document, | 524 |
525 "static"); | 525 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( |
526 Node dynamic = xmlutilities.createArtifactElement(document, | 526 document, |
527 "dynamic"); | 527 ArtifactNamespaceContext.NAMESPACE_URI, |
528 ArtifactNamespaceContext.NAMESPACE_PREFIX | |
529 ); | |
530 Node staticNode = creator.create("static"); | |
531 Node dynamic = creator.create("dynamic"); | |
532 | |
528 rootNode.appendChild(staticNode); | 533 rootNode.appendChild(staticNode); |
529 rootNode.appendChild(dynamic); | 534 rootNode.appendChild(dynamic); |
535 | |
536 XMLUtils.ElementCreator xCreator = new XMLUtils.ElementCreator( | |
537 document, | |
538 XMLUtils.XFORM_URL, | |
539 XMLUtils.XFORM_PREFIX | |
540 ); | |
541 | |
530 while (it.hasNext()) { | 542 while (it.hasNext()) { |
531 Object o = it.next(); | 543 Object o = it.next(); |
532 if ((!it.hasNext() && dataName != null)) { | 544 if ((!it.hasNext() && dataName != null)) { |
533 appendToDynamicNode(document, dynamic, callMeta, o); | 545 appendToDynamicNode( |
546 xCreator, document, dynamic, callMeta, o); | |
534 } | 547 } |
535 else { | 548 else { |
536 appendToStaticNode(document, staticNode, callMeta, o); | 549 appendToStaticNode( |
550 xCreator, document, staticNode, callMeta, o); | |
537 } | 551 } |
538 } | 552 } |
539 } | 553 } |
540 } | 554 } |
541 | 555 |
542 | 556 |
543 protected void appendToStaticNode( | 557 protected void appendToStaticNode( |
544 Document document, | 558 XMLUtils.ElementCreator creator, |
545 Node staticNode, | 559 Document document, |
546 CallMeta callMeta, | 560 Node staticNode, |
547 Object o | 561 CallMeta callMeta, |
562 Object o | |
548 ) { | 563 ) { |
549 if (o instanceof Collection<?>) { | 564 if (o instanceof Collection<?>) { |
550 String name = null; | 565 String name = null; |
551 boolean multiselect = false; | 566 boolean multiselect = false; |
552 if (o instanceof NamedCollection<?>) { | 567 if (o instanceof NamedCollection<?>) { |
556 } else { | 571 } else { |
557 Object[] names = this.inputValueNames.toArray(); | 572 Object[] names = this.inputValueNames.toArray(); |
558 name = names[names.length - 1].toString(); | 573 name = names[names.length - 1].toString(); |
559 } | 574 } |
560 | 575 |
561 log.debug("Name of attribute: " + name); | 576 Element selectNode = creator.create(multiselect?"select":"select1"); |
562 Element selectNode = ArtifactXMLUtilities.createXFormElement( | 577 creator.addAttr(selectNode, "ref", name); |
563 document, multiselect ? "select" : "select1"); | 578 |
564 selectNode.setAttribute("ref", name); | 579 Element lableNode = creator.create("label"); |
565 | |
566 Element lableNode = ArtifactXMLUtilities.createXFormElement( | |
567 document, "label"); | |
568 lableNode.setTextContent(RessourceFactory.getInstance() | 580 lableNode.setTextContent(RessourceFactory.getInstance() |
569 .getRessource(callMeta.getLanguages(), name, name)); | 581 .getRessource(callMeta.getLanguages(), name, name)); |
570 Element choiceNode = ArtifactXMLUtilities.createXFormElement( | 582 Element choiceNode = creator.create("choices"); |
571 document, "choices"); | |
572 | 583 |
573 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o; | 584 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o; |
574 Iterator<KeyValueDescibeData> resultIt = values.iterator(); | 585 Iterator<KeyValueDescibeData> resultIt = values.iterator(); |
575 while (resultIt.hasNext()) { | 586 while (resultIt.hasNext()) { |
576 KeyValueDescibeData result = resultIt.next(); | 587 KeyValueDescibeData result = resultIt.next(); |
577 | 588 |
578 if (result.isSelected()) { | 589 if (result.isSelected()) { |
579 Element itemNode = ArtifactXMLUtilities.createXFormElement( | 590 Element itemNode = creator.create("item"); |
580 document, "item"); | 591 |
581 | 592 creator.addAttr(itemNode, "selected", "true"); |
582 itemNode.setAttribute("selected", "true"); | 593 |
583 | 594 Element choiceLableNode = creator.create("label"); |
584 Element choiceLableNode = | |
585 ArtifactXMLUtilities.createXFormElement( | |
586 document, "label"); | |
587 choiceLableNode.setTextContent(result.getValue()); | 595 choiceLableNode.setTextContent(result.getValue()); |
588 itemNode.appendChild(choiceLableNode); | 596 itemNode.appendChild(choiceLableNode); |
589 | 597 |
590 Element choicValueNode = | 598 Element choiceValueNode = creator.create("value"); |
591 ArtifactXMLUtilities.createXFormElement( | 599 choiceValueNode.setTextContent("" + result.getKey()); |
592 document, "value"); | 600 itemNode.appendChild(choiceValueNode); |
593 choicValueNode.setTextContent("" + result.getKey()); | |
594 itemNode.appendChild(choicValueNode); | |
595 choiceNode.appendChild(itemNode); | 601 choiceNode.appendChild(itemNode); |
596 } | 602 } |
597 } | 603 } |
598 selectNode.appendChild(lableNode); | 604 selectNode.appendChild(lableNode); |
599 selectNode.appendChild(choiceNode); | 605 selectNode.appendChild(choiceNode); |
600 | 606 |
601 staticNode.appendChild(selectNode); | 607 staticNode.appendChild(selectNode); |
602 } | 608 } |
603 else if (o instanceof MinMaxDescribeData) { | 609 else if (o instanceof MinMaxDescribeData) { |
604 appendMinMaxDescribeData( | 610 appendMinMaxDescribeData( |
611 creator, | |
605 document, | 612 document, |
606 staticNode, | 613 staticNode, |
607 callMeta, | 614 callMeta, |
608 o); | 615 o); |
609 } | 616 } |
610 else if (o instanceof SingleValueDescribeData) { | 617 else if (o instanceof SingleValueDescribeData) { |
611 appendSingleValueDescribeData( | 618 appendSingleValueDescribeData( |
619 creator, | |
612 document, | 620 document, |
613 staticNode, | 621 staticNode, |
614 callMeta, | 622 callMeta, |
615 o); | 623 o); |
616 } | 624 } |
617 } | 625 } |
618 | 626 |
619 | 627 |
620 protected void appendToDynamicNode( | 628 protected void appendToDynamicNode( |
621 Document document, | 629 XMLUtils.ElementCreator creator, |
622 Node dynamicNode, | 630 Document document, |
623 CallMeta callMeta, | 631 Node dynamicNode, |
624 Object o | 632 CallMeta callMeta, |
633 Object o | |
625 ) { | 634 ) { |
626 if (o instanceof Collection<?>) { | 635 if (o instanceof Collection<?>) { |
627 String name = null; | 636 String name = null; |
628 boolean multiselect = false; | 637 boolean multiselect = false; |
629 if (o instanceof NamedCollection<?>) { | 638 if (o instanceof NamedCollection<?>) { |
631 name = nc.getName(); | 640 name = nc.getName(); |
632 multiselect = nc.isMultiSelect(); | 641 multiselect = nc.isMultiSelect(); |
633 } else { | 642 } else { |
634 Object[] names = this.inputValueNames.toArray(); | 643 Object[] names = this.inputValueNames.toArray(); |
635 name = names[names.length - 1].toString(); | 644 name = names[names.length - 1].toString(); |
636 } | 645 } |
637 | 646 |
638 Element selectNode = ArtifactXMLUtilities.createXFormElement( | 647 Element selectNode = creator.create(multiselect?"select":"select1"); |
639 document, multiselect ? "select" : "select1"); | 648 creator.addAttr(selectNode, "ref", name); |
640 selectNode.setAttribute("ref", name); | 649 |
641 | 650 Element lableNode = creator.create("label"); |
642 Element lableNode = ArtifactXMLUtilities.createXFormElement( | |
643 document, "label"); | |
644 lableNode.setTextContent(RessourceFactory.getInstance() | 651 lableNode.setTextContent(RessourceFactory.getInstance() |
645 .getRessource(callMeta.getLanguages(), name, name)); | 652 .getRessource(callMeta.getLanguages(), name, name)); |
646 Element choiceNode = ArtifactXMLUtilities.createXFormElement( | 653 Element choiceNode = creator.create("choices"); |
647 document, "choices"); | |
648 | 654 |
649 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o; | 655 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o; |
650 Iterator<KeyValueDescibeData> resultIt = values.iterator(); | 656 Iterator<KeyValueDescibeData> resultIt = values.iterator(); |
651 while (resultIt.hasNext()) { | 657 while (resultIt.hasNext()) { |
652 KeyValueDescibeData result = resultIt.next(); | 658 KeyValueDescibeData result = resultIt.next(); |
653 Element itemNode = ArtifactXMLUtilities.createXFormElement( | 659 Element itemNode = creator.create("item"); |
654 document, "item"); | |
655 | 660 |
656 if (result.isSelected()) { | 661 if (result.isSelected()) { |
657 itemNode.setAttribute("selected", "true"); | 662 itemNode.setAttribute("selected", "true"); |
658 } | 663 } |
659 | 664 |
660 Element choiceLableNode = | 665 Element choiceLableNode = creator.create("label"); |
661 ArtifactXMLUtilities.createXFormElement(document, "label"); | |
662 choiceLableNode.setTextContent(result.getValue()); | 666 choiceLableNode.setTextContent(result.getValue()); |
663 itemNode.appendChild(choiceLableNode); | 667 itemNode.appendChild(choiceLableNode); |
664 | 668 |
665 Element choicValueNode = ArtifactXMLUtilities.createXFormElement( | 669 Element choicValueNode = creator.create("value"); |
666 document, "value"); | |
667 choicValueNode.setTextContent("" + result.getKey()); | 670 choicValueNode.setTextContent("" + result.getKey()); |
668 itemNode.appendChild(choicValueNode); | 671 itemNode.appendChild(choicValueNode); |
669 choiceNode.appendChild(itemNode); | 672 choiceNode.appendChild(itemNode); |
670 } | 673 } |
671 selectNode.appendChild(lableNode); | 674 selectNode.appendChild(lableNode); |
673 | 676 |
674 dynamicNode.appendChild(selectNode); | 677 dynamicNode.appendChild(selectNode); |
675 } | 678 } |
676 else if (o instanceof MinMaxDescribeData) { | 679 else if (o instanceof MinMaxDescribeData) { |
677 appendMinMaxDescribeData( | 680 appendMinMaxDescribeData( |
681 creator, | |
678 document, | 682 document, |
679 dynamicNode, | 683 dynamicNode, |
680 callMeta, | 684 callMeta, |
681 o); | 685 o); |
682 } | 686 } |
683 else if (o instanceof SingleValueDescribeData) { | 687 else if (o instanceof SingleValueDescribeData) { |
684 appendSingleValueDescribeData( | 688 appendSingleValueDescribeData( |
689 creator, | |
685 document, | 690 document, |
686 dynamicNode, | 691 dynamicNode, |
687 callMeta, | 692 callMeta, |
688 o); | 693 o); |
689 } | 694 } |
690 } | 695 } |
691 | 696 |
692 | 697 |
693 protected void appendMinMaxDescribeData( | 698 protected void appendMinMaxDescribeData( |
694 Document document, | 699 XMLUtils.ElementCreator creator, |
695 Node node, | 700 Document document, |
696 CallMeta callMeta, | 701 Node node, |
697 Object o | 702 CallMeta callMeta, |
703 Object o | |
698 ) { | 704 ) { |
699 MinMaxDescribeData minMaxDescibeData = (MinMaxDescribeData) o; | 705 MinMaxDescribeData minMaxDescibeData = (MinMaxDescribeData) o; |
700 Object min = minMaxDescibeData.getMinValue(); | 706 Object min = minMaxDescibeData.getMinValue(); |
701 Object max = minMaxDescibeData.getMaxValue(); | 707 Object max = minMaxDescibeData.getMaxValue(); |
702 if (min instanceof GregorianCalendar) { | 708 if (min instanceof GregorianCalendar) { |
707 if (max instanceof GregorianCalendar) { | 713 if (max instanceof GregorianCalendar) { |
708 Date d = ((GregorianCalendar) max).getTime(); | 714 Date d = ((GregorianCalendar) max).getTime(); |
709 max = DateUtils.getPatternedDateAmer(d); | 715 max = DateUtils.getPatternedDateAmer(d); |
710 } | 716 } |
711 | 717 |
712 Element groupNode = ArtifactXMLUtilities.createXFormElement( | 718 Element groupNode = creator.create("group"); |
713 document, "group"); | 719 creator.addAttr(groupNode, "ref", minMaxDescibeData.getName()); |
714 groupNode.setAttribute("ref", minMaxDescibeData.getName()); | 720 Element groupNodeLableNode = creator.create("label"); |
715 Element groupNodeLableNode = | |
716 ArtifactXMLUtilities.createXFormElement(document, "label"); | |
717 groupNodeLableNode.setTextContent(RessourceFactory | 721 groupNodeLableNode.setTextContent(RessourceFactory |
718 .getInstance().getRessource( | 722 .getInstance().getRessource( |
719 callMeta.getLanguages(), | 723 callMeta.getLanguages(), |
720 minMaxDescibeData.getName(), | 724 minMaxDescibeData.getName(), |
721 minMaxDescibeData.getName())); | 725 minMaxDescibeData.getName())); |
722 groupNode.appendChild(groupNodeLableNode); | 726 groupNode.appendChild(groupNodeLableNode); |
723 | 727 |
724 Element inputMinNode = ArtifactXMLUtilities.createXFormElement( | 728 Element inputMinNode = creator.create("input"); |
725 document, "input"); | 729 creator.addAttr(inputMinNode, "ref", MINVALUEFIELDNAME); |
726 inputMinNode.setAttribute("ref", MINVALUEFIELDNAME); | 730 Element inputMinLableNode = creator.create("label"); |
727 Element inputMinLableNode = ArtifactXMLUtilities | |
728 .createXFormElement(document, "label"); | |
729 inputMinLableNode.setTextContent(RessourceFactory | 731 inputMinLableNode.setTextContent(RessourceFactory |
730 .getInstance().getRessource( | 732 .getInstance().getRessource( |
731 callMeta.getLanguages(), MINVALUEFIELDNAME, | 733 callMeta.getLanguages(), MINVALUEFIELDNAME, |
732 MINVALUEFIELDNAME)); | 734 MINVALUEFIELDNAME)); |
733 inputMinNode.appendChild(inputMinLableNode); | 735 inputMinNode.appendChild(inputMinLableNode); |
734 | 736 |
735 Element inputMinValueNode = ArtifactXMLUtilities.createXFormElement( | 737 Element inputMinValueNode = creator.create("value"); |
736 document, "value"); | |
737 inputMinValueNode.setTextContent(min.toString()); | 738 inputMinValueNode.setTextContent(min.toString()); |
738 inputMinNode.appendChild(inputMinValueNode); | 739 inputMinNode.appendChild(inputMinValueNode); |
739 | 740 |
740 Element inputMaxNode = ArtifactXMLUtilities.createXFormElement( | 741 Element inputMaxNode = creator.create("input"); |
741 document, "input"); | 742 creator.addAttr(inputMaxNode, "ref", MAXVALUEFIELDNAME); |
742 inputMaxNode.setAttribute("ref", MAXVALUEFIELDNAME); | 743 Element inputMaxLableNode = creator.create("label"); |
743 Element inputMaxLableNode = ArtifactXMLUtilities.createXFormElement( | |
744 document, "label"); | |
745 inputMaxLableNode.setTextContent(RessourceFactory | 744 inputMaxLableNode.setTextContent(RessourceFactory |
746 .getInstance().getRessource( | 745 .getInstance().getRessource( |
747 callMeta.getLanguages(), MAXVALUEFIELDNAME, | 746 callMeta.getLanguages(), MAXVALUEFIELDNAME, |
748 MAXVALUEFIELDNAME)); | 747 MAXVALUEFIELDNAME)); |
749 inputMaxNode.appendChild(inputMaxLableNode); | 748 inputMaxNode.appendChild(inputMaxLableNode); |
750 | 749 |
751 Element inputMaxValueNode = ArtifactXMLUtilities.createXFormElement( | 750 Element inputMaxValueNode = creator.create("value"); |
752 document, "value"); | |
753 inputMaxValueNode.setTextContent(max.toString()); | 751 inputMaxValueNode.setTextContent(max.toString()); |
754 inputMaxNode.appendChild(inputMaxValueNode); | 752 inputMaxNode.appendChild(inputMaxValueNode); |
755 | 753 |
756 groupNode.appendChild(inputMinNode); | 754 groupNode.appendChild(inputMinNode); |
757 groupNode.appendChild(inputMaxNode); | 755 groupNode.appendChild(inputMaxNode); |
760 } | 758 } |
761 | 759 |
762 | 760 |
763 | 761 |
764 protected void appendSingleValueDescribeData( | 762 protected void appendSingleValueDescribeData( |
765 Document document, | 763 XMLUtils.ElementCreator creator, |
766 Node node, | 764 Document document, |
767 CallMeta callMeta, | 765 Node node, |
768 Object o | 766 CallMeta callMeta, |
767 Object o | |
769 ) { | 768 ) { |
770 SingleValueDescribeData svdb = (SingleValueDescribeData) o; | 769 SingleValueDescribeData svdb = (SingleValueDescribeData) o; |
771 | 770 |
772 Element groupNode = ArtifactXMLUtilities.createXFormElement( | 771 Element groupNode = creator.create("group"); |
773 document, "group"); | 772 creator.addAttr(groupNode, "ref", svdb.getName()); |
774 groupNode.setAttribute("ref", svdb.getName()); | 773 |
775 Element groupNodeLableNode = ArtifactXMLUtilities.createXFormElement( | 774 Element groupNodeLableNode = creator.create("label"); |
776 document, "label"); | |
777 groupNodeLableNode.setTextContent(RessourceFactory | 775 groupNodeLableNode.setTextContent(RessourceFactory |
778 .getInstance().getRessource( | 776 .getInstance().getRessource( |
779 callMeta.getLanguages(), | 777 callMeta.getLanguages(), |
780 svdb.getName(), | 778 svdb.getName(), |
781 svdb.getName())); | 779 svdb.getName())); |
782 groupNode.appendChild(groupNodeLableNode); | 780 groupNode.appendChild(groupNodeLableNode); |
783 | 781 |
784 Element inputNode = ArtifactXMLUtilities.createXFormElement( | 782 Element inputNode = creator.create("input"); |
785 document, "input"); | 783 creator.addAttr(inputNode, "ref", svdb.getName()); |
786 inputNode.setAttribute("ref", svdb.getName()); | 784 |
787 | 785 Element inputLableNode = creator.create("label"); |
788 Element inputLableNode = ArtifactXMLUtilities.createXFormElement( | |
789 document, "label"); | |
790 inputLableNode.setTextContent(""); | 786 inputLableNode.setTextContent(""); |
791 inputNode.appendChild(inputLableNode); | 787 inputNode.appendChild(inputLableNode); |
792 | 788 |
793 Element inputValueNode = ArtifactXMLUtilities.createXFormElement( | 789 Element inputValueNode = creator.create("value"); |
794 document, "value"); | |
795 inputValueNode.setTextContent(svdb.getValue()); | 790 inputValueNode.setTextContent(svdb.getValue()); |
796 inputNode.appendChild(inputValueNode); | 791 inputNode.appendChild(inputValueNode); |
797 | 792 |
798 groupNode.appendChild(inputNode); | 793 groupNode.appendChild(inputNode); |
799 | 794 |
832 */ | 827 */ |
833 public Collection<InputData> getInputData() throws StateException { | 828 public Collection<InputData> getInputData() throws StateException { |
834 return this.inputData != null ? this.inputData.values() : null; | 829 return this.inputData != null ? this.inputData.values() : null; |
835 } | 830 } |
836 } | 831 } |
832 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |