Search in sources :

Example 1 with ValueFactory

use of javax.jcr.ValueFactory in project camel by apache.

the class JcrGetNodeByIdTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Session session = openSession();
    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();
    session.logout();
}
Also used : Node(javax.jcr.Node) Value(javax.jcr.Value) ValueFactory(javax.jcr.ValueFactory) Session(javax.jcr.Session) Before(org.junit.Before)

Example 2 with ValueFactory

use of javax.jcr.ValueFactory in project jackrabbit by apache.

the class TestContentLoader method addNodeTestData.

/**
     * Creates three nodes under the given node: one of type nt:resource
     * and the other nodes referencing it.
     */
private void addNodeTestData(Node node) throws RepositoryException, IOException {
    if (node.hasNode("multiReference")) {
        node.getNode("multiReference").remove();
    }
    if (node.hasNode("resReference")) {
        node.getNode("resReference").remove();
    }
    if (node.hasNode("myResource")) {
        node.getNode("myResource").remove();
    }
    Node resource = node.addNode("myResource", "nt:resource");
    // nt:resource not longer referenceable since JCR 2.0
    resource.addMixin("mix:referenceable");
    resource.setProperty("jcr:encoding", ENCODING);
    resource.setProperty("jcr:mimeType", "text/plain");
    resource.setProperty("jcr:data", new ByteArrayInputStream("Hello wörld.".getBytes(ENCODING)));
    resource.setProperty("jcr:lastModified", Calendar.getInstance());
    Node resReference = getOrAddNode(node, "reference");
    resReference.setProperty("ref", resource);
    // make this node itself referenceable
    resReference.addMixin("mix:referenceable");
    Node multiReference = node.addNode("multiReference");
    ValueFactory factory = node.getSession().getValueFactory();
    multiReference.setProperty("ref", new Value[] { factory.createValue(resource), factory.createValue(resReference) });
    // NodeDefTest requires a test node with a mandatory child node
    JcrUtils.putFile(node, "testFile", "text/plain", new ByteArrayInputStream("Hello, World!".getBytes("UTF-8")));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory)

Example 3 with ValueFactory

use of javax.jcr.ValueFactory in project jackrabbit by apache.

the class PathTest method testResolvedIdentifierBasedPropertyValue.

public void testResolvedIdentifierBasedPropertyValue() throws RepositoryException {
    ValueFactory vf = superuser.getValueFactory();
    Value pathValue = vf.createValue("[" + identifier + "]", PropertyType.PATH);
    Property p = testRootNode.setProperty(propertyName1, pathValue);
    assertTrue("Identifier-based PATH value must resolve to the Node the identifier has been obtained from.", testRootNode.isSame(p.getNode()));
}
Also used : Value(javax.jcr.Value) ValueFactory(javax.jcr.ValueFactory) Property(javax.jcr.Property)

Example 4 with ValueFactory

use of javax.jcr.ValueFactory in project jackrabbit by apache.

the class PathTest method testNotNormalizedPathValue.

public void testNotNormalizedPathValue() throws RepositoryException {
    ValueFactory vf = superuser.getValueFactory();
    Value pathValue = vf.createValue("/a/../b/./c/dd/..", PropertyType.PATH);
    Property p = testRootNode.setProperty(propertyName1, pathValue);
    assertEquals(PropertyType.PATH, p.getType());
    assertEquals(pathValue.getString(), p.getValue().getString());
    assertEquals(pathValue, p.getValue());
}
Also used : Value(javax.jcr.Value) ValueFactory(javax.jcr.ValueFactory) Property(javax.jcr.Property)

Example 5 with ValueFactory

use of javax.jcr.ValueFactory in project jackrabbit-oak by apache.

the class LucenePropertyFullTextTest method performQuery.

private boolean performQuery(@Nonnull final TestContext ec) throws RepositoryException {
    QueryManager qm = ec.session.getWorkspace().getQueryManager();
    ValueFactory vf = ec.session.getValueFactory();
    Query q = qm.createQuery("SELECT * FROM [nt:base] WHERE [title] = $title", Query.JCR_SQL2);
    q.bindValue("title", vf.createValue(ec.title));
    LOG.trace("statement: {} - title: {}", q.getStatement(), ec.title);
    RowIterator rows = q.execute().getRows();
    if (rows.hasNext()) {
        rows.nextRow().getPath();
        return true;
    } else {
        return false;
    }
}
Also used : Query(javax.jcr.query.Query) RowIterator(javax.jcr.query.RowIterator) QueryManager(javax.jcr.query.QueryManager) ValueFactory(javax.jcr.ValueFactory)

Aggregations

ValueFactory (javax.jcr.ValueFactory)105 Value (javax.jcr.Value)51 Node (javax.jcr.Node)50 Session (javax.jcr.Session)40 Test (org.junit.Test)17 RepositoryException (javax.jcr.RepositoryException)16 InputStream (java.io.InputStream)13 AccessControlManager (javax.jcr.security.AccessControlManager)13 HashMap (java.util.HashMap)12 Privilege (javax.jcr.security.Privilege)12 Property (javax.jcr.Property)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 Query (javax.jcr.query.Query)8 Calendar (java.util.Calendar)7 QueryManager (javax.jcr.query.QueryManager)7 RowIterator (javax.jcr.query.RowIterator)7 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)7 NodeIterator (javax.jcr.NodeIterator)6 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)6 IOException (java.io.IOException)5