Package org.brixcms.jcr.api

Examples of org.brixcms.jcr.api.JcrSession$Behavior


            super(title, workspaceModel, priority);
        }

        @Override
        public boolean isVisible() {
            JcrSession session = Brix.get().getCurrentSession(
                    getWorkspaceModel().getObject().getId());
            SitePlugin sp = SitePlugin.get();
            return sp.canEditNode(sp.getGlobalContainer(session), Context.ADMINISTRATION);
        }
View Full Code Here


            // allow site plugin to translate the node path into an actual jcr path
            final String jcrPath = SitePlugin.get().toRealWebNodePath(nodePath.toString());

            // retrieve jcr session
            final String workspace = getWorkspace();
            final JcrSession session = brix.getCurrentSession(workspace);

            if (session.itemExists(jcrPath)) {
                // node exists, return it
                node = (BrixNode) session.getItem(jcrPath);
            }
        }

        return node;
    }
View Full Code Here

                workspaceModel.setObject(newWorkspace);
            } else {
                // the workspace has changed, update the node
                // 1 try to get node with same UUID, 2 try to get node with same
                // path, 3 get root node
                JcrSession newSession = node.getBrix().getCurrentSession(workspace.getId());
                String uuid = node.getIdentifier();
                BrixNode newNode = JcrUtil.getNodeByUUID(newSession, uuid);
                if (newNode == null) {
                    String path = node.getPath();
                    if (newSession.getRootNode().hasNode(path.substring(1))) {
                        newNode = (BrixNode) newSession.getItem(path);
                    }
                }
                if (newNode == null) {
                    newNode = getRootNode(workspaceModel);
                }
View Full Code Here

    private static JcrNode createNodeWithUUID(JcrNode originalNode, JcrNode parentNode, String xmlns,
                                              Map<String, String> uuidMap) {
        // construct the import xml snippet
        String uuid = originalNode.getIdentifier();
        String name = originalNode.getName();
        JcrSession session = parentNode.getSession();
        StringBuilder xml = new StringBuilder();
        xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        xml.append("<sv:node ");
        xml.append(xmlns);
        xml.append(" sv:name=\"");
        xml.append(escapeMarkup(name));
        xml.append("\">");
        xml.append("<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>");
        xml.append(escapeMarkup(originalNode.getPrimaryNodeType().getName()));
        xml.append("</sv:value></sv:property>");
        xml.append("<sv:property sv:name=\"jcr:mixinTypes\" sv:type=\"Name\">");
        xml.append("<sv:value>mix:referenceable</sv:value></sv:property>");
        xml.append("<sv:property sv:name=\"jcr:uuid\" sv:type=\"Name\"><sv:value>");
        xml.append(uuid);
        xml.append("</sv:value></sv:property></sv:node>");

        InputStream stream = null;
        try {
            stream = new ByteArrayInputStream(xml.toString().getBytes("utf-8"));
        }
        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();
View Full Code Here

            JcrNodeIterator nodes = webNode.getNodes();
            while (nodes.hasNext()) {
                BrixNode node = (BrixNode) nodes.nextNode();
                if (node.isSame(site) == false && node instanceof GlobalContainerNode == false) {
                    JcrSession session = webNode.getSession();
                    session.move(node.getPath(), site.getPath() + "/" + node.getName());
                }
            }
        } else {
            // make reference for brix:site to brix:web to prevent creating prototypes
            // without selecting brix:web
View Full Code Here

    public Collection<SiteNodePlugin> getNodePlugins() {
        return brix.getConfig().getRegistry().lookupCollection(SiteNodePlugin.POINT);
    }

    public BrixNode getSiteRootNode(String workspaceId) {
        JcrSession workspaceSession = brix.getCurrentSession(workspaceId);
        BrixNode root = (BrixNode) workspaceSession.getItem(getSiteRootPath());
        return root;
    }
View Full Code Here

        List<Workspace> res = brix.getWorkspaceManager().getWorkspacesFiltered(attributes);
        return res.isEmpty() ? null : res.get(0);
    }

    private BrixNode wrapNode(Node node) {
        JcrSession session;
        try {
            session = brix.wrapSession(node.getSession());
            return (BrixNode) NodeWrapper.wrap(node, session);
        }
        catch (RepositoryException e) {
View Full Code Here

        final JcrNode parent = (JcrNode) getModelObject();

        final Path path = new Path(parent.getPath());
        final Path newPath = path.append(new Path(name));

        final JcrSession session = parent.getSession();

        if (session.itemExists(newPath.toString())) {
            class ModelObject implements Serializable {
                @SuppressWarnings("unused")
                public String path = SitePlugin.get().fromRealWebNodePath(newPath.toString());
            }
View Full Code Here

        this.workspaceModel = workspaceModel;
    }

    private static BrixNode getContainerNode(Workspace workspace) {
        JcrSession session = Brix.get().getCurrentSession(workspace.getId());
        return SitePlugin.get().getGlobalContainer(session);
    }
View Full Code Here

        Collection behaviors = new ArrayList();
        behaviors.addAll(this.metaObject.getOwnedBehaviors()); // For MD11.5
        behaviors.addAll(this.metaObject.getOwnedStateMachines()); // For RSM
        for (final Iterator iterator = behaviors.iterator(); iterator.hasNext() && activityGraph == null;)
        {
            final Behavior modelElement = (Behavior)iterator.next();
            if (modelElement instanceof StateMachine)
            {
                activityGraph = (StateMachine)modelElement;
            }
        }
View Full Code Here

TOP

Related Classes of org.brixcms.jcr.api.JcrSession$Behavior

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.