comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java @ 605:e8ebdbc7f1e3

First step of removing the cache blob. The static part of the describe document will be created by using the input data stored at each state. Some TODOs left (see ChangeLog). gnv-artifacts/trunk@671 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 09 Feb 2010 14:27:55 +0000
parents 9681ac6b6527
children 292fbcd5e9ac
comparison
equal deleted inserted replaced
604:938ce81a6bd0 605:e8ebdbc7f1e3
1 /**
2 *
3 */
4 package de.intevation.gnv.state; 1 package de.intevation.gnv.state;
5 2
6 import java.util.ArrayList; 3 import java.util.ArrayList;
7 import java.util.Arrays; 4 import java.util.Arrays;
8 import java.util.Collection; 5 import java.util.Collection;
59 56
60 /** 57 /**
61 * the logger, used to log exceptions and additonaly information 58 * the logger, used to log exceptions and additonaly information
62 */ 59 */
63 private static Logger log = Logger.getLogger(GNVArtifactBase.class); 60 private static Logger log = Logger.getLogger(GNVArtifactBase.class);
64 61
65 private final static String MINVALUEFIELDNAME = "minvalue"; 62 private final static String MINVALUEFIELDNAME = "minvalue";
66 private final static String MAXVALUEFIELDNAME = "maxvalue"; 63 private final static String MAXVALUEFIELDNAME = "maxvalue";
67 64
68 private final static String NODATASELECTIONKEY = "n/n"; 65 private final static String NODATASELECTIONKEY = "n/n";
69 66
70 public final static String DESCRIBEDATAKEY = "_DESCRIBEDATA"; 67 public final static String DESCRIBEDATAKEY = "_DESCRIBEDATA";
71 68
72 public final static String XPATH_STATIC_UI = "art:static"; 69 public final static String XPATH_STATIC_UI = "art:static";
73 public final static String XPATH_DYNAMIC_UI = "art:dynamic"; 70 public final static String XPATH_DYNAMIC_UI = "art:dynamic";
74 71
72 /** input value names which should not be rendered from State itself */
73 public final static String[] BLACKLIST = {"sourceid", "fisname"};
74
75 private String id = null; 75 private String id = null;
76 76
77 private String description = null; 77 private String description = null;
78 78
79 protected String dataName = null; 79 protected String dataName = null;
80 80
81 protected String preSettingsName = null; 81 protected String preSettingsName = null;
82 82
83 protected boolean dataMultiSelect = false; 83 protected boolean dataMultiSelect = false;
84 84
85 protected boolean dataNoSelect = false; 85 protected boolean dataNoSelect = false;
86 86
87 protected String queryID = null; 87 protected String queryID = null;
88 88
89 protected Collection<String> inputValueNames = null; 89 protected Collection<String> inputValueNames = null;
91 private Map<String, InputValue> inputValues = null; 91 private Map<String, InputValue> inputValues = null;
92 92
93 private State parent = null; 93 private State parent = null;
94 94
95 protected Map<String, InputData> inputData = null; 95 protected Map<String, InputData> inputData = null;
96 96
97 private Map<String, InputData> preSettings = null; 97 private Map<String, InputData> preSettings = null;
98 98
99 /** 99 /**
100 * Constructor 100 * Constructor
101 */ 101 */
562 } 562 }
563 } 563 }
564 return keyValueDescibeData; 564 return keyValueDescibeData;
565 } 565 }
566 566
567
568 public String findNewValue() {
569 Iterator iter = inputValueNames.iterator();
570
571 while (iter.hasNext()) {
572 String key = (String) iter.next();
573 boolean old = false;
574
575 StateBase parent = (StateBase) getParent();
576 if (parent == null) {
577 // first state should always render a dynamic part
578 old = true;
579 }
580
581 while (parent != null) {
582 if (parent.inputValueNames.contains(key) || inBlackList(key)) {
583 old = true;
584 break;
585 }
586
587 parent = (StateBase) parent.getParent();
588 }
589
590 if (!old) {
591 return key;
592 }
593 }
594
595 return null;
596 }
597
598
599 public static boolean inBlackList(String key) {
600 int length = BLACKLIST.length;
601 for (int i = 0; i < length; i++) {
602 if (BLACKLIST[i].equals(key)) {
603 return true;
604 }
605 }
606
607 return false;
608 }
609
567 /** 610 /**
568 * @see de.intevation.gnv.state.State#describe(org.w3c.dom.Document, 611 * @see de.intevation.gnv.state.State#describe(org.w3c.dom.Document,
569 * org.w3c.dom.Node, de.intevation.artifacts.CallMeta, 612 * org.w3c.dom.Node, de.intevation.artifacts.CallMeta,
570 * java.lang.String) 613 * java.lang.String)
571 */ 614 */
615 /*
572 public void describe( 616 public void describe(
573 Document document, 617 Document document,
574 Node rootNode, 618 Node rootNode,
575 CallContext context, 619 CallContext context,
576 String uuid 620 String uuid
619 creator, xCreator, document, staticNode, callMeta, o); 663 creator, xCreator, document, staticNode, callMeta, o);
620 } 664 }
621 } 665 }
622 } 666 }
623 } 667 }
668 */
669
670
671 public void describe(
672 Document document,
673 Node rootNode,
674 CallContext context,
675 String uuid)
676 {
677 log.debug("StateBase.describe");
678
679 XMLUtils.ElementCreator xCreator = new XMLUtils.ElementCreator(
680 document,
681 XMLUtils.XFORM_URL,
682 XMLUtils.XFORM_PREFIX
683 );
684
685 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
686 document,
687 ArtifactNamespaceContext.NAMESPACE_URI,
688 ArtifactNamespaceContext.NAMESPACE_PREFIX
689 );
690
691 // append dynamic node
692 Node dynamic = (Node) XMLUtils.xpath(
693 rootNode,
694 XPATH_DYNAMIC_UI,
695 XPathConstants.NODE,
696 ArtifactNamespaceContext.INSTANCE
697 );
698
699 describeDynamic(
700 creator, xCreator, document, dynamic, context, uuid);
701
702 // append static nodes
703 Node staticNode = (Node) XMLUtils.xpath(
704 rootNode,
705 XPATH_STATIC_UI,
706 XPathConstants.NODE,
707 ArtifactNamespaceContext.INSTANCE
708 );
709
710 describeStatic(
711 creator,xCreator, document, staticNode, context,uuid);
712 }
713
714
715 protected void describeDynamic(
716 XMLUtils.ElementCreator artCreator,
717 XMLUtils.ElementCreator creator,
718 Document document,
719 Node dynamic,
720 CallContext context,
721 String uuid)
722 {
723 log.debug("StateBase.describeDynamic");
724 CallMeta callMeta = context.getMeta();
725
726 List<Object> descibeData = getDescibeData(uuid);
727 if (descibeData != null) {
728 Iterator<Object> it = descibeData.iterator();
729
730 while (it.hasNext()) {
731 Object o = it.next();
732 if ((!it.hasNext() && dataName != null)) {
733 appendToDynamicNode(
734 artCreator, creator, document, dynamic, callMeta, o);
735 }
736 }
737 }
738 }
739
740
741 protected void describeStatic(
742 XMLUtils.ElementCreator artCreator,
743 XMLUtils.ElementCreator creator,
744 Document document,
745 Node staticNode,
746 CallContext context,
747 String uuid)
748 {
749 State parent = getParent();
750 if (parent != null && parent instanceof StateBase) {
751 ((StateBase) parent).describeStatic(
752 artCreator, creator, document, staticNode, context, uuid);
753 }
754
755 CallMeta callMeta = context.getMeta();
756 String inputKey = findNewValue();
757 appendToStaticNode(
758 artCreator, creator, document, staticNode, callMeta, inputKey);
759 }
624 760
625 761
626 protected void appendToStaticNode( 762 protected void appendToStaticNode(
627 XMLUtils.ElementCreator artCreator, 763 XMLUtils.ElementCreator artCreator,
628 XMLUtils.ElementCreator creator, 764 XMLUtils.ElementCreator creator,
629 Document document, 765 Document document,
630 Node staticNode, 766 Node staticNode,
631 CallMeta callMeta, 767 CallMeta callMeta,
632 Object o 768 String inputKey
633 ) { 769 ) {
634 if (o instanceof Collection<?>) { 770 InputValue meta = inputValues.get(inputKey);
635 String name = null; 771 InputData data = inputData.get(inputKey);
636 boolean multiselect = false; 772
637 if (o instanceof NamedCollection<?>) { 773 if (meta == null || data == null) {
638 NamedCollection<?> nc = ((NamedCollection<?>) o); 774 return;
639 name = nc.getName(); 775 }
640 multiselect = nc.isMultiSelect(); 776
641 } else { 777 boolean multiselect = meta.isMultiselect();
642 Object[] names = this.inputValueNames.toArray(); 778
643 name = names[names.length - 1].toString(); 779 Element selectNode = creator.create(multiselect?"select":"select1");
644 } 780 creator.addAttr(selectNode, "ref", inputKey);
645 781
646 Element selectNode = creator.create(multiselect?"select":"select1"); 782 Element lableNode = creator.create("label");
647 creator.addAttr(selectNode, "ref", name); 783 lableNode.setTextContent(RessourceFactory.getInstance()
648 784 .getRessource(callMeta.getLanguages(), inputKey, inputKey));
649 Element lableNode = creator.create("label"); 785 Element choiceNode = creator.create("choices");
650 lableNode.setTextContent(RessourceFactory.getInstance() 786
651 .getRessource(callMeta.getLanguages(), name, name)); 787 /* TODO InputData can have more than 1 value if multiselect, implement a
652 Element choiceNode = creator.create("choices"); 788 * loop over these values
653 789
654 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o; 790 while (resultIt.hasNext()) {
655 Iterator<KeyValueDescibeData> resultIt = values.iterator(); 791 KeyValueDescibeData result = resultIt.next();
656 while (resultIt.hasNext()) { 792 */
657 KeyValueDescibeData result = resultIt.next(); 793
658 794 artCreator.addAttr(
659 if (result.isSelected()) { 795 selectNode, "state", getID(), true
660 artCreator.addAttr( 796 );
661 selectNode, "state", result.getState(), true 797
662 ); 798 Element itemNode = creator.create("item");
663 799
664 Element itemNode = creator.create("item"); 800 creator.addAttr(itemNode, "selected", "true");
665 801
666 creator.addAttr(itemNode, "selected", "true"); 802 Element choiceLableNode = creator.create("label");
667 803 choiceLableNode.setTextContent(data.getValue());
668 Element choiceLableNode = creator.create("label"); 804 itemNode.appendChild(choiceLableNode);
669 choiceLableNode.setTextContent(result.getValue()); 805
670 itemNode.appendChild(choiceLableNode); 806 Element choiceValueNode = creator.create("value");
671 807 choiceValueNode.setTextContent(inputKey);
672 Element choiceValueNode = creator.create("value"); 808 itemNode.appendChild(choiceValueNode);
673 choiceValueNode.setTextContent("" + result.getKey()); 809 choiceNode.appendChild(itemNode);
674 itemNode.appendChild(choiceValueNode); 810 /*
675 choiceNode.appendChild(itemNode); 811 }
676 } 812 */
677 } 813 selectNode.appendChild(lableNode);
678 selectNode.appendChild(lableNode); 814 selectNode.appendChild(choiceNode);
679 selectNode.appendChild(choiceNode); 815
680 816 staticNode.appendChild(selectNode);
681 staticNode.appendChild(selectNode);
682 }
683 else if (o instanceof MinMaxDescribeData) {
684 appendMinMaxDescribeData(
685 artCreator,
686 creator,
687 document,
688 staticNode,
689 callMeta,
690 o);
691 }
692 else if (o instanceof SingleValueDescribeData) {
693 appendSingleValueDescribeData(
694 artCreator,
695 creator,
696 document,
697 staticNode,
698 callMeta,
699 o);
700 }
701 } 817 }
702 818
703 819
704 protected void appendToDynamicNode( 820 protected void appendToDynamicNode(
705 XMLUtils.ElementCreator artCreator, 821 XMLUtils.ElementCreator artCreator,
890 return (List<Object>) (value.getObjectValue()); 1006 return (List<Object>) (value.getObjectValue());
891 } 1007 }
892 } 1008 }
893 return null; 1009 return null;
894 } 1010 }
895 1011
896 /** 1012 /**
897 * @see de.intevation.gnv.state.State#getDescibeData() 1013 * @see de.intevation.gnv.state.State#getDescibeData()
898 */ 1014 */
899 protected void setDescibeData(String uuid, List<Object> describeData) { 1015 protected void setDescibeData(String uuid, List<Object> describeData) {
900 1016

http://dive4elements.wald.intevation.org