本文整理汇总了Java中com.day.cq.wcm.api.components.ComponentContext类的典型用法代码示例。如果您正苦于以下问题:Java ComponentContext类的具体用法?Java ComponentContext怎么用?Java ComponentContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ComponentContext类属于com.day.cq.wcm.api.components包,在下文中一共展示了ComponentContext类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setUp
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
@Before
public void setUp() {
when(this.request.getResource()).thenReturn(this.resource);
when(this.request.getResourceResolver()).thenReturn(this.resourceResolver);
when(this.request.getAttribute(ComponentContext.CONTEXT_ATTR_NAME)).thenReturn(this.componentContext);
when(this.request.getAttribute(WCMMode.REQUEST_ATTRIBUTE_NAME)).thenReturn(WCMMode.PREVIEW);
when(this.request.adaptTo(XSSAPI.class)).thenReturn(this.xssApi);
when(this.resource.getResourceResolver()).thenReturn(this.resourceResolver);
when(this.resourceResolver.adaptTo(PageManager.class)).thenReturn(this.pageManager);
when(this.resourceResolver.adaptTo(Designer.class)).thenReturn(this.designer);
when(this.componentContext.getPage()).thenReturn(this.currentPage);
when(this.componentContext.getCell()).thenReturn(this.cell);
when(this.pageManager.getContainingPage(this.resource)).thenReturn(this.resourcePage);
when(this.designer.getDesign(any(Page.class))).thenReturn(this.design);
when(this.design.getStyle(this.cell)).thenReturn(this.style);
}
开发者ID:wcm-io,项目名称:wcm-io-cq5,代码行数:17,代码来源:AemObjectInjectorRequestTest.java
示例2: process
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, final TemplateContentModelImpl contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
ComponentContext componentContext = WCMUtils.getComponentContext(request);
TemplateManager templateManager = request.getResourceResolver().adaptTo(TemplateManager.class);
if (templateManager != null) {
TemplatedContainer templatedContainer = new TemplatedContainer(templateManager, componentContext);
if (templatedContainer.hasStructureSupport()) {
List<Resource> structureResources = templatedContainer.getStructureResources();
Map<String, Object> structureResourcesMap = new HashMap<>();
for (Resource resource: structureResources) {
Map<String, String> resourceProperties = new HashMap<>();
resourceProperties.put("type", resource.getResourceType());
resourceProperties.put("path", resource.getPath());
structureResourcesMap.put(resource.getName(), resourceProperties);
}
contentModel.set(CONTENT + DOT + STRUCTURE_RESOURCES, structureResourcesMap);
}
}
} catch (Exception e) {
throw new ProcessException(e);
}
}
开发者ID:DantaFramework,项目名称:AEM,代码行数:31,代码来源:AddStructureResourcesContextProcessor.java
示例3: execute
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
@Override
public CharSequence execute(final Object valueObj)
throws Exception {
StringBuffer buffer = new StringBuffer();
TemplateContentModelImpl contentModel = contentModel();
SlingHttpServletRequest slingRequest = contentModel.request();
WCMMode wcmMode = WCMMode.fromRequest(slingRequest);
ClientLibraryUtil clientLibUtil = new ClientLibraryUtil(htmlLibraryManager, slingRequest);
clientLibUtil.setOptions(true, true, false, false, false, BLANK);
if (wcmMode != WCMMode.DISABLED) {
ComponentContext componentContext = WCMUtils.getComponentContext(slingRequest);
EditContext editContext = componentContext.getEditContext();
String dlgPath = null;
if (editContext != null && editContext.getComponent() != null) {
dlgPath = editContext.getComponent().getDialogPath();
}
if (AuthoringUIMode.fromRequest(slingRequest) == AuthoringUIMode.TOUCH) {
buffer.append(clientLibUtil.generateClientLibrariesPristine("cq.authoring.page"));
} else
if (AuthoringUIMode.fromRequest(slingRequest) == AuthoringUIMode.CLASSIC) {
buffer.append(clientLibUtil.generateClientLibrariesPristine("cq.wcm.edit"));
boolean isEditMode = (wcmMode == WCMMode.EDIT) ? true : false;
String dialogPath = dlgPath == null ? "" : dlgPath;
buffer.append(this.getJavaScript(slingRequest, isEditMode, dialogPath));
}
}
return new Handlebars.SafeString(buffer);
}
开发者ID:DantaFramework,项目名称:AEM,代码行数:34,代码来源:InitScriptHelperFunction.java
示例4: getCurrentPage
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
private Page getCurrentPage(final Object adaptable) {
if (adaptable instanceof SlingHttpServletRequest) {
ComponentContext context = getComponentContext((SlingHttpServletRequest)adaptable);
if (context != null) {
return context.getPage();
}
}
return getResourcePage(adaptable);
}
开发者ID:wcm-io,项目名称:wcm-io-cq5,代码行数:10,代码来源:AemObjectInjector.java
示例5: getStyle
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
private Style getStyle(final SlingHttpServletRequest request) {
Design currentDesign = getCurrentDesign(request);
ComponentContext componentContext = getComponentContext(request);
if (currentDesign != null && componentContext != null) {
return currentDesign.getStyle(componentContext.getCell());
}
return null;
}
开发者ID:wcm-io,项目名称:wcm-io-cq5,代码行数:9,代码来源:AemObjectInjector.java
示例6: getComponentContext
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
/**
* Get the current component context.
*
* @param adaptable a SlingHttpServletRequest
* @return the ComponentContext if the adaptable was a SlingHttpServletRequest, or null otherwise
*/
private ComponentContext getComponentContext(Object adaptable) {
if (adaptable instanceof SlingHttpServletRequest) {
SlingHttpServletRequest request = ((SlingHttpServletRequest) adaptable);
return WCMUtils.getComponentContext(request);
}
// ComponentContext is not reachable from Resource
return null;
}
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:17,代码来源:AemObjectInjector.java
示例7: getCurrentStyle
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
/**
* Get the current style.
*
* @param adaptable a SlingHttpServletRequest
* @return the current Style if the adaptable was a SlingHttpServletRequest, null otherwise
*/
private Style getCurrentStyle(Object adaptable) {
Design currentDesign = getCurrentDesign(adaptable);
ComponentContext componentContext = getComponentContext(adaptable);
if (currentDesign != null && componentContext != null) {
return currentDesign.getStyle(componentContext.getCell());
}
return null;
}
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:17,代码来源:AemObjectInjector.java
示例8: accepts
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
protected final boolean accepts(final SlingHttpServletRequest request, final SlingHttpServletResponse response) {
if (!StringUtils.endsWith(request.getRequestURI(), ".html")
|| !StringUtils.contains(response.getContentType(), "html")) {
// Do not inject around non-HTML requests
return false;
}
final ComponentContext componentContext = WCMUtils.getComponentContext(request);
if (componentContext == null // ComponentContext is null
|| componentContext.getComponent() == null // Component is null
|| componentContext.isRoot()) { // Suppress on root context
return false;
}
// Check to make sure the suppress key has not been added to the request
if (this.isComponentErrorHandlingSuppressed(request)) {
// Suppress key is detected, skip handling
return false;
}
// Check to make sure the SlingRequest's resource isn't in the suppress list
final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
for (final String suppressedResourceType : suppressedResourceTypes) {
if (slingRequest.getResource().isResourceType(suppressedResourceType)) {
return false;
}
}
return true;
}
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:33,代码来源:ComponentErrorHandlerImpl.java
示例9: TestModelAdapterFactory
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
public TestModelAdapterFactory() {
super();
org.osgi.service.component.ComponentContext componentCtx = mock(org.osgi.service.component.ComponentContext.class);
BundleContext bundleContext = mock(BundleContext.class);
when(componentCtx.getBundleContext()).thenReturn(bundleContext);
when(componentCtx.getProperties()).thenReturn(new Hashtable());
activate(componentCtx);
}
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:11,代码来源:AemObjectInjectorTest.java
示例10: getPageUnderTest
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
protected <T> T getPageUnderTest(Class<T> model, String pagePath, String designPath) {
Resource resource = CONTEXT.resourceResolver().getResource(pagePath + "/" + JcrConstants.JCR_CONTENT);
if (resource == null) {
throw new IllegalStateException("Did you forget to define test resource " + pagePath + "?");
}
com.day.cq.wcm.api.Page page = spy(CONTEXT.pageManager().getPage(pagePath));
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
SlingBindings slingBindings = new SlingBindings();
Design design = mock(Design.class);
if (designPath != null) {
when(design.getPath()).thenReturn(designPath);
} else {
when(design.getPath()).thenReturn(Designer.DEFAULT_DESIGN_PATH);
}
Resource templateResource = CONTEXT.resourceResolver().getResource("/conf/coretest/settings/wcm/templates/product-page");
Template template = mock(Template.class);
when(template.hasStructureSupport()).thenReturn(true);
when(template.adaptTo(Resource.class)).thenReturn(templateResource);
when(page.getTemplate()).thenReturn(template);
contentPolicyManager = mock(ContentPolicyManager.class);
ContentPolicyMapping mapping = templateResource.getChild(POLICIES_MAPPING_PATH).adaptTo(ContentPolicyMapping.class);
ContentPolicy contentPolicy = mapping.getPolicy();
Style style;
slingBindings.put(WCMBindings.CURRENT_DESIGN, design);
if (contentPolicy != null) {
Resource contentPolicyResource = CONTEXT.resourceResolver().getResource(contentPolicy.getPath());
style = new MockStyle(contentPolicyResource, contentPolicyResource.adaptTo(ValueMap.class));
when(contentPolicyManager.getPolicy(page.getContentResource())).thenReturn(contentPolicy);
} else {
style = mock(Style.class);
when(style.get(anyString(), Matchers.anyObject())).thenAnswer(
invocationOnMock -> invocationOnMock.getArguments()[1]
);
}
ComponentContext componentContext = mock(ComponentContext.class);
Set<String> cssClassNames = new LinkedHashSet<>(Arrays.asList("class1", "class2"));
when(componentContext.getCssClassNames()).thenReturn(cssClassNames);
slingBindings.put(WCMBindings.CURRENT_STYLE, style);
slingBindings.put(SlingBindings.RESOLVER, request.getResourceResolver());
slingBindings.put(WCMBindings.CURRENT_PAGE, page);
slingBindings.put(WCMBindings.PAGE_MANAGER, CONTEXT.pageManager());
slingBindings.put(SlingBindings.RESOURCE, resource);
slingBindings.put(WCMBindings.PAGE_PROPERTIES, page.getProperties());
slingBindings.put(WCMBindings.COMPONENT_CONTEXT, componentContext);
request.setContextPath(CONTEXT_PATH);
request.setResource(resource);
slingBindings.put(SlingBindings.REQUEST, request);
request.setAttribute(SlingBindings.class.getName(), slingBindings);
return request.adaptTo(model);
}
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:51,代码来源:PageImplTest.java
示例11: getValue
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
@Override
public Object getValue(final Object adaptable, final String name, final Type type, final AnnotatedElement element,
final DisposalCallbackRegistry callbackRegistry) {
// only class types are supported
if (!(type instanceof Class<?>)) {
return null;
}
Class<?> requestedClass = (Class<?>)type;
if (adaptable instanceof SlingHttpServletRequest) {
SlingHttpServletRequest request = (SlingHttpServletRequest)adaptable;
if (requestedClass.equals(WCMMode.class)) {
return getWcmMode(request);
}
if (requestedClass.equals(ComponentContext.class)) {
return getComponentContext(request);
}
if (requestedClass.equals(Style.class)) {
return getStyle(request);
}
if (requestedClass.equals(XSSAPI.class)) {
return getXssApi(request);
}
}
if (requestedClass.equals(PageManager.class)) {
return getPageManager(adaptable);
}
else if (requestedClass.equals(Page.class)) {
if (StringUtils.equals(name, RESOURCE_PAGE)) {
return getResourcePage(adaptable);
}
else {
return getCurrentPage(adaptable);
}
}
else if (requestedClass.equals(Designer.class)) {
return getDesigner(adaptable);
}
else if (requestedClass.equals(Design.class)) {
return getCurrentDesign(adaptable);
}
return null;
}
开发者ID:wcm-io,项目名称:wcm-io-cq5,代码行数:47,代码来源:AemObjectInjector.java
示例12: getComponentContext
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
private ComponentContext getComponentContext(final SlingHttpServletRequest request) {
return WCMUtils.getComponentContext(request);
}
开发者ID:wcm-io,项目名称:wcm-io-cq5,代码行数:4,代码来源:AemObjectInjector.java
示例13: testComponentContext
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
@Test
public void testComponentContext() {
Object result = this.injector.getValue(this.request, null, ComponentContext.class, this.annotatedElement, null);
assertSame(this.componentContext, result);
}
开发者ID:wcm-io,项目名称:wcm-io-cq5,代码行数:6,代码来源:AemObjectInjectorRequestTest.java
示例14: testComponentContext
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
@Test
public void testComponentContext() {
Object result = this.injector.getValue(this.resource, null, ComponentContext.class, this.annotatedElement, null);
assertNull(result);
}
开发者ID:wcm-io,项目名称:wcm-io-cq5,代码行数:6,代码来源:AemObjectInjectorResourceTest.java
示例15: testComponentContext
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
@Test
public void testComponentContext() {
Object result = this.injector.getValue(this.resourceResolver, null, ComponentContext.class, this.annotatedElement, null);
assertNull(result);
}
开发者ID:wcm-io,项目名称:wcm-io-cq5,代码行数:6,代码来源:AemObjectInjectorResourceResolverTest.java
示例16: getComponentContext
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
public ComponentContext getComponentContext() {
return componentContext;
}
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:4,代码来源:AemObjectInjectorTest.java
示例17: getComponentContext
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
public ComponentContext getComponentContext() {
return this.get(COMPONENT_CONTEXT, ComponentContext.class);
}
开发者ID:SixDimensions,项目名称:Component-Bindings-Provider,代码行数:4,代码来源:CQVariablesImpl.java
示例18: getCurrentPage
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
/**
* Get the current page.
*
* @param adaptable a SlingHttpServletRequest
* @return the current Page if the adaptable was a SlingHttpServletRequest, null otherwise
*/
private Page getCurrentPage(Object adaptable) {
ComponentContext context = getComponentContext(adaptable);
return (context != null) ? context.getPage() : null;
}
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:12,代码来源:AemObjectInjector.java
示例19: getComponentContext
import com.day.cq.wcm.api.components.ComponentContext; //导入依赖的package包/类
/**
* Gets the current component context.
*
* @return the current component context
*/
ComponentContext getComponentContext();
开发者ID:SixDimensions,项目名称:Component-Bindings-Provider,代码行数:7,代码来源:CQVariables.java
注:本文中的com.day.cq.wcm.api.components.ComponentContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论