Package org.apache.sling.api.resource

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


            return false;
        }
    }

    private static void updateThread(ResourceResolver resolver, Resource thread, Map<String, Object> msgProps) throws PersistenceException {
        final ModifiableValueMap thrdProps = thread.adaptTo(ModifiableValueMap.class);
        Long prop = (Long) thrdProps.get(MessageFieldName.LAST_UPDATE);
        Date updatedDate = null;
        if (prop != null) {
            updatedDate = new Date(prop);
        }
        final String msgProp = (String) msgProps.get(FieldName.DATE);
        SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
        final Date msgDate = sdf.parse(msgProp, new ParsePosition(0));
        if (updatedDate == null || msgDate.after(updatedDate)) {
            thrdProps.put(MessageFieldName.LAST_UPDATE, msgDate.getTime());
            resolver.commit();
        }
    }
View Full Code Here


        }
    }

    static void assertLayer(Resource root, List<String> types, int depth) {
        for (Resource child : root.getChildren()) {
            final ModifiableValueMap m = child.adaptTo(ModifiableValueMap.class);
            if (m.keySet().contains(MessageStoreImplRepositoryTest.TEST_RT_KEY)) {
                String type = m.get(MessageStoreImplRepositoryTest.TEST_RT_KEY, String.class);
                assertEquals(String.format("Expecting %s to have %s type", child.getPath(), types.get(depth)), types.get(depth), type);
            }
            if (child.getChildren().iterator().hasNext()) {
                assertLayer(child, types, depth+1);
            }
View Full Code Here

    }

    public boolean setLastModified(long arg0) {
        Resource content = getContent();
        if (content != null) {
            ModifiableValueMap map = content.adaptTo(ModifiableValueMap.class);
            if (map != null) {
                map.put("jcr:lastModified", arg0);
                try {
                    this.resolver.commit();
                    return true;
                } catch (PersistenceException e) {
                    // TODO: handle
View Full Code Here

            assertNotNull(rsrc);
            final ValueMap beforeVM = rsrc.getValueMap();
            assertEquals("1", beforeVM.get("a"));
            assertEquals("2", beforeVM.get("b"));

            final ModifiableValueMap mvm = rsrc.adaptTo(ModifiableValueMap.class);
            assertNotNull(mvm);
            assertEquals("1", mvm.get("a"));
            assertEquals("2", mvm.get("b"));

            mvm.put("c", "3");
            mvm.remove("a");

            assertNotNull(this.resolver.getResource("/libs/mvmTest"));
            assertNotNull(this.resolver.getResource("/apps/mvmTest"));

            final Resource rsrc2 = this.provider.getResource(this.resolver, path);
View Full Code Here

                final String paths[] = (String[])this.getResourceMetadata().get(MergedResourceConstants.METADATA_RESOURCES);

                final Resource copyResource = this.getResourceResolver().getResource(paths[paths.length - 1]);
                try {
                    final Resource newResource = ResourceUtil.getOrCreateResource(this.getResourceResolver(), highestRsrc.getPath(), copyResource.getResourceType(), null, false);
                    final ModifiableValueMap target = newResource.adaptTo(ModifiableValueMap.class);
                    if ( target != null ) {
                        return (AdapterType)new ModifiableProperties(this, target);
                    }
                } catch ( final PersistenceException pe) {
                    // we ignore this for now
                }
                return super.adaptTo(type);
            }
            final ModifiableValueMap target = highestRsrc.adaptTo(ModifiableValueMap.class);
            if ( target != null ) {
                return (AdapterType)new ModifiableProperties(this, target);
            }
        }
        return super.adaptTo(type);
View Full Code Here

        assertEquals("", num, attachmentsMsg.size());
       
        final Resource r = resolver.getResource(getResourcePath(msg, store));
        assertNotNull("Expecting non-null Resource", r);
        for (Resource aRes : r.getChildren()) {
            final ModifiableValueMap aMap = aRes.adaptTo(ModifiableValueMap.class);
            BodyPart aMsg = attachmentsMsg.poll();
            assertNotNull("JCR contains more attachments", aMsg);

            for (Field f : aMsg.getHeader().getFields()) {
                String name = f.getName();
                assertEquals("Field "+name+" is different", (aMap.get(name, String.class)), f.getBody());
            }
           
            if (aMsg.getBody() instanceof TextBody) {
                assertEquals("Content is not the same", MessageStoreImpl.getTextPart(aMsg), aMap.get(CONTENT, String.class));
            } else if (aMsg.getBody() instanceof BinaryBody) {
                assertEquals("Content is not the same", getBinPart(aMsg), aMap.get(CONTENT, String.class));
            } else {
                fail("Unknown type of attachment body");
            }
        }
        assertEquals("Message contains more attachments", attachmentsMsg.poll(), null);
View Full Code Here

    public void close() throws IOException {
        InputStream ins = null;
        try {
            super.close();

            ModifiableValueMap map = this.content.adaptTo(ModifiableValueMap.class);
            if (map != null) {
                ins = new FileInputStream(tmpFile);
                map.put("jcr:lastModified", System.currentTimeMillis());
                map.put("jcr:data", ins);
                this.content.getResourceResolver().commit();
            }
        } finally {
            if (ins != null) {
                try {
View Full Code Here

       
        {
            // Retrieve and check child resource
            final Resource r = resolver.getResource(fullPath);
            assertNotNull("Expecting Resource at " + fullPath, r);
            final ModifiableValueMap m = r.adaptTo(ModifiableValueMap.class);
            assertValueMap(m, "title", "hello", "text", "world");
           
            // Update child resource
            m.put("more", "fun");
            m.put("title", "changed");
            resolver.commit();
        }
       
        {
            // Retrieve and check updated resource
View Full Code Here

        }

        // get or create resource
        Resource result = parentResource.getChild(name);
        if ( result != null ) {
            final ModifiableValueMap vm = result.adaptTo(ModifiableValueMap.class);
            if ( vm == null ) {
                throw new PersistenceException("Resource at " + parentResource.getPath() + '/' + name + " is not modifiable.");
            }
            vm.putAll(props);
        } else {
            result = parentResource.getResourceResolver().create(parentResource, name, props);
        }
        for(final String key : props.keySet()) {
            changes.add(Modification.onModified(result.getPath() + '/' + key));
View Full Code Here

            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        } else if (type.equals(ModifiableValueMap.class)) {
            return (AdapterType) new ModifiableValueMap() {

                public Collection<Object> values() {
                    throw new UnsupportedOperationException();
                }
View Full Code Here

TOP

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

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.