Examples of JCRNodeWrapper


Examples of org.jahia.services.content.JCRNodeWrapper

                name = gwtJahiaNewPortletInstance.getGwtJahiaPortletDefinition().getDefinitionName().replaceAll("/", "___") + Math.round(Math.random() * 1000000l);
            }
            if (contentManager.checkExistence(parentPath + "/" + name, currentUserSession)) {
                throw new GWTJahiaServiceException("A node already exists with name '" + name + "'");
            }
            JCRNodeWrapper parentNode = currentUserSession.getNode(parentPath);
            if (!parentNode.isCheckedOut()) {
                parentNode.checkout();
            }

            JCRPortletNode node = (JCRPortletNode) contentManager.addNode(parentNode, name, gwtJahiaNewPortletInstance.getGwtJahiaPortletDefinition().getPortletType(), null, gwtJahiaNewPortletInstance.getProperties());

            node.setApplication(gwtJahiaNewPortletInstance.getGwtJahiaPortletDefinition().getApplicationId(), gwtJahiaNewPortletInstance.getGwtJahiaPortletDefinition().getDefinitionName());
            node.revokeAllRoles();

            // set modes permissions
            if (gwtJahiaNewPortletInstance.getModes() != null) {
                for (GWTJahiaNodeACE ace : gwtJahiaNewPortletInstance.getModes().getAce()) {
                    String user = ace.getPrincipalType() + ":" + ace.getPrincipal();
                    if (!ace.isInherited()) {
//                        node.changeRoles(user, ace.getPermissions());
                    }
                }
            }

            // set roles permissions
            if (gwtJahiaNewPortletInstance.getRoles() != null) {
                for (GWTJahiaNodeACE ace : gwtJahiaNewPortletInstance.getRoles().getAce()) {
                    String user = ace.getPrincipalType() + ":" + ace.getPrincipal();
                    if (!ace.isInherited()) {
//                        node.changeRoles(user, ace.getPermissions());
                    }
                }
            }
            // todo default permissions .. ?
//            node.changeRoles("g:users", "rw");
//            node.changeRoles("g:guest", "r-");
            try {
                parentNode.save();
            } catch (RepositoryException e) {
                logger.error(e.getMessage(), e);
                throw new GWTJahiaServiceException("A system error happened");
            }
            return navigation.getGWTJahiaNode(node);
View Full Code Here

Examples of org.jahia.services.content.JCRNodeWrapper

            if (!preconditionsMatched(request, response)) {
                return null;
            }

            JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(workspace);
            JCRNodeWrapper node = session.getNode(nodePath);
            if (node.isNodeType("nt:file")) {

                GoogleDocsService docsService = getDocsService(request, response);
                if (docsService == null) {
                    return null;
                }
View Full Code Here

Examples of org.jahia.services.content.JCRNodeWrapper

    private String requiredWorkspace;

    protected JCRNodeWrapper createNode(HttpServletRequest req, Map<String, List<String>> parameters,
                                        JCRNodeWrapper node, String nodeType, String nodeName, boolean forceCreation)
            throws RepositoryException {
        JCRNodeWrapper newNode;
        boolean isNodeNameToBeNormalized = ServletRequestUtils.getBooleanParameter(req, Render.NORMALIZE_NODE_NAME, false);
        if (StringUtils.isBlank(nodeName)) {
            String nodeNameProperty = "jcr:title";
            if (parameters.get(Render.NODE_NAME_PROPERTY) != null) {
                nodeNameProperty = parameters.get(Render.NODE_NAME_PROPERTY).get(0);
            }
            if (parameters.get(nodeNameProperty) != null) {
                nodeName = JCRContentUtils.generateNodeName(parameters.get(nodeNameProperty).get(0), 32);
            } else {
                nodeName = nodeType.substring(nodeType.lastIndexOf(":") + 1);
            }
            if (isNodeNameToBeNormalized) {
                nodeName = JCRContentUtils.generateNodeName(nodeName, 255);
            }
            nodeName = JCRContentUtils.findAvailableNodeName(node, nodeName);
        } else if (isNodeNameToBeNormalized) {
            nodeName = JCRContentUtils.generateNodeName(nodeName, 255);
        }
        if(forceCreation) {
            nodeName = JCRContentUtils.findAvailableNodeName(node, nodeName);
        }
        try {
            newNode = node.getNode(nodeName);
            if (!newNode.isCheckedOut()) {
                newNode.checkout();
            }
        } catch (PathNotFoundException e) {
            if (!node.isCheckedOut()) {
                node.checkout();
            }
            newNode = node.addNode(nodeName, nodeType);
        }

        if (parameters.containsKey(Constants.JCR_MIXINTYPES)) {
            for (Object o : ((ArrayList) parameters.get(Constants.JCR_MIXINTYPES))) {
                String mixin = (String) o;
                newNode.addMixin(mixin);
            }
        }
        Set<Map.Entry<String, List<String>>> set = parameters.entrySet();
        for (Map.Entry<String, List<String>> entry : set) {
            String key = entry.getKey();
            if (!Render.reservedParameters.contains(key)) {
                List<String> values = entry.getValue();
                ExtendedPropertyDefinition propertyDefinition = null;
                propertyDefinition = newNode.getApplicablePropertyDefinition(key);
                if (propertyDefinition == null) {
                    continue;
                }
                if (propertyDefinition.isMultiple()) {
                    newNode.setProperty(key, values.toArray(new String[values.size()]));
                } else if (values.get(0).length() > 0) {
                    if (propertyDefinition.getRequiredType() == ExtendedPropertyType.DATE) {
                        DateTime dateTime = ISODateTimeFormat.dateOptionalTimeParser().parseDateTime(values.get(0));
                        newNode.setProperty(key, dateTime.toCalendar(Locale.ENGLISH));
                    } else {
                        newNode.setProperty(key, values.get(0));
                    }
                }
            }
        }
View Full Code Here

Examples of org.jahia.services.content.JCRNodeWrapper

        }

        ExtendedNodeType type = null;
        JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(
                workspace, locale);
        JCRNodeWrapper node = null;
        try {
            if (request.getParameter("path") != null) {
                node = session.getNode(request.getParameter("path"));
                type = node.getPrimaryNodeType();
            } else if (request.getParameter("nodeuuid") != null) {
                node = session.getNodeByUUID(request.getParameter("nodeuuid"));
                type = node.getPrimaryNodeType();
            } else {
                node = null;
                type = NodeTypeRegistry.getInstance().getNodeType(request.getParameter("type"));
            }
        } catch (PathNotFoundException e) {
View Full Code Here

Examples of org.jahia.services.content.JCRNodeWrapper

        }

        InputStream is = null;
        try {
            JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(workspace);
            JCRNodeWrapper node = session.getNode(nodePath);
            if (node.isNodeType("nt:file")) {
                response.setContentType(targetFormat);
                response.setHeader("Content-Disposition", "attachment; filename=\""
                        + StringUtils.substringBeforeLast(node.getName(), ".") + "." + targetFileExtension + "\"");
                is = node.getFileContent().downloadFile();
                converterService.convert(is, converterService.getMimeType(FilenameUtils.getExtension(node.getName())),
                        response.getOutputStream(), targetFormat);
            } else {
                response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Path should correspond to a file node");
            }
        } catch (PathNotFoundException e) {
View Full Code Here

Examples of org.jahia.services.content.JCRNodeWrapper

               
                Map<String, FileCacheEntry> entries = contentCache.get(fileKey.getCacheKey());
                FileCacheEntry fileEntry = entries != null ? entries.get(fileKey.getThumbnail())
                        : null;
                if (fileEntry == null) {
                    JCRNodeWrapper n = getNode(fileKey);
                    if (n == null || !n.isFile()) {
                        // cannot find it or it is not a file
                        code = HttpServletResponse.SC_NOT_FOUND;
                        res.sendError(HttpServletResponse.SC_NOT_FOUND);
                        return;
                    }

                    Date lastModifiedDate = n.getLastModifiedAsDate();
                    long lastModified = lastModifiedDate != null ? lastModifiedDate.getTime() : 0;
                    String eTag = generateETag(n.getIdentifier(), lastModified);
                    lastModifiedEntry = new FileLastModifiedCacheEntry(eTag, lastModified);
                    lastModifiedCache.put(fileKey.getCacheKey(), lastModifiedEntry);

                    if (isNotModified(fileKey, lastModifiedEntry, req, res)) {
                        // resource is not changed
View Full Code Here

Examples of org.jahia.services.content.JCRNodeWrapper

                + "-" + lastModified + "\"";
    }

    protected JCRNodeWrapper getContentNode(JCRNodeWrapper n, String thumbnail)
            throws RepositoryException {
        JCRNodeWrapper content;
        if (StringUtils.isNotEmpty(thumbnail) && n.hasNode(thumbnail)) {
            // thumbnail requested -> try to find it
            content = n.getNode(thumbnail);
            if (!content.isNodeType(Constants.NT_RESOURCE)) {
                content = null;
            }
        } else {
            try {
                content = n.getNode(Constants.JCR_CONTENT);
View Full Code Here

Examples of org.jahia.services.content.JCRNodeWrapper

    protected FileCacheEntry getFileEntry(FileKey fileKey, JCRNodeWrapper node,
            FileLastModifiedCacheEntry lastModifiedEntry) throws RepositoryException, IOException {
        FileCacheEntry fileEntry = null;

        JCRNodeWrapper content = getContentNode(node, fileKey.getThumbnail());
        if (content == null) {
            return null;
        }

        Binary binary = null;
        try {
            binary = content.getProperty(Constants.JCR_DATA).getBinary();
        } catch (PathNotFoundException e) {
            logger.warn("Unable to get " + Constants.JCR_DATA + " property for node {}",
                    content.getPath());
            return null;
        }

        int contentLength = (int) binary.getSize();

        fileEntry = new FileCacheEntry(lastModifiedEntry.getETag(), content.getProperty(
                Constants.JCR_MIMETYPE).getString(), contentLength,
                lastModifiedEntry.getLastModified());
        if (contentLength <= cacheThreshold) {
            InputStream is = null;
            try {
View Full Code Here

Examples of org.jahia.services.content.JCRNodeWrapper

        return fileEntry;
    }

    protected JCRNodeWrapper getNode(FileKey fileKey) {
        JCRNodeWrapper n = null;
        JCRSessionWrapper session = null;
        try {
            session = JCRSessionFactory.getInstance().getCurrentUserSession(fileKey.getWorkspace());
            if (fileKey.getVersionDate() != null) {
                session.setVersionDate(new Date(Long.valueOf(fileKey.getVersionDate())));
View Full Code Here

Examples of org.jahia.services.content.JCRNodeWrapper

   *             in case of errors
   */
  public boolean createTag(final String tag, final String siteKey) throws RepositoryException {
    return JCRTemplate.getInstance().doExecuteWithSystemSession(new JCRCallback<Boolean>() {
      public Boolean doInJCR(JCRSessionWrapper session) throws RepositoryException {
        JCRNodeWrapper existingNode = getTag(tag, siteKey, session);
        if (existingNode == null) {
          createTag(tag, siteKey, session);
          session.save();
        }
        return existingNode == null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.