private static function exportSystemViewRecursive(NodeInterface $node, NamespaceRegistryInterface $ns, $stream, $skipBinary, $noRecurse, $root = false)
{
fwrite($stream, '<sv:node');
if ($root) {
self::exportNamespaceDeclarations($ns, $stream);
}
fwrite($stream, ' sv:name="' . (0 === $node->getDepth() ? 'jcr:root' : htmlspecialchars($node->getName())) . '">');
// the order MUST be primary type, then mixins, if any, then jcr:uuid if its a referenceable node
fwrite($stream, '<sv:property sv:name="jcr:primaryType" sv:type="Name"><sv:value>' . htmlspecialchars($node->getPropertyValue('jcr:primaryType')) . '</sv:value></sv:property>');
if ($node->hasProperty('jcr:mixinTypes')) {
fwrite($stream, '<sv:property sv:name="jcr:mixinTypes" sv:type="Name" sv:multiple="true">');
foreach ($node->getPropertyValue('jcr:mixinTypes') as $type) {
fwrite($stream, '<sv:value>' . htmlspecialchars($type) . '</sv:value>');
}
fwrite($stream, '</sv:property>');
}
if ($node->isNodeType('mix:referenceable')) {
fwrite($stream, '<sv:property sv:name="jcr:uuid" sv:type="String"><sv:value>' . $node->getIdentifier() . '</sv:value></sv:property>');
}
foreach ($node->getProperties() as $name => $property) {
/** @var $property PropertyInterface */
if (in_array($name, array('jcr:primaryType', 'jcr:mixinTypes', 'jcr:uuid'), true)) {
// explicitly handled before
continue;
}
if ($skipBinary && PropertyType::BINARY === $property->getType()) {
// do not output binary data in the xml
continue;
}
fwrite($stream, '<sv:property sv:name="' . htmlentities($name) . '" sv:type="' . PropertyType::nameFromValue($property->getType()) . '"' . ($property->isMultiple() ? ' sv:multiple="true"' : '') . '>');
$values = $property->isMultiple() ? $property->getString() : array($property->getString());
foreach ($values as $value) {
if (PropertyType::BINARY === $property->getType()) {
$val = base64_encode($value);
} else {
$val = htmlspecialchars($value);
//TODO: can we still have invalid characters after this? if so base64 and property, xsi:type="xsd:base64Binary"
}
fwrite($stream, "<sv:value>{$val}</sv:value>");
}
fwrite($stream, "</sv:property>");
}
if (!$noRecurse) {
foreach ($node as $child) {
if (!($child->getDepth() === 1 && NodeHelper::isSystemItem($child))) {
self::exportSystemViewRecursive($child, $ns, $stream, $skipBinary, $noRecurse);
}
}
}
fwrite($stream, '</sv:node>');
}