Java Code Examples for org.apache.jackrabbit.commons.JcrUtils#putFile()

The following examples show how to use org.apache.jackrabbit.commons.JcrUtils#putFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBinarylessExport.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
@Before
@Ignore
public void setup() throws RepositoryException, PackageException, IOException {
    // test only works for Jackrabbit 2.0 or Oak with FileDataStore
    Assume.assumeTrue(!isOak() || useFileStore());

    Node binaryNode = JcrUtils.getOrCreateByPath(BINARY_NODE_PATH, "nt:unstructured", admin);

    Binary bigBin = admin.getValueFactory().createBinary(IOUtils.toInputStream(BIG_TEXT, "UTF-8"));
    Property bigProperty = binaryNode.setProperty(BIG_BINARY_PROPERTY, bigBin);
    String referenceBigBinary = ((ReferenceBinary) bigProperty.getBinary()).getReference();
    assertNotNull(referenceBigBinary);

    Binary smallBin = admin.getValueFactory().createBinary(IOUtils.toInputStream(SMALL_TEXT, "UTF-8"));
    Property smallProperty = binaryNode.setProperty(SMALL_BINARY_PROPERTY, smallBin);
    if (isOak()) {
        assertTrue(smallProperty.getBinary() instanceof ReferenceBinary);
    } else {
        assertFalse(smallProperty.getBinary() instanceof ReferenceBinary);
    }

    JcrUtils.putFile(binaryNode.getParent(), "file", "text/plain", IOUtils.toInputStream(BIG_TEXT, "UTF-8"));
    admin.save();
}
 
Example 2
Source File: TestEmptyPackage.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
/**
 * Installs a package that contains /tmp/test/content/foo/foo.jsp and then creates a new node
 * /tmp/test/content/bar/bar.jsp. Tests if after reinstall the new node was deleted.
 */
@Test
public void installEmptyFolder() throws RepositoryException, IOException, PackageException {
    JcrPackage pack = packMgr.upload(getStream("/test-packages/tmp_test_folders.zip"), false);
    assertNotNull(pack);
    pack.install(getDefaultOptions());
    assertNodeExists("/tmp/test/content/foo/foo.jsp");

    // create new node
    Node content = admin.getNode("/tmp/test/content");
    Node bar = content.addNode("bar", NodeType.NT_FOLDER);
    InputStream is = new ByteArrayInputStream("hello, world.".getBytes());
    JcrUtils.putFile(bar, "bar.jsp", "text/plain", is);
    admin.save();

    // now re-install package
    pack.install(getDefaultOptions());

    assertNodeMissing("/tmp/test/content/bar");
    assertNodeMissing("/tmp/test/content/bar/bar.jsp");
}
 
Example 3
Source File: TestCompressionExport.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
private String storeFile(boolean compressible, String mimeType, int size)
        throws RepositoryException {
    String path = String.format("%s/%s", TEST_PARENT_PATH, fileName(compressible, mimeType, size));
    Node node = JcrUtils.getOrCreateByPath(path, "nt:unstructured", admin);
    byte[] data = compressible ? compressibleData(size) : incompressibleData(size);
    JcrUtils.putFile(node, "file", mimeType, new ByteArrayInputStream(data));
    admin.save();
    return node.getPath();
}