use of org.apache.jackrabbit.oak.spi.xml.NodeInfo in project jackrabbit-oak by apache.
the class DocViewImportHandler method processCharacters.
/**
* Translates character data reported by the
* {@code {@link #characters(char[], int, int)}} &
* {@code {@link #ignorableWhitespace(char[], int, int)}} SAX events
* into a {@code jcr:xmltext} child node with one
* {@code jcr:xmlcharacters} property.
*
* @throws SAXException if an error occurs
* @see #appendCharacters(char[], int, int)
*/
private void processCharacters() throws SAXException {
try {
if (textHandler != null && textHandler.length() > 0) {
// there is character data that needs to be added to
// the current node
// check for pure whitespace character data
Reader reader = textHandler.reader();
try {
int ch;
while ((ch = reader.read()) != -1) {
if (ch > 0x20) {
break;
}
}
if (ch == -1) {
// the character data consists of pure whitespace, ignore
log.debug("ignoring pure whitespace character data...");
// reset handler
textHandler.dispose();
textHandler = null;
return;
}
} finally {
reader.close();
}
NodeInfo node = new NodeInfo(getJcrName(NamespaceRegistry.NAMESPACE_JCR, "xmltext"), null, null, null);
ArrayList<PropInfo> props = new ArrayList<PropInfo>();
props.add(new PropInfo(getJcrName(NamespaceRegistry.NAMESPACE_JCR, "xmlcharacters"), PropertyType.STRING, textHandler));
// call Importer
importer.startNode(node, props);
importer.endNode(node);
// reset handler
textHandler.dispose();
textHandler = null;
}
} catch (IOException ioe) {
String msg = "internal error while processing internal buffer data";
log.error(msg, ioe);
throw new SAXException(msg, ioe);
} catch (RepositoryException re) {
throw new SAXException(re);
}
}
use of org.apache.jackrabbit.oak.spi.xml.NodeInfo in project jackrabbit-oak by apache.
the class SysViewImportHandler method processNode.
private void processNode(ImportState state, boolean start, boolean end) throws SAXException {
if (!start && !end) {
return;
}
String id = state.uuid;
NodeInfo node = new NodeInfo(state.nodeName, state.nodeTypeName, state.mixinNames, id);
// call Importer
try {
if (start) {
importer.startNode(node, state.props);
// dispose temporary property values
for (PropInfo pi : state.props) {
pi.dispose();
}
}
if (end) {
importer.endNode(node);
}
} catch (RepositoryException re) {
throw new SAXException(re);
}
}
use of org.apache.jackrabbit.oak.spi.xml.NodeInfo in project jackrabbit-oak by apache.
the class AccessControlImporterBaseTest method testStartChildInfoUnknownType.
@Test(expected = ConstraintViolationException.class)
public void testStartChildInfoUnknownType() throws Exception {
NodeInfo invalidChildInfo = new NodeInfo("anyName", NodeTypeConstants.NT_OAK_UNSTRUCTURED, ImmutableList.of(), null);
init();
importer.start(aclTree);
importer.startChildInfo(invalidChildInfo, ImmutableList.of());
}
use of org.apache.jackrabbit.oak.spi.xml.NodeInfo in project jackrabbit-oak by apache.
the class DocViewImportHandler method startElement.
//-------------------------------------------------------< ContentHandler >
/**
* {@inheritDoc}
* <p>
* See also {@link org.apache.jackrabbit.commons.xml.Exporter#exportProperties(Node)}
* regarding special handling of multi-valued properties on export.
*/
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
// process buffered character data
processCharacters();
try {
NameInfo nameInfo = new NameInfo(qName);
nameInfo = processName(nameInfo);
// properties
String id = null;
String nodeTypeName = null;
Iterable<String> mixinTypes = null;
List<PropInfo> props = new ArrayList<PropInfo>(atts.getLength());
for (int i = 0; i < atts.getLength(); i++) {
if (atts.getURI(i).equals(NamespaceConstants.NAMESPACE_XMLNS)) {
// see http://issues.apache.org/jira/browse/JCR-620#action_12448164
continue;
}
NameInfo propNameInfo = processName(new NameInfo(atts.getQName(i)));
String attrValue = atts.getValue(i);
if (NamespaceRegistry.NAMESPACE_JCR.equals(propNameInfo.getNamespaceUri()) && "primaryType".equals(propNameInfo.getLocalName())) {
// jcr:primaryType
if (!attrValue.isEmpty()) {
//TODO
nodeTypeName = attrValue;
}
} else if (NamespaceRegistry.NAMESPACE_JCR.equals(propNameInfo.getNamespaceUri()) && "mixinTypes".equals(propNameInfo.getLocalName())) {
// jcr:mixinTypes
mixinTypes = parseNames(attrValue);
} else if (NamespaceRegistry.NAMESPACE_JCR.equals(propNameInfo.getNamespaceUri()) && "uuid".equals(propNameInfo.getLocalName())) {
// jcr:uuid
if (!attrValue.isEmpty()) {
id = attrValue;
}
} else {
// always assume single-valued property for the time being
// until a way of properly serializing/detecting multi-valued
// properties on re-import is found (see JCR-325);
// see also DocViewSAXEventGenerator#leavingProperties(Node, int)
// TODO proper multi-value serialization support
TextValue tv = new StringValue(attrValue, sessionContext.getValueFactory(), currentNamePathMapper());
props.add(new PropInfo(propNameInfo.getRepoQualifiedName(), PropertyType.UNDEFINED, tv));
}
}
NodeInfo node = new NodeInfo(nameInfo.getRepoQualifiedName(), nodeTypeName, mixinTypes, id);
// all information has been collected, now delegate to importer
importer.startNode(node, props);
// push current node data onto stack
stack.push(node);
} catch (RepositoryException re) {
throw new SAXException(re);
}
}
use of org.apache.jackrabbit.oak.spi.xml.NodeInfo in project jackrabbit-oak by apache.
the class DocViewImportHandler method endElement.
@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
// process buffered character data
processCharacters();
NodeInfo node = stack.peek();
try {
// call Importer
importer.endNode(node);
} catch (RepositoryException re) {
throw new SAXException(re);
}
// we're done with this node, pop it from stack
stack.pop();
}
Aggregations