本文整理汇总了Java中com.day.cq.wcm.api.Page.adaptTo方法的典型用法代码示例。如果您正苦于以下问题:Java Page.adaptTo方法的具体用法?Java Page.adaptTo怎么用?Java Page.adaptTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.day.cq.wcm.api.Page
的用法示例。
在下文中一共展示了Page.adaptTo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pageExistsAt
import com.day.cq.wcm.api.Page; //导入方法依赖的package包/类
public static Matcher<Page> pageExistsAt(String path) {
return new TypeSafeMatcher<Page>() {
@Override
protected boolean matchesSafely(Page actual) {
if (actual == null || actual.getContentResource() == null) {
return false;
}
Resource resource = actual.adaptTo(Resource.class);
ValueMap content = actual.getContentResource().adaptTo(ValueMap.class);
return resource != null
&& !resource.isResourceType(Resource.RESOURCE_TYPE_NON_EXISTING)
&& ResourceType.PAGE_CONTENT_TYPE.getName().equals(actual.getProperties().get(ResourceProperty.PRIMARY_TYPE))
&& StringUtils.isNotBlank(actual.getTemplate().getPath())
&& path.endsWith(content.get(ResourceProperty.TITLE).toString())
&& path.equals(resource.getPath());
}
@Override
public void describeTo(Description description) {
description.appendText(MessageFormat.format("Page with valid jcr:resourceType at {0} should exist.", path));
}
};
}
示例2: aPageWithParents
import com.day.cq.wcm.api.Page; //导入方法依赖的package包/类
@Override
public Resource aPageWithParents(String path, Object... properties) throws Exception {
Resource result = null;
Page page = client.getPageManager().getPage(path);
if (page != null) {
return page.adaptTo(Resource.class);
}
PathIterator it = new PathIterator(path);
it.first(); // root
while (it.hasNext()) {
String curPath = it.next();
if (Arrays.asList("/content", "/libs", "/apps").contains(curPath)) {
continue;
}
result = client.getResourceResolver().getResource(curPath);
if (result == null) {
if (it.hasNext()) {
result = client.getContentBuilder().page(curPath, PageType.DEFAULT_TEMPLATE.getTemplate().getName(), new HashMap<>()).adaptTo(Resource.class);
} else {
Properties pairs = new Properties(properties);
String template = toStringValue(pairs.remove(TEMPLATE));
if (StringUtils.isEmpty(template)) {
template = PageType.DEFAULT_TEMPLATE.getTemplate().getName();
}
if (client.getResourceResolver().getResource(template) == null) {
client.getContentBuilder().resource(template, Collections.singletonMap(PRIMARY_TYPE, ResourceType.TEMPLATE_TYPE));
}
result = client.getContentBuilder().page(curPath, template, pairs.toMap()).adaptTo(Resource.class);
}
}
}
if (result == null) {
throw new RuntimeException(MessageFormat.format("Cannot create result at '{0}'", result));
}
return result;
}
示例3: adaptToWithValueMapReturnsPagesProperties
import com.day.cq.wcm.api.Page; //导入方法依赖的package包/类
@Test
public void adaptToWithValueMapReturnsPagesProperties() throws Exception {
Page target = aPage("/content/ko");
ValueMap actual = target.adaptTo(ValueMap.class);
// jcr:created, jcr:createdBy are added
assertEquals(target.getProperties().size(), actual.size() + 2);
}
示例4: adaptToWithValueMapReturnsPagesProperties
import com.day.cq.wcm.api.Page; //导入方法依赖的package包/类
@Test
public void adaptToWithValueMapReturnsPagesProperties() throws Exception {
Page target = aPage("/content/ko");
ValueMap actual = target.adaptTo(ValueMap.class);
// cq:Template, jcr:title are removed
assertEquals(target.getProperties().size(), actual.size() + 2);
}
示例5: adaptToWithValueMapPreservePrimaryTypeProperty
import com.day.cq.wcm.api.Page; //导入方法依赖的package包/类
@Test
public void adaptToWithValueMapPreservePrimaryTypeProperty() throws Exception {
Page target = aPage("/content/ko");
ValueMap actual = target.adaptTo(ValueMap.class);
assertEquals(ResourceType.PAGE_TYPE, actual.get(ResourceProperty.PRIMARY_TYPE));
}
示例6: adaptToWithResourceReturnsPagesResource
import com.day.cq.wcm.api.Page; //导入方法依赖的package包/类
@Test
public void adaptToWithResourceReturnsPagesResource() throws Exception {
Page target = aPage("/content/test");
Resource actual = target.adaptTo(Resource.class);
assertEquals(client.getResourceResolver().getResource("/content/test").getPath(), actual.getPath());
}
示例7: findExperienceFragmentSocialVariation
import com.day.cq.wcm.api.Page; //导入方法依赖的package包/类
private ExperienceFragmentSocialVariation findExperienceFragmentSocialVariation() {
Page variantPage = currentPage.getPageManager().getPage(variantPath);
if (variantPage == null)
return null;
ExperienceFragmentSocialVariation socialVariant = variantPage.adaptTo(ExperienceFragmentSocialVariation.class);
return socialVariant;
}