Checks if the given selector is present in the current URL request (at any position).
@param request Sling request
@param expectedSelector Selector string to check for.
@return true if the selector was found
162775
public static boolean hasSelector(@NotNull SlingHttpServletRequest request, @NotNull String expectedSelector) {
    String[] selectors = request.getRequestPathInfo().getSelectors();
    return ArrayUtils.contains(selectors, expectedSelector);
  }
1120973
public static boolean isJsonRequest(ServletRequest request) {

        HttpServletRequest sr = (HttpServletRequest)request;
        return (sr.getQueryString() != null) && (sr.getQueryString().contains("__json=true"));
    }
486098
public static boolean isSourceMapsEnabled(HttpServletRequest request) {
		IAggregator aggr = (IAggregator)request.getAttribute(IAggregator.AGGREGATOR_REQATTRNAME);
		IOptions options = aggr.getOptions();
		boolean result = false;
		if (options.isSourceMapsEnabled()) {
			result = TypeUtil.asBoolean(request.getAttribute(IHttpTransport.GENERATESOURCEMAPS_REQATTRNAME));
		}
		return result;
	}
135684
@Override
	public void serviceRequest(final Request request) {
		// Get the expected session token
		UIContext uic = UIContextHolder.getCurrent();
		String expected = uic.getEnvironment().getSessionToken();

		// Session token should already be set
		if (expected == null) {
			LOG.error("Session token should already be set on the session before AJAX request. Can be due to the session timing out.");
			handleError();
		}

		// Get the session token from the request
		String got = request.getParameter(Environment.SESSION_TOKEN_VARIABLE);

		// Check tokens match (both must be provided)
		if (Util.equals(expected, got)) {
			// Process Service Request
			getBackingComponent().serviceRequest(request);
		} else { // Invalid token
			LOG.error("Wrong session token detected for AJAX request. Expected token [" + expected
					+ "] but got token [" + got + "].");
			handleError();
		}
	}
1210493
private Set<String> getNewSelections(final Request request) {

		// Check for any selections on the request
		String[] paramValue = request.getParameterValues(getId());
		String[] selectedRowIds = removeEmptyStrings(paramValue);
		if (selectedRowIds == null || selectedRowIds.length == 0) {
			return Collections.EMPTY_SET;
		}

		Set<String> newSelectionIds = new HashSet<>();

		boolean singleSelect = getSelectMode() == SelectMode.SINGLE;

		int offset = getItemIdPrefix().length();
		for (String selectedRowId : selectedRowIds) {
			if (selectedRowId.length() <= offset) {
				LOG.warn("Selected row id [" + selectedRowId + "] does not have a valid prefix and will be ignored.");
				continue;
			}
			String itemId = selectedRowId.substring(offset);
			if (isValidTreeItem(itemId)) {
				newSelectionIds.add(itemId);
				if (singleSelect) {
					break;
				}
			} else {
				LOG.warn("Selected row id [" + itemId + "] is not valid and will be ignored.");
			}
		}

		return newSelectionIds;
	}
650035
function validateAndGetQuerySelector (selector) {
  try {
    var el = document.querySelector(selector);
    if (!el) {
      warn('No element was found matching the selector: "%s"', selector);
    }
    return el;
  } catch (e) {  // Capture exception if it's not a valid selector.
    warn('"%s" is not a valid selector', selector);
    return undefined;
  }
}
14452
public static boolean isExplodeRequires(HttpServletRequest request) {
		if (isIncludeRequireDeps(request)) {
			// don't expand require deps if we're including them in the response.
			return false;
		}
		boolean result = false;
		IAggregator aggr = (IAggregator)request.getAttribute(IAggregator.AGGREGATOR_REQATTRNAME);
		IOptions options = aggr.getOptions();
		IConfig config = aggr.getConfig();
		Boolean reqattr = TypeUtil.asBoolean(request.getAttribute(IHttpTransport.EXPANDREQUIRELISTS_REQATTRNAME));
		result = (options == null || !options.isDisableRequireListExpansion())
				&& (config == null || !isServerExpandedLayers(request))
				&& reqattr != null && reqattr;
		return result;
	}
992893
@Override
	protected void preparePaintComponent(final Request request) {
		super.preparePaintComponent(request);
		WComponent content = getContent();

		if (content != null) {
			switch (getMode()) {
				case EAGER: {
					// Will always be visible
					content.setVisible(true);
					AjaxHelper.registerContainer(getId(), getId() + "-content", content.getId());
					break;
				}
				case LAZY: {
					content.setVisible(isOpen());
					if (!isOpen()) {
						AjaxHelper.registerContainer(getId(), getId() + "-content", content.getId());
					}

					break;
				}
				case DYNAMIC: {
					content.setVisible(isOpen());
					AjaxHelper.registerContainer(getId(), getId() + "-content", content.getId());
					break;
				}
				case SERVER: {
					content.setVisible(isOpen());
					break;
				}
				case CLIENT: {
					// Will always be visible
					content.setVisible(true);
					break;
				}

				default:
					// do nothing.
					break;
			}
		}
	}
627695
public static boolean isHttpPostRequest(HttpServletRequest request) {
        boolean isSane = isSaneRequest(request);
        boolean isPost = isSane && request.getMethod().equals(HttpMethod.POST.toString());
        return isSane && isPost;
    }
823341
public static ElementSelector selectorForElementNamed(final String expectedName,
                                                          final ElementSelector es) {
        if (expectedName == null) {
            throw new IllegalArgumentException("expectedName must not be null");
        }

        return conditionalSelector(elementNamePredicate(expectedName), es);
    }
733825
private void findSelections(final Request request, final MenuSelectContainer selectContainer,
			final List<MenuItemSelectable> selections) {

		// Don't bother checking disabled or invisible containers
		if (!selectContainer.isVisible()
				|| (selectContainer instanceof Disableable && ((Disableable) selectContainer).isDisabled())) {
			return;
		}

		// Get any selectable children of this container
		List<MenuItemSelectable> selectableItems = getSelectableItems(selectContainer);

		// Now add the selections (if in the request)
		for (MenuItemSelectable selectableItem : selectableItems) {
			// Check if the item is on the request
			if (request.getParameter(selectableItem.getId() + ".selected") != null) {
				selections.add(selectableItem);
				if (SelectionMode.SINGLE.equals(selectContainer.getSelectionMode())) {
					// Only select the first item at this level.
					// We still need to check other levels of the menu for selection.
					break;
				}
			}
		}

		// We need to recurse through and check for other selectable containers
		for (MenuItem item : selectContainer.getMenuItems()) {
			if (item instanceof MenuItemGroup) {
				for (MenuItem groupItem : ((MenuItemGroup) item).getMenuItems()) {
					if (groupItem instanceof MenuSelectContainer) {
						findSelections(request, (MenuSelectContainer) groupItem, selections);
					}
				}
			} else if (item instanceof MenuSelectContainer) {
				findSelections(request, (MenuSelectContainer) item, selections);
			}
		}
	}
1322988
public boolean validateCrumb(ServletRequest request) {
        CrumbIssuerDescriptor<CrumbIssuer> desc = getDescriptor();
        String crumbField = desc.getCrumbRequestField();
        String crumbSalt = desc.getCrumbSalt();

        return validateCrumb(request, crumbSalt, request.getParameter(crumbField));
    }
377742
private boolean isIncluded(final HttpServletRequest request) {
		final String uri = (String) request.getAttribute("javax.servlet.include.request_uri");
		final boolean includeRequest = !(uri == null);

		if (includeRequest && log.isDebugEnabled()) {
			log.debug("{} resulted in an include request. This is unusable, because"
					+ "the response will be assembled into the overrall response. Not gzipping.",
					request.getRequestURL());
		}
		return includeRequest;
	}
151698
public static boolean isCachedContentRequest(final Request request) {

		// Get target id on request
		String targetId = request.getParameter(Environment.TARGET_ID);
		if (targetId == null) {
			return false;
		}

		// Get target
		ComponentWithContext targetWithContext = WebUtilities.getComponentById(targetId, true);
		if (targetWithContext == null) {
			return false;
		}

		// Check for caching key
		WComponent target = targetWithContext.getComponent();
		UIContextHolder.pushContext(targetWithContext.getContext());

		try {
			// TODO Look at implementing CacheableTarget interface
			String key = null;
			if (target instanceof WContent) {
				key = ((WContent) target).getCacheKey();
			} else if (target instanceof WImage) {
				key = ((WImage) target).getCacheKey();
			} else if (target instanceof WVideo) {
				key = ((WVideo) target).getCacheKey();
			} else if (target instanceof WAudio) {
				key = ((WAudio) target).getCacheKey();
			}
			return !Util.empty(key);
		} finally {
			UIContextHolder.popContext();
		}
	}
436764
private boolean checkAndRespond(Request request) {
        if (!URIBean.checkUri(request.getUrl())) {
            ServerResponseBean responseBean = new ServerResponseBean();
            responseBean.setMsgId(request.getMsgId());
            responseBean.setHttpContentType(HttpContentType.APPLICATION_JSON);
            responseBean.setResponseBody(UnitResponse.createError(Group.CODE_BAD_REQUEST, null, String.format("URI %s is illegal.", request.getUrl()))
                    .toVoJSONString());
            IServerResponder.singleton.response(responseBean);
            return false;
        }
        return true;
    }
824097
private void handleSelectionRequest(final Request request) {
		String[] paramValue = request.getParameterValues(getId() + ".selected");

		if (paramValue == null) {
			paramValue = new String[0];
		}

		Map<List<Integer>, Object> pageRowKeys = getCurrentRowIndexAndKeys();

		String[] selectedRows = removeEmptyStrings(paramValue);
		Set<?> oldSelections = getSelectedRows();
		Set<Object> newSelections;

		boolean singleSelect = getSelectMode() == SelectMode.SINGLE;

		if (getTableModel().getRowCount() == 0) {
			newSelections = new HashSet<>();
			selectedRows = new String[0];
		} else if (getPaginationMode() == PaginationMode.NONE || getPaginationMode() == PaginationMode.CLIENT
				|| oldSelections == null || !isPaginated()) {
			newSelections = new HashSet<>(selectedRows.length);
		} else if (singleSelect && selectedRows.length > 0) {
			// For single-select, we need to remove the old entries
			newSelections = new HashSet<>(1);
		} else {
			// For multi-select, we need the entries for the current page only
			newSelections = (Set<Object>) new HashSet<>(oldSelections);
			newSelections.removeAll(pageRowKeys.values());
		}

		for (String selectedRow : selectedRows) {
			List<Integer> rowIndex = TableUtil.rowIndexStringToList(selectedRow);
			Object key = pageRowKeys.get(rowIndex);
			if (key == null) {
				continue;
			}
			newSelections.add(key);
			if (singleSelect) {
				break;
			}
		}

		setSelectedRows(newSelections);

		// If there is a selection change action specified, it may need to be fired
		Action selectionChangeAction = getSelectionChangeAction();

		if (selectionChangeAction != null && !newSelections.equals(oldSelections)) {
			selectionChangeAction.execute(new ActionEvent(this, SELECTION_ACTION_COMMAND));
		}
	}
806857
public static boolean isDirectEditDisabled(ServletRequest request) {

        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(request.getParameter(CmsGwtConstants.PARAM_TEMPLATE_CONTEXT))) {
            return true;
        }
        String disabledParam = request.getParameter(CmsGwtConstants.PARAM_DISABLE_DIRECT_EDIT);
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(disabledParam)) {
            return Boolean.parseBoolean(disabledParam);
        } else {
            HttpSession session = ((HttpServletRequest)request).getSession(false);
            Boolean disabledAttr = null == session
            ? null
            : (Boolean)session.getAttribute(CmsGwtConstants.PARAM_DISABLE_DIRECT_EDIT);
            return (disabledAttr != null) && disabledAttr.booleanValue();
        }
    }