Package org.apache.sling.api.resource

Examples of org.apache.sling.api.resource.Resource


            primaryType = JcrConstants.NT_UNSTRUCTURED;
        }
        props.put(JcrConstants.JCR_PRIMARYTYPE, primaryType);

        // create resource
        Resource resource = resourceResolver.create(parentResource, childName, props);

        // add child resources
        for (int i = 0; names != null && i < names.length(); i++) {
            final String name = names.getString(i);
            if (!IGNORED_NAMES.contains(name)) {
View Full Code Here


     * @return Resource with binary data
     */
    public Resource binaryFile(InputStream inputStream, String path, String mimeType) {
        String parentPath = ResourceUtil.getParent(path, 1);
        String name = ResourceUtil.getName(path);
        Resource parentResource = resourceResolver.getResource(parentPath);
        if (parentResource == null) {
            parentResource = createResourceHierarchy(parentPath);
        }
        return binaryFile(inputStream, parentResource, name, mimeType);
    }
View Full Code Here

     * @param mimeType Mime type of binary data
     * @return Resource with binary data
     */
    public Resource binaryFile(InputStream inputStream, Resource parentResource, String name, String mimeType) {
        try {
            Resource file = resourceResolver.create(parentResource, name,
                    ImmutableMap.<String, Object> builder().put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_FILE)
                            .build());
            resourceResolver.create(file, JcrConstants.JCR_CONTENT,
                    ImmutableMap.<String, Object> builder().put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_RESOURCE)
                            .put(JcrConstants.JCR_DATA, inputStream).put(JcrConstants.JCR_MIMETYPE, mimeType).build());
View Full Code Here

     * @return Resource with binary data
     */
    public Resource binaryResource(InputStream inputStream, String path, String mimeType) {
        String parentPath = ResourceUtil.getParent(path, 1);
        String name = ResourceUtil.getName(path);
        Resource parentResource = resourceResolver.getResource(parentPath);
        if (parentResource == null) {
            parentResource = createResourceHierarchy(parentPath);
        }
        return binaryResource(inputStream, parentResource, name, mimeType);
    }
View Full Code Here

    private void create(final String path, final Map<String, Object> properties) throws PersistenceException {
        final String parentPath = ResourceUtil.getParent(path);
        final String name = ResourceUtil.getName(path);

        final Resource parent = this.resolver.getResource(parentPath);
        this.resolver.create(parent, name, properties);
    }
View Full Code Here

     * @param resourcePath Resource path
     * @return Current resource
     */
    public final Resource currentResource(String resourcePath) {
        if (resourcePath != null) {
            Resource resource = resourceResolver().getResource(resourcePath);
            if (resource == null) {
                throw new IllegalArgumentException("Resource does not exist: " + resourcePath);
            }
            return currentResource(resource);
        } else {
View Full Code Here

    public void tearDown() {
        // simulate bundle remove for ModelPackageBundleListener
        factory.listener.removedBundle(bundle, bundleEvent, registeredAdapterFactories);
       
        // make sure adaption is not longer possible: implementation class mapping is removed
        Resource res = getMockResourceWithProps();
        SampleServiceInterface model = factory.getAdapter(res, SampleServiceInterface.class);
        assertNull(model);
    }
View Full Code Here

    /**
     * Try to adapt to interface, with an different implementation class that has the @Model annotation
     */
    @Test
    public void testImplementsInterfaceModel() {
        Resource res = getMockResourceWithProps();
        SampleServiceInterface model = factory.getAdapter(res, SampleServiceInterface.class);
        assertNotNull(model);
        assertEquals(ImplementsInterfacePropertyModel.class, model.getClass());
        assertEquals("first-value|null|third-value", model.getAllProperties());
        assertTrue(factory.canCreateFromAdaptable(res, SampleServiceInterface.class));
View Full Code Here

     */
    @Test
    public void testImplementsNoPicker() {
        factory.unbindImplementationPicker(firstImplementationPicker, firstImplementationPickerProps);

        Resource res = getMockResourceWithProps();
        SampleServiceInterface model = factory.getAdapter(res, SampleServiceInterface.class);
        assertNull(model);
        assertFalse(factory.isModelClass(res, SampleServiceInterface.class));

        model = factory.getAdapter(res, ImplementsInterfacePropertyModel.class);
View Full Code Here

    /**
     * Test implementation class with a mapping that is not valid (an interface that is not implemented).
     */
    @Test
    public void testInvalidImplementsInterfaceModel() {
        Resource res = getMockResourceWithProps();
        InvalidSampleServiceInterface model = factory.getAdapter(res, InvalidSampleServiceInterface.class);
        assertNull(model);
        assertFalse(factory.isModelClass(res, InvalidSampleServiceInterface.class));
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.api.resource.Resource

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.