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


Java SlingBindings类代码示例

本文整理汇总了Java中org.apache.sling.api.scripting.SlingBindings的典型用法代码示例。如果您正苦于以下问题:Java SlingBindings类的具体用法?Java SlingBindings怎么用?Java SlingBindings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getResource

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
/**
 * get a resource
 *
 * @param path
 * @param depth
 * @return json string
 */
public String getResource(final String path, final Integer depth) {
  SlingHttpServletRequest request = (SlingHttpServletRequest) context.getBindings(ScriptContext.ENGINE_SCOPE).get(SlingBindings.REQUEST);

  int actualDepth;
  try {
    if (depth == null || depth < 1) {
      actualDepth = -1;
    } else {
      actualDepth = depth.intValue();
    }

    Resource resource = request.getResourceResolver().getResource(path);
    if (resource == null) {
      return null;
    }
    return JsonObjectCreator.create(resource, actualDepth).toString();

  } catch (JSONException e) {
    throw new TechnicalException("could not get current resource", e);
  }

}
 
开发者ID:sinnerschrader,项目名称:aem-react,代码行数:30,代码来源:Sling.java

示例2: prepareRequestResponsePair

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
private Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> prepareRequestResponsePair(String resourcePath,
                                                                                                   long lastModifiedDate,
                                                                                                   String selectorString,
                                                                                                   String requestExtension,
                                                                                                   String suffixExtension) {
    final MockSlingHttpServletRequest request =
            new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
    final MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
    Resource resource = resourceResolver.getResource(resourcePath);
    request.setResource(resource);
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSuffix("/" + lastModifiedDate + "." + suffixExtension);
    requestPathInfo.setSelectorString(selectorString);
    requestPathInfo.setExtension(requestExtension);
    requestPathInfo.setResourcePath(resourcePath);
    request.setContextPath(CONTEXT_PATH);
    SlingBindings bindings = new SlingBindings();
    bindings.put(SlingBindings.REQUEST, request);
    bindings.put(SlingBindings.RESPONSE, response);
    bindings.put(SlingBindings.SLING, CONTEXT.slingScriptHelper());
    bindings.put(SlingBindings.RESOLVER, resourceResolver);
    request.setAttribute(SlingBindings.class.getName(), bindings);
    return new RequestResponsePair(request, response);
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:25,代码来源:AdaptiveImageServletTest.java

示例3: getContainerUnderTest

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
private Container getContainerUnderTest(String resourcePath) {
    Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
    if (resource == null) {
        throw new IllegalStateException("Does the test resource " + resourcePath + " exist?");
    }
    SlingBindings bindings = new SlingBindings();
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
    MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
    request.setContextPath(CONTEXT_PATH);
    request.setResource(resource);
    bindings.put(SlingBindings.RESOURCE, resource);
    bindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
    bindings.put(SlingBindings.REQUEST, request);
    bindings.put(SlingBindings.RESPONSE, response);
    Page page = CONTEXT.currentPage(CONTAINING_PAGE);
    bindings.put(WCMBindings.CURRENT_PAGE, page);
    request.setRequestDispatcherFactory(requestDispatcherFactory);
    request.setAttribute(SlingBindings.class.getName(), bindings);
    return request.adaptTo(Container.class);
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:21,代码来源:ContainerImplTest.java

示例4: getBreadcrumbUnderTest

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
private Breadcrumb getBreadcrumbUnderTest(String resourcePath, Style style) {
    Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
    if (resource == null) {
        throw new IllegalStateException("Did you forget to define test resource " + resourcePath + "?");
    }
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
    request.setResource(resource);
    request.setContextPath("");
    SlingBindings bindings = new SlingBindings();
    bindings.put(SlingBindings.RESOURCE, resource);
    bindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
    bindings.put(WCMBindings.CURRENT_PAGE, CONTEXT.pageManager().getPage(CURRENT_PAGE));
    if (style == null) {
        style = mock(Style.class);
        when(style.get(any(), any(Object.class))).thenAnswer(
                invocation -> invocation.getArguments()[1]
        );
    }
    bindings.put(WCMBindings.CURRENT_STYLE, style);
    request.setAttribute(SlingBindings.class.getName(), bindings);
    return request.adaptTo(Breadcrumb.class);
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:23,代码来源:BreadcrumbImplTest.java

示例5: getListUnderTest

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
private List getListUnderTest(String resourcePath) {
    Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
    if (resource == null) {
        throw new IllegalStateException("Did you forget to defines test resource " + resourcePath + "?");
    }
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
    request.setResource(resource);
    SlingBindings bindings = new SlingBindings();
    bindings.put(SlingBindings.RESOURCE, resource);
    bindings.put(SlingBindings.REQUEST, request);
    bindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
    Style style = mock(Style.class);
    when(style.get(any(), any(Object.class))).thenAnswer(
            invocation -> invocation.getArguments()[1]
    );
    bindings.put(WCMBindings.CURRENT_STYLE, style);
    bindings.put(WCMBindings.CURRENT_PAGE, CONTEXT.pageManager().getPage(CURRENT_PAGE));
    request.setAttribute(SlingBindings.class.getName(), bindings);
    return request.adaptTo(List.class);
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:21,代码来源:ListImplTest.java

示例6: getSocialMediaHelperUnderTest

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
private SocialMediaHelper getSocialMediaHelperUnderTest(String pagePath) {
    Resource currentResource = CONTEXT.resourceResolver().getResource(pagePath);
    Page currentPage = currentResource.adaptTo(Page.class);
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
    MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
    request.setContextPath(CONTEXT_PATH);
    request.setResource(currentResource);
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setExtension(EXTENSION);
    requestPathInfo.setResourcePath(currentResource.getPath());
    SlingBindings slingBindings = new SlingBindings();
    slingBindings.put(WCMBindings.CURRENT_PAGE, currentPage);
    slingBindings.put(SlingBindings.RESOLVER, CONTEXT.resourceResolver());
    slingBindings.put(SlingBindings.RESPONSE, response);
    request.setAttribute(SlingBindings.class.getName(), slingBindings);
    return request.adaptTo(SocialMediaHelper.class);
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:18,代码来源:SocialMediaHelperImplTest.java

示例7: getTitleUnderTest

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
private Title getTitleUnderTest(String resourcePath, Style style) {
    Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
    if (resource == null) {
        throw new IllegalStateException("Did you forget to define test resource " + resourcePath + "?");
    }
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
    SlingBindings bindings = new SlingBindings();
    bindings.put(SlingBindings.RESOURCE, resource);
    bindings.put(SlingBindings.REQUEST, request);
    bindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
    bindings.put(WCMBindings.CURRENT_PAGE, CONTEXT.pageManager().getPage(TEST_PAGE));
    if (style == null) {
        style = mock(Style.class);
    }
    bindings.put(WCMBindings.CURRENT_STYLE, style);
    request.setResource(resource);
    request.setAttribute(SlingBindings.class.getName(), bindings);
    return request.adaptTo(Title.class);
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:20,代码来源:TitleImplTest.java

示例8: getListUnderTest

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
private List getListUnderTest(String resourcePath) {
    Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
    if (resource == null) {
        throw new IllegalStateException("Did you forget to defines test resource " + resourcePath + "?");
    }
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
    request.setResource(resource);
    request.setContextPath(CONTEXT_PATH);
    SlingBindings bindings = new SlingBindings();
    bindings.put(SlingBindings.RESOURCE, resource);
    bindings.put(SlingBindings.REQUEST, request);
    bindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
    Style style = mock(Style.class);
    when(style.get(any(), any(Object.class))).thenAnswer(
            invocation -> invocation.getArguments()[1]
    );
    bindings.put(WCMBindings.CURRENT_STYLE, style);
    bindings.put(WCMBindings.CURRENT_PAGE, CONTEXT.pageManager().getPage(CURRENT_PAGE));
    request.setAttribute(SlingBindings.class.getName(), bindings);
    return request.adaptTo(List.class);
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:22,代码来源:ListImplTest.java

示例9: init

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
@Override
public void init(Bindings bindings) {
    Resource resource = (Resource) bindings.get(SlingBindings.RESOURCE);

    Object location = bindings.get("location");
    if (location != null) {
        if (location instanceof Resource) {
            resource = (Resource) location;
        } else {
            if (location instanceof String) {
                resource = resource.getResourceResolver().getResource((String) location);
            }
        }
    }

    String name = (String) bindings.get("name");
    if (StringUtils.isBlank(name)) {
        log.info("Invalid property name");
        return;
    }

    values = MultiFieldPanelFunctions.getMultiFieldPanelValues(resource, name);
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:24,代码来源:MultiFieldPanelWCMUse.java

示例10: doEndTag

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public int doEndTag() throws JspException {
    final SlingHttpServletRequest request = TagUtil.getRequest(pageContext);
    final SlingBindings bindings = (SlingBindings) request.getAttribute(SlingBindings.class.getName());
    final DesignHtmlLibraryManager manager = bindings.getSling().getService(DesignHtmlLibraryManager.class);
    if (manager != null) {
        try {
            if (js && css) {
                manager.writeIncludes(request, getDesign(), region, pageContext.getOut());
            } else if (js) {
                manager.writeJsInclude(request, getDesign(), region, pageContext.getOut());
            } else if (css) {
                manager.writeCssInclude(request, getDesign(), region, pageContext.getOut());
            }
        } catch (IOException e) {
            throw new JspException("Unable to write client library includes", e);
        }
    }
    reset();
    return EVAL_PAGE;
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:25,代码来源:IncludeDesignLibrariesTag.java

示例11: currentResource

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
/**
 * get the current resource
 *
 * @param depth
 * @return
 */
public String currentResource(int depth) {
  SlingHttpServletRequest request = (SlingHttpServletRequest) context.getBindings(ScriptContext.ENGINE_SCOPE).get(SlingBindings.REQUEST);

  try {
    return JsonObjectCreator.create(request.getResource(), depth).toString();
  } catch (JSONException e) {
    throw new TechnicalException("could not get current resource", e);
  }
}
 
开发者ID:sinnerschrader,项目名称:aem-react,代码行数:16,代码来源:Sling.java

示例12: getTextUnderTest

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
private Text getTextUnderTest(String resourcePath) {
    Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
    request.setResource(resource);
    SlingBindings bindings = new SlingBindings();
    bindings.put(SlingBindings.RESOURCE, resource);
    bindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
    request.setAttribute(SlingBindings.class.getName(), bindings);
    return request.adaptTo(Text.class);
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:11,代码来源:TextImplTest.java

示例13: getButtonUnderTest

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
private Button getButtonUnderTest(String resourcePath) {
    Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
    request.setResource(resource);
    SlingBindings bindings = new SlingBindings();
    bindings.put(SlingBindings.RESOURCE, resource);
    request.setAttribute(SlingBindings.class.getName(), bindings);
    return request.adaptTo(Button.class);
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:10,代码来源:ButtonImplTest.java

示例14: prepareHiddenFieldForTest

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
private Field prepareHiddenFieldForTest(String resourcePath) {
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
    Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
    request.setResource(resource);
    Page currentPage = CONTEXT.pageManager().getPage(CONTAINING_PAGE);
    SlingBindings slingBindings = new SlingBindings();
    slingBindings.put(WCMBindings.CURRENT_PAGE, currentPage);
    slingBindings.put(SlingBindings.RESOURCE, resource);
    slingBindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
    request.setAttribute(SlingBindings.class.getName(), slingBindings);
    return request.adaptTo(Field.class);
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:13,代码来源:HiddenImplTest.java

示例15: getImageUnderTest

import org.apache.sling.api.scripting.SlingBindings; //导入依赖的package包/类
protected <T> T getImageUnderTest(String resourcePath, Class<T> imageClass) {
    Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
    if (resource == null) {
        throw new IllegalStateException("Does the test resource " + resourcePath + " exist?");
    }
    ContentPolicyMapping mapping = resource.adaptTo(ContentPolicyMapping.class);
    ContentPolicy contentPolicy = null;
    if (mapping != null) {
        contentPolicy = mapping.getPolicy();
    }
    SlingBindings slingBindings = new SlingBindings();
    Style style = null;
    if (contentPolicy != null) {
        when(contentPolicyManager.getPolicy(resource)).thenReturn(contentPolicy);
        style = new MockContentPolicyStyle(contentPolicy);
    }
    if (style == null) {
        style = mock(Style.class);
        when(style.get(anyString(), (Object) Matchers.anyObject())).thenAnswer(
                invocationOnMock -> invocationOnMock.getArguments()[1]
        );
    }
    slingBindings.put(SlingBindings.RESOURCE, resource);
    final MockSlingHttpServletRequest request =
            new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
    request.setContextPath(CONTEXT_PATH);
    request.setResource(resource);
    Page page = CONTEXT.pageManager().getPage(PAGE);
    slingBindings.put(WCMBindings.CURRENT_PAGE, page);
    slingBindings.put(WCMBindings.WCM_MODE, new SightlyWCMMode(request));
    slingBindings.put(WCMBindings.PAGE_MANAGER, CONTEXT.pageManager());
    slingBindings.put(WCMBindings.CURRENT_STYLE, style);
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    request.setAttribute(SlingBindings.class.getName(), slingBindings);
    return request.adaptTo(imageClass);
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:37,代码来源:ImageImplTest.java


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