我希望在满足x!=y
时取消激活某个页面。我试图用EventHandler
来做这件事。作者点击了activate Page
中的sidekick
,我的EventHandler
获得了一个复制事件并测试了x!=y
。如果满足,则必须取消激活页面。我的问题是如何取消页面激活?
@Component(immediate = true, label = "TEST")
@Service
@Property(name = "event.topics", value = { ReplicationAction.EVENT_TOPIC })
public class EventHandler implements EventHandler {
String feedback = "";
public void handleEvent(final Event event) {
String x = "foo";
String y = "baar";
if (x != y) {
canclePageActivation();
feedbackForAuthor = "Page can not be activated because x is not equal y";
}
}
}
答案 0 :(得分:3)
EventHandler
被调用。你需要的是com.day.cq.replication.Preprocessor
。如果在ReplicationException
方法中抛出preprocess()
,则复制将被取消,用户将收到异常消息:
@Component(metatype = false, immediate = true)
@Service
public class SamplePreprocessor implements Preprocessor {
@Override
public void preprocess(ReplicationAction action, ReplicationOptions options) throws ReplicationException {
if (somethingIsWrong()) {
throw new ReplicationException("this message will be displayed to the user");
}
}
}