本文整理汇总了Java中org.apache.sling.api.scripting.SlingScriptHelper类的典型用法代码示例。如果您正苦于以下问题:Java SlingScriptHelper类的具体用法?Java SlingScriptHelper怎么用?Java SlingScriptHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SlingScriptHelper类属于org.apache.sling.api.scripting包,在下文中一共展示了SlingScriptHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: activate
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
@Override
@SuppressWarnings("checkstyle:parametername")
public void activate() throws Exception {
SlingScriptHelper sling = getSlingScriptHelper();
User user = sling.getRequest().getResourceResolver().adaptTo(User.class);
ProcessDefinitionFactory[] allDefinitionFactories = sling.getServices(ProcessDefinitionFactory.class, null);
definitions = Stream.of(allDefinitionFactories)
.filter(o-> o.isAllowed(user))
.collect(Collectors.toMap(ProcessDefinitionFactory::getName, o -> o, (a,b)->a, TreeMap::new));
String processDefinitionName = get("processDefinition", String.class);
if (StringUtils.isEmpty(processDefinitionName)) {
processDefinitionName = getRequest().getParameter("processDefinition");
}
if (StringUtils.isNotEmpty(processDefinitionName) && definitions.containsKey(processDefinitionName)) {
Class clazz = definitions.get(processDefinitionName).createProcessDefinition().getClass();
fieldComponents = AnnotatedFieldDeserializer.getFormFields(clazz, sling);
}
}
示例2: getFormFields
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
public static Map<String, FieldComponent> getFormFields(Class source, SlingScriptHelper sling) {
return FieldUtils.getFieldsListWithAnnotation(source, FormField.class)
.stream()
.collect(Collectors.toMap(Field::getName, f -> {
FormField fieldDefinition = f.getAnnotation(FormField.class);
FieldComponent component;
try {
component = fieldDefinition.component().newInstance();
component.setup(f.getName(), f, fieldDefinition, sling);
return component;
} catch (InstantiationException | IllegalAccessException ex) {
log.error("Unable to instantiate field component for " + f.getName(), ex);
}
return null;
}, (a, b) -> a, LinkedHashMap::new));
}
示例3: createFrom
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
public static RenderContext createFrom(Bindings bindings, SlingScriptHelper slingScriptHelper) {
final ScriptContext scriptContext = new SimpleScriptContext();
scriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
final RenderContext renderContext = new RenderContextImpl(scriptContext, slingScriptHelper);
renderContext.getBindings().putAll(bindings);
return renderContext;
}
示例4: init
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
@Override
public void init(Bindings bindings) {
final PrintWriter out = (PrintWriter) bindings.get(OUT_BINDING);
final SlingHttpServletRequest request = (SlingHttpServletRequest) bindings.get(REQUEST_BINDING);
final String template = (String) bindings.get(PatternLabConstants.TEMPLATE_PROPERTY);
final String path = (String) bindings.get(PatternLabConstants.PATH_PROPERTY);
final String data = (String) bindings.get(PatternLabConstants.DATA_PROPERTY);
final SlingScriptHelper slingScriptHelper = (SlingScriptHelper) bindings.get(SLING_BINDING);
final Map<String, Object> patternData = retrievePatternData(request, data);
renderPattern(template, path, patternData, bindings, slingScriptHelper, out);
}
示例5: renderPattern
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
private void renderPattern(String template, String path, Map<String, Object> patternData, Bindings bindings, SlingScriptHelper slingScriptHelper,
PrintWriter out) {
final RenderContext renderContext = RenderContextImpl.createFrom(bindings, slingScriptHelper);
final PatternConfiguration patternConfiguration = PatternConfiguration.extractFromPatternData(patternData);
final RenderUnit renderUnit = StringUtils.isNotBlank(template) ?
new TemplateCallRenderUnit(path, template, patternData, patternConfiguration) :
new IncludePatternRenderUnit(path, patternConfiguration);
renderUnit.render(out, renderContext, bindings);
}
示例6: activate
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
/**
* Initialization of the component.
*
* Reads the resource, gets the properties and site key.
*
* Options for "theme" are:
* <ul>
* <li>dark
* <li>light (default)
* </ul>
*
* Options for "type" are:
* <ul>
* <li>audio
* <li>image (default)
* </ul>
*
* Options for "size" are:
* <ul>
* <li>compact
* <li>normal (default)
* </ul>
*/
@Override
public void activate() {
SlingScriptHelper scriptHelper = getSlingScriptHelper();
RecaptchaService recaptchaService = scriptHelper.getService(RecaptchaService.class);
if (recaptchaService == null) {
show = false;
} else {
resource = getResource();
ValueMap properties = resource.adaptTo(ValueMap.class);
String sizeProperty = properties.get(SIZE_PROPERTY, String.class);
String themeProperty = properties.get(THEME_PROPERTY, String.class);
String typeProperty = properties.get(TYPE_PROPERTY, String.class);
boolean enableProperty = properties.get(ENABLE_PROPERTY, true);
boolean enableService = recaptchaService.getEnabled();
siteKey = recaptchaService.getSiteKey();
if (enableService && enableProperty && StringUtils.isNotBlank(siteKey)) {
show = true;
if (THEME_DARK.equals(themeProperty)) {
theme = themeProperty;
}
if (TYPE_AUDIO.equals(typeProperty)) {
type = typeProperty;
}
if (SIZE_COMPACT.equals(sizeProperty)) {
size = sizeProperty;
}
} else {
show = false;
}
}
}
示例7: activate
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
/**
* Sightly component initialization.
*/
@Override
public void activate() {
resource = getResource();
request = getRequest();
resolver = getResourceResolver();
listView = Arrays.asList(request.getRequestPathInfo().getSelectors()).contains(LIST_VIEW_SELECTOR);
SlingScriptHelper scriptHelper = getSlingScriptHelper();
linkRewriter = scriptHelper.getService(LinkRewriterService.class);
getBlog(resource);
}
示例8: activate
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
@Override
public void activate() throws Exception {
try {
// get basic bindings and classes:
SlingBindings bindings = (SlingBindings) getRequest().getAttribute(SlingBindings.class.getName());
SlingScriptHelper sling = bindings.getSling();
ConfigurationAdmin configAdmin = sling.getService(ConfigurationAdmin.class);
// AEM Solr Search - Solr Configuration Service
Configuration config = configAdmin.getConfiguration(SOLR_CONFIG_PID);
Dictionary props = config.getProperties();
if (props != null) {
this.protocol = PropertiesUtil.toString(props.get(SOLR_CONFIG_PROTOCOL), "http");
this.host = PropertiesUtil.toString(props.get(SOLR_CONFIG_HOST), "localhost");
this.port = PropertiesUtil.toString(props.get(SOLR_CONFIG_PORT), "8080");
} else {
this.protocol = "http";
this.host = "localhost";
this.port = "8080";
}
// FIXME: this ideally shouldn't be hard coded
this.updatePath = "/apps/infield/solr/updatehandler";
} catch (Exception e) {
}
}
示例9: setup
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
public final void setup(String name, Field javaField, FormField field, SlingScriptHelper sling) {
this.name = name;
this.formField = field;
this.sling = sling;
this.javaField = javaField;
componentMetadata.put("name", name);
componentMetadata.put("fieldLabel", formField.name());
componentMetadata.put("fieldDescription", formField.description());
componentMetadata.put("required", formField.required());
componentMetadata.put("emptyText", formField.hint());
getOption("default").ifPresent(val->componentMetadata.put("value", val));
init();
}
示例10: syntheticResourceTest
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
@Test
public void syntheticResourceTest() throws DeserializeException {
SlingHttpServletRequest mockRequest = mock(SlingHttpServletRequest.class);
SlingScriptHelper mockScriptHelper = mock(SlingScriptHelper.class);
when(mockScriptHelper.getRequest()).thenReturn(mockRequest);
Map<String, FieldComponent> form = AnnotatedFieldDeserializer.getFormFields(getClass(), mockScriptHelper);
assertNotNull(form.get("textComponentTest"));
Resource fieldResource = form.get("textComponentTest").buildComponentResource();
assertEquals("granite/ui/components/coral/foundation/form/textfield", fieldResource.getResourceType());
assertEquals("granite/ui/components/coral/foundation/form/field", fieldResource.getResourceSuperType());
assertEquals("textComponentTest", fieldResource.getResourceMetadata().get("name"));
assertEquals("Text component", fieldResource.getResourceMetadata().get("fieldLabel"));
assertEquals(true, fieldResource.getResourceMetadata().get("required"));
}
示例11: setPageContext
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
@Override
public void setPageContext(PageContext pageContext) {
super.setPageContext(pageContext);
sling = (SlingScriptHelper) pageContext.findAttribute("sling");
currentNode = (Node) pageContext.findAttribute("currentNode");
webResourceScriptCache = sling.getService(WebResourceScriptCache.class);
}
示例12: RenderContextImpl
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
private RenderContextImpl(ScriptContext scriptContext, SlingScriptHelper helper) {
bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
extensionRegistryService = helper.getService(ExtensionRegistryService.class);
}
示例13: getSlingScriptHelper
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
@Override
public SlingScriptHelper getSlingScriptHelper() {
return slingScriptHelper();
}
示例14: getHelper
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
public SlingScriptHelper getHelper() {
return sling;
}
示例15: getSlingScriptHelper
import org.apache.sling.api.scripting.SlingScriptHelper; //导入依赖的package包/类
/**
* Get the Sling script helper instance used by the SlingMock layer.
*
* @return script helper instance; never null
*/
SlingScriptHelper getSlingScriptHelper();