use of com.day.cq.wcm.api.PageManager in project acs-aem-commons by Adobe-Consulting-Services.
the class DispatcherFlusherServlet method doPost.
@Override
@SuppressWarnings("squid:S3776")
protected final void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
final Resource resource = request.getResource();
final ResourceResolver resourceResolver = request.getResourceResolver();
final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
final Page currentPage = pageManager.getContainingPage(resource);
final ValueMap properties = resource.getValueMap();
/* Properties */
final String[] paths = properties.get("paths", new String[0]);
final ReplicationActionType replicationActionType = ReplicationActionType.valueOf(properties.get("replicationActionType", ReplicationActionType.ACTIVATE.name()));
final List<FlushResult> overallResults = new ArrayList<FlushResult>();
boolean caughtException = false;
ResourceResolver flushingResourceResolver = null;
try {
if (paths.length > 0) {
if (flushWithAdminResourceResolver) {
// Use the admin resource resolver for replication to ensure all
// replication permission checks are OK
// Make sure to close this resource resolver
flushingResourceResolver = resourceResolverFactory.getServiceResourceResolver(AUTH_INFO);
} else {
// Use the HTTP Request's resource resolver; don't close this resource resolver
flushingResourceResolver = resourceResolver;
}
final Map<Agent, ReplicationResult> results = dispatcherFlusher.flush(flushingResourceResolver, replicationActionType, true, paths);
for (final Map.Entry<Agent, ReplicationResult> entry : results.entrySet()) {
final Agent agent = entry.getKey();
final ReplicationResult result = entry.getValue();
overallResults.add(new FlushResult(agent, result));
}
}
} catch (ReplicationException e) {
log.error("Replication exception occurred during Dispatcher Flush request.", e);
caughtException = true;
} catch (LoginException e) {
log.error("Could not obtain an Admin Resource Resolver during Dispatcher Flush request.", e);
caughtException = true;
} finally {
if (flushWithAdminResourceResolver && flushingResourceResolver != null) {
// Close the admin resource resolver if opened by this servlet
flushingResourceResolver.close();
}
}
if (request.getRequestPathInfo().getExtension().equals("json")) {
response.setContentType("application/json");
JSONWriter writer = new JSONWriter(response.getWriter());
try {
writer.object();
for (final FlushResult result : overallResults) {
writer.key(result.agentId);
writer.value(result.success);
}
writer.endObject();
} catch (JSONException e) {
throw new ServletException("Unable to output JSON data", e);
}
} else {
String suffix;
if (caughtException) {
suffix = "replication-error";
} else {
suffix = StringUtils.join(overallResults, '/');
}
response.sendRedirect(request.getContextPath() + currentPage.getPath() + ".html/" + suffix);
}
}
use of com.day.cq.wcm.api.PageManager in project acs-aem-commons by Adobe-Consulting-Services.
the class PagesReferenceProvider method findReferences.
@Override
public List<Reference> findReferences(Resource resource) {
List<Reference> references = new ArrayList<Reference>();
ResourceResolver resolver = resource.getResourceResolver();
PageManager pageManager = resolver.adaptTo(PageManager.class);
Set<Page> pages = new HashSet<Page>();
search(resource, pages, pageManager);
for (Page page : pages) {
Resource contentResource = page.getContentResource();
if (contentResource != null && !contentResource.getPath().equals(resource.getPath())) {
references.add(getReference(page));
}
}
return references;
}
use of com.day.cq.wcm.api.PageManager in project acs-aem-commons by Adobe-Consulting-Services.
the class SiteMapServlet method doGet.
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setContentType(request.getResponseContentType());
if (StringUtils.isNotEmpty(this.characterEncoding)) {
response.setCharacterEncoding(characterEncoding);
}
ResourceResolver resourceResolver = request.getResourceResolver();
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
Page page = pageManager.getContainingPage(request.getResource());
XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
try {
XMLStreamWriter stream = outputFactory.createXMLStreamWriter(response.getWriter());
stream.writeStartDocument("1.0");
stream.writeStartElement("", "urlset", NS);
stream.writeNamespace("", NS);
// first do the current page
write(page, stream, resourceResolver);
for (Iterator<Page> children = page.listChildren(new PageFilter(false, true), true); children.hasNext(); ) {
write(children.next(), stream, resourceResolver);
}
if (damAssetTypes.size() > 0 && damAssetProperty.length() > 0) {
for (Resource assetFolder : getAssetFolders(page, resourceResolver)) {
writeAssets(stream, assetFolder, resourceResolver);
}
}
stream.writeEndElement();
stream.writeEndDocument();
} catch (XMLStreamException e) {
throw new IOException(e);
}
}
use of com.day.cq.wcm.api.PageManager in project acs-aem-commons by Adobe-Consulting-Services.
the class SystemNotificationsImpl method isActiveNotification.
private boolean isActiveNotification(final SlingHttpServletRequest request, final Resource resource) {
if (JcrConstants.JCR_CONTENT.equals(resource.getName()) || REP_POLICY.equals(resource.getName())) {
return false;
}
final PageManager pageManager = request.getResourceResolver().adaptTo(PageManager.class);
final Page notificationPage = pageManager.getContainingPage(resource);
if (notificationPage == null) {
log.warn("Trying to get a invalid System Notification page at [ {} ]", resource.getPath());
return false;
} else if (this.isDismissed(request, notificationPage)) {
// System Notification previously dismissed by the user
return false;
}
// Looks like a valid Notification Page; now check if the properties are valid
final ValueMap properties = notificationPage.getProperties();
final boolean enabled = properties.get(PN_ENABLED, false);
if (!enabled) {
// Disabled
return false;
} else {
final Calendar onTime = properties.get(PN_ON_TIME, Calendar.class);
final Calendar offTime = properties.get(PN_OFF_TIME, Calendar.class);
if (onTime == null && offTime == null) {
// No on time or off time is set, but is enabled so always show
return true;
}
final Calendar now = Calendar.getInstance();
if (onTime != null && now.before(onTime)) {
return false;
}
if (offTime != null && now.after(offTime)) {
return false;
}
return true;
}
}
use of com.day.cq.wcm.api.PageManager in project acs-aem-commons by Adobe-Consulting-Services.
the class WorkflowHelperImpl method getPageOrAssetResource.
/**
* @{inheritDoc}
*/
@Override
public final Resource getPageOrAssetResource(ResourceResolver resourceResolver, String path) {
Resource payloadResource = resourceResolver.getResource(path);
if (payloadResource == null) {
return null;
}
Asset asset = DamUtil.resolveToAsset(payloadResource);
if (asset != null) {
return asset.adaptTo(Resource.class);
}
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
Page page = pageManager.getContainingPage(payloadResource);
if (page != null) {
return page.adaptTo(Resource.class);
}
return null;
}
Aggregations