确定Adobe CQ中的运行模式 [英] Determine runmode in Adobe CQ

查看:78
本文介绍了确定Adobe CQ中的运行模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式知道实例正在运行的运行模式?我创建了一个自定义标签,该标签根据实例运行模式提供配置,但是我无法确定当前的运行模式.
我找到了一种返回run-mods实例列表的方法:

How do I programmatically know which run-mode the instance is running? I created a custom tag that provides the config depending on the instance run-mode, but I can not determine the current run-mode.
I found a method that returns a list of run-mods instance:

SlingSettings settings = ...get from BundleContext...
Set<String> currentRunModes = settings.getRunModes();

但是我无法获得对象SlingSettings或BundleContext.如何获取这些对象,或者还有另一种获取当前运行模式的方法?

But I can not get the objects SlingSettings or BundleContext. How can I get these objects or perhaps there is another way to get the current run-mode?

推荐答案

SlingSetttings是正确的方法-如果来自Java,则最简单的获取方法是在SCR @Component类中使用SCR @Reference批注保存您不必通过BundleContext.

SlingSetttings is the right way - If it's from Java the simplest way to get it is with an SCR @Reference annotation in a class that's an SCR @Component, saves you from having to go through BundleContext.

如果来自Sling脚本,则可以使用sling.getService(....)来获取SlingSettings.

If it's from a Sling script, you can use sling.getService(....) to get the SlingSettings.

请注意,很少需要读取运行模式的情况,通常,您宁愿将OSGi配置设置为取决于运行模式,并让OSGi组件根据此模式修改其行为.

Note that the cases where you need to read the run modes are rare, usually you'd rather setup your OSGi configurations to depend on the run modes and have the OSGi components modify their behavior based on that.

这篇关于确定Adobe CQ中的运行模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆