use of org.apache.jackrabbit.oak.spi.xml.PropInfo 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.PropInfo in project jackrabbit-oak by apache.
the class ImporterImpl method importProperties.
private void importProperties(@NotNull Tree tree, @NotNull List<PropInfo> propInfos, boolean ignoreRegular) throws RepositoryException {
// process properties
for (PropInfo pi : propInfos) {
// find applicable definition
// TODO find better heuristics?
EffectiveNodeType ent = effectiveNodeTypeProvider.getEffectiveNodeType(tree);
PropertyDefinition def = ent.getPropertyDefinition(pi.getName(), pi.getType(), pi.isUnknownMultiple());
if (def == null) {
throw new ConstraintViolationException("No matching property definition found for " + pi.getName());
}
if (def.isProtected()) {
// skip protected property
log.debug("Protected property {}", pi.getName());
// notify the ProtectedPropertyImporter.
for (ProtectedPropertyImporter ppi : getPropertyImporters()) {
if (ppi.handlePropInfo(tree, pi, def)) {
log.debug("Protected property -> delegated to ProtectedPropertyImporter");
break;
}
/* else: p-i-Importer isn't able to deal with this property. try next pp-importer */
}
} else if (!ignoreRegular) {
// regular property -> create the property
createProperty(tree, pi, def);
}
}
for (ProtectedPropertyImporter ppi : getPropertyImporters()) {
ppi.propertiesCompleted(tree);
}
}
Aggregations