如何以编程方式取消页面激活? [英] How to cancel page activation programmatically?
问题描述
当 x!= y
被满足时,我想取消某些页面的激活。我试图用 EventHandler
这样做。作者点击 sidekick
中的激活页面
,我的 EventHandler
获取复制事件,并测试 x!= y
。如果满足,则必须取消页面激活。我的问题是如何取消页面激活?
I would like to cancel the activation of some page, when x!=y
is met. I am trying to do this with EventHandler
. The author clicks on activate Page
in the sidekick
, and my EventHandler
gets a replication event and tests if x!=y
. If this is met, the page activation has to be canceled. My question is how do I cancel the page activation?
@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";
}
}
}
推荐答案
EventHandler
在页面复制后被调用。你在这里需要的是 com.day.cq.replication.Preprocessor
。如果在 preprocess()
方法中抛出一个 ReplicationException
,复制将被取消,用户将获得异常消息:
EventHandler
is invoked after page is replicated. What you need here is com.day.cq.replication.Preprocessor
. If you throw a ReplicationException
in the preprocess()
method, replication will be cancelled and user will get the exception message:
@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");
}
}
}
这篇关于如何以编程方式取消页面激活?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!