Package javax.jcr

Examples of javax.jcr.Node


            resParent = parentResource;
        }

        // create resource node
        Resource newResource = getOrCreateChildResource(resParent, name, typeHint, changes);
        Node res = newResource.adaptTo(Node.class);

        // set properties
        changes.add(Modification.onModified(
                res.setProperty(JCR_LASTMODIFIED, Calendar.getInstance()).getPath()
                ));
        changes.add(Modification.onModified(
                res.setProperty(JCR_MIMETYPE, contentType).getPath()
                ));
        try {
            // process chunk upload request separately
            if (prop.isChunkUpload()) {
                processChunk(resParent, res, prop, value, changes);
            } else {
                changes.add(Modification.onModified(res.setProperty(JCR_DATA,
                        value.getInputStream()).getPath()));
            }
        } catch (IOException e) {
            throw new RepositoryException("Error while retrieving inputstream from parameter value.", e);
        }
View Full Code Here


                    changes.add(Modification.onModified(res.setProperty(
                        JCR_DATA, fileIns).getPath()));
                    NodeIterator nodeItr = res.getNodes(SlingPostConstants.CHUNK_NODE_NAME
                        + "*");
                    while (nodeItr.hasNext()) {
                        Node nodeRange = nodeItr.nextNode();
                        changes.add(Modification.onDeleted(nodeRange.getPath()));
                        nodeRange.remove();
                    }
                    if (res.hasProperty(SlingPostConstants.NT_SLING_FILE_LENGTH)) {
                        javax.jcr.Property expLenProp = res.getProperty(SlingPostConstants.NT_SLING_FILE_LENGTH);
                        changes.add(Modification.onDeleted(expLenProp.getPath()));
                        expLenProp.remove();
                    }
                    if (res.hasProperty(SlingPostConstants.NT_SLING_CHUNKS_LENGTH)) {
                        javax.jcr.Property currLenProp = res.getProperty(SlingPostConstants.NT_SLING_CHUNKS_LENGTH);
                        changes.add(Modification.onDeleted(currLenProp.getPath()));
                        currLenProp.remove();
                    }
                    res.removeMixin(SlingPostConstants.NT_SLING_CHUNK_MIXIN);
                } finally {
                    try {
                        fileIns.close();
                        file.delete();
                    } catch (IOException ign) {

                    }

                }
            } else {
                Node rangeNode = res.addNode(nodeName,
                    SlingPostConstants.NT_SLING_CHUNK_NODETYPE);
                changes.add(Modification.onCreated(rangeNode.getPath()));
                changes.add(Modification.onModified(rangeNode.setProperty(
                    JCR_DATA, value.getInputStream()).getPath()));
                changes.add(Modification.onModified(rangeNode.setProperty(
                    SlingPostConstants.NT_SLING_CHUNK_OFFSET, chunkOffset).getPath()));
                changes.add(Modification.onModified(res.setProperty(
                    SlingPostConstants.NT_SLING_CHUNKS_LENGTH,
                    currentLength + value.getSize()).getPath()));
            }
View Full Code Here

    @Test
    public void test() throws Exception {
    String value = RandomStringUtils.randomAlphanumeric(10);

    ResourceResolver resolver = null;
    Node createdNode = null;
    try {
        resolver = rrFactory.getAdministrativeResourceResolver(null);
        Session session = resolver.adaptTo(Session.class);
        Node rootNode = session.getRootNode();
        createdNode = rootNode.addNode("test_" + RandomStringUtils.randomAlphanumeric(10));
        createdNode.setProperty("testProperty", value);
        session.save();

        Resource resource = resolver.getResource(createdNode.getPath());
View Full Code Here

    @Test
    public void test() throws Exception {
        String value = RandomStringUtils.randomAlphanumeric(10);

        ResourceResolver resolver = null;
        Node createdNode = null;
        try {
            resolver = rrFactory.getAdministrativeResourceResolver(null);
            Session session = resolver.adaptTo(Session.class);
            Node rootNode = session.getRootNode();
            createdNode = rootNode.addNode("test_" + RandomStringUtils.randomAlphanumeric(10));
            createdNode.setProperty("testProperty", value);
            session.save();

            Resource resource = resolver.getResource(createdNode.getPath());
            SourceObject obj = new SourceObject(resource);
View Full Code Here

        firstValue = RandomStringUtils.randomAlphanumeric(10);
        thirdValue = RandomStringUtils.randomAlphanumeric(10);

        resolver = rrFactory.getAdministrativeResourceResolver(null);    
        Session session = resolver.adaptTo(Session.class);
        Node rootNode = session.getRootNode();
        createdNode = rootNode.addNode("test_" + RandomStringUtils.randomAlphanumeric(10));
        createdNode.setProperty("first", firstValue);
        createdNode.setProperty("third", thirdValue);
        session.save();

        resource = resolver.getResource(createdNode.getPath());
View Full Code Here

     */
    @Test
    public void testImplementsInterfaceModelWithPickLastImplementationPicker() throws RepositoryException {
       
        Session session = resolver.adaptTo(Session.class);
        Node node = resource.adaptTo(Node.class);
        Node childNode = node.addNode(CustomLastImplementationPicker.CUSTOM_NAME);
        childNode.setProperty("first", firstValue);
        childNode.setProperty("third", thirdValue);
        session.save();
       
        Resource childResource = resolver.getResource(childNode.getPath());
       
        SampleServiceInterface model = adapterManager.getAdapter(childResource, SampleServiceInterface.class);
        assertNotNull(model);
        assertEquals(ImplementsInterfacePropertyModel2.class, model.getClass());
        assertEquals(firstValue + "|" + secondValue + "|" + thirdValue, model.getAllProperties());
       
        childNode.remove();
        session.save();
    }
View Full Code Here

      return true;
    }
    if (!isValidType(resourceType)) {
      return false;
    }
    Node node = resource.adaptTo(Node.class);
    try {
      if (node != null) {
        return node.isNodeType(resourceType);
      }
    } catch (RepositoryException e) {
      LOG.error("Can't check node type", e);
    }
    return false;
View Full Code Here

    }

    protected void checkoutIfNecessary(Node node, List<Modification> changes,
            VersioningConfiguration versioningConfiguration) throws RepositoryException {
        if (versioningConfiguration.isAutoCheckout()) {
            Node versionableNode = findVersionableAncestor(node);
            if (versionableNode != null) {
                if (!versionableNode.isCheckedOut()) {
                    versionableNode.checkout();
                    changes.add(Modification.onCheckout(versionableNode.getPath()));
                }
            }
        }
    }
View Full Code Here

        }
    }

    private boolean checkin(final ResourceResolver resolver, final String path) throws RepositoryException {
        final Resource rsrc = resolver.getResource(path);
        final Node node = (rsrc == null ? null : rsrc.adaptTo(Node.class));
        if (node != null) {
            if (node.isCheckedOut() && isVersionable(node)) {
                node.checkin();
                return true;
            }
        }
        return false;
    }
View Full Code Here

    }

    @Override
    protected byte[] execute0(Session session) throws RepositoryException, IOException {

        Node node = session.getNode(getPath());

        Property property;
        if (node.hasProperty("jcr:data")) {
          property = node.getProperty("jcr:data");
        } else {
          if (!node.hasNode("jcr:content")) {
              return null;
          }
 
          Node contentNode = node.getNode("jcr:content");
 
          if (!contentNode.hasProperty("jcr:data")) {
              return null;
          }
 
          property = contentNode.getProperty("jcr:data");
        }

        if (property.getType() == PropertyType.BINARY) {
            Binary binary = property.getBinary();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
View Full Code Here

TOP

Related Classes of javax.jcr.Node

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.