All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.aemds.guide.themes.ThemePostProcessor 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 com.adobe.aemds.guide.themes.model.BreakpointInfo;
import com.adobe.aemds.guide.themes.model.Theme;
import com.adobe.aemds.guide.utils.GuideStyleMigrationUtils;
import com.adobe.aemds.guide.utils.GuideThemeUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
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.ResourceResolver;
import org.apache.sling.resourcemerger.api.ResourceMergerService;
import org.apache.sling.servlets.post.Modification;
import org.apache.sling.servlets.post.SlingPostProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.jcr.Session;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * The ThemePostProcessor generates CSS for the updated Theme JSON.
 */

@Component(metatype = false)
@Service(SlingPostProcessor.class)
public class ThemePostProcessor implements SlingPostProcessor {

    /**
     * The logger
     */
    private Logger log = LoggerFactory.getLogger(ThemePostProcessor.class);

    @Reference
    private ResourceMergerService resourceMergerService;

    /**
     * @see SlingPostProcessor#process(org.apache.sling.api.SlingHttpServletRequest, java.util.List)
     */
    @Override
    public void process(SlingHttpServletRequest request, List changes)
            throws Exception {
        if (accepts(request)) {
            ResourceResolver resolver = request.getResourceResolver();
            Session session = resolver.adaptTo(Session.class);
            String themePath = request.getParameter("themePath");
            if (themePath != null) {
                Resource themeResource = resolver.resolve(themePath);
                Theme theme = themeResource.adaptTo(Theme.class);
                GuideThemeUtils themeUtils = new GuideThemeUtils();
                themeUtils.saveThemeCSS(theme, resolver, resourceMergerService);
            } else {
                String formPath = request.getParameter("formPath");
                Resource resource = request.getResource();
                GuideThemeUtils.saveInlineCSS(resource, formPath, resourceMergerService);
            }
        }
    }

    protected boolean accepts(SlingHttpServletRequest request) {
        return ("af:saveStyleOperation".equals(request.getParameter(":operation")) ||
                "af:copyStyleOperation".equals(request.getParameter(":operation")));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy