EditPropertiesActionFactory.java 3.93 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.wcm.api.WCMException
 *  com.day.cq.wcm.msm.api.LiveAction
 *  com.day.cq.wcm.msm.api.LiveRelationship
 *  com.day.cq.wcm.msm.commons.BaseAction
 *  com.day.cq.wcm.msm.commons.BaseActionFactory
 *  javax.jcr.Node
 *  javax.jcr.RepositoryException
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Modified
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ValueMap
 *  org.osgi.service.component.ComponentContext
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.wcm.msm.impl.actions;

import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveAction;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.commons.BaseAction;
import com.day.cq.wcm.msm.commons.BaseActionFactory;
import com.day.cq.wcm.msm.impl.Utils;
import com.day.cq.wcm.msm.impl.actions.PropertyEditor;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Modified;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=0)
@Service
public class EditPropertiesActionFactory
extends BaseActionFactory<BaseAction> {
    private static final String PROP_MAP = "editMap";
    @Deprecated
    @Property(name="cq.wcm.msm.action.rank")
    private static final int RANK = 10002;
    @Deprecated
    @Property(name="cq.wcm.msm.action.title")
    private static final String TITLE = "Edit properties";
    @Deprecated
    @Property(name="cq.wcm.msm.action.parameter")
    private static final String PARAMETER = "msm:actionEditProperties";
    @Deprecated
    @Property(name="actiontype")
    private static final String ACTION_TYPE = "contentupdate";
    @Deprecated
    @Property(name="cq.wcm.msm.action.properties")
    private static final String[] PROPS = new String[]{"editMap"};
    private static final Logger log = LoggerFactory.getLogger(EditPropertiesActionFactory.class);
    @Property(name="liveActionName")
    private static final String[] LIVE_ACTION_NAME = new String[]{EditPropertiesAction.class.getSimpleName(), "editProperties"};

    public String createsAction() {
        return LIVE_ACTION_NAME[0];
    }

    protected EditPropertiesAction newActionInstance(ValueMap config) {
        return new EditPropertiesAction(config, this);
    }

    @Activate
    @Modified
    protected void activate(ComponentContext context) {
    }

    private static final class EditPropertiesAction
    extends BaseAction {
        private final PropertyEditor editor;

        protected EditPropertiesAction(ValueMap config, BaseActionFactory<BaseAction> factory) {
            super(config, factory);
            this.editor = new PropertyEditor((String)this.getConfig().get("editMap", (Object)""));
        }

        protected boolean handles(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws RepositoryException, WCMException {
            return target != null && Utils.getWorkingNode((Node)target.adaptTo(Node.class)) != null;
        }

        protected void doExecute(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws RepositoryException, WCMException {
            Node slaveNode = Utils.getWorkingNode((Node)target.adaptTo(Node.class));
            log.debug("Created {} for node {}", (Object)this.editor, (Object)slaveNode.getPath());
            this.editor.editNode(slaveNode);
        }
    }

}