Package org.jahia.services.content

Examples of org.jahia.services.content.JCRNodeWrapper


    }

    public String getStringRendering(Locale locale, ExtendedPropertyDefinition propDef,
            Object propertyValue) throws RepositoryException {
        String displayValue = "";
        JCRNodeWrapper node = (JCRNodeWrapper) propertyValue;
        if (node != null) {
            String title = null;
            if (node.hasProperty(Constants.JCR_TITLE)) {
                title = node.getProperty(Constants.JCR_TITLE).getString();
            }
            displayValue = StringUtils.isNotEmpty(title) ? title : node.getName();
        }
        return displayValue;
    }
View Full Code Here


    public void cancel(final List<String> subscriptionIds, JCRSessionWrapper session) {
        try {
            int count = 0;
            for (String id : subscriptionIds) {
                try {
                    JCRNodeWrapper target = session.getNodeByIdentifier(id);
                    count++;
                    session.checkout(target.getParent());
                    target.remove();
                } catch (ItemNotFoundException e) {
                    logger.warn("Unable to find subscription node for identifier {}. Skip cancelling subscription.",
                            id);
                }
            }
View Full Code Here

                                       JCRSessionWrapper session) {
        try {
            int count = 0;
            for (String subscriptionId : subscriptionIds) {
                try {
                    JCRNodeWrapper subscriptionNode = session.getNodeByIdentifier(subscriptionId);
                    JCRPropertyWrapper property = subscriptionNode.getProperty(J_SUSPENDED);
                    if (doSuspend && !property.getBoolean() || !doSuspend && property.getBoolean()) {
                        count++;
                        session.checkout(subscriptionNode);
                        subscriptionNode.setProperty(J_SUSPENDED, Boolean.valueOf(doSuspend));
                    }
                } catch (ItemNotFoundException nfe) {
                    logger.warn("Unable to find subscription node for identifier {}", subscriptionId);
                } catch (RepositoryException e) {
                    logger.error("Error changing suspended status of the subscription with ID " + subscriptionId, e);
View Full Code Here

                                                     List<ChoiceListValue> values, Locale locale, Map<String, Object> context) {
        if (context == null) {
            return Collections.emptyList();
        }

        JCRNodeWrapper node = (JCRNodeWrapper) context.get("contextNode");
        ExtendedNodeType realNodeType = (ExtendedNodeType) context.get("contextType");

        ExtendedPropertyDefinition[] propertyDefs;
        CommonDefinitions commonChildNodeDefinitions = null;
        try {
            if (node == null && realNodeType == null) {
                return Collections.emptyList();
            } else if (node != null && node.getNodes().hasNext()) {
                commonChildNodeDefinitions = getCommonChildNodeDefinitions(node, showHidden,
                        showProtected, excludedNodeTypes);
                propertyDefs = commonChildNodeDefinitions.getPropertyDefinitions();
            } else {
                propertyDefs = realNodeType.getPropertyDefinitions();
View Full Code Here

        long timer = System.currentTimeMillis();

        int total = 0;
        final List<Subscription> subscriptions = new LinkedList<Subscription>();
        try {
            JCRNodeWrapper target = session.getNodeByIdentifier(subscribableIdentifier);
            if (!target.isNodeType(JMIX_SUBSCRIBABLE)) {
                logger.warn("The target node {} does not have the " + JMIX_SUBSCRIBABLE + " mixin." +
                        " No subscriptions can be found.", target.getPath());
                return new PaginatedList<Subscription>(subscriptions, 0);
            }
            QueryManager queryManager = session.getWorkspace().getQueryManager();
            if (queryManager == null) {
                logger.error("Unable to obtain QueryManager instance");
                return new PaginatedList<Subscription>(subscriptions, 0);
            }

            StringBuilder q = new StringBuilder();
            q.append("select * from [" + JNT_SUBSCRIPTION + "] where isdescendantnode([").append(target.getPath())
                    .append("/" + J_SUBSCRIPTIONS + "])");
            if (activeOnly) {
              q.append(" and [" + J_SUSPENDED + "]=false");
            }
            if (confirmedOnly) {
              q.append(" and [" + J_CONFIRMED + "]=true");
            }
            if (orderBy != null) {
                q.append(" order by [").append(orderBy).append("]").append(orderAscending ? "asc" : "desc");
            }
            Query query = queryManager.createQuery(q.toString(), Query.JCR_SQL2);

            if (limit > 0 || offset > 0) {
              total = (int) JCRContentUtils.size(query.execute().getNodes());
            }

            query.setLimit(limit);
            query.setOffset(offset);

            for (NodeIterator nodes = query.execute().getNodes(); nodes.hasNext();) {
                JCRNodeWrapper subscriptionNode = (JCRNodeWrapper) nodes.next();
                subscriptions.add(toSubscription(subscriptionNode, session));
            }
        } catch (RepositoryException e) {
            logger.error("Error retrieving subscriptions for node " + subscribableIdentifier, e);
        }
View Full Code Here

        Map<String, Map<ExtendedPropertyDefinition, Map<String, ExtendedPropertyDefinition>>> referencedDefs = null;
        if (node.hasNodes()) {
            NodeIterator children = node.getNodes();
            while (children.hasNext()) {

                JCRNodeWrapper child = (JCRNodeWrapper) children.nextNode();
                if (defs == null) {
                    // first child
                    defs = LazyMap.decorate(new HashMap<String, Map<String, ExtendedPropertyDefinition>>(),
                                            new Factory() {
                                                public Object create() {
                                                    return new HashMap<String, ExtendedPropertyDefinition>();
                                                }
                                            });
                    referencedDefs = LazyMap.decorate(
                            new HashMap<String, Map<String, Map<String, ExtendedPropertyDefinition>>>(), new Factory() {
                                public Object create() {
                                    return LazyMap.decorate(
                                            new HashMap<ExtendedPropertyDefinition, Map<String, ExtendedPropertyDefinition>>(),
                                            new Factory() {
                                                public Object create() {
                                                    return new HashMap<String, ExtendedPropertyDefinition>();
                                                }
                                            });
                                }
                            });
                    for (ExtendedPropertyDefinition propertyDef : child.getPrimaryNodeType().getPropertyDefinitions()) {
                        // filter out hidden and protected if needed
                        if ((showHidden || !propertyDef.isHidden()) && (showProtected || !propertyDef.isProtected())) {
                            if (propertyDef.getRequiredType() == PropertyType.WEAKREFERENCE || propertyDef.getRequiredType() == PropertyType.REFERENCE) {
                                ExtendedNodeType nodeType = propertyDef.getDeclaringNodeType();
                                if (excludedNodeTypes.isEmpty() || !excludedNodeTypes.contains(nodeType.getName())) {
                                    String[] constraints = propertyDef.getValueConstraints();
                                    for (String constraint : constraints) {
                                        ExtendedNodeType extendedNodeType = NodeTypeRegistry.getInstance().getNodeType(
                                                constraint);
                                        ExtendedPropertyDefinition[] declaredPropertyDefinitions = extendedNodeType.getPropertyDefinitions();
                                        for (ExtendedPropertyDefinition declaredPropertyDefinition : declaredPropertyDefinitions) {
                                            if ((showHidden || !declaredPropertyDefinition.isHidden()) && (showProtected || !declaredPropertyDefinition.isProtected())) {
                                                referencedDefs.get(nodeType.getName()).get(propertyDef).put(declaredPropertyDefinition.getName(),declaredPropertyDefinition);
                                            }
                                        }
                                    }
                                }
                            } else {
                                ExtendedNodeType nodeType = propertyDef.getDeclaringNodeType();
                                if (excludedNodeTypes.isEmpty() || !excludedNodeTypes.contains(nodeType.getName())) {
                                    defs.get(nodeType.getName()).put(propertyDef.getName(), propertyDef);
                                }
                            }
                        }
                    }
                } else {
                    // filter out node types
                    for (Iterator<String> iterator = defs.keySet().iterator(); iterator.hasNext();) {
                        String commonType = iterator.next();
                        if (!child.isNodeType(commonType)) {
                            // the node has no such type --> remove the type from common
                            iterator.remove();
                            referencedDefs.remove(commonType);
                        }
                    }
View Full Code Here

     * @return <code>true</code> if the provided user is subscribed to the
     *         specified node
     */
    public String getSubscription(final String subscribableIdentifier, final String user, JCRSessionWrapper session) {
        try {
            JCRNodeWrapper target = session.getNodeByIdentifier(subscribableIdentifier);
            if (!target.isNodeType(JMIX_SUBSCRIBABLE)) {
                logger.warn("The target node {} does not have the " + JMIX_SUBSCRIBABLE + " mixin." +
                        " No subscriptions can be found.", target.getPath());
                return null;
            }

            JCRNodeWrapper sub = getSubscription(target, user, session);
            if (sub != null) {
                return sub.getIdentifier();
            }
            return null;
        } catch (RepositoryException e) {
            logger.error(
                    "Error checking subscription status for user '" + user + "' and node " + subscribableIdentifier, e);
View Full Code Here

     * @param session
     */
    public JCRNodeWrapper subscribe(final String subscribableIdentifier,
                                    final Map<String, Map<String, Object>> subscribers, JCRSessionWrapper session) {

        JCRNodeWrapper newSubscriptionNode = null;
        try {
            JCRNodeWrapper target = session.getNodeByIdentifier(subscribableIdentifier);
            if (!target.isNodeType(JMIX_SUBSCRIBABLE)) {
                logger.warn("The target node {} does not have the " + JMIX_SUBSCRIBABLE + " mixin." +
                        " No subscriptions can be created.", target.getPath());
                return null;
            }
            JCRNodeWrapper subscriptionsNode = target.getNode(J_SUBSCRIPTIONS);
            String targetPath = subscriptionsNode.getPath();
            if (target.isLocked() || subscriptionsNode.isLocked()) {
                logger.info("The target {} is locked and no subscriptions can be created. Skipping {} subscribers.",
                        targetPath, subscribers.size());
            }

            boolean allowUnregisteredUsers = target.hasProperty(J_ALLOW_UNREGISTERED_USERS) ?
                    target.getProperty(J_ALLOW_UNREGISTERED_USERS).getBoolean() : true;

            for (Map.Entry<String, Map<String, Object>> subscriber : subscribers.entrySet()) {
                String username = subscriber.getKey();
                String provider = null;
                if (username.charAt(0) == '{') {
                    // we deal with a registered user
                    username = StringUtils.substringAfter(subscriber.getKey(), "}");
                    provider = StringUtils.substringBetween(subscriber.getKey(), "{", "}");
                } else if (!allowUnregisteredUsers) {
                    logger.info(
                            "The target {} does not allow unregistered users to be subscribed. Skipping subscription for {}.",
                            targetPath, subscriber.getKey());
                    continue;
                }

                if (getSubscription(target, subscriber.getKey(), session) == null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Creating subscription to the {} for {}.", targetPath, subscriber.getKey());
                    }
                    session.checkout(subscriptionsNode);
                    newSubscriptionNode = subscriptionsNode
                            .addNode(JCRContentUtils.findAvailableNodeName(subscriptionsNode, "subscription"),
                                    JNT_SUBSCRIPTION);
                    newSubscriptionNode.setProperty(J_SUBSCRIBER, username);
                    if (provider != null) {
                        newSubscriptionNode.setProperty(J_PROVIDER, provider);
View Full Code Here

    }

    public List<ChoiceListValue> getChoiceListValues(ExtendedPropertyDefinition epd, String param, List<ChoiceListValue> values, Locale locale,
                                                     Map<String, Object> context) {
        List<ChoiceListValue> choiceListValues = new ArrayList<ChoiceListValue>();
        JCRNodeWrapper nodeWrapper = (JCRNodeWrapper) context.get("contextNode");
        ExtendedPropertyDefinition[] propertyDefs;
        if (nodeWrapper == null) {
            return Collections.emptyList();
        }
        try {
            if (nodeWrapper.hasProperty(param)) {
                JCRNodeWrapper bindedNode = (JCRNodeWrapper) nodeWrapper.getProperty(param).getNode();
                if (bindedNode.isNodeType("jnt:contentList"|| bindedNode.isNodeType("jnt:absoluteArea") || bindedNode.isNodeType("jnt:levelAbsoluteArea") || bindedNode.isNodeType("jnt:area")) {
                    if (bindedNode.hasProperty("j:allowedTypes") && bindedNode.isNodeType("jmix:listRestrictions")) {
                        final Value[] values1 = bindedNode.getProperty("j:allowedTypes").getValues();
                        propertyDefs = getCommonChildNodeDefinitions(values1, true, true,
                                                                     new LinkedHashSet<String>());
                    } else if (bindedNode.hasNodes()) {
                        propertyDefs = SortableFieldnamesChoiceListInitializerImpl.getCommonChildNodeDefinitions(
                                bindedNode, true, true, new LinkedHashSet<String>()).getPropertyDefinitions();
                    } else {
                        return Collections.emptyList();
                    }
                } else {
                    propertyDefs = bindedNode.getPrimaryNodeType().getPropertyDefinitions();
                }
            } else {
                return Collections.emptyList();
            }
        } catch (RepositoryException e) {
View Full Code Here

                    currentCtx.peek().pushSkip();
                    break;
                case CTX_NAVLINK:
                    currentCtx.peek().pushNavLink(getCurrentContentType(), attributes.getValue(HTTP_WWW_JAHIA_ORG,"acl"));
                    currentCtx.peek().properties.peek().putAll(convertToProperties(attributes));
                    final JCRNodeWrapper page = currentCtx.peek().contents.peek();

                    String title = attributes.getValue("jahia:title");
                    if (HTTP_WWW_JAHIA_ORG.equals(uri) && PAGE.equals(localName)) {
                        String acl = null;
                        System.out.println(currentCtx.peek().acls);
View Full Code Here

TOP

Related Classes of org.jahia.services.content.JCRNodeWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.