incubator-odf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Svante Schubert <svante.schub...@gmail.com>
Subject Re: Bug in getNamespaceURI() implementation of OdfFileDom
Date Wed, 01 Feb 2012 00:19:26 GMT
Hi Ashok,

I have once spend quite some time on the XPath support. Therefore there
is an own test for XPath in ODFDOM (ie.
org.odftoolkit.odfdom.dom.XPathTest).
I suggest that you extend this test class in a way that your problem
becomes apparent. By doing the test driven approach it is easier for us
to comprehend the problem at the beginning and in the end to test the
following patch.

Thanks for your participation, Ashok!
Svante


On 31.01.2012 12:15, Ashok Hariharan wrote:
> The current implementation of getNamespaceURI() in OdfFileDom looks like this :
>
> 	public String getNamespaceURI(String prefix) {
> 		String nsURI = null;
> 		nsURI = mUriByPrefix.get(prefix);
> 		if (nsURI == null) {
> 			nsURI = XMLConstants.NULL_NS_URI;
> 		}
> 		return nsURI;
> 	}
>
> However this is incomplete -- since there is also support for
> duplicate NS prefixes in OdfFileDom .e.g , you look at getPrefixes() :
>
>
> 	public Iterator<String> getPrefixes(String namespaceURI) {
> 		Set<String> prefixes = mDuplicatePrefixesByUri.get(namespaceURI);
> 		if (prefixes == null) {
> 			prefixes = new HashSet<String>();
> 			mDuplicatePrefixesByUri.put(namespaceURI, prefixes);
> 		}
> 		prefixes.add(mPrefixByUri.get(namespaceURI));
> 		return prefixes.iterator();
> 	}
>
> So if you pass a duplicate prefix to getNamespaceURI() it doesnt
> return anything -- which means any XPath queries done using the XPath
> context provided by OdfFileDom also fail - so I have to end up using a
> custom Namespacecontext ...which kind of defeats the purpose.
>
> E.g. this is RDF metadata as recorded by OpenOffice 3.3 , OOo uses
> duplicate namespace prefixes to record custom RDF triples. I cannot
> query it with any of these prefixes, nor can I use a fixed NS prefix
> to query ... it always fails at getNamespaceURI()
>
>
> <?xml version="1.0" encoding="utf-8"?>
> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
>  <rdf:Description rdf:about="../content.xml#id1535901849">
>    <ns1:BungeniQuestionBy
> xmlns:ns1="http://editor.bungeni.org/1.0/anx/">Harold
> Kariuki</ns1:BungeniQuestionBy>
>    <ns2:BungeniQuestionByURI
> xmlns:ns2="http://editor.bungeni.org/1.0/anx/">/ke/person/kariuki/harol/1934-01-02</ns2:BungeniQuestionByURI>
>    <ns3:BungeniQuestionNo
> xmlns:ns3="http://editor.bungeni.org/1.0/anx/">33</ns3:BungeniQuestionNo>
>    <ns4:BungeniQuestionTo
> xmlns:ns4="http://editor.bungeni.org/1.0/anx/">/ontology/ke/2010/ministries/tourism/</ns4:BungeniQuestionTo>
>    <ns5:BungeniSectionID
> xmlns:ns5="http://editor.bungeni.org/1.0/anx/">p1o7uz/vSzumrcj5aT4MPQ</ns5:BungeniSectionID>
>    <ns6:BungeniSectionType
> xmlns:ns6="http://editor.bungeni.org/1.0/anx/">QuestionAnswer</ns6:BungeniSectionType>
> </rdf:Description>
>
> I could be able to submit a patch for getNamespaceURI(), if I have
> indeed identified a problem --
>
> Ashok


Mime
View raw message