use of org.apache.jackrabbit.oak.spi.xml.PropInfo 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.PropInfo in project jackrabbit-oak by apache.
the class SysViewImportHandler method endElement.
@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
// check element name
ImportState state = stack.peek();
if (namespaceURI.equals(NamespaceConstants.NAMESPACE_SV) && "node".equals(localName)) {
// sv:node element
if (!state.started) {
// need to start & end current node
processNode(state, true, true);
state.started = true;
} else {
// need to end current node
processNode(state, false, true);
}
// pop current state from stack
stack.pop();
} else if (namespaceURI.equals(NamespaceConstants.NAMESPACE_SV) && "property".equals(localName)) {
// have been collected and create node as necessary primaryType
if (isSystemProperty("primaryType")) {
BufferedStringValue val = currentPropValues.get(0);
String s = null;
try {
s = val.retrieve();
state.nodeTypeName = new NameInfo(s).getRepoQualifiedName();
} catch (IOException e) {
throw new SAXException(new InvalidSerializedDataException("illegal node type name: " + s, e));
} catch (RepositoryException e) {
throw new SAXException(new InvalidSerializedDataException("illegal node type name: " + s, e));
}
} else if (isSystemProperty("mixinTypes")) {
if (state.mixinNames == null) {
state.mixinNames = new ArrayList<String>(currentPropValues.size());
}
for (BufferedStringValue val : currentPropValues) {
String s = null;
try {
s = val.retrieve();
state.mixinNames.add(new NameInfo(s).getRepoQualifiedName());
} catch (IOException ioe) {
throw new SAXException("error while retrieving value", ioe);
} catch (RepositoryException e) {
throw new SAXException(new InvalidSerializedDataException("illegal mixin type name: " + s, e));
}
}
} else if (isSystemProperty("uuid")) {
BufferedStringValue val = currentPropValues.get(0);
try {
state.uuid = val.retrieve();
} catch (IOException ioe) {
throw new SAXException("error while retrieving value", ioe);
}
} else {
if (currentPropMultipleStatus == PropInfo.MultipleStatus.UNKNOWN && currentPropValues.size() != 1) {
currentPropMultipleStatus = PropInfo.MultipleStatus.MULTIPLE;
}
PropInfo prop = new PropInfo(currentPropName == null ? null : currentPropName.getRepoQualifiedName(), currentPropType, currentPropValues, currentPropMultipleStatus);
state.props.add(prop);
}
// reset temp fields
currentPropValues.clear();
} else if (namespaceURI.equals(NamespaceConstants.NAMESPACE_SV) && "value".equals(localName)) {
// sv:value element
currentPropValues.add(currentPropValue);
// reset temp fields
currentPropValue = null;
} else {
throw new SAXException(new InvalidSerializedDataException("invalid element in system view xml document: " + localName));
}
}
use of org.apache.jackrabbit.oak.spi.xml.PropInfo 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.PropInfo in project jackrabbit-oak by apache.
the class CugImporterTest method testInvalidPropInfo.
@Test
public void testInvalidPropInfo() throws Exception {
createCug(root, SUPPORTED_PATH, "principalName");
Tree parent = root.getTree(SUPPORTED_PATH);
PropInfo propInfo = new PropInfo(JcrConstants.JCR_PRIMARYTYPE, PropertyType.STRING, ImmutableList.of(new TextValue() {
@Override
public String getString() {
return "principalName";
}
@Override
public Value getValue(int targetType) throws RepositoryException {
return getValueFactory(root).createValue("principalName", PropertyType.STRING);
}
@Override
public void dispose() {
}
}));
PropertyDefinition propDef = Mockito.mock(PropertyDefinition.class);
assertFalse(importer.handlePropInfo(parent, propInfo, propDef));
}
use of org.apache.jackrabbit.oak.spi.xml.PropInfo in project jackrabbit-oak by apache.
the class PrincipalPolicyImporterTest method testStartChildInfoWrongEffectivePathPropertyType.
@Test(expected = ConstraintViolationException.class)
public void testStartChildInfoWrongEffectivePathPropertyType() throws Exception {
init(true, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
User user = getTestSystemUser();
Tree policyTree = createPolicyTree(user);
importer.handlePropInfo(policyTree, mockPropInfo(user.getPrincipal()), mockPropertyDefinition(getJcrName(NT_REP_PRINCIPAL_POLICY)));
List<PropInfo> propInfos = mockPropInfos(null, PrivilegeConstants.JCR_REMOVE_CHILD_NODES);
// effective path with wrong type
TextValue tx = when(mock(TextValue.class).getString()).thenReturn("/effective/path").getMock();
PropInfo propInfo = mockPropInfo(getJcrName(REP_EFFECTIVE_PATH));
when(propInfo.getTextValue()).thenReturn(tx);
when(propInfo.getType()).thenReturn(PropertyType.STRING);
propInfos.add(propInfo);
importer.startChildInfo(mockNodeInfo("entry", getJcrName(NT_REP_PRINCIPAL_ENTRY)), propInfos);
}
Aggregations