Search in sources :

Example 1 with PropertyImpl

use of org.apache.jackrabbit.core.PropertyImpl in project jackrabbit by apache.

the class ImpersonationImpl method updateImpersonatorNames.

private void updateImpersonatorNames(Set<String> principalNames) throws RepositoryException {
    NodeImpl userNode = user.getNode();
    try {
        String[] pNames = principalNames.toArray(new String[principalNames.size()]);
        if (pNames.length == 0) {
            PropertyImpl prop = userNode.getProperty(P_IMPERSONATORS);
            userManager.removeProtectedItem(prop, userNode);
        } else {
            Value[] values = new Value[pNames.length];
            for (int i = 0; i < pNames.length; i++) {
                values[i] = new StringValue(pNames[i]);
            }
            userManager.setProtectedProperty(userNode, P_IMPERSONATORS, values);
        }
    } catch (RepositoryException e) {
        // revert pending changes
        userNode.refresh(false);
        throw e;
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl) RepositoryException(javax.jcr.RepositoryException) StringValue(org.apache.jackrabbit.value.StringValue)

Example 2 with PropertyImpl

use of org.apache.jackrabbit.core.PropertyImpl in project jackrabbit by apache.

the class UserImpl method disable.

/**
 * @see User#disable(String)
 */
public void disable(String reason) throws RepositoryException {
    if (isAdmin()) {
        throw new RepositoryException("The administrator user cannot be disabled.");
    }
    if (reason == null) {
        if (isDisabled()) {
            // enable the user again.
            PropertyImpl disableProp = getNode().getProperty(P_DISABLED);
            userManager.removeProtectedItem(disableProp, getNode());
        }
    // else: nothing to do.
    } else {
        Value v = getSession().getValueFactory().createValue(reason);
        userManager.setProtectedProperty(getNode(), P_DISABLED, v);
    }
}
Also used : Value(javax.jcr.Value) RepositoryException(javax.jcr.RepositoryException) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl)

Example 3 with PropertyImpl

use of org.apache.jackrabbit.core.PropertyImpl in project jackrabbit by apache.

the class AuthorizableImplTest method testUserGetProperties.

public void testUserGetProperties() throws RepositoryException, NotExecutableException {
    AuthorizableImpl user = (AuthorizableImpl) getTestUser(superuser);
    NodeImpl n = user.getNode();
    for (PropertyIterator it = n.getProperties(); it.hasNext(); ) {
        PropertyImpl p = (PropertyImpl) it.nextProperty();
        if (p.getDefinition().isProtected()) {
            assertFalse(user.hasProperty(p.getName()));
            assertNull(user.getProperty(p.getName()));
        } else {
            // authorizable defined property
            assertTrue(user.hasProperty(p.getName()));
            assertNotNull(user.getProperty(p.getName()));
        }
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) PropertyIterator(javax.jcr.PropertyIterator) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl)

Example 4 with PropertyImpl

use of org.apache.jackrabbit.core.PropertyImpl in project jackrabbit by apache.

the class RetentionManagerImpl method removeHold.

/**
 * @see RetentionManager#removeHold(String, Hold)
 */
public void removeHold(String absPath, Hold hold) throws PathNotFoundException, AccessDeniedException, LockException, VersionException, RepositoryException {
    NodeImpl n = (NodeImpl) session.getNode(absPath);
    if (hold instanceof HoldImpl && n.getNodeId().equals(((HoldImpl) hold).getNodeId()) && n.isNodeType(REP_RETENTION_MANAGEABLE) && n.hasProperty(REP_HOLD)) {
        PropertyImpl p = n.getProperty(REP_HOLD);
        Value[] vls = p.getValues();
        List<Value> newValues = new ArrayList<Value>(vls.length - 1);
        for (Value v : vls) {
            if (!hold.equals(HoldImpl.createFromValue(v, n.getNodeId(), session))) {
                newValues.add(v);
            }
        }
        if (newValues.size() < vls.length) {
            if (newValues.size() == 0) {
                removeItem(p);
            } else {
                setProperty(n, REP_HOLD, newValues.toArray(new Value[newValues.size()]));
            }
        } else {
            // no matching hold.
            throw new RepositoryException("Cannot remove '" + hold.getName() + "' at " + absPath + ".");
        }
    } else {
        // invalid hold or no hold at absPath
        throw new RepositoryException("Cannot remove '" + hold.getName() + "' at " + absPath + ".");
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) Value(javax.jcr.Value) ArrayList(java.util.ArrayList) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl) RepositoryException(javax.jcr.RepositoryException)

Example 5 with PropertyImpl

use of org.apache.jackrabbit.core.PropertyImpl in project jackrabbit by apache.

the class VirtualNodeTypeStateManager method recursiveAdd.

/**
 * Adds a subtree of itemstates as 'added' to a list of events
 *
 * @param events
 * @param parent
 * @param node
 * @throws RepositoryException
 */
private void recursiveAdd(List<EventState> events, NodeImpl parent, NodeImpl node) throws RepositoryException {
    events.add(EventState.childNodeAdded(parent.getNodeId(), parent.getPrimaryPath(), node.getNodeId(), node.getPrimaryPath().getLastElement(), ((NodeTypeImpl) parent.getPrimaryNodeType()).getQName(), parent.getMixinTypeNames(), node.getSession()));
    PropertyIterator iter = node.getProperties();
    while (iter.hasNext()) {
        PropertyImpl prop = (PropertyImpl) iter.nextProperty();
        events.add(EventState.propertyAdded((NodeId) node.getId(), node.getPrimaryPath(), prop.getPrimaryPath().getLastElement(), ((NodeTypeImpl) node.getPrimaryNodeType()).getQName(), node.getMixinTypeNames(), node.getSession()));
    }
    NodeIterator niter = node.getNodes();
    while (niter.hasNext()) {
        NodeImpl n = (NodeImpl) niter.nextNode();
        recursiveAdd(events, node, n);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) NodeTypeImpl(org.apache.jackrabbit.core.nodetype.NodeTypeImpl) NodeImpl(org.apache.jackrabbit.core.NodeImpl) PropertyIterator(javax.jcr.PropertyIterator) NodeId(org.apache.jackrabbit.core.id.NodeId) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl)

Aggregations

PropertyImpl (org.apache.jackrabbit.core.PropertyImpl)11 NodeImpl (org.apache.jackrabbit.core.NodeImpl)9 RepositoryException (javax.jcr.RepositoryException)6 PropertyIterator (javax.jcr.PropertyIterator)5 Value (javax.jcr.Value)4 NodeIterator (javax.jcr.NodeIterator)2 NodeId (org.apache.jackrabbit.core.id.NodeId)2 Path (org.apache.jackrabbit.spi.Path)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AccessDeniedException (javax.jcr.AccessDeniedException)1 ItemNotFoundException (javax.jcr.ItemNotFoundException)1 Session (javax.jcr.Session)1 Event (javax.jcr.observation.Event)1 NodeTypeImpl (org.apache.jackrabbit.core.nodetype.NodeTypeImpl)1 Name (org.apache.jackrabbit.spi.Name)1 StringValue (org.apache.jackrabbit.value.StringValue)1