954 | | |
955 | | protected boolean addAllDisplayInfo(Element description, String lang) |
956 | | { |
957 | | Document doc = description.getOwnerDocument(); |
958 | | NodeList items = this.display_item_list.getChildNodes(); |
959 | | for (int i = 0; i < items.getLength(); i++) |
960 | | { // for each key |
961 | | Element m = (Element) items.item(i); |
962 | | // findthe child with the correct language |
963 | | Element new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang); |
964 | | if (new_m == null && lang != DEFAULT_LANG) |
965 | | { |
966 | | // use the default lang |
967 | | new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG); |
968 | | } |
969 | | if (new_m == null) |
970 | | { |
971 | | // just get the first one |
972 | | new_m = (Element) GSXML.getChildByTagName(m, GSXML.DISPLAY_TEXT_ELEM); |
973 | | } |
974 | | description.appendChild(doc.importNode(new_m, true)); |
975 | | } |
976 | | return true; |
977 | | |
978 | | } |
979 | | |
980 | | protected Element getDisplayTextElement(String key, String lang) |
981 | | { |
982 | | |
983 | | Element this_item = GSXML.getNamedElement(this.display_item_list, GSXML.DISPLAY_TEXT_ELEM, GSXML.NAME_ATT, key); |
984 | | if (this_item == null) |
985 | | { |
986 | | return null; |
987 | | } |
988 | | |
989 | | Element this_lang = GSXML.getNamedElement(this_item, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang); |
990 | | if (this_lang == null && lang != DEFAULT_LANG) |
991 | | { |
992 | | // try the default |
993 | | this_lang = GSXML.getNamedElement(this_item, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG); |
994 | | } |
995 | | if (this_lang == null) |
996 | | { |
997 | | // just return the first one |
998 | | return GSXML.getFirstElementChild(this_item);//(Element)this_item.getFirstChild().cloneNode(true); |
999 | | } |
1000 | | return (Element) this_lang.cloneNode(true); |
1001 | | |
1002 | | } |
| 934 | // from our store of displayItems, (eg name, description etc) add one of each to response. PIck the best fit for request lang. |
| 935 | |
| 936 | protected boolean addAllDisplayInfo(Element description, String lang) |
| 937 | { |
| 938 | Document doc = description.getOwnerDocument(); |
| 939 | NodeList items = this.display_item_list.getChildNodes(); |
| 940 | for (int i = 0; i < items.getLength(); i++) |
| 941 | { // for each key |
| 942 | Element m = (Element) items.item(i); |
| 943 | // is there one with the specified language? |
| 944 | Element new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang); |
| 945 | if (new_m == null) { |
| 946 | // if not, have we got one with a key? |
| 947 | new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.KEY_ATT, null); |
| 948 | if (new_m != null) { |
| 949 | // look up the dictionary |
| 950 | String value = getTextString(new_m.getAttribute(GSXML.KEY_ATT), lang, new_m.getAttribute(GSXML.DICTIONARY_ATT)); |
| 951 | if (value != null) { |
| 952 | GSXML.setNodeText(new_m, value); |
| 953 | } |
| 954 | else { |
| 955 | // haven't found the key in the dictionary, ignore this display item |
| 956 | new_m = null; |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | if (new_m == null && lang != DEFAULT_LANG) { |
| 961 | // still haven't got a value. can we use the defualt lang? |
| 962 | new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG); |
| 963 | } |
| 964 | if (new_m == null) |
| 965 | { |
| 966 | // STILL haven't found one, lets use the first one with a lang att (so we don't just get the key one back |
| 967 | new_m = (Element) GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, null); |
| 968 | } |
| 969 | if (new_m != null) { |
| 970 | description.appendChild(doc.importNode(new_m, true)); |
| 971 | } |
| 972 | } // for each key |
| 973 | return true; |
| 974 | |
| 975 | } |
| 976 | |
| 977 | |
| 978 | protected String getTextString(String key, String lang, String dictionary) { |
| 979 | return getTextString(key, lang, dictionary, null); |
| 980 | } |
| 981 | |
| 982 | protected String getTextString(String key, String lang, String dictionary, String[] args) |
| 983 | { |
| 984 | Dictionary dict = new Dictionary(dictionary, lang); |
| 985 | String result = dict.get(key, args); |
| 986 | return result; |
| 987 | } |
| 988 | |