> Is that normal SAX behavior - and we should replace the null value with an

Oh! I should have read the doc. From the Javadocs for the org.w3c.dom.Node
interface:
http://java.sun.com/j2se/1.4.1/docs/api/org/w3c/dom/Node.html#getNamespaceUR
I()

"
public String getNamespaceURI()
    The namespace URI of this node, or null if it is unspecified.
"

Now, should 'MirrorRecord.nodeToEvents()' handle the 'node.getNamespaceURI()
== null' case? Is it correct to replace null with an empty string? (Would
you expect that this uri==null case crashes Cocoon?)

>From the Log transformer, I see that all other elements have an empty string
for the uri= when there is no namespace for an attribute.

Olivier


-----Message d'origine-----
De : Olivier Lange [mailto:[EMAIL PROTECTED]
Envoyé : mercredi, 10. septembre 2003 19:42
À : [EMAIL PROTECTED]
Objet : RE: i18n trouble with nested elements in catalog messages


Bruno, Konstantin,

> Oliver, could you try putting the following between those two:
> factory.setNamespaceAware(true);

Thanks for the tip. I added factory.setNamespaceAware(true); to
XMLResourceBundle.loadResourceBundle(). It looks like this:

  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(true);
  DocumentBuilder builder = factory.newDocumentBuilder();

The resulting SAX events look much better, namespaces are there.

But any transformation placed after the 18n transformer still throws an NPE.
Here are the last line logged by the Log transformer:

  [startElement] uri=urn:pro-helvetia.ch:phga:docmini:v1.1,local=d:p,raw=d:p
  [characters] Zu «Alpdurchblick. Filme zur NEAT» ist ein Katalog mit
ausführlichen Informationen zum Gesamtprogramm erhältlich. Zu beziehen ist
er bei Filmkreis Oberwallis ...
  [startElement]
uri=urn:pro-helvetia.ch:phga:docmini:v1.1,local=d:link,raw=d:link
  [            ] 1.
uri=null,local=href,qname=href,type=CDATA,value=mailto:[EMAIL PROTECTED]

uri=null for the attribute, and local=raw for the element d:link.

I also changed the code in MirrorRecorder.nodeToEvents() and replaced (lines
229-236):

  startElement(n.getNamespaceURI(), n.getNodeName(), n.getNodeName(),
attrs);
  ...
  endElement(n.getNamespaceURI(), n.getNodeName(), n.getNodeName());

with

  startElement(n.getNamespaceURI(), n.getLocalName(), n.getNodeName(),
attrs);
  ...
  endElement(n.getNamespaceURI(), n.getLocalName(), n.getNodeName());

which enhances the result for the elements:

  [characters] Zu «Alpdurchblick. Filme zur NEAT» ist ein Katalog mit
ausführlichen Informationen zum Gesamtprogramm erhältlich. Zu beziehen ist
er bei Filmkreis Oberwallis ...
  [startElement]
uri=urn:pro-helvetia.ch:phga:docmini:v1.1,local=link,raw=d:link
  [            ] 1.
uri=null,local=href,qname=href,type=CDATA,value=mailto:[EMAIL PROTECTED]

but still uri=null for the attributes.

I tried to change the message in the catalogue and introduced a 'xlink'
prefix before the 'href' attribute. If the attribute's prefix is present, it
works, it doesn't throw a NPE anymore:

  [characters] Zu «Alpdurchblick. Filme zur NEAT» ist ein Katalog mit
ausführlichen Informationen zum Gesamtprogramm erhältlich. Zu beziehen ist
er bei Filmkreis Oberwallis ...
  [startElement]
uri=urn:pro-helvetia.ch:phga:docmini:v1.1,local=link,raw=d:link
  [            ] 1.
uri=http://www.w3.org/1999/xlink,local=href,qname=xlink:href,type=CDATA,valu
e=mailto:[EMAIL PROTECTED]
  [characters] email @ domain.ch
  ...
  [endDocument]

So the problem arises only when there is no namespace for an attribute. I
modified MirrorRecorder.nodeToEvents(), replacing (line 220):

      ((AttributesImpl) attrs).addAttribute(node.getNamespaceURI(),
      ... );

with:

      String sNamespaceURI = node.getNamespaceURI();
      if( sNamespaceURI == null) { sNamespaceURI = ""; }
      ((AttributesImpl) attrs).addAttribute(sNamespaceURI,
      ... );

and this fixes the problem.

But why would the uri=null when no prefix is present for an attribute of an
element in a catalogue's message?

Is that normal SAX behavior - and we should replace the null value with an
empty string in MirrorRecord.nodeToEvents while recording the attributes, as
I did? Or is it a bug? (i.e. node.getNamespaceURI() returns null)

Olivier


-----Message d'origine-----
De : Bruno Dumon [mailto:[EMAIL PROTECTED]
Envoyé : mercredi, 10. septembre 2003 11:36
À : [EMAIL PROTECTED]
Objet : Re: i18n trouble with nested elements in catalog messages


On Wed, 2003-09-10 at 11:05, Konstantin Piroumian wrote:
> Hi Oliver,
>
> Sorry, hadn't time to investigate the problem, but from looking through
the
> code I didn't notice anything that could possibly be related to the
problem.
>
> Your suggestion with the getLocaleName() instead of getName() is correct
and
> should be fixed, though it doesn't solve the problem.
>
> As a suggestion, try to add some logging to the XMLResourceBundle which is
> in the i18n packet (src/java/org/apache/cocoon/i18n) and see if it parses
> the namespace at all and does it give out the URI.
>
> I'll try to take a look at it myself more closely a little later.
>

Just had a quick look too, I think the problem is that the files are not
parsed namespace-aware: see these lines in the class "XMLResourceBundle"
(line 201-202):

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();

Oliver, could you try putting the following between those two:
factory.setNamespaceAware(true);

and let us know if it helps?

--
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
[EMAIL PROTECTED]                          [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to