ModifiableSource ws = (ModifiableSource) source;
frag.normalize();
if ( null != serializerName) {
ComponentManager manager = CocoonComponentManager.getSitemapComponentManager();
ComponentSelector selector = null;
Serializer serializer = null;
OutputStream oStream = null;
try {
selector = (ComponentSelector)manager.lookup(Serializer.ROLE + "Selector");
serializer = (Serializer)selector.select(serializerName);
oStream = ws.getOutputStream();
serializer.setOutputStream(oStream);
serializer.startDocument();
DOMStreamer streamer = new DOMStreamer(serializer);
streamer.stream(frag);
serializer.endDocument();
} catch (ComponentException e) {
throw new ProcessingException("Unable to lookup serializer.", e);
} finally {
if (oStream != null) {
oStream.flush();
try {
oStream.close();
} catch (Exception ignore) {
}
}
if ( selector != null ) {
selector.release( serializer );
manager.release( selector );
}
}
} else {
final String content = XMLUtils.serializeNode(frag,
XMLUtils.defaultSerializeToXMLFormat(false));
OutputStream oStream = ws.getOutputStream();
oStream.write(content.getBytes());
oStream.flush();
oStream.close();
}
} else {
String content;
if ( null != serializerName) {
ComponentManager manager = CocoonComponentManager.getSitemapComponentManager();
ComponentSelector selector = null;
Serializer serializer = null;
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
try {
selector = (ComponentSelector)manager.lookup(Serializer.ROLE + "Selector");
serializer = (Serializer)selector.select(serializerName);
serializer.setOutputStream(oStream);
serializer.startDocument();
DOMStreamer streamer = new DOMStreamer(serializer);
streamer.stream(frag);
serializer.endDocument();
} catch (ComponentException e) {
throw new ProcessingException("Unable to lookup serializer.", e);
} finally {
if (oStream != null) {
oStream.flush();
try {
oStream.close();
} catch (Exception ignore) {
}
}
if ( selector != null ) {
selector.release( serializer );
manager.release( selector );
}
}
content = oStream.toString();
} else {
content = XMLUtils.serializeNode(frag,