/*-------------------------------------------------------------------------
Filtering:
-------------------------------------------------------------------------
972893
public function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false)
    {
        $field_id = $this->get('id');

        if (preg_match('/^mimetype:/', $data[0])) {
            $data[0] = str_replace('mimetype:', '', $data[0]);
            $column = 'mimetype';
        } elseif (preg_match('/^size:/', $data[0])) {
            $data[0] = str_replace('size:', '', $data[0]);
            $column = 'size';
        } else {
            $column = 'file';
        }

        if (self::isFilterRegex($data[0])) {
            $this->buildRegexSQL($data[0], array($column), $joins, $where);
        } elseif (self::isFilterSQL($data[0])) {
            $this->buildFilterSQL($data[0], array($column), $joins, $where);
        } elseif ($andOperation) {
            foreach ($data as $value) {
                $this->_key++;
                $value = $this->cleanValue($value);
                $joins .= "
                    LEFT JOIN
                        `tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key}
                        ON (e.id = t{$field_id}_{$this->_key}.entry_id)
                ";
                $where .= "
                    AND t{$field_id}_{$this->_key}.{$column} = '{$value}'
                ";
            }
        } else {
            if (!is_array($data)) {
                $data = array($data);
            }

            foreach ($data as &$value) {
                $value = $this->cleanValue($value);
            }

            $this->_key++;
            $data = implode("', '", $data);
            $joins .= "
                LEFT JOIN
                    `tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key}
                    ON (e.id = t{$field_id}_{$this->_key}.entry_id)
            ";
            $where .= "
                AND t{$field_id}_{$this->_key}.{$column} IN ('{$data}')
            ";
        }

        return true;
    }
329636
function(filter) {
        if (!filter) {
            return;
        }
        if (!this.filters[filter.userId]) {
            this.filters[filter.userId] = {};
        }
        this.filters[filter.userId][filter.filterId] = filter;
    }
822771
@Override
    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain) throws IOException,
            ServletException {
        // if a response has already been committed, bypass this filter...
        if (response.isCommitted()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Response has already been committed. Bypassing PEP.");
            }
            // continuing the chain once auth has failed causes errors. Short
            // circuiting the path here.
            // remove this if it causes problems
            // chain.doFilter(request, response);
            return;
        }

        // Need to make sure we are dealing with HttpServlets
        if (!(request instanceof HttpServletRequest)
                || !(response instanceof HttpServletResponse)) {
            logger.error("Servlets are not HttpServlets!");
            throw new ServletException("Servlets are not HttpServlets!");
        }

        ServletOutputStream out = null;
        ParameterRequestWrapper req = null;
        HttpServletResponse res = (HttpServletResponse)response;

        // the request and response context
        RequestCtx reqCtx = null;
        ResponseCtx resCtx = null;

        String uri = ((HttpServletRequest) request).getRequestURI();
        String servletPath = ((HttpServletRequest) request).getServletPath();
        if (logger.isDebugEnabled()) {
            logger.debug("Incoming URI: {}", uri);
            logger.debug("Incoming servletPath: {}", servletPath);
        }

        // Fix-up for direct web.xml servlet mappings for:
        // /objects/nextPID and /objects/nextPID.xml
        // (so servlet path will be different in these cases)
        // FIXME: we don't support .xml any more? but included as the servlet mapping is still specified
        if (uri.endsWith("/nextPID") || uri.endsWith("/nextPID.xml")) {
            servletPath = "/objects";
        }


        // get the filter (or null if no filter)
        RESTFilter filter = m_filters.get(servletPath);

        if (filter != null && logger.isDebugEnabled())
            logger.debug("obtaining filter: {}", filter.getClass().getName());

        if(ObjectsFilter.class.isInstance(filter)) { // go find the ObjectHandler
            HttpServletRequest httpRequest = (HttpServletRequest)request;
      	  filter = this.m_objectsRESTFilterMatcher.getObjectsHandler(httpRequest);
      	  if (filter == null) {
            logger.error("No FeSL REST objects handler found for \"{}\"", httpRequest.getPathInfo());
            throw new ServletException(new PEPException("No FeSL REST objects handler found for " + servletPath));
      	  }
        }
        try {
            // handle the request if we have a filter
            if (filter != null) {
                // substitute our own request object that manages parameters
                try {
                    req = new ParameterRequestWrapper((HttpServletRequest) request);
                } catch (Exception e) {
                    throw new PEPException(e);
                }

                logger.debug("Filtering URI: [{}] with: [{}]" , req.getRequestURI(), filter.getClass().getName());

                if(ResponseHandlingRESTFilter.class.isInstance(filter)) {
               	    // substitute our own response object that captures the data
               	    res = new DataResponseWrapper(((HttpServletResponse) response));
                    // get a handle for the original OutputStream
                    out = response.getOutputStream();
                    logger.debug("Filtering will include post-processing the response");
                }

                reqCtx = filter.handleRequest(req, res);
                if (reqCtx != null) {
                    resCtx = m_ctxHandler.evaluate(reqCtx);
                    enforce(resCtx);
                }

                // pass the request along to the next chain...
                chain.doFilter(req, res);
            } else {
                // there must always be a filter, even if it is a NOOP
                logger.error("No FeSL REST filter found for \"{}\"", servletPath);
                throw new PEPException("No FeSL REST filter found for " + servletPath);
            }

            if(ResponseHandlingRESTFilter.class.isInstance(filter)) {
            	// handle the response if we have a non-null response handling filter
            	reqCtx = ((ResponseHandlingRESTFilter)filter).handleResponse(req, res);
            	if (reqCtx != null) {
            		resCtx = m_ctxHandler.evaluate(reqCtx);
            		enforce(resCtx);
            	}

            	out.write(((DataResponseWrapper)res).getData());
            	out.flush();
            	out.close();
            }
        } catch (AuthzDeniedException ae) {
            if (!res.isCommitted()
                    && (req.getRemoteUser() == null || req
                            .getRemoteUser().trim().isEmpty())) {
                loginForm(res);
            } else {
                denyAccess((HttpServletResponse) response, ae.getMessage());
            }
        } catch (PEPException pe) {
            throw new ServletException("Error evaluating request", pe);
        }
    }
770339
function (orderBy) {

/*Line 195 - 'atom-filter.js' */            if (!AtomFilter.isString(orderBy)) {
/*Line 196 - 'atom-filter.js' */                return orderBy;
/*Line 197 - 'atom-filter.js' */            }

/*Line 199 - 'atom-filter.js' */            var fields = orderBy.split(',');
/*Line 200 - 'atom-filter.js' */            fields = fields.map(function (item) {
/*Line 201 - 'atom-filter.js' */                var tokens = item.split(' ');
/*Line 202 - 'atom-filter.js' */                var desc = tokens[1] || 'asc';
/*Line 203 - 'atom-filter.js' */                return {
/*Line 204 - 'atom-filter.js' */                    field: tokens[0],
/*Line 205 - 'atom-filter.js' */                    desc: /desc/i.test(desc),
/*Line 206 - 'atom-filter.js' */                    cs: /^cs/i.test(desc)
/*Line 207 - 'atom-filter.js' */                }
/*Line 208 - 'atom-filter.js' */            });

/*Line 210 - 'atom-filter.js' */            return function (a, b) {

/*Line 212 - 'atom-filter.js' */                if (a == null || a == undefined) {
/*Line 213 - 'atom-filter.js' */                    return b == null || b == undefined ? 0 : 1;
/*Line 214 - 'atom-filter.js' */                }
/*Line 215 - 'atom-filter.js' */                if (b == null || b == undefined) {
/*Line 216 - 'atom-filter.js' */                    return 1;
/*Line 217 - 'atom-filter.js' */                }

/*Line 219 - 'atom-filter.js' */                for (var i = 0; i < fields.length; i++) {
/*Line 220 - 'atom-filter.js' */                    var f = fields[i];
/*Line 221 - 'atom-filter.js' */                    var field = f.field;
/*Line 222 - 'atom-filter.js' */                    var af = a[field];
/*Line 223 - 'atom-filter.js' */                    var bf = b[field];
/*Line 224 - 'atom-filter.js' */                    if (f.desc) {
/*Line 225 - 'atom-filter.js' */                        var t = af;
/*Line 226 - 'atom-filter.js' */                        af = bf;
/*Line 227 - 'atom-filter.js' */                        bf = t;
/*Line 228 - 'atom-filter.js' */                    }
/*Line 229 - 'atom-filter.js' */                    if (af == bf)
/*Line 230 - 'atom-filter.js' */                        continue;
/*Line 231 - 'atom-filter.js' */                    if (!af) {
/*Line 232 - 'atom-filter.js' */                        return !bf ? 0 : -1;
/*Line 233 - 'atom-filter.js' */                    }
/*Line 234 - 'atom-filter.js' */                    if (!bf) {
/*Line 235 - 'atom-filter.js' */                        return !af ? 0 : 1;
/*Line 236 - 'atom-filter.js' */                    }
/*Line 237 - 'atom-filter.js' */                    if (AtomFilter.isString(af)) {
/*Line 238 - 'atom-filter.js' */                        if (f.cs) {
/*Line 239 - 'atom-filter.js' */                            return af.localeCompare(bf);
/*Line 240 - 'atom-filter.js' */                        } else {
/*Line 241 - 'atom-filter.js' */                            af = af.toLowerCase();
/*Line 242 - 'atom-filter.js' */                            bf = bf.toLowerCase();
/*Line 243 - 'atom-filter.js' */                            if (af == bf)
/*Line 244 - 'atom-filter.js' */                                continue;
/*Line 245 - 'atom-filter.js' */                            return af.localeCompare(bf);
/*Line 246 - 'atom-filter.js' */                        }
/*Line 247 - 'atom-filter.js' */                    }

/*Line 249 - 'atom-filter.js' */                }
/*Line 250 - 'atom-filter.js' */                return 0;
/*Line 251 - 'atom-filter.js' */            }
/*Line 252 - 'atom-filter.js' */        }
1196743
function () {
			this.writeDebug('formFiltersReset');
			if (this.settings.taxonomyFilters === null) {
				return;
			}

			var $inputs = $('.' + this.settings.taxonomyFiltersContainer + ' input'),
				$selects = $('.' + this.settings.taxonomyFiltersContainer + ' select');

			if ( typeof($inputs) !== 'object') {
				return;
			}

			// Loop over the input fields
			$inputs.each(function() {
				if ($(this).is('input[type="checkbox"]') || $(this).is('input[type="radio"]')) {
					$(this).prop('checked',false);
				}
			});

			// Loop over select fields
			$selects.each(function() {
				$(this).prop('selectedIndex',0);
			});
		}
553500
public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		int localPort = request.getLocalPort();
		if (mode == MODE_ALLOW && !portHit(localPort) ||
				mode == MODE_DENY && portHit(localPort)){
			if (message == null){
				((HttpServletResponse) response).sendError(statusCode, ((HttpServletRequest)request).getRequestURI());
			}else if (message.length() == 0){
				((HttpServletResponse) response).sendError(statusCode);
			}else{
				((HttpServletResponse) response).sendError(statusCode, message);
			}
		}else{
			chain.doFilter(request, response);
		}
	}
1109750
void filterTree(String filter) {

        HierarchicalContainer container = (HierarchicalContainer)m_tree.getContainerDataSource();
        container.removeAllContainerFilters();
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(filter)) {
            final String lowerCaseFilter = filter.toLowerCase();
            container.addContainerFilter(new Filter() {

                private static final long serialVersionUID = 1L;

                public boolean appliesToProperty(Object propertyId) {

                    return true;
                }

                public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException {

                    CmsCategory cat = (CmsCategory)itemId;

                    return cat.getPath().toLowerCase().contains(lowerCaseFilter)
                        || ((cat.getTitle() != null) && cat.getTitle().toLowerCase().contains(lowerCaseFilter));
                }
            });
        }
    }
526034
function Filter(name, init, update, reset) {
    this.name = name;
    this.update = update;
    this.reset = reset;
    this.sliders = [];
    this.curves = [];
    this.segmented = [];
    this.nubs = [];
    init.call(this);
}
365860
@Override
    public void filtrate(DataBinder parameters) {
        first.filtrate(parameters);
        second.filtrate(parameters);
    }
283289
@Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) res;
        response.setHeader("Access-Control-Allow-Origin", allowOrigin);
        response.setHeader("Access-Control-Allow-Methods", allowMethod);
        response.setHeader("Access-Control-Max-Age", maxAge);
        response.setHeader("Access-Control-Allow-Headers", allowHeaders);
        chain.doFilter(req, res);
    }
719202
@Override
    public void doFilter(EventRequest request, EventResponse response, FilterChain chain) throws IOException,
            PortletException {
        doCommonFilter(request, response, chain);
    }
747713
function setFilters (config) {
  const parts = config.filter.split(/[\s,]+/)
  config.filters = {
    should: {},
    ignore: {}
  }
  _.each(parts, addFilter.bind(null, config))
}
926835
def addFilter(self, filterclass):
        """"""
        if filterclass not in self.filters:
            self.filters.append(filterclass)
263674
@Override
  public void init(final FilterConfig filterConfig) throws ServletException {
    super.init(filterConfig);

    configUrl = filterConfig.getInitParameter("xslt");

    if ((configUrl != null) && debug()) {
      debug("Filter " + filterConfig.getFilterName() +
                                        " using xslt " + configUrl);
    }

    String temp = filterConfig.getInitParameter("ignoreContentType");

    ignoreContentType = "true".equals(temp);
  }
1067968
function runFilter(data, filter) {
  var k, key, keys = Object.keys(filter), keysLength = keys.length;
  var i;

  if (!Object.keys(filter).length) {
    return true;
  }

  keyCheck: for (k = 0; k < keysLength; k++) {
    key = keys[k];

    // Match
    if (key.startsWith('$')) {
      //if (key.startsWith(
      switch (key) {
        case '$or':
          for (i = 0; i < filter[key].length; i++) {
            if (runFilter(data, filter[key][i])) {
              continue keyCheck;
            }
          }
          return false;
        case '$and':
          for (i = 0; i < filter[key].length; i++) {
            if (!runFilter(data, filter[key][i])) {
              return false;
            }
          }
          break;
        case '$not':
          if(runFilter(data, filter[key])) {
            return false;
          }
          break;
      }
    } else if (typeof data === 'object') {
      if (typeof filter[key] === 'object') {
        if (Object.keys(filter[key]).find(function(operator) {
          switch (operator) {
            case '$eq':
              if (data[key] instanceof Array) {
                return data[key].indexOf(filter[key]['$eq']) === -1;
              } else {
                return !data[key] || data[key] !== filter[key]['$eq'];
              }
            case '$ne':
              if (data[key] instanceof Array) {
                return data[key].indexOf(filter[key]['$ne']) !== -1;
              } else {
                return data[key] === filter[key]['$ne'];
              }
            case '$gt':
              return !data[key] || data[key] <= filter[key]['$gt'];
            case '$gte':
              return !data[key] || data[key] < filter[key]['$gte'];
            case '$lt':
              return !data[key] || data[key] >= filter[key]['$lt'];
            case '$lte':
              return !data[key] || data[key] > filter[key]['$lte'];
            case '$in':
              if (!filter[key]['$in'] instanceof Array) {
                throw new Error('$in test values should be an array');
              }

              return filter[key]['$in'].indexOf(data[key]) === -1;
            case '$nin':
              if (!filter[key]['$nin'] instanceof Array) {
                throw new Error('$in test values should be an array');
              }

              return filter[key]['$nin'].indexOf(data[key]) !== -1;
            default:
              throw new Error('Unknown operator ' + operator);
          }
        })) {
          return false;
        }
      } else if (!((data[key] instanceof Array
          && data[key].indexOf(filter[key]) !== -1)
          || data[key] === filter[key])) {
        return false;
      }
    } else {
      return false;
    }
  }

  return true;
  // TODO Handle logical operators
}
1054733
public void postOrderFilterNodes(final NaryTreeNodeFilter filter) {
        postOrderTraversal(new FnO1ToVoid<IntNaryTree>() {
            @Override
            public void call(IntNaryTree node) {
                if (!node.isLeaf()) {
                    ArrayList<IntNaryTree> filtChildren = new ArrayList<IntNaryTree>();
                    for (IntNaryTree child : node.children) {
                        if (filter.accept(child)) {
                            filtChildren.add(child);
                        }
                    }
                    node.children = filtChildren;
                }
            }
        });
        updateStartEnd();
    }
617211
function (postPostRequestOptions, parentFilterCallback) {
            // The parentFilterNext is the filter next to the merged filter.
            // For 2 filters, that'd be the actual operation.
            parentFilterNext(postPostRequestOptions, function (responseObject, responseCallback, finalCallback) {
              parentFilterCallback(responseObject, finalCallback, function (postResponseObject) {
                newFilterCallback(postResponseObject, responseCallback, finalCallback);
              });
            });
          }