Search in sources :

Example 36 with PropInfo

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);
    }
}
Also used : TextValue(org.apache.jackrabbit.oak.spi.xml.TextValue) NodeInfo(org.apache.jackrabbit.oak.spi.xml.NodeInfo) ArrayList(java.util.ArrayList) PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) RepositoryException(javax.jcr.RepositoryException) SAXException(org.xml.sax.SAXException)

Example 37 with PropInfo

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);
    }
}
Also used : EffectiveNodeType(org.apache.jackrabbit.oak.spi.nodetype.EffectiveNodeType) ProtectedPropertyImporter(org.apache.jackrabbit.oak.spi.xml.ProtectedPropertyImporter) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Aggregations

PropInfo (org.apache.jackrabbit.oak.spi.xml.PropInfo)37 Test (org.junit.Test)26 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)15 Tree (org.apache.jackrabbit.oak.api.Tree)14 MockUtility.mockTree (org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl.MockUtility.mockTree)8 TextValue (org.apache.jackrabbit.oak.spi.xml.TextValue)8 ArrayList (java.util.ArrayList)5 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)5 RepositoryException (javax.jcr.RepositoryException)4 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)4 SAXException (org.xml.sax.SAXException)4 User (org.apache.jackrabbit.api.security.user.User)3 NodeInfo (org.apache.jackrabbit.oak.spi.xml.NodeInfo)3 ImmutableList (com.google.common.collect.ImmutableList)2 IOException (java.io.IOException)2 List (java.util.List)2 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Reader (java.io.Reader)1 Map (java.util.Map)1