Package org.jahia.services.content

Examples of org.jahia.services.content.JCRNodeWrapper


    }   

    public void restoreVersionLabel(String nodeUuid, Date versionDate, String versionLabel, boolean allSubTree,
                                    JCRSessionWrapper currentUserSession) {
        try {
            JCRNodeWrapper node = currentUserSession.getNodeByUUID(nodeUuid);
            versionService.restoreVersionLabel(node, versionDate, versionLabel, allSubTree);
            currentUserSession.save();
            String label = "restored_at_"+ new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(GregorianCalendar.getInstance().getTime());
            versionService.addVersionLabel(node,label);
            // fluch caches: Todo: flush only the nested cache
View Full Code Here


        }

        private String getCommonChildNodeTypes(String parentPath, Set<String> commonNodeTypes)
                throws RepositoryException {
            String commonPrimaryType = null;
            JCRNodeWrapper node = session.getNode(parentPath);
            Set<String> checkedPrimaryTypes = new HashSet<String>();
            if (node.hasNodes()) {
                NodeIterator children = node.getNodes();
                if (children.getSize() < 100) {
                    while (children.hasNext()) {

                        JCRNodeWrapper child = (JCRNodeWrapper) children.nextNode();
                        if (commonPrimaryType == null && commonNodeTypes.isEmpty()) {
                            commonPrimaryType = child.getPrimaryNodeType().getName();
                            commonNodeTypes.addAll(child.getNodeTypes());
                        } else if (commonPrimaryType != null
                                && child.getPrimaryNodeType().getName().equals(commonPrimaryType)) {
                            commonPrimaryType = null;
                        }
                        if (!checkedPrimaryTypes.contains(child.getPrimaryNodeType().getName())) {
                            checkedPrimaryTypes.add(child.getPrimaryNodeType().getName());
                            commonNodeTypes.retainAll(child.getNodeTypes());
                        }
                    }
                }
            }
            return commonPrimaryType;
View Full Code Here

    public List<ChoiceListValue> getChoiceListValues(ExtendedPropertyDefinition epd, String param,
                                                     List<ChoiceListValue> values, Locale locale,
                                                     Map<String, Object> context) {
        List<ChoiceListValue> vs = new ArrayList<ChoiceListValue>();
        try {
            JCRNodeWrapper node = (JCRNodeWrapper) context.get("contextNode");
            ExtendedNodeType nodetype;
            if (node == null) {
                node = (JCRNodeWrapper) context.get("contextParent");
                nodetype = (ExtendedNodeType) context.get("contextType");
            } else {
                nodetype = node.getPrimaryNodeType();
            }


            JCRNodeWrapper site = node.getResolveSite();

            final JCRSessionWrapper session = site.getSession();
            final QueryManager queryManager = session.getWorkspace().getQueryManager();
            String type = "contentTemplate";
            if (StringUtils.isEmpty(param)) {
                if (nodetype.isNodeType("jnt:page")) {
                    type = "pageTemplate";
                }
            } else {
                type = param;
            }

            QueryResult result = queryManager.createQuery(
                    "select * from [jnt:" + type + "] as n where isdescendantnode(n,['" +site.getPath()+"'])", Query.JCR_SQL2).execute();
            // get default template
            JCRNodeWrapper  defaultTemplate = null;
            try {
                defaultTemplate = site.hasProperty("j:defaultTemplate")? (JCRNodeWrapper) site.getProperty("j:defaultTemplate").getNode():null;
            } catch (ItemNotFoundException e) {
                logger.warn("A default template has been set on site '" + site.getName() + "' but the template has been deleted");
            }
                final NodeIterator iterator = result.getNodes();
            while (iterator.hasNext()) {
                JCRNodeWrapper templateNode = (JCRNodeWrapper) iterator.next();

                boolean ok = true;
                if (templateNode. hasProperty("j:applyOn")) {
                    ok = false;
                    Value[] types = templateNode.getProperty("j:applyOn").getValues();
                    for (Value value : types) {
                        if (nodetype.isNodeType(value.getString())) {
                            ok = true;
                            break;
                        }
                    }
                    if (types.length == 0) {
                        ok = true;
                    }
                }
                if (ok && templateNode.hasProperty("j:hiddenTemplate")) {
                    ok = !templateNode.getProperty("j:hiddenTemplate").getBoolean();
                }
                if ("pageTemplate".equals(type)) {
                    ok &= node.hasPermission("template-"+templateNode.getName());
                }

                if (ok) {
                    ChoiceListValue v = new ChoiceListValue(templateNode.getName(), null, session.getValueFactory().createValue(templateNode.getIdentifier(),
                            PropertyType.WEAKREFERENCE));
                    if (defaultTemplate !=  null && templateNode.getPath().equals(defaultTemplate.getPath())) {
                        v.addProperty("defaultProperty",true);
                    }
                    vs.add(v);
                }
            }
View Full Code Here

                                              final Map<String, List<String>> contextParams, boolean editMode, String configName,
                                              HttpServletRequest request, HttpServletResponse response,
                                              JCRSessionWrapper currentUserSession) throws GWTJahiaServiceException {
        GWTRenderResult result = null;
        try {
            JCRNodeWrapper node = currentUserSession.getNode(path);

            Resource r = new Resource(node, "html", template, configuration);
            request.setAttribute("mode", "edit");

            request = new HttpServletRequestWrapper(request) {
                @Override
                public String getParameter(String name) {
                    if (contextParams != null && contextParams.containsKey(name)) {
                        return contextParams.get(name).get(0);
                    }
                    return super.getParameter(name);
                }

                @Override
                public Map getParameterMap() {
                    Map r = new HashMap(super.getParameterMap());
                    if (contextParams != null) {
                        for (Map.Entry<String, List<String>> entry : contextParams.entrySet()) {
                            r.put(entry.getKey(), entry.getValue().toArray(new String[entry.getValue().size()]));
                        }
                    }
                    return r;
                }

                @Override
                public Enumeration getParameterNames() {
                    return new Vector(getParameterMap().keySet()).elements();
                }

                @Override
                public String[] getParameterValues(String name) {
                    if (contextParams != null && contextParams.containsKey(name)) {
                        List<String> list = contextParams.get(name);
                        return list.toArray(new String[list.size()]);
                    }
                    return super.getParameterValues(name);
                }
            };

            RenderContext renderContext = new RenderContext(request, response, currentUserSession.getUser());
            renderContext.setEditMode(editMode);
            renderContext.setEditModeConfigName(configName);
            renderContext.setMainResource(r);
            String permission = null;
            if (Edit.EDIT_MODE.equals(configName)) {
                renderContext.setServletPath(Edit.getEditServletPath());
                permission = "editModeAccess";
            } else if (Studio.STUDIO_MODE.equals(configName)) {
                renderContext.setServletPath(Studio.getStudioServletPath());
                permission = "studioModeAccess";
            } else {
                renderContext.setServletPath(Render.getRenderServletPath());
            }

            if (permission != null) {
                if (!node.hasPermission(permission)) {
                    throw new GWTJahiaServiceException("Access denied");
                }
            }

            if (contextParams != null) {
                for (Map.Entry<String, List<String>> entry : contextParams.entrySet()) {
                    r.getModuleParams().put(entry.getKey(), entry.getValue().get(0));
                }
            }

            JCRSiteNode site = node.getResolveSite();
            renderContext.setSite(site);
            String res = renderService.render(r, renderContext);
            Map<String, Set<String>> map = (Map<String, Set<String>>) renderContext.getRequest().getAttribute("staticAssets");
            String constraints = ConstraintsHelper.getConstraints(node);
            if (constraints == null) {
                constraints = "";
            }
            Map<String, List<String>> m = new HashMap<String, List<String>>();
            if (map != null) {
                for (Map.Entry<String, Set<String>> entry : map.entrySet()) {
                    m.put(entry.getKey(), new ArrayList<String>(entry.getValue()));
                }
            }
            result = new GWTRenderResult(res, m, constraints, node.getDisplayableName());
        } catch (PathNotFoundException e) {
            throw new GWTJahiaServiceException(path + " not found for user " + currentUserSession.getUser().getName());
        } catch (RepositoryException e) {
            logger.error(e.getMessage(), e);
            throw new GWTJahiaServiceException("Repository exception on path " + path);
View Full Code Here

            ExecutionImpl execution = ((ExecutionContext)EnvironmentImpl.getCurrent().getContext("execution")).getExecution();
            WorkflowDefinition def = (WorkflowDefinition) execution.getVariable("workflow");
            String id = (String) execution.getVariable("nodeId");
            for (String userId : strings) {
                if (userId.equals("previousTaskAssignable")) {
                    JCRNodeWrapper node = JCRSessionFactory.getInstance().getCurrentUserSession().getNodeByUUID(id);
                    List<JahiaPrincipal> principals = WorkflowService.getInstance().getAssignedRole(node, def,
                            execution.getActivity().getIncomingTransitions().get(0).getSource().getName(), execution.getProcessInstance().getId());
                    iterateOverPrincipals(emails, userId, principals);
                } else if (userId.equals("nextTaskAssignable")) {
                    JCRNodeWrapper node = JCRSessionFactory.getInstance().getCurrentUserSession().getNodeByUUID(id);
                    List<JahiaPrincipal> principals = WorkflowService.getInstance().getAssignedRole(node, def,
                            execution.getActivity().getDefaultOutgoingTransition().getDestination().getName(), execution.getProcessInstance().getId());
                    iterateOverPrincipals(emails, userId, principals);
                } else if (userId.equals("currentWorkflowStarter")) {
                    String jahiaUser = (String) execution.getVariable("user");
View Full Code Here

    public List<String[]> getViewsSet(String path, JCRSessionWrapper currentUserSession)
            throws GWTJahiaServiceException {
        List<String[]> templatesPath = new ArrayList<String[]>();
        try {
            JCRNodeWrapper node = currentUserSession.getNode(path);
            String def = null;
            if (node.hasProperty("j:view")) {
                templatesPath.add(new String[]{"--unset--", "--unset--"});
                def = node.getProperty("j:view").getString();
            }

            SortedSet<View> set = getViewsSet(node);
            for (View s : set) {
                String tpl;
View Full Code Here

        this(session, rootPath, null, null, siteKey);
    }

    @SuppressWarnings("unchecked")
    public DocumentViewImportHandler(JCRSessionWrapper session, String rootPath, File archive, List<String> fileList, String siteKey) throws IOException {
        JCRNodeWrapper node = null;
        try {
            this.session = session;
            this.uuidMapping = session.getUuidMapping();
            this.pathMapping = session.getPathMapping();
            if (rootPath == null) {
                node = (JCRNodeWrapper) session.getRootNode();
            } else {
                node = (JCRNodeWrapper) session.getNode(rootPath);
            }
            if (node.isNodeType("jnt:user")) {
                placeHoldersMap.put("$user", "u:" + node.getPath().substring(node.getPath().lastIndexOf("/") + 1));
            }
        } catch (RepositoryException e) {
            e.printStackTrace();
            throw new IOException();
        }
View Full Code Here

                path = "/sites/" + siteKey;
            }
            if (noSubNodesImport.contains(pt)) {
                ignorePath = path;
            }
            JCRNodeWrapper child = null;

            boolean isValid = true;
            try {
                child = session.getNode(path);
                if (child.hasPermission("jcr:versionManagement") && child.isVersioned() && !child.isCheckedOut()) {
                    session.getWorkspace().getVersionManager().checkout(child.getPath());
                }

            } catch (PathNotFoundException e) {
                isValid = false;
            }
            if (!isValid || child.getDefinition().allowsSameNameSiblings()) {
                if (nodes.peek().hasPermission("jcr:addChildNodes")) {
                    if ("jnt:acl".equals(pt) && !nodes.peek().isNodeType("jmix:accessControlled")) {
                        nodes.peek().addMixin("jmix:accessControlled");
                    }
                    Calendar created = null;
                    String createdBy = null;
                    Calendar lastModified = null;
                    String lastModifiedBy = null;
                    if (!StringUtils.isEmpty(atts.getValue("jcr:created"))) {
                        created = ISO8601.parse(atts.getValue("jcr:created"));
                    }
                    if (!StringUtils.isEmpty(atts.getValue("jcr:lastModified"))) {
                        lastModified = ISO8601.parse(atts.getValue("jcr:lastModified"));
                    }
                    if (!StringUtils.isEmpty(atts.getValue("jcr:createdBy"))) {
                        createdBy = atts.getValue("jcr:createdBy");
                    }
                    if (!StringUtils.isEmpty(atts.getValue("jcr:lastModifiedBy"))) {
                        lastModifiedBy = atts.getValue("jcr:lastModifiedBy");
                    }

                    String uuid = atts.getValue("jcr:uuid");
//                    String share = atts.getValue("j:share");
//                    if (!StringUtils.isEmpty(uuid) && uuidMapping.containsKey(uuid)) {
//                        child = nodes.peek().clone(session.getNodeByUUID(uuidMapping.get(uuid)), decodedQName);
//                    } else if (!StringUtils.isEmpty(share)) {
//                        for (Map.Entry<String, String> entry : pathMapping.entrySet()) {
//                            if (share.startsWith(entry.getKey())) {
//                                share = entry.getValue() + StringUtils.substringAfter(share, entry.getKey());
//                                break;
//                            }
//                        }
//                        child = nodes.peek().clone(session.getNode(share), decodedQName);
//                    } else {
                    if (!StringUtils.isEmpty(uuid)) {
                        switch (uuidBehavior) {
                            case ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW:
                                try {
                                    JCRNodeWrapper node = session.getNodeByUUID(uuid);
                                    if (node.isNodeType("mix:shareable")) {
                                        // ..
                                    } else {
                                        throw new ItemExistsException(uuid);
                                    }
                                } catch (ItemNotFoundException e) {
                                }
                            case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING:
                                try {
                                    JCRNodeWrapper node = session.getNodeByUUID(uuid);
                                    // make sure conflicting node is not importTargetNode or an ancestor thereof
                                    if (nodes.peek().getPath().startsWith(node.getPath())) {
                                        String msg = "cannot remove ancestor node";
                                        logger.debug(msg);
                                        throw new ConstraintViolationException(msg);
                                    }
                                    // remove conflicting
                                    node.remove();
                                } catch (ItemNotFoundException e) {
                                }
                                break;
                            case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING:
                                throw new UnsupportedOperationException();
View Full Code Here

        if (error > 0) {
            error--;
            return;
        }

        JCRNodeWrapper w = nodes.pop();
        pathes.pop();

        if (w != null && ignorePath != null && w.getPath().equals(ignorePath)) {
            ignorePath = null;
        }
        if (w != null && currentFilePath != null && w.getPath().equals(currentFilePath)) {
            currentFilePath = null;
        }

        if (w != null && w.isFile()) {
            try {
                if (!w.hasNode(Constants.JCR_CONTENT) || !w.getNode(Constants.JCR_CONTENT).hasProperty(Constants.JCR_DATA)) {
                    logger.warn("Cannot find the file content for the node " + w.getPath()
                            + ". Skipping importing it.");
                    w.remove();
                }
            } catch (RepositoryException e) {
                throw new SAXException(e);
            }
        }
View Full Code Here

                                                     Map<String, Object> context) {
        if (context == null) {
            return new ArrayList<ChoiceListValue>();
        }

        JCRNodeWrapper node = (JCRNodeWrapper) context.get("contextNode");
        ExtendedNodeType realNodeType = (ExtendedNodeType) context.get("contextType");
        String propertyName = context.containsKey("dependentProperties") ? ((List<String>)context.get("dependentProperties")).get(0) : null;

        SortedSet<View> views = new TreeSet<View>();

        try {
            final List<String> nodeTypeList = new ArrayList<String>();
            String nextParam = "";
            if (param.contains(",")) {
                nextParam = StringUtils.substringAfter(param, ",");
                param =  StringUtils.substringBefore(param, ",");
            }
            if ("subnodes".equals(param)) {
                if (propertyName == null) {
                    propertyName = "j:allowedTypes";
                }
                if (context.containsKey(propertyName)) {
                    List<String> types = (List<String>)context.get(propertyName);
                    for (String type : types) {
                        nodeTypeList.add(type);
                    }
                } else if (node != null && node.hasProperty(propertyName)) {
                    JCRPropertyWrapper property = node.getProperty(propertyName);
                    if (property.isMultiple()) {
                        Value[] types = property.getValues();
                        for (Value type : types) {
                            nodeTypeList.add(type.getString());
                        }
                    } else {
                        nodeTypeList.add(property.getValue().getString());
                    }
                } else if (node != null && !"j:allowedTypes".equals(propertyName) && node.hasProperty("j:allowedTypes")) {
                    Value[] types = node.getProperty("j:allowedTypes").getValues();
                    for (Value type : types) {
                        nodeTypeList.add(type.getString());
                    }
                } else if (node !=null) {
                    // No restrictions get node type list from already existing nodes
                    NodeIterator nodeIterator = node.getNodes();
                    while (nodeIterator.hasNext()) {
                        Node next = (Node) nodeIterator.next();
                        String name = next.getPrimaryNodeType().getName();
                        if (!nodeTypeList.contains(name)) {
                            nodeTypeList.add(name);
                        }
                    }
                }
                param = nextParam;
            } else if ("reference".equals(param)) {
                if (propertyName == null) {
                    propertyName = "j:node";
                }
                if (context.containsKey(propertyName)) {
                    JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession();
                    List<String> refNodeUuids = (List<String>)context.get(propertyName);
                    for (String refNodeUuid : refNodeUuids) {
                        try {
                            JCRNodeWrapper refNode = (JCRNodeWrapper) session.getNodeByUUID(refNodeUuid);
                            nodeTypeList.addAll(refNode.getNodeTypes());
                        } catch (Exception e) {
                            logger.warn("Referenced node not found to retrieve its nodetype for initializer", e);
                        }
                    }
                } else if (node != null && node.hasProperty(propertyName)) {
                    try {
                        JCRNodeWrapper refNode = (JCRNodeWrapper) node.getProperty(propertyName).getNode();
                        nodeTypeList.addAll(refNode.getNodeTypes());
                    } catch (ItemNotFoundException e) {
                    }
                } else if (node != null && !"j:node".equals(propertyName) && node.hasProperty("j:node")) {
                    try {
                        JCRNodeWrapper refNode = (JCRNodeWrapper) node.getProperty("j:node")
                                .getNode();
                        nodeTypeList.addAll(refNode.getNodeTypes());
                    } catch (ItemNotFoundException e) {
                    }
                }
                param = nextParam;
            } else if ("mainresource".equals(param)) {
                JCRNodeWrapper matchingParent;
                JCRNodeWrapper parent;
                if (node == null) {
                    parent = (JCRNodeWrapper) context.get("contextParent");
                } else {
                    parent = node.getParent();
                }
                try {
                    while (true) {
                        if (parent.isNodeType("jnt:template")) {
                            matchingParent = parent;
                            break;
                        }
                        parent = parent.getParent();
                    }
                    if (matchingParent.hasProperty("j:applyOn")) {
                        Value[] vs = matchingParent.getProperty("j:applyOn").getValues();
                        for (Value v : vs) {
                            nodeTypeList.add(v.getString());
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.