Package org.brixcms.jcr.api

Examples of org.brixcms.jcr.api.JcrNode


        }
        catch (UnsupportedEncodingException e) {
            // retarded
        }

        JcrNode existing = null;
        try {
            // there doesn't seem to be a way in JCR to check if there is
            // such node in workspace
            // except trying to get it and then catching the exception
            existing = session.getNodeByIdentifier(uuid);
        }
        catch (JcrException e) {
        }

        int uuidBehavior;

        if (existing != null && existing.getParent().equals(parentNode)) {
            uuidBehavior = ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING;
        } else {
            uuidBehavior = ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW;
        }

        if (uuidBehavior != ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW) {
            // simpler alternative - if we replace node or throw error on UUID
            // clash
            session.importXML(parentNode.getPath(), stream, uuidBehavior);
            return session.getNodeByIdentifier(uuid);
        } else {
            // more complicated alternative - on uuid clash node gets new uuid
            // and all
            // cloned references should use the new one

            boolean exists = existing != null;

            session.importXML(parentNode.getPath(), stream, uuidBehavior);
            if (exists == false) {
                // if there was no node with such uuid in target workspace
                return session.getNodeByIdentifier(uuid);
            } else {
                // otherwise get the latest child with such name
                JcrNodeIterator iterator = parentNode.getNodes(name);
                iterator.skip(iterator.getSize() - 1);
                JcrNode newNode = iterator.nextNode();
                String newUuid = newNode.getIdentifier();

                // and if it has uuid other than the existing one (should always
                // be the case)
                if (uuid.equals(newUuid) == false) {
                    uuidMap.put(uuid, newUuid);
View Full Code Here


     * @param nodes        list of pair <originalNode, targetNode). used to track added nodes so that the properties can
     *                     be set after all nodes are created.
     */
    private static void createNodeAndChildren(JcrNode originalNode, JcrNode targetParent, String xmlns,
                                              Map<String, String> uuidMap, List<NodePair> nodes) {
        JcrNode targetNode = cloneNode(originalNode, targetParent, xmlns, uuidMap);

        // add to nodes list so that we can set properties later
        NodePair pair = new NodePair();
        pair.originalNode = originalNode;
        pair.targetNode = targetNode;
View Full Code Here

     * @param nodes
     * @param uuidMap
     */
    private static void assignProperties(List<NodePair> nodes, Map<String, String> uuidMap) {
        for (NodePair current : nodes) {
            JcrNode originalNode = current.originalNode;
            JcrNode targetNode = current.targetNode;

            JcrValueFactory vf = targetNode.getSession().getValueFactory();
            JcrPropertyIterator propertyIterator = originalNode.getProperties();
            while (propertyIterator.hasNext()) {
                JcrProperty property = propertyIterator.nextProperty();
                String name = property.getName();
                if (!property.getDefinition().isProtected()) {
                    if (!property.getDefinition().isMultiple()) {
                        JcrValue value = property.getValue();
                        targetNode.setProperty(name, remapReference(value, uuidMap, vf));
                    } else {
                        JcrValue values[] = property.getValues();
                        for (int i = 0; i < values.length; ++i) {
                            values[i] = remapReference(values[i], uuidMap, vf);
                        }
                        targetNode.setProperty(name, values);
                    }
                }
            }
        }
    }
View Full Code Here

        }

        // go through children and do a recursive check for dependencies
        JcrNodeIterator nodes = node.getNodes();
        while (nodes.hasNext()) {
            JcrNode child = nodes.nextNode();
            checkDependencies(child, paths, targetWorkspace, result);
        }
    }
View Full Code Here

     * @param result
     */
    private static void checkReferenceValue(JcrValue value, JcrNode node, List<String> paths,
                                            JcrWorkspace targetWorkspace, Map<JcrNode, List<JcrNode>> result) {
        // get the referenced node and it's path
        JcrNode target = node.getSession().getNodeByIdentifier(value.getString());
        String path = target.getPath();

        // check if the node is child of node from paths
        boolean found = false;
        for (String p : paths) {
            if (path.startsWith(p)) {
View Full Code Here

    public void save(JcrNode parent) {
        if (parent.hasNode(name)) {
            parent.getNode(name).remove();
        }
        JcrNode node = parent.addNode(name, "nt:unstructured");
        node.setProperty(PROPERTY_PATH_PREFIX, pathPrefix);
        node.setProperty(PROPERTY_PRIORITY, priority);
        node.setProperty(PROPERTY_TEMPLATE, templateModel != null ? templateModel.getObject() : null);
        node.setProperty(PROPERTY_TYPE, type != null ? type.toString() : null);
        node.setProperty(PROPERTY_EXTENSIONS, extensions);
    }
View Full Code Here

        return (requiresSSL != null && !requiresSSL.booleanValue()) || (getTemplate() != null && getTemplate().requiresNonSSL());
    }

    public List<String> getSavedVariableKeys() {
        if (hasNode(VARIABLES_NODE_NAME)) {
            JcrNode node = getNode(VARIABLES_NODE_NAME);
            List<String> result = new ArrayList<String>();
            JcrPropertyIterator i = node.getProperties();
            while (i.hasNext()) {
                String name = i.nextProperty().getName();
                // filter out jcr: properties (or other possible brix properties)
                if (!name.contains(":")) {
                    result.add(name);
View Full Code Here

        }
    }

    public String getVariableValue(String key, boolean followTemplate) {
        if (hasNode(VARIABLES_NODE_NAME)) {
            JcrNode node = getNode(VARIABLES_NODE_NAME);
            if (node.hasProperty(key)) {
                return node.getProperty(key).getString();
            }
        }
        if (followTemplate) {
            TemplateNode template = getTemplate();
            if (template != null) {
View Full Code Here

    public void setTitle(String title) {
        setProperty(Properties.TITLE, title);
    }

    public void setVariableValue(String key, String value) {
        final JcrNode node;
        if (hasNode(VARIABLES_NODE_NAME)) {
            node = getNode(VARIABLES_NODE_NAME);
        } else {
            node = addNode(VARIABLES_NODE_NAME, "nt:unstructured");
        }
        node.setProperty(key, value);
    }
View Full Code Here

                new WebDAVRulesTab(new ResourceModel("webdav.rules", "WebDAV Rules"), workspaceModel)};
        return Arrays.asList(tabs);
    }

    public void initWorkspace(Workspace workspace, JcrSession workspaceSession) {
        JcrNode root = (JcrNode) workspaceSession.getItem(brix.getRootPath());
        JcrNode web = null;
        if (root.hasNode(WEB_NODE_NAME)) {
            web = root.getNode(WEB_NODE_NAME);
        } else if (isSiteWorkspace(workspace)) {
            web = root.addNode(WEB_NODE_NAME, "nt:folder");
        }

        if (web != null) {
            if (!web.isNodeType(BrixNode.JCR_TYPE_BRIX_NODE)) {
                web.addMixin(BrixNode.JCR_TYPE_BRIX_NODE);
            }

            checkForSiteRoot(web);

            if (!web.hasNode(GLOBAL_CONTAINER_NODE_NAME)) {
                GlobalContainerNode.initialize(web.addNode(GLOBAL_CONTAINER_NODE_NAME, "nt:file"));
            }

            if (!web.hasNode(WEBDAV_RULES_NODE_NAME)) {
                RulesNode.initialize((BrixNode) web.addNode(WEBDAV_RULES_NODE_NAME,
                        "nt:unstructured"));
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.brixcms.jcr.api.JcrNode

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.