Package org.jahia.services.content

Examples of org.jahia.services.content.JCRNodeWrapper


            new JCRCallback<JahiaPasswordPolicy>() {
              public JahiaPasswordPolicy doInJCR(JCRSessionWrapper session)
                      throws RepositoryException {
                JahiaPasswordPolicy policy = null;
                try {
                  JCRNodeWrapper policyNode = session.getNode("/"
                          + POLICY_NODENAME);
                  String serializedPolicy = policyNode.getProperty(
                          POLICY_PROPERTY).getString();
                  if (serializedPolicy != null) {
                    policy = (JahiaPasswordPolicy) SERIALIZER.fromXML(serializedPolicy);
                  }
                } catch (PathNotFoundException e) {
View Full Code Here


                  pwds = new LinkedList<PasswordHistoryEntry>();
                  for (@SuppressWarnings("unchecked")
                  Iterator<JCRNodeWrapper> iterator = ((JCRUser) user).getNode(session)
                          .getNode(HISTORY_NODENAME).getNodes(); iterator
                          .hasNext();) {
                    JCRNodeWrapper historyEntryNode = (JCRNodeWrapper) iterator.next();
                    pwds.add(new PasswordHistoryEntry(historyEntryNode
                            .getPropertyAsString("j:password"), historyEntryNode
                            .getProperty(Constants.JCR_CREATED).getDate().getTime()));
                  }
                  Collections.sort(pwds);
                } catch (PathNotFoundException e) {
                  // ignore
View Full Code Here

        }
    }

    private void createPage(String primaryType, String title, String template, String pageKey, String uuid, Map<String, String> creationMetadata)
            throws RepositoryException {
        JCRNodeWrapper subPage;
        ExtendedNodeType t = null;
        try {
            t = registry.getNodeType(primaryType);
        } catch (NoSuchNodeTypeException e) {
            t = registry.getNodeType("jnt:page");
        }
        if (uuidMapping.containsKey(uuid)) {
            subPage = session.getNodeByIdentifier(uuidMapping.get(uuid));
        } else {
            JCRNodeWrapper parent = (currentCtx.isEmpty() ? currentSiteNode : getCurrentPageNode());

            if (!parent.isCheckedOut()) {
                session.checkout(parent);
            }

            if (currentCtx.isEmpty()) {
                pageKey = "home";
            }

            if (pageKey == null) {
                pageKey = JCRContentUtils.generateNodeName(title, 32);
            }

            // remove all unsupported characters
            pageKey = pageKey.replace('/', '_');
            pageKey = pageKey.replace(':', '_');
            pageKey = pageKey.replace('[', '_');
            pageKey = pageKey.replace(']', '_');

            ExtendedNodeType pageType = registry.getNodeType("jnt:page");
            JCRNodeWrapper templateNode = null;
            try {
                if (!StringUtils.isEmpty(template)) {
                    template = mapping.getMappedPropertyValue(pageType, "jahia:template", template);
                }
                templateNode = !StringUtils.isEmpty(template) ? currentSiteNode.getNode("templates/" + template) : null;
View Full Code Here

    }

    private void createExternalLink(JCRNodeWrapper page, String title, String uuid, final String url,
                                    final String nodeType, Map<String, String> creationMetadata)
            throws RepositoryException {
        JCRNodeWrapper sub;
        if (uuidMapping.containsKey(uuid)) {
            sub = session.getNodeByIdentifier(uuidMapping.get(uuid));
        } else {
            sub = addOrCheckoutNode(page, "link_" + (ctnId++), nodeType, null, creationMetadata);
            sub.setProperty("j:url", url);
            uuidMapping.put(uuid, sub.getIdentifier());
        }

        Node translation = sub.getOrCreateI18N(locale);
        if (title != null && title.length() > 0) {
            translation.setProperty("jcr:title", title);
        }
    }
View Full Code Here

   *             in case of a JCR error
   */
  public void storePasswordHistory(final JahiaUser user) throws RepositoryException {
    JCRTemplate.getInstance().doExecuteWithSystemSession(new JCRCallback<Boolean>() {
      public Boolean doInJCR(JCRSessionWrapper session) throws RepositoryException {
        JCRNodeWrapper pwdHistory = ((JCRUser) user).getNode(session).getNode(
                HISTORY_NODENAME);
        session.checkout(pwdHistory);
        JCRNodeWrapper entry = pwdHistory.addNode(
                JCRContentUtils.findAvailableNodeName(pwdHistory,
                        "pwd-" + NODENAME_FORMAT.format(System.currentTimeMillis())),
                "jnt:passwordHistoryEntry");
        entry.setProperty("j:password", user.getProperty("j:password"));
        session.save();
        return true;
      }
    });
  }
View Full Code Here

   *             in case of a JCR error
   */
  public void update(final JahiaPasswordPolicy policy) throws RepositoryException {
    JCRTemplate.getInstance().doExecuteWithSystemSession(new JCRCallback<Boolean>() {
      public Boolean doInJCR(JCRSessionWrapper session) throws RepositoryException {
        JCRNodeWrapper policyNode = null;
        try {
          policyNode = session.getNode("/" + POLICY_NODENAME);
        } catch (PathNotFoundException e) {
          // no policy was persisted yet -> create it
          JCRNodeWrapper root = session.getRootNode();
          session.checkout(root);
          policyNode = root.addNode(POLICY_NODENAME, POLICY_NODETYPE);
        }
        policyNode.setProperty(POLICY_PROPERTY, SERIALIZER.toXML(policy));

        session.save();

View Full Code Here

    }

    private void createInternalLink(JCRNodeWrapper page, String title, String uuid, final String reference,
                                    final String nodeType, Map<String, String> creationMetadata)
            throws RepositoryException {
        JCRNodeWrapper sub;
        if (uuidMapping.containsKey(uuid)) {
            sub = session.getNodeByIdentifier(uuidMapping.get(uuid));
        } else {
            // System.out.println("link Field-node : " + localName);

            sub = addOrCheckoutNode(page, "link_" + (ctnId++), nodeType, null, creationMetadata);
            if (!references.containsKey(reference)) {
                references.put(reference, new ArrayList<String>());
            }
            references.get(reference).add(sub.getIdentifier() + "/j:node");
            uuidMapping.put(uuid, sub.getIdentifier());
        }

        Node translation = sub.getOrCreateI18N(locale);
        if (title != null && title.length() > 0) {
            if (!translation.isCheckedOut()) {
                session.checkout(translation);
            }
            translation.setProperty("jcr:title", title);
        }
        if (!sub.isCheckedOut()) {
            session.checkout(sub);
        }
        sub.setProperty("jcr:title", title);
    }
View Full Code Here

    }


    private JCRNodeWrapper addOrCheckoutPageNode(JCRNodeWrapper template, JCRNodeWrapper parent, String nodeName, Map<String, String> creationMetadata)
            throws RepositoryException {
        JCRNodeWrapper node = null;
        try {
            node = parent.getNode(nodeName);
            if (!node.isCheckedOut()) {
                session.checkout(node);
            }
        } catch (PathNotFoundException e) {
            if (!parent.isCheckedOut()) {
                session.checkout(parent);
            }
//            if (template != null) {
//                template.copy(parent, nodeName, true, true);
//                node = parent.getNode(nodeName);
//                node.setProperty("j:sourceTemplate", template);
//            } else {
            node = parent.addNode(
                    nodeName,
                    Constants.JAHIANT_PAGE,
                    null,
                    !StringUtils.isEmpty(creationMetadata.get("jcr:created")) ? ISO8601
                            .parse(creationMetadata.get("jcr:created")) : null,
                    creationMetadata.get("jahia:createdBy"),
                    !StringUtils.isEmpty(creationMetadata.get("jcr:lastModified")) ? ISO8601
                            .parse(creationMetadata.get("jcr:lastModified")) : null,
                    creationMetadata.get("jahia:lastModifiedBy"));
            if (template != null) {
                node.setProperty("j:templateNode", template);
                Query q = session.getWorkspace().getQueryManager().createQuery("select * from [jnt:area] as a where isdescendantnode(a,['" + template.getPath() + "'])", Query.JCR_SQL2);
                NodeIterator ni = q.execute().getNodes();
                while (ni.hasNext()) {
                    JCRNodeWrapper nodeWrapper = (JCRNodeWrapper) ni.next();
                    node.addNode(nodeWrapper.getName(), "jnt:contentList");
                }
            }
//            }
        }
        return node;
View Full Code Here

        return node;
    }

    private JCRNodeWrapper addOrCheckoutNode(JCRNodeWrapper parent, String nodeName, String nodeType,
                                             List<String> followingNodeNames, Map<String, String> creationMetadata) throws RepositoryException {
        JCRNodeWrapper node = null;
        try {
            node = parent.getNode(nodeName);
            if (!node.isCheckedOut()) {
                session.checkout(node);
            }
        } catch (PathNotFoundException e) {
            if (!parent.isCheckedOut()) {
                session.checkout(parent);
            }
            if (StringUtils.isEmpty(nodeType)) {
                nodeType = Constants.JAHIANT_CONTENTLIST;
            }
            node = parent.addNode(
                    nodeName,
                    nodeType,
                    null,
                    !StringUtils.isEmpty(creationMetadata.get("jcr:created")) ? ISO8601
                            .parse(creationMetadata.get("jcr:created")) : null,
                    creationMetadata.get("jahia:createdBy"),
                    !StringUtils.isEmpty(creationMetadata.get("jcr:lastModified")) ? ISO8601
                            .parse(creationMetadata.get("jcr:lastModified")) : null,
                    creationMetadata.get("jahia:lastModifiedBy"));
            if (!CollectionUtils.isEmpty(followingNodeNames)) {
                boolean takeNextName = false;
                for (NodeIterator it = parent.getNodes(); it.hasNext();) {
                    JCRNodeWrapper nextNode = (JCRNodeWrapper) it.next();
                    int index = followingNodeNames.indexOf(nextNode.getName());
                    if (index > -1) {
                        if (followingNodeNames.get(index).equals(nodeName)) {
                            takeNextName = true;
                        } else {
                            parent.orderBefore(node.getName(), nextNode.getName());
                            break;
                        }
                    } else if (takeNextName) {
                        parent.orderBefore(node.getName(), nextNode.getName());
                        break;
                    }
                }
            }
        }
View Full Code Here

        if ("#skip".equals(nodeName) || "#skip".equals(mappedNodeType)) {
            currentCtx.peek().pushSkip();
        } else if ("#navlink".equals(nodeName) || "#navlink".equals(mappedNodeType)) {
            currentCtx.peek().pushNavLink(listDefinition.getRequiredPrimaryTypes()[0], null);
        } else {
            JCRNodeWrapper parent = getCurrentContentNode();
            if (StringUtils.contains(nodeName, "/")) {
                String parentPath = StringUtils.substringBeforeLast(nodeName, "/");
                if (parent.hasNode(parentPath)) {
                    parent = parent.getNode(parentPath);
                }
                nodeName = StringUtils.substringAfterLast(nodeName, "/");
            }
            if (StringUtils.isEmpty(nodeType) &&
                    parent.getPrimaryNodeType().getChildNodeDefinitionsAsMap().get(nodeName) != null) {
                String[] strings = parent.getPrimaryNodeType().getChildNodeDefinitionsAsMap().get(nodeName)
                        .getRequiredPrimaryTypeNames();
                nodeType = strings[0];
            }
            List<String> mappedOldNodeNames = mapping.getMappedNodesForType(getCurrentContentType(), true);
            int indexOfName = mappedOldNodeNames.indexOf(listDefinition.getName());
            List<String> mappedNewNodeNames = null;
            if (indexOfName != -1) {
                mappedNewNodeNames = mapping.getMappedNodesForType(getCurrentContentType(), false)
                        .subList(indexOfName, mappedOldNodeNames.size());
            }
            JCRNodeWrapper node = addOrCheckoutNode(parent, nodeName, nodeType, mappedNewNodeNames, creationMetadata);

            performActions(mapping.getActions(getCurrentContentType(), listDefinition.getName()), node);
            uuidMapping.put(uuid, node.getIdentifier());

            ExtendedNodeType listType = listDefinition.getRequiredPrimaryTypes()[0];
            currentCtx.peek().pushList(node, listType);

            if (currentCtx.peek().properties.peek() != null) {
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.