// tags enabling Castor XML binding; see JETSPEED-INF/castor/page-mapping.xml
writer = new OutputStreamWriter(new FileOutputStream(f), PSML_DOCUMENT_ENCODING);
Serializer serializer = new XMLSerializer(writer, this.format);
final ContentHandler handler = serializer.asContentHandler();
Marshaller marshaller = new Marshaller(new ContentHandler()
{
private int menuDepth = 0;
public void characters(char[] ch, int start, int length) throws SAXException
{
handler.characters(ch, start, length);
}
public void endDocument() throws SAXException
{
handler.endDocument();
}
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
{
handler.ignorableWhitespace(ch, start, length);
}
public void processingInstruction(String target, String data) throws SAXException
{
handler.processingInstruction(target, data);
}
public void setDocumentLocator(Locator locator)
{
handler.setDocumentLocator(locator);
}
public void startDocument() throws SAXException
{
handler.startDocument();
}
public void endElement(String uri, String localName, String qName) throws SAXException {
// track menu depth
if (qName.equals("menu"))
{
menuDepth--;
}
// filter menu-element noded within menu definition
if ((menuDepth == 0) || !qName.equals("menu-element"))
{
handler.endElement(uri, localName, qName);
}
}
public void endPrefixMapping(String prefix) throws SAXException {
}
public void skippedEntity(String name) throws SAXException {
handler.skippedEntity(name);
}
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
// filter menu-element noded within menu definition
if ((menuDepth == 0) || !qName.equals("menu-element"))
{
handler.startElement(uri,localName, qName, atts);
}
// track menu depth
if (qName.equals("menu"))
{
menuDepth++;
}
}
public void startPrefixMapping(String prefix, String uri) throws SAXException {
}
});
marshaller.setResolver((XMLClassDescriptorResolver) classDescriptorResolver);
marshaller.setValidation(false); // results in better performance
marshaller.marshal(document);
}
catch (MarshalException e)
{
log.error("Could not marshal the file " + f.getAbsolutePath(), e);
throw new FailedToUpdateDocumentException(e);