PageSubscription.java 3.03 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.replication.ReplicationAction
 *  com.day.cq.replication.ReplicationActionType
 *  com.day.cq.wcm.api.PageEvent
 *  com.day.cq.wcm.api.PageModification
 *  com.day.cq.wcm.api.PageModification$ModificationType
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Properties
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.resource.PersistableValueMap
 *  org.osgi.service.event.Event
 */
package com.day.cq.wcm.notification.impl;

import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.wcm.api.PageEvent;
import com.day.cq.wcm.api.PageModification;
import com.day.cq.wcm.notification.AbstractSubscription;
import com.day.cq.wcm.notification.NotificationContext;
import com.day.cq.wcm.notification.Subscription;
import java.util.Iterator;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.PersistableValueMap;
import org.osgi.service.event.Event;

@Component(metatype=0)
@Service(value={Subscription.class})
@Properties(value={@Property(name="type", value={"page"}, propertyPrivate=1), @Property(name="event.filter", value={"(!(event.application=*))"})})
public class PageSubscription
extends AbstractSubscription {
    public static final String PAGE_TYPE = "page";

    @Override
    public boolean matches(NotificationContext context, Event event) {
        String action;
        String path;
        boolean result = false;
        if (event.getTopic().equals("com/day/cq/wcm/core/page")) {
            PageEvent pageEvent = PageEvent.fromEvent((Event)event);
            PageModification mod = (PageModification)pageEvent.getModifications().next();
            path = mod.getPath();
            action = mod.getType().toString();
        } else if (event.getTopic().equals("com/day/cq/replication")) {
            ReplicationAction repEvent = ReplicationAction.fromEvent((Event)event);
            path = repEvent.getPath();
            action = repEvent.getType().toString();
        } else {
            path = null;
            action = null;
        }
        if (path != null) {
            AbstractSubscription.Filter filter = new AbstractSubscription.Filter(context.getConfiguration());
            boolean found = false;
            int index = 0;
            while (!found && index < filter.actions.length) {
                if (filter.actions[index].toLowerCase().equals(action.toLowerCase())) {
                    found = true;
                    continue;
                }
                ++index;
            }
            if (found) {
                for (int i = 0; i < filter.list.length; ++i) {
                    result = filter.list[i].apply(path, result);
                }
            }
        }
        return result;
    }
}