Search in sources :

Example 6 with PropertyId

use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.

the class BatchTest method testEmptyValueArray.

public void testEmptyValueArray() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    Name propName = resolver.getQName("mvProperty");
    Batch b = rs.createBatch(si, nid);
    b.addProperty(nid, propName, new QValue[0]);
    rs.submit(b);
    PropertyId pid = getPropertyId(nid, propName);
    PropertyInfo pi = rs.getPropertyInfo(si, pid);
    assertTrue(pi.isMultiValued());
    assertEquals(Arrays.asList(new QValue[0]), Arrays.asList(pi.getValues()));
    assertFalse(pi.getType() == PropertyType.UNDEFINED);
    Iterator<? extends ItemInfo> it = rs.getItemInfos(si, nid);
    while (it.hasNext()) {
        ItemInfo info = it.next();
        if (!info.denotesNode()) {
            PropertyInfo pInfo = (PropertyInfo) info;
            if (propName.equals((pInfo.getId().getName()))) {
                assertTrue(pi.isMultiValued());
                assertEquals(Arrays.asList(new QValue[0]), Arrays.asList(pi.getValues()));
                assertFalse(pi.getType() == PropertyType.UNDEFINED);
                break;
            }
        }
    }
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) Batch(org.apache.jackrabbit.spi.Batch) ItemInfo(org.apache.jackrabbit.spi.ItemInfo) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.spi.PropertyId)

Example 7 with PropertyId

use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.

the class ItemInfoJsonHandler method endArray.

public void endArray() throws IOException {
    try {
        if (propertyType == PropertyType.UNDEFINED) {
            if (propValues.isEmpty()) {
                // make sure that type is set for mv-properties with empty value array.
                propertyType = vFactory.retrieveType(getValueURI());
            } else {
                propertyType = propValues.get(0).getType();
            }
        }
        // create multi-valued property info
        NodeInfoImpl parent = getCurrentNodeInfo();
        Path p = pFactory.create(parent.getPath(), name, true);
        PropertyId id = idFactory.createPropertyId(parent.getId(), name);
        PropertyInfoImpl propInfo = new PropertyInfoImpl(id, p, propertyType, propValues.toArray(new QValue[propValues.size()]));
        propInfo.checkCompleted();
        getCurrentPropInfos().add(propInfo);
    } catch (RepositoryException e) {
        throw new IOException(e.getMessage(), e);
    } finally {
        // reset property-related handler state
        propertyType = PropertyType.UNDEFINED;
        multiValuedProperty = false;
        propValues.clear();
        name = null;
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) QValue(org.apache.jackrabbit.spi.QValue) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) PropertyId(org.apache.jackrabbit.spi.PropertyId)

Example 8 with PropertyId

use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.

the class NodeInfoImpl method createSerializableNodeInfo.

/**
 * Creates a new serializable <code>NodeInfo</code> for the given
 * <code>NodeInfo</code>.
 *
 * @param nodeInfo
 */
public static NodeInfo createSerializableNodeInfo(NodeInfo nodeInfo, final IdFactory idFactory) {
    if (nodeInfo instanceof Serializable) {
        return nodeInfo;
    } else {
        List<PropertyId> serRefs = new ArrayList<PropertyId>();
        for (PropertyId ref : nodeInfo.getReferences()) {
            NodeId parentId = ref.getParentId();
            parentId = idFactory.createNodeId(parentId.getUniqueID(), parentId.getPath());
            serRefs.add(idFactory.createPropertyId(parentId, ref.getName()));
        }
        NodeId nodeId = nodeInfo.getId();
        nodeId = idFactory.createNodeId(nodeId.getUniqueID(), nodeId.getPath());
        final Iterator<PropertyId> propIds = nodeInfo.getPropertyIds();
        final Iterator<ChildInfo> childInfos = nodeInfo.getChildInfos();
        return new NodeInfoImpl(nodeInfo.getPath(), nodeId, nodeInfo.getIndex(), nodeInfo.getNodetype(), nodeInfo.getMixins(), serRefs.iterator(), new Iterator<PropertyId>() {

            public boolean hasNext() {
                return propIds.hasNext();
            }

            public PropertyId next() {
                PropertyId propId = propIds.next();
                NodeId parentId = propId.getParentId();
                idFactory.createNodeId(parentId.getUniqueID(), parentId.getPath());
                return idFactory.createPropertyId(parentId, propId.getName());
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }
        }, ((childInfos == null) ? null : new Iterator<ChildInfo>() {

            public boolean hasNext() {
                return childInfos.hasNext();
            }

            public ChildInfo next() {
                ChildInfo cInfo = childInfos.next();
                if (cInfo instanceof Serializable) {
                    return cInfo;
                } else {
                    return new ChildInfoImpl(cInfo.getName(), cInfo.getUniqueID(), cInfo.getIndex());
                }
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }
        }));
    }
}
Also used : Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) NodeId(org.apache.jackrabbit.spi.NodeId) ChildInfo(org.apache.jackrabbit.spi.ChildInfo) PropertyId(org.apache.jackrabbit.spi.PropertyId)

Example 9 with PropertyId

use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.

the class NodeImpl method getReferences.

/**
 * @param name
 * @param weak
 * @return
 * @throws RepositoryException
 */
private LazyItemIterator getReferences(String name, boolean weak) throws RepositoryException {
    checkStatus();
    Name propName = (name == null) ? null : getQName(name);
    Iterator<PropertyId> itr = getNodeState().getNodeReferences(propName, weak);
    return new LazyItemIterator(getItemManager(), session.getHierarchyManager(), itr);
}
Also used : Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.spi.PropertyId)

Example 10 with PropertyId

use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.

the class RepositoryServiceImpl method getItemInfos.

/**
 * {@inheritDoc}
 */
public Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo, ItemId itemId) throws ItemNotFoundException, RepositoryException {
    if (!itemId.denotesNode()) {
        PropertyId propertyId = (PropertyId) itemId;
        PropertyInfo propertyInfo = getPropertyInfo(sessionInfo, propertyId);
        return Iterators.singleton(propertyInfo);
    } else {
        NodeId nodeId = (NodeId) itemId;
        final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
        Node node = getNode(nodeId, sInfo);
        Name ntName = null;
        try {
            ntName = sInfo.getNamePathResolver().getQName(node.getProperty(JcrConstants.JCR_PRIMARYTYPE).getString());
        } catch (NameException e) {
        // ignore. should never occur
        }
        int depth = batchReadConfig.getDepth(ntName);
        if (depth == BatchReadConfig.DEPTH_DEFAULT) {
            NodeInfo info;
            try {
                info = new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver());
            } catch (NameException e) {
                throw new RepositoryException(e);
            }
            return Collections.singletonList(info).iterator();
        } else {
            final List<ItemInfo> itemInfos = new ArrayList<ItemInfo>();
            ItemVisitor visitor = new TraversingItemVisitor(false, depth) {

                @Override
                protected void entering(Property property, int i) throws RepositoryException {
                    try {
                        itemInfos.add(new PropertyInfoImpl(property, idFactory, sInfo.getNamePathResolver(), getQValueFactory()));
                    } catch (NameException e) {
                        throw new RepositoryException(e);
                    }
                }

                @Override
                protected void entering(Node node, int i) throws RepositoryException {
                    try {
                        itemInfos.add(new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver()));
                    } catch (NameException e) {
                        throw new RepositoryException(e);
                    }
                }

                @Override
                protected void leaving(Property property, int i) {
                // nothing to do
                }

                @Override
                protected void leaving(Node node, int i) {
                // nothing to do
                }
            };
            visitor.visit(node);
            return itemInfos.iterator();
        }
    }
}
Also used : ItemInfo(org.apache.jackrabbit.spi.ItemInfo) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) PropertyId(org.apache.jackrabbit.spi.PropertyId) Name(org.apache.jackrabbit.spi.Name) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) ItemVisitor(javax.jcr.ItemVisitor) NodeInfo(org.apache.jackrabbit.spi.NodeInfo) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) Property(javax.jcr.Property)

Aggregations

PropertyId (org.apache.jackrabbit.spi.PropertyId)21 NodeId (org.apache.jackrabbit.spi.NodeId)13 Name (org.apache.jackrabbit.spi.Name)10 RepositoryException (javax.jcr.RepositoryException)8 ArrayList (java.util.ArrayList)6 Path (org.apache.jackrabbit.spi.Path)6 PropertyInfo (org.apache.jackrabbit.spi.PropertyInfo)5 QValue (org.apache.jackrabbit.spi.QValue)5 Batch (org.apache.jackrabbit.spi.Batch)4 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)4 IOException (java.io.IOException)3 ItemNotFoundException (javax.jcr.ItemNotFoundException)3 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)3 Serializable (java.io.Serializable)2 Node (javax.jcr.Node)2 HttpResponse (org.apache.http.HttpResponse)2 ChildInfo (org.apache.jackrabbit.spi.ChildInfo)2 ItemId (org.apache.jackrabbit.spi.ItemId)2 ItemInfo (org.apache.jackrabbit.spi.ItemInfo)2 NamePathResolver (org.apache.jackrabbit.spi.commons.conversion.NamePathResolver)2