Examples of ValueFactory


Examples of javax.jcr.ValueFactory

     * @throws RepositoryException in case of error, accessing the Repository
     */
    public static Value createValue(Object value, Session session)
            throws RepositoryException {
        Value val;
        ValueFactory fac = session.getValueFactory();
        if(value instanceof Calendar) {
            val = fac.createValue((Calendar)value);
        } else if (value instanceof InputStream) {
            val = fac.createValue(fac.createBinary((InputStream)value));
        } else if (value instanceof Node) {
            val = fac.createValue((Node)value);
        } else if (value instanceof BigDecimal) {
            val = fac.createValue((BigDecimal)value);
        } else if (value instanceof Long) {
            val = fac.createValue((Long)value);
        } else if (value instanceof Short) {
            val = fac.createValue((Short)value);
        } else if (value instanceof Integer) {
            val = fac.createValue((Integer)value);
        } else if (value instanceof Number) {
            val = fac.createValue(((Number)value).doubleValue());
        } else if (value instanceof Boolean) {
            val = fac.createValue((Boolean) value);
        } else if ( value instanceof String ){
            val = fac.createValue((String)value);
        } else {
            val = null;
        }
        return val;
    }
View Full Code Here

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

Examples of javax.jcr.ValueFactory

        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

Examples of javax.jcr.ValueFactory

            }
        } 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

Examples of javax.jcr.ValueFactory

                    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

Examples of javax.jcr.ValueFactory

                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

Examples of javax.jcr.ValueFactory

    /**
     * @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

Examples of javax.jcr.ValueFactory

        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

Examples of javax.jcr.ValueFactory

        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

Examples of javax.jcr.ValueFactory

    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
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.