From: Robert K. <ro...@ko...> - 2006-11-25 17:05:08
|
Hi again, One more thing on this: I have to check the endElement callback to find the end of the associated document, otheriwise endDocument is the end of the site.xml. If I throw a SAXException on the associated document's ending element (in endElement) it registers an XMLDBException in the SiteXmlIndexer, but continues to parse the site.xml in the MetadataIndexHandler. Robert Koberg wrote: > Hi, > > I am using eXist's LocalCollection and LocalXMLResource. > > I have a LocalXMLResource that is basically a hierarchical > representation of a website - site.xml[1]. I want to run that through > content handler and trigger 'sub' content handlers that handle > LocalXMLResources that are associated to elements in the site.xml. (This > is to use lucene to index the XML resources of a website project.) So I > start out like: > > Collection rootCollection = user.getCurrentProjectCollection(); > try { > siteXmlRes = (XMLResource)rootCollection.getResource("site.xml"); > if (siteXmlRes == null) throw... > > siteXmlRes.getContentAsSAX(new SiteXmlIndexer(project, rootCollection, > luceneWriter)); > > } catch (XMLDBException e) { > ... > } > > The SiteXmlIndexer (extending DefaultHandler2) basically: > - sets up a lucene document for each element in the site.xml > - adds some fields to the document for each elem > - finds associated LocalXMLResources > --- each element in the site.xml has an associated {@id}.xml metadata file > --- content elements have an associated {@id}.xml content file > - then run the associated resources through their own content handler > --- return to SiteXmlIndexer at endDocument and continue down the > site.xml hierarchy. > > The problem is that once the first 'sub' content handler gets used, it > takes over the processing/handling of the other resources. So, at end > document on the first metadata resource, the MetadataIndexHandler keeps > going on the site.xml rather than returning to the SiteXmlIndexer > handler. I have tried adding a 'return;' at the end of my endDocument > method in the MetadataIndexHandler. > > How can I get the sub handlers to return on endDocument? > > The relevant part of the code in SiteXmlIndexer looks like: > > public void startElement(String uri, String localName, > String qName, Attributes atts) throws SAXException { > ... > StringBuilder fileName = new StringBuilder(id.length() + 4); > fileName.append(id); > fileName.append(".xml"); > try { > LocalXMLResource md = (LocalXMLResource) > metadataCol.getResource(fileName.toString()); > if (md == null) { > ... > } else { > ... > md.getContentAsSAX(new MetadataIndexHandler(luceneDoc)); > } > } catch (XMLDBException e) { > ... > } > if (localName.equals("content")) { > try { > LocalXMLResource c = (LocalXMLResource) > contentCol.getResource(fileName.toString()); > if (c == null) { > ... > } else { > ... > c.getContentAsSAX(new ContentIndexHandler(luceneDoc)); > } > } catch (XMLDBException e) { > ... > } > } > > thanks, > -Rob > > [1] site.xml: > <site generate="1" id="site_root" label="Home" name="" xmlns="myns" > layout="default"> > <page generate="1" id="P88007" label="qa aq" name="P88007.html" > onnav="1"/> > <content generate="1" id="C27597" label="New Content" > name="C27597.html" onnav="1"/> > <content generate="1" id="C26068" label="blah blah" name="C26068.html" > onnav="1"/> > </site> > |