From: <jes...@us...> - 2009-06-04 10:38:39
|
Revision: 4209 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=4209&view=rev Author: jesseeichar Date: 2009-06-04 10:38:29 +0000 (Thu, 04 Jun 2009) Log Message: ----------- fixed 14751: Edit keyword GIve nullpointer Modified Paths: -------------- sandbox/geocat.ch/trunk/src/org/fao/geonet/kernel/search/KeywordsSearcher.java sandbox/geocat.ch/trunk/web/geonetwork/xsl/thesaurus-util.xsl Modified: sandbox/geocat.ch/trunk/src/org/fao/geonet/kernel/search/KeywordsSearcher.java =================================================================== --- sandbox/geocat.ch/trunk/src/org/fao/geonet/kernel/search/KeywordsSearcher.java 2009-06-04 08:34:30 UTC (rev 4208) +++ sandbox/geocat.ch/trunk/src/org/fao/geonet/kernel/search/KeywordsSearcher.java 2009-06-04 10:38:29 UTC (rev 4209) @@ -141,8 +141,6 @@ public Concept searchById(String id, String sThesaurusName, String lang, String locales) throws Exception { - String[] langs = locales.split(","); - if (lang.length()>2) lang=lang.substring(0, 2); @@ -150,10 +148,10 @@ _query = "SELECT prefLab, note, id, lowc, uppc, lang(prefLab) " + " FROM {id} rdf:type {skos:Concept}; " + " skos:prefLabel {prefLab};" - + " [skos:scopeNote {note} WHERE lang(note) LIKE \""+lang+"\"]; " + + " [skos:scopeNote {note} WHERE lang(note) LIKE \"*\"]; " + " [gml:BoundedBy {} gml:lowerCorner {lowc}]; " + " [gml:BoundedBy {} gml:upperCorner {uppc}] " - + " WHERE lang(prefLab) LIKE \""+lang+"\" " + + " WHERE lang(prefLab) LIKE \"*\" " + " AND id LIKE \"" + id + "\" " + " IGNORE CASE " + " USING NAMESPACE skos=<" + Concept.NS_SKOS + ">, gml=<" + Concept.NS_GML + "> "; @@ -167,38 +165,15 @@ if (rowCount == 0){ return null; }else{ - Value value = resultsTable.getValue(0, 0); - Value uri = resultsTable.getValue(0, 2); - - Concept kb = new Concept(0, - (value==null?"":value.toString()), - "", - (uri==null?"":uri.toString()), - "", "", "", "", - sThesaurusName, false, lang); - - // Add translation to keywords - if (langs.length > 1) { - for (int i=0; i<langs.length; i++) { - String locale = langs[i].toLowerCase(); - - _query = "SELECT prefLab " - + " FROM {id} rdf:type {skos:Concept}; " - + " skos:prefLabel {prefLab}" - + " WHERE lang(prefLab) LIKE \""+locale+"\" " - + " AND id LIKE \"" + id + "\" " - + " IGNORE CASE " - + " USING NAMESPACE skos=<" + Concept.NS_SKOS + ">, gml=<" + Concept.NS_GML + "> "; - Log.debug(Geonet.THESAURUS_MAN, "Searching for translation of '"+ kb.getDefaultPrefLabel() + "' in '"+ locale + "' with " + _query); - - // Perform request & add it to concept - QueryResultsTable rt = thesaurus.performRequest(_query); - int labelsCount = rt.getRowCount(); - if (labelsCount != 0) - if (rt.getValue(0, 0) != null) - kb.setPrefLabel(rt.getValue(0, 0).toString(), locale); - } - } + Concept kb = null; + for (int row = 0; row < rowCount; row++) { + Concept newKb = createConcept(lang, 0, sThesaurusName, resultsTable, row); + if(kb==null){ + kb = newKb; + } else { + kb.setPrefLabel(newKb.getDefaultPrefLabel(), newKb.getDefaultLocale()); + } + } return kb; } @@ -330,65 +305,8 @@ int rowCount = resultsTable.getRowCount(); for (int row = 0; row < rowCount; row++) { - // preflab - Value value = resultsTable.getValue(row, 0); - String sValue = ""; - if (value != null) { - sValue = value.toString(); - } - // definition - Value definition = resultsTable.getValue(row, 1); - String sDefinition = ""; - if (definition != null) { - sDefinition = definition.toString(); - } - // uri (= id in RDF file != id in list) - Value uri = resultsTable.getValue(row, 2); - String sUri = ""; - if (uri != null) { - sUri = uri.toString(); - } + Concept kb = createConcept(defaultLangCode, idKeyword, sThesaurusName, resultsTable, row); - // language of the result - Value lang = resultsTable.getValue(row, 5); - String sLang = defaultLangCode; - if (lang != null) { - sLang = lang.toString(); - } - - sLang = LangUtils.two2ThreeLangCode(sLang); - - - Value lowCorner = resultsTable.getValue(row, 3); - Value upperCorner = resultsTable.getValue(row, 4); - - String sUpperCorner = ""; - String sLowCorner = ""; - - String sEast = ""; - String sSouth = ""; - String sWest = ""; - String sNorth = ""; - - // lowcorner - if (lowCorner != null) { - sLowCorner = lowCorner.toString(); - sWest = sLowCorner.substring(0, sLowCorner.indexOf(' ')).trim(); - sSouth = sLowCorner.substring(sLowCorner.indexOf(' ')).trim(); - } - - // uppercorner - if (upperCorner != null) { - sUpperCorner = upperCorner.toString(); - sEast = sUpperCorner.substring(0,sUpperCorner.indexOf(' ')).trim(); - sNorth = sUpperCorner.substring(sUpperCorner.indexOf(' ')) - .trim(); - } - - Concept kb = new Concept(idKeyword, sValue, - sDefinition, sUri, sEast, sWest, sSouth, sNorth, - sThesaurusName, false, sLang ); - if( bag.containsKey(kb.getCode()) ){ bag.get(kb.getCode()).setPrefLabel(kb.getDefaultPrefLabel(), kb.getDefaultLocale()); }else{ @@ -400,6 +318,70 @@ } } + private Concept createConcept(String defaultLangCode, int idKeyword, String sThesaurusName, + QueryResultsTable resultsTable, int row) + { + // preflab + Value value = resultsTable.getValue(row, 0); + String sValue = ""; + if (value != null) { + sValue = value.toString(); + } + // definition + Value definition = resultsTable.getValue(row, 1); + String sDefinition = ""; + if (definition != null) { + sDefinition = definition.toString(); + } + // uri (= id in RDF file != id in list) + Value uri = resultsTable.getValue(row, 2); + String sUri = ""; + if (uri != null) { + sUri = uri.toString(); + } + + // language of the result + Value lang = resultsTable.getValue(row, 5); + String sLang = defaultLangCode; + if (lang != null) { + sLang = lang.toString(); + } + + sLang = LangUtils.two2ThreeLangCode(sLang); + + + Value lowCorner = resultsTable.getValue(row, 3); + Value upperCorner = resultsTable.getValue(row, 4); + + String sUpperCorner = ""; + String sLowCorner = ""; + + String sEast = ""; + String sSouth = ""; + String sWest = ""; + String sNorth = ""; + + // lowcorner + if (lowCorner != null) { + sLowCorner = lowCorner.toString(); + sWest = sLowCorner.substring(0, sLowCorner.indexOf(' ')).trim(); + sSouth = sLowCorner.substring(sLowCorner.indexOf(' ')).trim(); + } + + // uppercorner + if (upperCorner != null) { + sUpperCorner = upperCorner.toString(); + sEast = sUpperCorner.substring(0,sUpperCorner.indexOf(' ')).trim(); + sNorth = sUpperCorner.substring(sUpperCorner.indexOf(' ')) + .trim(); + } + + Concept kb = new Concept(idKeyword, sValue, + sDefinition, sUri, sEast, sWest, sSouth, sNorth, + sThesaurusName, false, sLang ); + return kb; + } + public void searchBN(ServiceContext srvContext, Element params, String request) throws Exception { // TODO : Add geonetinfo elements. Modified: sandbox/geocat.ch/trunk/web/geonetwork/xsl/thesaurus-util.xsl =================================================================== --- sandbox/geocat.ch/trunk/web/geonetwork/xsl/thesaurus-util.xsl 2009-06-04 08:34:30 UTC (rev 4208) +++ sandbox/geocat.ch/trunk/web/geonetwork/xsl/thesaurus-util.xsl 2009-06-04 10:38:29 UTC (rev 4209) @@ -137,10 +137,20 @@ </form> </xsl:when> - <xsl:otherwise> + <xsl:otherwise> + + <xsl:variable name="UPPER">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable> + <xsl:variable name="LOWER">abcdefghijklmnopqrstuvwxyz</xsl:variable> + <xsl:variable name="lang" select="translate(/root/gui/language, $LOWER, $UPPER)" /> <a href="javascript:popWindow('{/root/gui/locService}/thesaurus.editelement?locales=en,fr,it,de&mode={$mode}&ref={$thesaurus}&id={./id}');"> <xsl:choose> - <xsl:when test="$keyword/value and string-length($keyword/value)"> + <xsl:when test="$keyword/value[@lang=$lang] and string-length($keyword/value[@lang=$lang])>0"> + <xsl:value-of select="$keyword/value[@lang=$lang]"/> + </xsl:when> + <xsl:when test="$keyword/value[string-length(text()) > 0])"> + <xsl:value-of select="$keyword/value[string-length(text()) > 0]"/> + </xsl:when> + <xsl:when test="$keyword/value and string-length($keyword/value)"> <xsl:value-of select="$keyword/value"/> </xsl:when> <xsl:otherwise>n/a</xsl:otherwise> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |