use of com.day.cq.wcm.api.components.Component in project acs-aem-commons by Adobe-Consulting-Services.
the class SharedComponentPropertiesBindingsValuesProviderTest method setUp.
@Before
public void setUp() throws Exception {
resource = mock(Resource.class);
pageRootProvider = mock(PageRootProvider.class);
page = mock(Page.class);
bindings = new SimpleBindings();
component = mock(Component.class);
sharedPropsResource = mock(Resource.class);
globalPropsResource = mock(Resource.class);
resourceResolver = mock(ResourceResolver.class);
componentManager = mock(ComponentManager.class);
String globalPropsPath = SITE_ROOT + "/jcr:content/" + SharedComponentProperties.NN_GLOBAL_COMPONENT_PROPERTIES;
String sharedPropsPath = SITE_ROOT + "/jcr:content/" + SharedComponentProperties.NN_SHARED_COMPONENT_PROPERTIES + "/" + RESOURCE_TYPE;
bindings.put("resource", resource);
when(resource.getResourceResolver()).thenReturn(resourceResolver);
when(resourceResolver.getResource(sharedPropsPath)).thenReturn(sharedPropsResource);
when(resourceResolver.getResource(globalPropsPath)).thenReturn(globalPropsResource);
when(resourceResolver.adaptTo(ComponentManager.class)).thenReturn(componentManager);
when(componentManager.getComponentOfResource(resource)).thenReturn(component);
when(page.getPath()).thenReturn(SITE_ROOT);
when(pageRootProvider.getRootPage(resource)).thenReturn(page);
when(component.getResourceType()).thenReturn(RESOURCE_TYPE);
when(sharedPropsResource.getName()).thenReturn("Shared Properties Resource");
when(globalPropsResource.getName()).thenReturn("Global Properties Resource");
sharedProps = new ValueMapDecorator(new HashMap<String, Object>());
globalProps = new ValueMapDecorator(new HashMap<String, Object>());
sharedProps.put("shared", "value");
globalProps.put("global", "value");
when(globalPropsResource.getValueMap()).thenReturn(globalProps);
when(sharedPropsResource.getValueMap()).thenReturn(sharedProps);
}
use of com.day.cq.wcm.api.components.Component in project acs-aem-commons by Adobe-Consulting-Services.
the class SharedComponentPropertiesBindingsValuesProvider method addBindings.
@Override
public void addBindings(Bindings bindings) {
Resource resource = (Resource) bindings.get("resource");
Component component = WCMUtils.getComponent(resource);
if (component != null) {
if (pageRootProvider != null) {
setSharedProperties(bindings, resource, component);
} else {
log.debug("Page Root Provider must be configured for shared component properties to be supported");
}
setMergedProperties(bindings, resource);
}
}
use of com.day.cq.wcm.api.components.Component in project acs-aem-commons by Adobe-Consulting-Services.
the class SharedComponentPropertiesPageInfoProvider method updateSharedComponentsMap.
/**
* Traverse the entire set of components in the /apps directory and create a map of all component types
* that have shared/global config dialogs.
*
* This is used by the JS libs in the authoring interface to determine if a component should show the
* options for editing shared/global configs.
*/
private void updateSharedComponentsMap() {
ResourceResolver resourceResolver = null;
try {
log.debug("Calculating map of components with shared properties dialogs");
Map<String, Object> authInfo = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, (Object) SERVICE_NAME);
resourceResolver = resourceResolverFactory.getServiceResourceResolver(authInfo);
resourceResolver.refresh();
ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class);
Map<String, List<Boolean>> localComponentsWithSharedProperties = new HashMap<>();
for (Component component : componentManager.getComponents()) {
if (component.getPath().startsWith("/apps")) {
boolean hasSharedDialogForTouch = componentHasTouchDialog(component, "dialogshared");
boolean hasGlobalDialogForTouch = componentHasTouchDialog(component, "dialogglobal");
boolean hasSharedDialogForClassic = componentHasClassicDialog(component, "dialog_shared");
boolean hasGlobalDialogForClassic = componentHasClassicDialog(component, "dialog_global");
if (hasSharedDialogForTouch || hasGlobalDialogForTouch || hasSharedDialogForClassic || hasGlobalDialogForClassic) {
localComponentsWithSharedProperties.put(component.getResourceType(), Arrays.asList(hasSharedDialogForTouch, hasGlobalDialogForTouch, hasSharedDialogForClassic, hasGlobalDialogForClassic));
}
}
}
componentsWithSharedProperties = Collections.unmodifiableMap(localComponentsWithSharedProperties);
log.debug("Calculated map of components with shared properties dialogs: {}", componentsWithSharedProperties);
} catch (org.apache.sling.api.resource.LoginException e) {
log.error("Unable to log into service user to determine list of components with shared properties dialogs", e);
} catch (RepositoryException e) {
log.error("Unexpected error attempting to determine list of components with shared properties dialogs", e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
}
use of com.day.cq.wcm.api.components.Component in project acs-aem-commons by Adobe-Consulting-Services.
the class WCMViewsFilter method getComponentViews.
/**
* Get the WCM Views for the component; Looks at both the content resource for the special wcmViews property
* and looks up to the resourceType's cq:Component properties for wcmViews.
*
* @param request the request
* @return the WCM Views for the component
*/
private List<String> getComponentViews(final SlingHttpServletRequest request) {
final Set<String> views = new HashSet<String>();
final Resource resource = request.getResource();
if (resource == null) {
return new ArrayList<String>(views);
}
final Component component = WCMUtils.getComponent(resource);
final ValueMap properties = resource.adaptTo(ValueMap.class);
if (component != null) {
views.addAll(Arrays.asList(component.getProperties().get(PN_WCM_VIEWS, new String[] {})));
}
if (properties != null) {
views.addAll(Arrays.asList(properties.get(PN_WCM_VIEWS, new String[] {})));
}
return new ArrayList<String>(views);
}
use of com.day.cq.wcm.api.components.Component in project acs-aem-commons by Adobe-Consulting-Services.
the class UrlFilter method findUrlFilterDefinitionComponent.
private Component findUrlFilterDefinitionComponent(Resource resource, ComponentManager componentManager) {
if (resource == null) {
return null;
}
Resource contentResource = resource.getChild("jcr:content");
if (contentResource != null) {
resource = contentResource;
}
Component component = componentManager.getComponentOfResource(resource);
return findUrlFilterDefinitionComponent(component);
}
Aggregations