}
String thesaType = Util.getParam(params, "refType");
Element elResp = new Element(Jeeves.Elem.RESPONSE);
ThesaurusManager manager = gc.getBean(ThesaurusManager.class);
Thesaurus thesaurus = manager.getThesaurusByName(ref);
if (thesaurus.isFreeCode(null, newid)) {
KeywordBean keyword = new KeywordBean(context.getBean(IsoLanguagesMapper.class))
.setNamespaceCode(namespace)
.setUriCode(newid);
Map<Pair<String, String>, String> localizations = getLocalizedElements(params);
if (localizations.isEmpty()) {
String prefLab = Util.getParam(params, PREF_LAB);
String lang = Util.getParam(params, "lang");
String definition = Util.getParam(params, DEFINITION,"");
keyword.setValue(prefLab, lang)
.setDefinition(definition, lang);
} else {
Set<Map.Entry<Pair<String, String>, String>> entries = localizations.entrySet();
for (Map.Entry<Pair<String, String>, String> entry : entries) {
String lang = entry.getKey().one();
if (entry.getKey().two().equals(DEFINITION)) {
final String definition = entry.getValue();
keyword.setDefinition(definition, lang);
} else if (entry.getKey().two().equals(PREF_LAB)) {
final String label = entry.getValue();
keyword.setValue(label, lang);
} else {
throw new IllegalArgumentException("Unknown localization type: "+entry.getKey().two());
}
}
}
if (thesaType.equals("place")) {
String east = Util.getParam(params, "east");
String west = Util.getParam(params, "west");
String south = Util.getParam(params, "south");
String north = Util.getParam(params, "north");
keyword.setCoordEast(east)
.setCoordNorth(north)
.setCoordSouth(south)
.setCoordWest(west);
}
thesaurus.addElement(keyword);
elResp.addContent(new Element("selected").setText(ref));
elResp.addContent(new Element("mode").setText("edit"));
} else {
elResp.addContent(new Element("error").addContent(new Element("message").setText("Code value already exists in thesaurus")));