0

我想取消某些页面的激活,什么时候x!=y满足。我正在尝试使用EventHandler. 作者在 中单击activate PagesidekickEventHandler得到一个复制事件并测试是否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";
        }
    }

}
4

1 回答 1

3

EventHandler在复制页面调用。你在这里需要的是com.day.cq.replication.Preprocessor. 如果ReplicationExceptionpreprocess()方法中抛出 a,复制将被取消,用户将收到异常消息:

@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");
        }
    }
}
于 2013-10-29T15:20:20.483 回答