Package javax.jcr

Examples of javax.jcr.ValueFactory


    public void testInputStream() throws Exception {
        this.rootNode.getSession().refresh(false);
        InputStream instream = new ByteArrayInputStream("this too shall pass".getBytes());

        ValueFactory valueFactory = rootNode.getSession().getValueFactory();

        rootNode.setProperty("bin", valueFactory.createBinary(instream));
        rootNode.getSession().save();

        ValueMap map = new JcrPropertyMap(rootNode);
        instream = map.get("bin", InputStream.class);
        assertNotNull(instream);
View Full Code Here


        if (node.hasProperty(PROP_NAME)) {
            node.getProperty(PROP_NAME).remove();
        }

        Value jcrValue;
        ValueFactory fac = session.getValueFactory();
        if (value instanceof String) {
            jcrValue = fac.createValue((String) value);
        } else if (value instanceof Calendar) {
            jcrValue = fac.createValue((Calendar) value);
        } else if (value instanceof Date) {
            Calendar cal = Calendar.getInstance();
            cal.setTime((Date) value);
            jcrValue = fac.createValue(cal);
        } else if (value instanceof Boolean) {
            jcrValue = fac.createValue(((Boolean) value).booleanValue());
        } else if (value instanceof Double) {
            jcrValue = fac.createValue(((Double) value).doubleValue());
        } else if (value instanceof Long) {
            jcrValue = fac.createValue(((Long) value).longValue());
        } else if (value instanceof BigDecimal) {
            jcrValue = fac.createValue((BigDecimal) value);
        } else {
            fail("Cannot create JCR value from " + value);
            return null;
        }
View Full Code Here

            }
        } else if (propertyType == PropertyType.DATE) {
            checkoutIfNecessary(node);
            try {
                // This modification is to remove the colon in the JSON Timezone
                ValueFactory valueFactory = node.getSession().getValueFactory();
                Value[] jcrValues = new Value[values.length];

                for (int i = 0; i < values.length; i++) {
                    jcrValues[i] = valueFactory.createValue(parseDateString(values[i]));
                }

                node.setProperty(name, jcrValues, propertyType);
            } catch (ParseException e) {
                // If this fails, fallback to the default
View Full Code Here

                    group.addMember(memberAuthorizable);
                }
            }
        }
        if (extraProperties != null) {
            ValueFactory valueFactory = session.getValueFactory();
            Set<Entry<String, Object>> entrySet = extraProperties.entrySet();
            for (Entry<String, Object> entry : entrySet) {
                Value value = createValue(valueFactory, entry.getValue());
                authorizable.setProperty(entry.getKey(), value);
            }
View Full Code Here

                throw new RepositoryException("A group already exists with the requested name: " + name);
            }
            //user already exists so just update it below
        }
        if (extraProperties != null) {
            ValueFactory valueFactory = session.getValueFactory();
            Set<Entry<String, Object>> entrySet = extraProperties.entrySet();
            for (Entry<String, Object> entry : entrySet) {
                Value value = createValue(valueFactory, entry.getValue());
                authorizable.setProperty(entry.getKey(), value);
            }
View Full Code Here

    /**
     * @see org.apache.sling.jcr.ocm.ObjectContentManagerFactory#getObjectContentManager(javax.jcr.Session)
     */
    public ObjectContentManager getObjectContentManager(Session session) {

        ValueFactory valueFactory;
        try {
            valueFactory = session.getValueFactory();
        } catch (RepositoryException re) {
            log.info(
                "getObjectContentManager: Cannot get ValueFactory from Session ("
View Full Code Here

        repo.createFile("/content/test-root/file.txt", "hello, world".getBytes());
        repo.doWithSession(new SessionRunnable<Void>() {
            @Override
            public Void doWithSession(Session session) throws RepositoryException {

                ValueFactory valueFactory = session.getValueFactory();
               
                Node contentNode = session.getNode("/content/test-root/file.txt/jcr:content");
                contentNode.addMixin("sling:chunks");

                Node chunkNode = contentNode.addNode("firstChunk", "sling:chunk");
                chunkNode.setProperty("sling:offset", valueFactory.createValue(0));
                chunkNode.setProperty( "jcr:data",
                        valueFactory.createValue( valueFactory.createBinary(
                                        new ByteArrayInputStream("hello, world".getBytes()))));

                session.save();

                return null;
View Full Code Here

        Node node = session.getRootNode().addNode("home").addNode("test");
        node.setProperty("content.approved", APPROVED);
        node.setProperty("my.contents.property", CONTENT);
       
       
        ValueFactory valFact = session.getValueFactory();
        Value[] vals = new Value[] {valFact.createValue("value-1"), valFact.createValue("value-2")};
        node.setProperty("my.multi.valued", vals);
       
        identifier = node.getIdentifier();

        session.save();
View Full Code Here

    public void setUp() throws Exception {
        super.setUp();

        Session session = openSession();

        ValueFactory valFact = session.getValueFactory();
        multiValued = new Value[]{valFact.createValue("value-1"),
                valFact.createValue("value-2")};

        session.logout();
    }
View Full Code Here

    @Reference
    private SlingRepository repository;

    private void createOrUpdateIndex(Node indexNode, IndexDefinition def) throws RepositoryException {
        ValueFactory valueFactory = indexNode.getSession().getValueFactory();

        indexNode.setProperty(PN_TYPE, TYPE_PROPERTY);
        indexNode.setProperty(PN_PROPERTY_NAMES,
                new Value[] { valueFactory.createValue(def.propertyName, PropertyType.NAME) });
        if (def.async) {
            indexNode.setProperty(PN_ASYNC, PN_ASYNC);
        } else if (indexNode.hasProperty(PN_ASYNC)) {
            indexNode.getProperty(PN_ASYNC).remove();
        }
        if (def.unique) {
            indexNode.setProperty(PN_UNIQUE, true);
        } else if (indexNode.hasProperty(PN_ASYNC)) {
            indexNode.getProperty(PN_UNIQUE).remove();
        }
        if (def.declaringNodeTypes != null && def.declaringNodeTypes.length > 0) {
            Value[] values = new Value[def.declaringNodeTypes.length];
            for (int i = 0; i < def.declaringNodeTypes.length; i++) {
                values[i] = valueFactory.createValue(def.declaringNodeTypes[0], PropertyType.NAME);
            }
            indexNode.setProperty(PN_DECLARING_NODE_TYPES, values);
        } else if (indexNode.hasProperty(PN_DECLARING_NODE_TYPES)) {
            indexNode.getProperty(PN_DECLARING_NODE_TYPES).remove();
        }
View Full Code Here

TOP

Related Classes of javax.jcr.ValueFactory

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.