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 {
Properties props = XMLUtils.createPropertiesForXML(false);
props.put(OutputKeys.ENCODING, "ISO-8859-1");
final String content = XMLUtils.serializeNode(frag, props);
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 {
oStream.flush();
try {
oStream.close();
} catch (Exception ignore) {
// do nothing
}
if (selector != null) {
selector.release(serializer);
manager.release(selector);
}
}
content = oStream.toString();
} else {
Properties props = XMLUtils.createPropertiesForXML(false);