org.apache.sling.api.wrappers.ValueMapDecorator Java Examples

The following examples show how to use org.apache.sling.api.wrappers.ValueMapDecorator. 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: RelationTypesDataSourceServlet.java    From aem-core-cif-components with Apache License 2.0 7 votes vote down vote up
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {

    ResourceBundle resourceBundle = request.getResourceBundle(null);
    List<Resource> values = new ArrayList<>();

    for (RelationType relationType : RelationType.values()) {
        ValueMap vm = new ValueMapDecorator(new HashMap<String, Object>());
        vm.put("value", relationType);
        vm.put("text", toText(resourceBundle, relationType.getText()));
        values.add(new ValueMapResource(request.getResourceResolver(), new ResourceMetadata(), JcrConstants.NT_UNSTRUCTURED, vm));
    }

    DataSource ds = new SimpleDataSource(values.iterator());
    request.setAttribute(DataSource.class.getName(), ds);
}
 
Example #2
Source File: ResourceModelClassesTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Test
public void testListModel() {
    Map<String, Object> map = new HashMap<>();
    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());
    assertEquals(new Integer(2), model.getIntList().get(1));

    assertEquals(2, model.getStringList().size());
    assertEquals("hello", model.getStringList().get(0));
}
 
Example #3
Source File: DefaultTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultPrimitivesField() {
    ValueMap vm = new ValueMapDecorator(Collections.<String, Object>emptyMap());

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

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

    assertEquals(true, model.getBooleanProperty());
    // we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays, https://github.com/junit-team/junit/issues/86!
    assertTrue(Arrays.equals(new boolean[] { true, true }, model.getBooleanArrayProperty()));

    assertEquals(1L, model.getLongProperty());
    assertArrayEquals(new long[] { 1L, 1L }, model.getLongArrayProperty());
}
 
Example #4
Source File: DefaultTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultWrappersField() {
    ValueMap vm = new ValueMapDecorator(Collections.<String, Object>emptyMap());

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

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

    assertEquals(Boolean.valueOf(true), model.getBooleanWrapperProperty());
    // we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays, https://github.com/junit-team/junit/issues/86!
    assertTrue(Arrays.equals(new Boolean[] { Boolean.TRUE, Boolean.TRUE }, model.getBooleanWrapperArrayProperty()));

    assertEquals(Long.valueOf(1L), model.getLongWrapperProperty());
    assertArrayEquals(new Long[] { Long.valueOf(1L), Long.valueOf(1L) }, model.getLongWrapperArrayProperty());
}
 
Example #5
Source File: DefaultTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultPrimitivesConstructor() {
    ValueMap vm = new ValueMapDecorator(Collections.<String, Object>emptyMap());

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

    org.apache.sling.models.testmodels.classes.constructorinjection.DefaultPrimitivesModel model
            = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultPrimitivesModel.class);
    assertNotNull(model);

    assertEquals(true, model.getBooleanProperty());
    // we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays, https://github.com/junit-team/junit/issues/86!
    assertTrue(Arrays.equals(new boolean[] { true, true }, model.getBooleanArrayProperty()));

    assertEquals(1L, model.getLongProperty());
    assertArrayEquals(new long[] { 1L, 1L }, model.getLongArrayProperty());
}
 
Example #6
Source File: DefaultTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultWrappersConstructor() {
    ValueMap vm = new ValueMapDecorator(Collections.<String, Object>emptyMap());

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

    org.apache.sling.models.testmodels.classes.constructorinjection.DefaultWrappersModel model
            = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultWrappersModel.class);
    assertNotNull(model);

    assertEquals(Boolean.valueOf(true), model.getBooleanWrapperProperty());
    // we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays, https://github.com/junit-team/junit/issues/86!
    assertTrue(Arrays.equals(new Boolean[] { Boolean.TRUE, Boolean.TRUE }, model.getBooleanWrapperArrayProperty()));

    assertEquals(Long.valueOf(1L), model.getLongWrapperProperty());
    assertArrayEquals(new Long[] { Long.valueOf(1L), Long.valueOf(1L) }, model.getLongWrapperArrayProperty());
}
 
Example #7
Source File: AnnotationConflictsTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
private <T extends Methods> void failing(Class<T> modelClass) {
    ValueMap map = new ValueMapDecorator(Collections.<String, Object>singletonMap("otherText", "hello"));
    when(resource.adaptTo(ValueMap.class)).thenReturn(map);

    boolean thrown = false;

    try {
        factory.createModel(resource, modelClass);
    } catch (MissingElementsException e) {
        assertEquals("Adaptation to " + modelClass.getSimpleName() + " failed, but with the wrong number of exceptions.",1, e.getMissingElements().size());
        MissingElementException me = e.getMissingElements().iterator().next();
        assertTrue("Adaptation to " + modelClass.getSimpleName() + " didn't fail due to emptyText.", me.getElement().toString().endsWith("emptyText"));
        thrown = true;
    }
    assertTrue("Adaptation to " + modelClass.getSimpleName() + " was successful.", thrown);
}
 
Example #8
Source File: ResourceModelClassesTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Test
public void testRequiredPropertyModelOptionalStrategy() {
    Map<String, Object> map = new HashMap<>();
    map.put("required1", "required value");
    map.put("required2", "required value");
    map.put("required3", "required value");
    ValueMap vm = spy(new ValueMapDecorator(map));

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

    ResourceModelWithRequiredFieldOptionalStrategy model = factory.getAdapter(res, ResourceModelWithRequiredFieldOptionalStrategy.class);
    assertNotNull(model);
    assertEquals("required value", model.getRequired1());
    assertEquals("required value", model.getRequired2());

    verify(vm).get("optional1", String.class);
    verify(vm).get("required1", String.class);
}
 
Example #9
Source File: InjectorSpecificAnnotationTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleValueModelField() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("first", "first-value");
    map.put("second", "second-value");
    ValueMap vm = new ValueMapDecorator(map);

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

    InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
    assertNotNull("Could not instanciate model", model);
    assertEquals("first-value", model.getFirst());
    assertEquals("second-value", model.getSecond());
}
 
Example #10
Source File: ResourceModelClassesTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Test
public void testRequiredPropertyModelWithException() {
    Map<String, Object> map = new HashMap<>();
    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);

    boolean thrown = false;
    try {
        factory.createModel(res, ResourceModelWithRequiredField.class);
    } catch (MissingElementsException e) {
        assertEquals("required", ((Field) e.getMissingElements().iterator().next().getElement()).getName());
        thrown = true;
    }
    assertTrue(thrown);

    verify(vm).get("required", String.class);
}
 
Example #11
Source File: InjectorSpecificAnnotationTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrderForValueAnnotationField() {
    // make sure that that the correct injection is used
    // make sure that log is adapted from value map
    // and not coming from request attribute
    Logger logFromValueMap = LoggerFactory.getLogger(this.getClass());

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

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

    InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
    assertNotNull("Could not instanciate model", model);
    assertEquals("first-value", model.getFirst());
    assertEquals(logFromValueMap, model.getLog());
}
 
Example #12
Source File: ResourceModelClassesTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Test
public void testArrayWrappersModel() {
    Map<String, Object> map = new HashMap<>();
    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();
    assertEquals(4, intArray.length);
    assertEquals(new Integer(2), intArray[1]);

    Integer[] secondIntArray = model.getSecondIntArray();
    assertEquals(4, secondIntArray.length);
    assertEquals(new Integer(2), secondIntArray[1]);
}
 
Example #13
Source File: ResourceModelClassesTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Test
public void testArrayPrimitivesModel() {
    Map<String, Object> map = new HashMap<>();
    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();
    assertEquals(4, primitiveIntArray.length);
    assertEquals(2, primitiveIntArray[1]);

    int[] secondPrimitiveIntArray = model.getSecondIntArray();
    assertEquals(4, secondPrimitiveIntArray.length);
    assertEquals(2, secondPrimitiveIntArray[1]);
}
 
Example #14
Source File: InjectorSpecificAnnotationTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleValueModelConstructor() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("first", "first-value");
    map.put("second", "second-value");
    ValueMap vm = new ValueMapDecorator(map);

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

    org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model
            = factory.getAdapter(request, org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel.class);
    assertNotNull("Could not instanciate model", model);
    assertEquals("first-value", model.getFirst());
    assertEquals("second-value", model.getSecond());
}
 
Example #15
Source File: NavigationImplTest.java    From aem-core-cif-components with Apache License 2.0 6 votes vote down vote up
private void initCatalogPage(boolean catalogRoot, boolean showMainCategories, boolean useCaConfig) {
    Page catalogPage = mock(Page.class);
    Resource catalogPageContent = mock(Resource.class);
    when(catalogPageContent.isResourceType(RT_CATALOG_PAGE)).thenReturn(catalogRoot);
    Map<String, Object> catalogPageProperties = new HashMap<>();
    catalogPageProperties.put(PN_SHOW_MAIN_CATEGORIES, showMainCategories);

    if (!useCaConfig) {
        catalogPageProperties.put(PN_MAGENTO_ROOT_CATEGORY_ID, 4);
    }
    when(catalogPageContent.adaptTo(ComponentsConfiguration.class)).thenReturn(new ComponentsConfiguration(new ValueMapDecorator(
        ImmutableMap.of(PN_MAGENTO_ROOT_CATEGORY_ID, 4))));
    when(catalogPageContent.getValueMap()).thenReturn(new ValueMapDecorator(catalogPageProperties));
    when(catalogPage.getContentResource()).thenReturn(catalogPageContent);
    when(catalogPage.getPath()).thenReturn("/content/catalog");
    when(catalogPageContent.getPath()).thenReturn("/content/catalog/jcr:content");
    ResourceResolver mockResourceResolver = mock(ResourceResolver.class);
    when(mockResourceResolver.getResource(any(String.class))).thenReturn(null);
    when(catalogPageContent.getResourceResolver()).thenReturn(mockResourceResolver);
    when(pageManager.getPage(CATALOG_PAGE_PATH)).thenReturn(catalogPage);

    ValueMap configProperties = new ValueMapDecorator(ImmutableMap.of(PN_MAGENTO_ROOT_CATEGORY_ID, 4));

    when(catalogPage.adaptTo(ComponentsConfiguration.class)).thenReturn(new ComponentsConfiguration(configProperties));
}
 
Example #16
Source File: InjectorSpecificAnnotationTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrderForValueAnnotationConstructor() {
    // make sure that that the correct injection is used
    // make sure that log is adapted from value map
    // and not coming from request attribute
    Logger logFromValueMap = LoggerFactory.getLogger(this.getClass());

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

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

    org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model
            = factory.getAdapter(request, org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel.class);
    assertNotNull("Could not instanciate model", model);
    assertEquals("first-value", model.getFirst());
    assertEquals(logFromValueMap, model.getLog());
}
 
Example #17
Source File: ResourceModelInterfacesTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimplePropertyModel() {
    Map<String, Object> map = new HashMap<>();
    map.put("first", "first-value");
    map.put("third", "third-value");
    map.put("fourth", true);
    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());
    assertEquals("third-value", model.getThirdProperty());
    assertTrue(model.isFourth());

    verify(res, times(1)).adaptTo(ValueMap.class);
}
 
Example #18
Source File: AdapterFactoryTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 5 votes vote down vote up
@Test(expected=MissingElementsException.class)
public void testCreatedNestedModelWithMissingElements() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("invalid", "required");
    ValueMap vm = new ValueMapDecorator(map);
    when(resource.adaptTo(ValueMap.class)).thenReturn(vm);

    factory.createModel(resource, NestedModel.class);
}
 
Example #19
Source File: ResourceModelInterfacesTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 5 votes vote down vote up
@Test
public void testChildValueMap() {
    ValueMap map = ValueMapDecorator.EMPTY;

    Resource child = mock(Resource.class);
    when(child.adaptTo(ValueMap.class)).thenReturn(map);

    Resource res = mock(Resource.class);
    when(res.getChild("firstChild")).thenReturn(child);

    ChildValueMapModel model = factory.getAdapter(res, ChildValueMapModel.class);
    assertNotNull(model);
    assertEquals(map, model.getFirstChild());
}
 
Example #20
Source File: ResourceModelInterfacesTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 5 votes vote down vote up
@Test
public void testRequiredPropertyModel() {
    Map<String, Object> map = new HashMap<>();
    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);
}
 
Example #21
Source File: InterfaceInheritanceTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimplePropertyModel() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("superClassString", "first-value");
    map.put("subClassString", "second-value");
    ValueMap vm = new ValueMapDecorator(map);

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

    SubClassModel model = factory.getAdapter(res, SubClassModel.class);
    assertNotNull(model);
    assertEquals("first-value", model.getSuperClassString());
    assertEquals("second-value", model.getSubClassString());
}
 
Example #22
Source File: InvalidAdaptationsTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonModelClass() {
    Map<String, Object> emptyMap = Collections.<String, Object> emptyMap();

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

    assertNull(factory.getAdapter(res, NonModel.class));
}
 
Example #23
Source File: ViaTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 5 votes vote down vote up
@Test
public void testProjectionToResource() {
    String value = RandomStringUtils.randomAlphanumeric(10);
    ValueMap map = new ValueMapDecorator(Collections.<String, Object> singletonMap("firstProperty", value));
    when(resource.adaptTo(ValueMap.class)).thenReturn(map);

    ViaModel model = factory.getAdapter(request, ViaModel.class);
    assertNotNull(model);
    assertEquals(value, model.getFirstProperty());
}
 
Example #24
Source File: ViaTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 5 votes vote down vote up
@Test
public void testProjectionToChildResource() {
    String value = RandomStringUtils.randomAlphanumeric(10);
    ValueMap map = new ValueMapDecorator(Collections.<String, Object> singletonMap("firstProperty", value));
    when(childResource.adaptTo(ValueMap.class)).thenReturn(map);
    ChildResourceViaModel model = factory.getAdapter(resource, ChildResourceViaModel.class);
    assertNotNull(model);
    assertEquals(value, model.getFirstProperty());
}
 
Example #25
Source File: ResourcePathInjectionTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("propertyContainingAPath", "/some/other/path");
    map.put("anotherPropertyContainingAPath", "/some/other/path2");
    String[] paths= new String[2];
    paths[0]="/some/other/path";
    paths[1]="/some/other/path2";
   
    String[] invalidPaths= new String[3];
    invalidPaths[0]="/does/not/exist";
    invalidPaths[1]="/does/not/exist2";
    invalidPaths[2]="/some/other/path";
    map.put("propertyWithSeveralPaths",paths);
    map.put("propertyWithMissingPaths", invalidPaths);

    ValueMap properties = new ValueMapDecorator(map);

    when(adaptable.getResourceResolver()).thenReturn(resourceResolver);
    when(adaptable.adaptTo(ValueMap.class)).thenReturn(properties);

    when(resourceResolver.getResource("/some/path")).thenReturn(byPathResource);
    when(resourceResolver.getResource("/some/path2")).thenReturn(byPathResource2);
    when(resourceResolver.getResource("/some/other/path")).thenReturn(byPropertyValueResource);
    when(resourceResolver.getResource("/some/other/path2")).thenReturn(byPropertyValueResource2);

    factory = AdapterFactoryTest.createModelAdapterFactory();
    factory.bindInjector(new SelfInjector(), new ServicePropertiesMap(1, Integer.MAX_VALUE));
    factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(2, 2000));
    factory.bindInjector(new ResourcePathInjector(), new ServicePropertiesMap(3, 2500));
    factory.bindStaticInjectAnnotationProcessorFactory(new ResourcePathInjector(), new ServicePropertiesMap(3, 2500));
    factory.adapterImplementations.addClassesAsAdapterAndImplementation(ResourcePathModel.class, ResourcePathPartialModel.class,
            ResourcePathAllOptionalModel.class, ResourcePathModelWrapping.class);
}
 
Example #26
Source File: AnnotationConflictsTest.java    From sling-org-apache-sling-models-impl with Apache License 2.0 5 votes vote down vote up
private <T extends Methods> void successful(Class<T> modelClass) {
    ValueMap map = new ValueMapDecorator(Collections.<String, Object>singletonMap("otherText", "hello"));
    when(resource.adaptTo(ValueMap.class)).thenReturn(map);

    Methods model = factory.createModel(resource, modelClass);
    assertNotNull("Adaptation to " + modelClass.getSimpleName() + " was not null.", model);
    assertNull("Adaptation to " + modelClass.getSimpleName() + " had a non-null emptyText value.", model.getEmptyText());
    assertEquals("Adaptation to " + modelClass.getSimpleName() + " had an unexpected value in the otherText value.", "hello", model.getOtherText());
}
 
Example #27
Source File: TagsResource.java    From sling-samples with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
    if(type == ValueMap.class) {
        return (AdapterType)new ValueMapDecorator(properties);
    }
    return super.adaptTo(type);
}
 
Example #28
Source File: FileResource.java    From sling-whiteboard with Apache License 2.0 5 votes vote down vote up
@Override
public ValueMap getValueMap() {
    Map<String, Object> props = new HashMap<>();
    props.put("sling:resourceType", getResourceType());

    return new ValueMapDecorator(props);
}
 
Example #29
Source File: CacheableResource.java    From sling-whiteboard with Apache License 2.0 5 votes vote down vote up
public CacheableResource(RemoteStorageProvider remoteStorageProvider, RemoteResourceReference remoteResourceReference, String path,
                         Map<String, Object> properties) {
    this.remoteStorageProvider = remoteStorageProvider;
    this.remoteResourceReference = remoteResourceReference;
    this.path = path;
    resourceType = Optional.of((String) properties.get(ResourceResolver.PROPERTY_RESOURCE_TYPE)).orElse(NT_UNSTRUCTURED);
    resourceSuperType = (String) properties.get(SlingConstants.NAMESPACE_PREFIX + ":" + SlingConstants.PROPERTY_RESOURCE_SUPER_TYPE);
    valueMap = new ValueMapDecorator(Collections.unmodifiableMap(properties));
    resourceMetadata = new ResourceMetadata();
    resourceMetadata.setCreationTime(remoteResourceReference.getCreated());
    resourceMetadata.setModificationTime(remoteResourceReference.getLastModified());
    if (remoteResourceReference.getType() == RemoteResourceReference.Type.FILE) {
        resourceMetadata.setContentLength(remoteResourceReference.getSize());
    }
}
 
Example #30
Source File: SimpleDataSourceBuilder.java    From APM with Apache License 2.0 5 votes vote down vote up
private Resource createDataSourceItem(ResourceResolver resolver, String name, String value) {
  Map<String, Object> valueMap = ImmutableMap.of(
      CONFIGURATION_NAME_PROP, name,
      CONFIGURATION_PATH_PROP, value
  );
  ValueMapDecorator result = new ValueMapDecorator(valueMap);
  return new ValueMapResource(resolver, new ResourceMetadata(), JcrConstants.NT_RESOURCE, result);
}