
com.adobe.aemds.guide.themes.CopyStylePostOperation Maven / Gradle / Ivy
/*
* **********************************************************************
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2016 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
* **********************************************************************
*/
package com.adobe.aemds.guide.themes;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import java.lang.Exception;
import java.util.List;
import java.util.ArrayList;
import org.apache.sling.servlets.post.Modification;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingException;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.servlets.post.PostOperation;
import org.apache.sling.servlets.post.PostResponse;
import org.apache.sling.servlets.post.SlingPostProcessor;
import org.apache.sling.api.resource.PersistenceException;
import com.adobe.aemds.guide.service.GuideException;
import java.util.Iterator;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.Session;
import javax.jcr.RepositoryException;
import javax.jcr.version.VersionException;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.AccessDeniedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adobe.aemds.guide.utils.GuideThemeUtils;
@Component(metatype = false)
@Service
@Property(name = PostOperation.PROP_OPERATION_NAME, value = "af:copyStyleOperation")
public class CopyStylePostOperation implements PostOperation {
private Logger log = LoggerFactory.getLogger(CopyStylePostOperation.class);
/**
* This needs to be written as simple copy post-operation does not create node if destination
* does not exits.
*/
public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) {
try {
Resource toResource = request.getResource();
ResourceResolver resourceResolver = request.getResourceResolver();
String fromResourcePath = request.getParameter("fromEditablePath");
Resource fromResource = resourceResolver.getResource(fromResourcePath);
String fromResourceStylePath = fromResourcePath + "/" + GuideThemeConstants.STYLE_NODE;
Resource fromResourceStyle = resourceResolver.getResource(fromResourceStylePath);
String cssClass = request.getParameter("cssClass");
if (toResource != null && fromResource != null) {
GuideThemeUtils.copyAssets(fromResource, toResource, resourceResolver);
GuideThemeUtils.copyStyles(fromResource, toResource, resourceResolver, cssClass);
}
if (fromResourceStyle!= null && processors != null) {
for (SlingPostProcessor processor : processors) {
final List changes = new ArrayList();
processor.process(request, changes);
}
}
} catch(Exception e) {
log.error("Error in copyStyleAsset postOperation", e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy