Page tree
Skip to end of metadata
Go to start of metadata

What is it all about?

Action availability rules determine whether a certain action is applicable to an Item. The logic of the rule might be different: whether Item is marked as deleted or not, whether its underlying JCR node  has versions or not etc. The problem is that there is some default availability logic kept in AbstractActionxecutor and BrowserSubApp:

AbstractActionExecutor#isAvailableForItem
   private boolean isAvailableForItem(AvailabilityDefinition availability, Item item) {
        if (item == null) {
            return availability.isRoot();
        }
        if (!item.isNode()) {
            return availability.isProperties(); 
        }
        //Must have _any_ of the node types if any are specified, otherwise its available by default
        if (availability.getNodeTypes().isEmpty()) {
            return availability.isNodes();
        }
        for (String nodeType : availability.getNodeTypes()) {
            try {
                if (NodeUtil.isNodeType(item, nodeType)) {
                    return true;
                }
            } catch (RepositoryException e) {
                log.error("Could not determine node type of node " + NodeUtil.getNodePathIfPossible((Node) item));
            }
        }
        return true;
    }
BrowserSubApp#verifyAvailability (ex. isSectionVisible)
    protected boolean verifyAvailability(Item item, AvailabilityDefinition availability) {
		if (item instanceof JcrItemAdapter) {
            JcrItemAdapter jcrItemAdapter = (JcrItemAdapter)item;
            // If its a property we display it only if the properties property is set
            if (!jcrItemAdapter.isNode()) {
                return availability.isProperties();
            }
            // If node is selected and the section is available for nodes
            if (availability.isNodes()) {
                // if no node type defined, the for all node types
                if (availability.getNodeTypes().isEmpty()) {
                    return true;
                }
                // else the node must match at least one of the configured node types
                for (String nodeType : availability.getNodeTypes()) {
                    try {
                        if (NodeUtil.isNodeType((Node) jcrItemAdapter.getJcrItem(), nodeType)) {
                            return true;
                        }
                    } catch (RepositoryException e) {
                        continue;
                    }
                }
            }
        }
        // If this is the root item we display the section only if the root property is set
        if (item == null) {
            return availability.isRoot();
        }
        return true;
    }
  • No labels