Changeset 6247
- Timestamp:
- 2003-12-12T16:34:22+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Retrieve.java
r6165 r6247 766 766 protected String getMetadata(String node_id, DBInfo info, 767 767 String metadata) { 768 boolean multiple = false; 769 String relation = ""; 770 String separator = ", "; 768 771 int pos = metadata.indexOf(RELATION_SEP_CHAR); 769 772 if (pos ==-1) { 773 // just a plain meta entry eg dc.Title 770 774 return info.getInfo(metadata); 771 775 } 772 776 773 String relation = metadata.substring(0, pos); 774 if (!relation.equals("parent") && !relation.equals("root") && !relation.startsWith("ancestors") ) { 775 // its not a valid relation 776 return info.getInfo(metadata); 777 } 778 779 String relation_id = ""; 780 if (relation.equals("root")) { 777 String temp = metadata.substring(0, pos); 778 metadata = metadata.substring(pos+1); 779 // check for all on the front 780 if (temp.equals("all")) { 781 multiple=true; 782 pos = metadata.indexOf(RELATION_SEP_CHAR); 783 if (pos ==-1) { 784 temp = ""; 785 } else { 786 temp = metadata.substring(0, pos); 787 metadata = metadata.substring(pos+1); 788 } 789 } 790 791 // now check for relational info 792 if (temp.equals("parent") || temp.equals("root") || temp.equals( "ancestors")) { // "current" "siblings" "children" "descendents" 793 relation = temp; 794 pos = metadata.indexOf(RELATION_SEP_CHAR); 795 if (pos == -1) { 796 temp = ""; 797 } else { 798 temp = metadata.substring(0, pos); 799 metadata = metadata.substring(pos+1); 800 } 801 } 802 803 // now look for separator info 804 if (temp.startsWith(SEPARATOR_SEP_STRING) && temp.endsWith(SEPARATOR_SEP_STRING)) { 805 separator = temp.substring(1, temp.length()-1); 806 807 } 808 809 String relation_id = node_id; 810 if (relation.equals("parent") || relation.equals("ancestors")) { 811 relation_id = OID.getParent(node_id); 812 // parent or ancestor does not include self 813 if (relation_id.equals(node_id)){ 814 return ""; 815 } 816 } else if (relation.equals("root")) { 781 817 relation_id = OID.getTop(node_id); 818 } 819 820 // now we either have a single node, or we have ancestors 821 DBInfo relation_info; 822 if (relation_id.equals(node_id)) { 823 relation_info = info; 782 824 } else { 783 relation_id = OID.getParent(node_id); 784 } 785 786 if (relation_id.equals(node_id)){ 787 // no parents or ancestors 788 return ""; 789 } 790 791 DBInfo relation_info = this.gdbm_src.getInfo(relation_id); 825 relation_info = this.gdbm_src.getInfo(relation_id); 826 } 792 827 if (relation_info == null) { 793 828 return ""; 794 829 } 795 796 String new_meta = metadata.substring(pos+1); 797 if (relation.equals("parent") || relation.equals("root")) { 798 return relation_info.getInfo(new_meta); 799 } 800 801 // do ancestor stuff 802 // get teh separating string 803 String items [] = relation.split(SEPARATOR_SEP_STRING); 804 String separator = ""; 805 if (items.length > 1) { 806 separator = items[1]; 807 relation = items[0]; 808 } 809 810 StringBuffer value = new StringBuffer(); 811 value.append(relation_info.getInfo(new_meta)); 830 831 StringBuffer result = new StringBuffer(); 832 833 if (!multiple) { 834 result.append(relation_info.getInfo(metadata)); 835 } else { 836 // we have multiple meta 837 Vector values = relation_info.getMultiInfo(metadata); 838 if (values != null) { 839 boolean first = true; 840 for (int i=0; i<values.size(); i++) { 841 if (first) { 842 first = false; 843 } else { 844 result.append(separator); 845 } 846 result.append(values.elementAt(i)); 847 } 848 } 849 } 850 // if not ancestors, then this is all we do 851 if (!relation.equals("ancestors")) { 852 return result.toString(); 853 } 854 855 // now do the ancestors 812 856 String current_id = relation_id; 813 857 relation_id = OID.getParent(current_id); 814 858 while (!relation_id.equals(current_id)) { 815 859 relation_info = this.gdbm_src.getInfo(relation_id); 816 if (relation_info == null) return value.toString(); 817 value.insert(0, separator); 818 value.insert(0, relation_info.getInfo(new_meta)); 819 860 if (relation_info == null) return result.toString(); 861 if (!multiple) { 862 result.insert(0, separator); 863 result.insert(0, relation_info.getInfo(metadata)); 864 } else { 865 Vector values = relation_info.getMultiInfo(metadata); 866 if (values != null) { 867 for (int i=values.size()-1; i>=0; i--) { 868 result.insert(0, separator); 869 result.insert(0, values.elementAt(i)); 870 } 871 } 872 873 } 820 874 current_id = relation_id; 821 875 relation_id = OID.getParent(current_id); 822 876 } 823 877 824 return value.toString();878 return result.toString(); 825 879 } 826 880
Note:
See TracChangeset
for help on using the changeset viewer.