Package org.apache.sling.api.resource

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


            final Resource clusterInstancesResource, final Config config) {
        final Set<String> myView = new HashSet<String>();
        final Iterator<Resource> it = clusterInstancesResource.getChildren()
                .iterator();
        while (it.hasNext()) {
            Resource aClusterInstance = it.next();
            if (isHeartBeatCurrent(aClusterInstance, config)) {
                myView.add(aClusterInstance.getName());
            }
        }
        return myView;
    }
View Full Code Here


     *
     * @param resourceResolver
     * @return
     */
    public static View getEstablishedView(final ResourceResolver resourceResolver, final Config config) {
        final Resource establishedParent = resourceResolver
                .getResource(config.getEstablishedViewPath());
        if (establishedParent == null) {
            return null;
        }
        final Iterable<Resource> children = establishedParent.getChildren();
        if (children == null) {
            return null;
        }
        final Iterator<Resource> it = children.iterator();
        if (!it.hasNext()) {
            return null;
        }
        Resource establishedView = it.next();
        if (!it.hasNext()) {
            return new View(establishedView);
        }
        // emergency cleanup in case there is more than one established view:
        while (true) {
View Full Code Here

     * @param view a set of slingIds against which to compare this view
     * @return true if this view matches the given set of slingIds
     */
    public boolean matches(final Set<String> view) {
        final Set<String> viewCopy = new HashSet<String>(view);
        final Resource members = getResource().getChild("members");
        if (members == null) {
            return false;
        }
        try{
          final Iterator<Resource> it = members.getChildren().iterator();
          while (it.hasNext()) {
              Resource aMemberRes = it.next();
 
              if (!viewCopy.remove(aMemberRes.getName())) {
                  return false;
              }
          }
        } catch(RuntimeException re) {
          // SLING-2945 : the members resource could have been deleted
View Full Code Here

    public DefaultInstanceDescriptionImpl constructInstanceDescription(
            DefaultClusterViewImpl clusterView, boolean isLeader,
            boolean isOwn, String theSlingId, Map<String, String> properties)
            throws Exception {

        Resource res = new MockedResource(new MockedResourceResolver(),
                "/foo/bar", "nt:unstructured");

        return new EstablishedInstanceDescription(clusterView, res, theSlingId,
                isLeader, isOwn);
    }
View Full Code Here

            ResourceResolver resourceResolver = (ResourceResolver) adaptable;
            if (requestedClass.equals(ResourceResolver.class)) {
                return resourceResolver;
            }
        } else if (adaptable instanceof Resource) {
            Resource resource = (Resource) adaptable;
            if (requestedClass.equals(ResourceResolver.class)) {
                return resource.getResourceResolver();
            }
            if (requestedClass.equals(Resource.class) && element.isAnnotationPresent(SlingObject.class)) {
                return resource;
            }
        }
View Full Code Here

        map.put("third", "third-value");
        map.put("intProperty", new Integer(3));
        map.put("arrayProperty", new String[] { "three", "four" });
        ValueMap vm = new ValueMapDecorator(map);

        Resource res = mock(Resource.class);
        when(res.adaptTo(ValueMap.class)).thenReturn(vm);

        SimplePropertyModel model = factory.getAdapter(res, SimplePropertyModel.class);
        assertNotNull(model);
        assertEquals("first-value", model.getFirst());
        assertNull(model.getSecond());
View Full Code Here

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("intArray", new int[] { 1, 2, 9, 8 });
        map.put("secondIntArray", new Integer[] {1, 2, 9, 8});

        ValueMap vm = new ValueMapDecorator(map);
        Resource res = mock(Resource.class);
        when(res.adaptTo(ValueMap.class)).thenReturn(vm);

        ArrayPrimitivesModel model = factory.getAdapter(res, ArrayPrimitivesModel.class);
        assertNotNull(model);

        int[] primitiveIntArray = model.getIntArray();
View Full Code Here

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("intArray", new Integer[] {1, 2, 9, 8});
        map.put("secondIntArray", new int[] {1, 2, 9, 8});

        ValueMap vm = new ValueMapDecorator(map);
        Resource res = mock(Resource.class);
        when(res.adaptTo(ValueMap.class)).thenReturn(vm);

        ArrayWrappersModel model = factory.getAdapter(res, ArrayWrappersModel.class);
        assertNotNull(model);

        Integer[] intArray = model.getIntArray();
View Full Code Here

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("intList", new Integer[] {1, 2, 9, 8});
        map.put("stringList", new String[] {"hello", "world"});

        ValueMap vm = new ValueMapDecorator(map);
        Resource res = mock(Resource.class);
        when(res.adaptTo(ValueMap.class)).thenReturn(vm);

        ListModel model = factory.getAdapter(res, ListModel.class);
        assertNotNull(model);

        assertEquals(4, model.getIntList().size());
View Full Code Here

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("first", "first-value");
        map.put("third", "third-value");
        ValueMap vm = spy(new ValueMapDecorator(map));

        Resource res = mock(Resource.class);
        when(res.adaptTo(ValueMap.class)).thenReturn(vm);

        ResourceModelWithRequiredField model = factory.getAdapter(res, ResourceModelWithRequiredField.class);
        assertNull(model);

        verify(vm).get("required", String.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.