* @throws IOException {@link IOException}
*/
public InputStream getContentAsStream(final String rootHref) throws IOException
{
final PipedOutputStream po = new PipedOutputStream();
final PipedInputStream pi = new PipedInputStream(po);
new Thread()
{
@Override
public void run()
{
try
{
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = factory.createXMLStreamWriter(po, Constants.DEFAULT_ENCODING);
writer.writeStartDocument(Constants.DEFAULT_ENCODING, "1.0");
writer.writeStartElement(XML_NODE);
writer.writeAttribute(PREFIX_XMLNS, PREFIX_LINK);
writer.writeAttribute(XLINK_XMLNS, XLINK_LINK);
writer.writeAttribute(XML_NAME, node.getName());
writer.writeAttribute(XML_HREF, rootHref + TextUtil.escape(node.getPath(), '%', true));
if (!node.getPath().equals("/"))
{
// this is added to fix EXOJCR-1379
// XSLT string operations with actual node href, (which are used during XSLT transformation
// to receive parent href) produce wrong parent-href if node path containes non-latin symbols,
// so instead we simply add one more attribute which already contains parent-href
// as result: no XLST processor string manipulation is needed
String nodeParentHref = rootHref + TextUtil.escape(node.getParent().getPath(), '%', true);
writer.writeAttribute(XML_PARENT_HREF, nodeParentHref);
}
// add properties
for (PropertyIterator pi = node.getProperties(); pi.hasNext();)
{
Property curProperty = pi.nextProperty();
writer.writeStartElement(XML_PROPERTY);
writer.writeAttribute(XML_NAME, curProperty.getName());
String propertyHref = rootHref + curProperty.getPath();
writer.writeAttribute(XML_HREF, propertyHref);
writer.writeEndElement();