当前位置: 首页>>代码示例>>Java>>正文


Java ValueMap.put方法代码示例

本文整理汇总了Java中org.apache.sling.api.resource.ValueMap.put方法的典型用法代码示例。如果您正苦于以下问题:Java ValueMap.put方法的具体用法?Java ValueMap.put怎么用?Java ValueMap.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.sling.api.resource.ValueMap的用法示例。


在下文中一共展示了ValueMap.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateLikeCounter

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
private void updateLikeCounter(SlingHttpServletRequest request) throws PersistenceException {

    ValueMap props = request.getResource().getValueMap();

    // check if a user with this ip address has already liked this
    String ipAddress = request.getRemoteAddr();
    String[] likedAddresses = props.get("likedAddresses", new String[0]);
    if (ArrayUtils.contains(likedAddresses, ipAddress)) {
      return;
    }

    // increment like counter and store ip address
    ValueMap writeProps = request.getResource().adaptTo(ModifiableValueMap.class);
    writeProps.put("likes", writeProps.get("likes", 0L) + 1);

    List<String> updatedLikedAddresses = new ArrayList<>(Arrays.asList(likedAddresses));
    updatedLikedAddresses.add(ipAddress);
    writeProps.put("likedAddresses", updatedLikedAddresses.toArray());

    // save to repository
    request.getResourceResolver().commit();

  }
 
开发者ID:adaptto,项目名称:2015-sling-rookie-session,代码行数:24,代码来源:LikeMe.java

示例2: decorate

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
@Override
public Resource decorate(final Resource resource) {
    // Remember to return early (as seen above) as this decorator is executed on all
    // Resource resolutions (this happens A LOT), especially if the decorator performs
    // any complex/slow running logic.

    if (!this.accepts(resource)) {
        return resource;
    }

    // Any overridden methods (ex. adaptTo) on the wrapper, will be used when invoked on the
    // resultant Resource object (even before casting).

    final ValueMap overlay = new ValueMapDecorator(new HashMap<String, Object>());
    overlay.put("foo", 100);
    overlay.put("cat", "meow");

    // See ACS AEM Samples com.adobe.acs.samples.resources.SampleResourceWrapper for how
    // these above overlay properties are added to the resource's ValueMap
    return new SampleResourceWrapper(resource, overlay);
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-samples,代码行数:22,代码来源:SampleResourceDecorator.java

示例3: getJSONResults

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
private JSONObject getJSONResults(Command cmd, SlingHttpServletRequest request, final Collection<Result> results) throws
        JSONException {
    final JSONObject json = new JSONObject();

    json.put(KEY_RESULTS, new JSONArray());

    final ValueMap requestConfig = new ValueMapDecorator(new HashMap<String, Object>());

    // Collect all items collected from OSGi Properties
    requestConfig.putAll(this.config);

    // Add Request specific configurations
    requestConfig.put(AuthoringUIMode.class.getName(),
            authoringUIModeService.getAuthoringUIMode(request));

    for (final Result result : results) {
        final JSONObject tmp = resultBuilder.toJSON(cmd, result, requestConfig);

        if (tmp != null) {
            json.accumulate(KEY_RESULTS, tmp);
        }
    }

    return json;
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:26,代码来源:QuicklyEngineImpl.java

示例4: doGet

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
@Test
public void doGet() throws Exception {
    final ValueMap graniteUiFormValues = new ValueMapDecorator(new HashMap<>());
    graniteUiFormValues.put("ootb", "ootb value");

    slingContext.create().resource("/content/dam/do-get/folder", ImmutableMap.<String, Object>builder().put("resource", "resource value").build());

    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(slingContext.resourceResolver(), osgiContext.bundleContext());
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo)request.getRequestPathInfo();
    requestPathInfo.setResourcePath("wizard.html");
    requestPathInfo.setSuffix("/content/dam/do-get/folder");
    request.setAttribute("granite.ui.form.values", graniteUiFormValues);

    assetsFolderPropertiesSupport.doGet(request, response);

    ValueMap actual = (ValueMap) request.getAttribute("granite.ui.form.values");

    assertEquals("ootb value", actual.get("ootb", String.class));
    assertEquals("resource value", actual.get("resource", String.class));
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:21,代码来源:AssetsFolderPropertiesSupportTest.java

示例5: testAdd_Unsorted

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
@Test
public void testAdd_Unsorted() throws Exception {
    valueMap.put("animals", unsortedJSON.toString());

    ValueMap properties = new ValueMapDecorator(new HashMap<String, Object>());
    properties.put("name", "hyena");
    properties.put("sound", "lolz");
    properties.put("jcr:primaryType", "nt:unstructured");

    JSONObject expectedJSON = new JSONObject(unsortedJSON.toString());
    expectedJSON.put("entry-4", new JSONObject(properties));

    childrenAsPropertyResource =
            new ChildrenAsPropertyResource(resource, "animals");

    childrenAsPropertyResource.create("entry-4", "nt:unstructured", properties);
    childrenAsPropertyResource.persist();

    String actual = resource.getValueMap().get("animals", String.class);
    String expected = expectedJSON.toString();

    Assert.assertEquals(expected, actual);
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:24,代码来源:ChildrenAsPropertyResourceTest.java

示例6: testAdd_Sorted

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
@Test
public void testAdd_Sorted() throws Exception {
    valueMap.put("animals", unsortedJSON.toString());

    ValueMap properties = new ValueMapDecorator(new HashMap<String, Object>());
    properties.put("name", "hyena");
    properties.put("sound", "lolz");
    properties.put("jcr:primaryType", "nt:unstructured");

    JSONObject expectedJSON = new JSONObject(sortedJSON.toString());
    expectedJSON.put("entry-4", new JSONObject(properties));

    childrenAsPropertyResource =
            new ChildrenAsPropertyResource(resource, "animals",
                    ChildrenAsPropertyResource.RESOURCE_NAME_COMPARATOR);

    childrenAsPropertyResource.create("entry-4", "nt:unstructured", properties);
    childrenAsPropertyResource.persist();

    String actual = resource.getValueMap().get("animals", String.class);
    String expected = expectedJSON.toString();

    Assert.assertEquals(expected, actual);
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:25,代码来源:ChildrenAsPropertyResourceTest.java

示例7: addCountry

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
private void addCountry(ResourceResolver resolver, List<Resource> countries, String countryCode, String countryName) {
    ValueMap vm = new ValueMapDecorator(new HashMap<String, Object>());
    vm.put("value", countryCode);
    vm.put("text", i18n.get(countryName));
    ValueMapResource countryRes = new ValueMapResource(resolver, "", "", vm);
    countries.add(countryRes);
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-sample-we-retail,代码行数:8,代码来源:CountriesFormOptionsDataSource.java

示例8: addCountryOptionHeader

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
private void addCountryOptionHeader(ResourceResolver resolver, List<Resource> countries) {
    ValueMap vm = new ValueMapDecorator(new HashMap<String, Object>());
    vm.put("value", "");
    vm.put("text", i18n.get(COUNTRY_OPTIONS_HEADER));
    vm.put("selected", true);
    vm.put("disabled", true);
    ValueMapResource countryRes = new ValueMapResource(resolver, "", "", vm);
    countries.add(0, countryRes);
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-sample-we-retail,代码行数:10,代码来源:CountriesFormOptionsDataSource.java

示例9: deserializeToSyntheticChildResources

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
/**
 * Converts a JSONObject to the list of SyntheticChildAsPropertyResources.
 *
 * @param jsonObject the JSONObject to deserialize.
 * @return the list of SyntheticChildAsPropertyResources the jsonObject represents.
 * @throws JSONException
 */
protected final List<SyntheticChildAsPropertyResource> deserializeToSyntheticChildResources(JSONObject jsonObject)
        throws JSONException {
    final List<SyntheticChildAsPropertyResource> resources = new ArrayList<SyntheticChildAsPropertyResource>();

    final Iterator<String> keys = jsonObject.keys();

    while (keys.hasNext()) {
        final String nodeName = keys.next();

        JSONObject entryJSON = jsonObject.optJSONObject(nodeName);

        if (entryJSON == null) {
            continue;
        }

        final ValueMap properties = new ValueMapDecorator(new HashMap<String, Object>());
        final Iterator<String> propertyNames = entryJSON.keys();

        while (propertyNames.hasNext()) {
            final String propName = propertyNames.next();
            properties.put(propName, entryJSON.optString(propName));
        }

        resources.add(new SyntheticChildAsPropertyResource(this.getParent(), nodeName, properties));
    }

    return resources;
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:36,代码来源:ChildrenAsPropertyResource.java

示例10: doPost

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
/**
 * Persists the Users to CSV form data to the underlying jcr:content node.
 * @param request the Sling HTTP Request object
 * @param response the Sling HTTP Response object
 * @throws IOException
 * @throws ServletException
 */
public void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException {
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");

    final ValueMap properties = request.getResource().adaptTo(ModifiableValueMap.class);

    final Parameters parameters = new Parameters(request);
    properties.put(GROUP_FILTER, parameters.getGroupFilter());
    properties.put(GROUPS, parameters.getGroups());
    properties.put(CUSTOM_PROPERTIES, parameters.getCustomProperties());
    request.getResourceResolver().commit();

}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:21,代码来源:UsersSaveServlet.java

示例11: getImageTransforms

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
@Override
public Map<String, ValueMap> getImageTransforms() {
    final Map<String, ValueMap> small = new LinkedHashMap<String, ValueMap>();

    ValueMap inner = new ValueMapDecorator(new LinkedHashMap<String, Object>());
    inner.put("width", "10");
    small.put("resize", inner);

    return small;
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:11,代码来源:SmallNamedImageTransformer.java

示例12: adaptTo

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <AdapterType> AdapterType adaptTo(Class<AdapterType> clazz) {
    if (clazz == ValueMap.class) {
        ValueMap vm = new ValueMapDecorator(new HashMap<String, Object>());
        for(String key : Collections.list(getKeys())) {
            vm.put(key, getString(key));
        }
        return (AdapterType) vm;
    }
    return null;
}
 
开发者ID:steeleforge,项目名称:ironsites,代码行数:12,代码来源:I18nResourceBundle.java

示例13: transform

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
@Override
public final Layer transform(Layer layer, final ValueMap properties) {

    if (properties == null || properties.isEmpty()) {
        log.warn("Transform [ {} ] requires parameters.", TYPE);
        return layer;
    }

    log.debug("Transforming with [ {} ]", TYPE);

    Double scale = properties.get(KEY_SCALE, 1D);
    String round = StringUtils.trim(properties.get(KEY_ROUND, String.class));

    if (scale == null) {
        log.warn("Could not derive a Double value for key [ {} ] from value [ {} ]",
                KEY_SCALE, properties.get(KEY_SCALE, String.class));
        scale = 1D;
    }

    if (scale != 1D) {

        int currentWidth = layer.getWidth();
        int currentHeight = layer.getHeight();

        double newWidth = scale * currentWidth;
        double newHeight = scale * currentHeight;

        if (StringUtils.equals(ROUND_UP, round)) {
            newWidth = (int) Math.ceil(newWidth);
            newHeight = (int) Math.ceil(newHeight);
        } else if (StringUtils.equals(ROUND_DOWN, round)) {
            newWidth = (int) Math.floor(newWidth);
            newHeight = (int) Math.floor(newHeight);
        } else {
            // "round"
            newWidth = (int) Math.round(newWidth);
            newHeight = (int) Math.round(newHeight);
        }


        // Invoke the ResizeImageTransformer with the new values

        final ValueMap params = new ValueMapDecorator(new HashMap<String, Object>());
        params.put(ResizeImageTransformerImpl.KEY_WIDTH, (int)newWidth);
        params.put(ResizeImageTransformerImpl.KEY_HEIGHT, (int)newHeight);

        layer = resizeImageTransformer.transform(layer, params);
    }

    return layer;
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:52,代码来源:ScaleImageTransformerImpl.java

示例14: test_getQuality

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
@Test
public void test_getQuality() throws Exception {
    ValueMap qualityTransforms = new ValueMapDecorator(new HashMap<String, Object>());

    qualityTransforms.put("quality", 0);
    assertEquals(0D, servlet.getQuality("image/jpg", qualityTransforms), 0);

    qualityTransforms.put("quality", 100);
    assertEquals(1D, servlet.getQuality("image/jpg", qualityTransforms), 0);

    qualityTransforms.put("quality", 50);
    assertEquals(0.5D, servlet.getQuality("image/jpg", qualityTransforms), 0);

    qualityTransforms.put("quality", 101);
    assertEquals(.82D, servlet.getQuality("image/jpg", qualityTransforms), 0);

    qualityTransforms.put("quality", -1);
    assertEquals(.82D, servlet.getQuality("image/jpg", qualityTransforms), 0);

    /* Gifs */
    
    qualityTransforms.put("quality", 0);
    assertEquals(0D, servlet.getQuality("image/gif", qualityTransforms), 0);

    qualityTransforms.put("quality", 100);
    assertEquals(255D, servlet.getQuality("image/gif", qualityTransforms), 0);

    qualityTransforms.put("quality", 50);
    assertEquals(127.5D, servlet.getQuality("image/gif", qualityTransforms), 0);

    qualityTransforms.put("quality", 101);
    assertEquals(209.1D, servlet.getQuality("image/gif", qualityTransforms), 0);

    qualityTransforms.put("quality", -1);
    assertEquals(209.1D, servlet.getQuality("image/gif", qualityTransforms), 0);

}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:38,代码来源:NamedTransformImageServletTest.java

示例15: test_isProgressiveJpeg

import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
@Test
public void test_isProgressiveJpeg() throws Exception {
    ValueMap progressiveTransforms = new ValueMapDecorator(new HashMap<String, Object>());

    // Disabled

    progressiveTransforms.put("enabled", false);
    assertFalse(servlet.isProgressiveJpeg("image/png", progressiveTransforms));

    progressiveTransforms.put("enabled", false);
    assertFalse(servlet.isProgressiveJpeg("image/jpg", progressiveTransforms));

    progressiveTransforms.put("enabled", false);
    assertFalse(servlet.isProgressiveJpeg("image/jpeg", progressiveTransforms));

    // Enabled

    progressiveTransforms.put("enabled", true);
    assertFalse(servlet.isProgressiveJpeg("image/png", progressiveTransforms));

    progressiveTransforms.put("enabled", true);
    assertTrue(servlet.isProgressiveJpeg("image/jpg", progressiveTransforms));

    progressiveTransforms.put("enabled", true);
    assertTrue(servlet.isProgressiveJpeg("image/jpeg", progressiveTransforms));

    // Invalid

    progressiveTransforms.put("enabled", true);
    assertFalse(servlet.isProgressiveJpeg(null, progressiveTransforms));

    progressiveTransforms.put("enabled", true);
    assertFalse(servlet.isProgressiveJpeg("", progressiveTransforms));

    progressiveTransforms.remove("enabled");
    assertFalse(servlet.isProgressiveJpeg("", progressiveTransforms));

}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:39,代码来源:NamedTransformImageServletTest.java


注:本文中的org.apache.sling.api.resource.ValueMap.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。