本文整理汇总了Java中com.adobe.granite.xss.XSSAPI类的典型用法代码示例。如果您正苦于以下问题:Java XSSAPI类的具体用法?Java XSSAPI怎么用?Java XSSAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XSSAPI类属于com.adobe.granite.xss包,在下文中一共展示了XSSAPI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
@Before
public void setUp() {
when(this.request.getResource()).thenReturn(this.resource);
when(this.request.getResourceResolver()).thenReturn(this.resourceResolver);
when(this.request.getAttribute(ComponentContext.CONTEXT_ATTR_NAME)).thenReturn(this.componentContext);
when(this.request.getAttribute(WCMMode.REQUEST_ATTRIBUTE_NAME)).thenReturn(WCMMode.PREVIEW);
when(this.request.adaptTo(XSSAPI.class)).thenReturn(this.xssApi);
when(this.resource.getResourceResolver()).thenReturn(this.resourceResolver);
when(this.resourceResolver.adaptTo(PageManager.class)).thenReturn(this.pageManager);
when(this.resourceResolver.adaptTo(Designer.class)).thenReturn(this.designer);
when(this.componentContext.getPage()).thenReturn(this.currentPage);
when(this.componentContext.getCell()).thenReturn(this.cell);
when(this.pageManager.getContainingPage(this.resource)).thenReturn(this.resourcePage);
when(this.designer.getDesign(any(Page.class))).thenReturn(this.design);
when(this.design.getStyle(this.cell)).thenReturn(this.style);
}
示例2: getRedirect
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
/**
* Set and return redirect given a path
*
* @param path
* @return xss scrubbed URL or null
*/
private String getRedirect(final String path) {
// immediately return previously acquired target or blank path
if (null != redirectPath || StringUtils.isBlank(path)) return redirectPath;
String target = null;
XSSAPI xssApi = getSlingScriptHelper().getService(XSSAPI.class);
// consider relative paths
if (StringUtils.startsWith(path, WCMConstants.DELIMITER_PATH)) {
Page page = WCMUtil.getPage(getRequest(), path);
if (null != page) {
if (!page.isValid()) {
// empty target for invalid page
return redirectPath;
}
// attempt to get URL of valid Page
target = WCMUtil.getPageURL(getRequest(), path);
} else if (null != getResourceResolver().resolve(path)) {
// may be a valid resource but not a page
target = path;
}
// path is not a valid, visible resource per request
}
// external location or possibly fully qualified URL
target = path;
redirectPath = xssApi.getValidHref(target);
return redirectPath;
}
示例3: doTag
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
@Override
public void doTag() throws JspException, IOException {
ResourceResolver resourceResolver = request.getResourceResolver();
XSSAPI xssAPI = resourceResolver.adaptTo(XSSAPI.class);
String q = xssAPI.encodeForHTML(this.q);
String appName= "", apikey = "", contextNumber = "";
if (currentPage != null) {
Page rootPage = currentPage.getAbsoluteParent(1);
ValueMap properties = rootPage.getProperties();
String[] cloudServices = properties.get("cq:cloudserviceconfigs", new String[0]);
for (String cloudService : cloudServices) {
if (cloudService.contains("/etc/cloudservices/googlecustomsearch")) {
Resource searchConfigResource = resourceResolver.getResource(cloudService);
Page searchConfigPage = (searchConfigResource != null) ? searchConfigResource.adaptTo(Page.class) : null;
if (searchConfigPage!= null) {
ValueMap searchConfigProperties = searchConfigPage.getContentResource().adaptTo(ValueMap.class);
appName = searchConfigProperties.get("appname", "");
apikey = searchConfigProperties.get("apikey", "");
contextNumber = searchConfigProperties.get("cx", "");
}
}
}
}
if (!"".equals(appName) && !"".equals(apikey) && !"".equals(contextNumber) &&
this.q.length() > 0 && this.currentTab.length() > 0 && this.numberOfResults > 0 && this.numberOfPages > 0) {
ResultList resultList = new GoogleSearchService(apikey, appName, contextNumber)
.getResults(q, currentTab, numberOfResults, numberOfPages);
LinkedList<ResultItem> resultItems = resultList.getResultItems();
getJspContext().setAttribute("resultList", resultList);
getJspContext().setAttribute("resultItems", resultItems);
}
}
示例4: getValue
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
@Override
public Object getValue(final Object adaptable, final String name, final Type type, final AnnotatedElement element,
final DisposalCallbackRegistry callbackRegistry) {
// only class types are supported
if (!(type instanceof Class<?>)) {
return null;
}
Class<?> requestedClass = (Class<?>)type;
if (adaptable instanceof SlingHttpServletRequest) {
SlingHttpServletRequest request = (SlingHttpServletRequest)adaptable;
if (requestedClass.equals(WCMMode.class)) {
return getWcmMode(request);
}
if (requestedClass.equals(ComponentContext.class)) {
return getComponentContext(request);
}
if (requestedClass.equals(Style.class)) {
return getStyle(request);
}
if (requestedClass.equals(XSSAPI.class)) {
return getXssApi(request);
}
}
if (requestedClass.equals(PageManager.class)) {
return getPageManager(adaptable);
}
else if (requestedClass.equals(Page.class)) {
if (StringUtils.equals(name, RESOURCE_PAGE)) {
return getResourcePage(adaptable);
}
else {
return getCurrentPage(adaptable);
}
}
else if (requestedClass.equals(Designer.class)) {
return getDesigner(adaptable);
}
else if (requestedClass.equals(Design.class)) {
return getCurrentDesign(adaptable);
}
return null;
}
示例5: getXssApi
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
private XSSAPI getXssApi(final SlingHttpServletRequest request) {
return request.adaptTo(XSSAPI.class);
}
示例6: testXssApi
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
@Test
public void testXssApi() {
Object result = this.injector.getValue(this.request, null, XSSAPI.class, this.annotatedElement, null);
assertSame(this.xssApi, result);
}
示例7: testXssApi
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
@Test
public void testXssApi() {
Object result = this.injector.getValue(this.resource, null, XSSAPI.class, this.annotatedElement, null);
assertNull(result);
}
示例8: testXssApi
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
@Test
public void testXssApi() {
Object result = this.injector.getValue(this.resourceResolver, null, XSSAPI.class, this.annotatedElement, null);
assertNull(result);
}
示例9: getXssApi
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
public XSSAPI getXssApi() {
return xssApi;
}
示例10: getXssAPI
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
@Override
public XSSAPI getXssAPI() {
return this.get(XSS_API, XSSAPI.class);
}
示例11: encodeForHTML
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
/**
* Encode a string for HTML.
*
* @param xssAPI the XSSAPI
* @param source the source string
* @return the encoded string
*/
@Function
public static CharSequence encodeForHTML(XSSAPI xssAPI, String source) {
return xssAPI.encodeForHTML(source);
}
示例12: encodeForHTMLAttr
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
/**
* Encode a string for an HTML attribute.
*
* @param xssAPI the XSSAPI
* @param source the source string
* @return the encoded string
*/
@Function
public static CharSequence encodeForHTMLAttr(XSSAPI xssAPI, String source) {
return xssAPI.encodeForHTMLAttr(source);
}
示例13: encodeForJSString
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
/**
* Encode a string for an JavaScript string.
*
* @param xssAPI the XSSAPI
* @param source the source string
* @return the encoded string
*/
@Function
public static CharSequence encodeForJSString(XSSAPI xssAPI, String source) {
return xssAPI.encodeForJSString(source);
}
示例14: filterHTML
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
/**
* Filter a string for HTML.
*
* @param xssAPI the XSSAPI
* @param source the source string
* @return the encoded string
*/
@Function
public static CharSequence filterHTML(XSSAPI xssAPI, String source) {
return xssAPI.filterHTML(source);
}
示例15: getValidHref
import com.adobe.granite.xss.XSSAPI; //导入依赖的package包/类
/**
* Get a valid href. This does not use the standard XSS API due to a bug
* impacting CQ 5.6.1 (and earlier). Internal bug reference: GRANITE-4193
*
* @param xssAPI the XSSAPI
* @param source the source string
* @return the encoded string
*/
@Function
public static CharSequence getValidHref(XSSAPI xssAPI, String source) {
return xssAPI.getValidHref(source);
}