Skip to content

Instantly share code, notes, and snippets.

@helms-charity
Last active May 11, 2016 12:50
Show Gist options
  • Save helms-charity/bff8d9383d9dcaff463a5e7e283a9a22 to your computer and use it in GitHub Desktop.
Save helms-charity/bff8d9383d9dcaff463a5e7e283a9a22 to your computer and use it in GitHub Desktop.
Internal Content Filter - cq 5.6
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.wmd.filter.impl;
import com.day.cq.replication.ReplicationContentFilter;
import com.day.cq.wcm.api.NameConstants;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Filters author information out of replicated data.
* @author Matthias Wermund, Acquity Group part of Accenture
*/
public class InternalContentFilter implements ReplicationContentFilter {
private static final Logger LOG = LoggerFactory.getLogger(InternalContentFilter.class);
private static final Set<String> FILTER_PROPERTIES = new HashSet<String>();
static {
FILTER_PROPERTIES.add(NameConstants.PN_CREATED_BY);
FILTER_PROPERTIES.add(NameConstants.PN_LAST_MOD_BY);
FILTER_PROPERTIES.add(NameConstants.PN_PAGE_LAST_MOD_BY);
}
public boolean accepts(Node node) {
return true;
}
public boolean accepts(Property prop) {
try {
String name = prop.getName();
return !FILTER_PROPERTIES.contains(name);
} catch (RepositoryException e) {
LOG.error("Error while analyzing property.", e);
return true;
}
}
public boolean allowsDescent(Node node) {
return true;
}
public List<String> getFilteredPaths() {
return null;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.wmd.filter.impl;
import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationContentFilter;
import com.day.cq.replication.ReplicationContentFilterFactory;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Factory for the custom content filter. Will only apply the filter for ACTIVATE
* replication question.
* @author Matthias Wermund, Acquity Group part of Accenture
*/
@Component
@Service
public class InternalContentFilterFactory implements ReplicationContentFilterFactory {
private static final Logger LOG = LoggerFactory.getLogger(InternalContentFilterFactory.class);
private InternalContentFilter internalFilter;
protected void activate(ComponentContext context) {
internalFilter = new InternalContentFilter();
}
public ReplicationContentFilter createFilter(ReplicationAction action) {
ReplicationContentFilter filter = null;
if (ReplicationActionType.ACTIVATE.equals(action.getType())) {
LOG.info("Agent {}", action.getConfig().getAgentId());
filter = internalFilter;
}
return filter;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment