List of usage examples for org.apache.commons.collections CollectionUtils exists
public static boolean exists(Collection collection, Predicate predicate)
From source file:org.archive.modules.extractor.JerichoExtractorHTMLTest.java
/** * Test a POST FORM ACTION being found with non-default setting * /*w w w .j av a 2 s .c o m*/ * @throws URIException */ public void testFormsLinkFindPost() throws URIException { UURI uuri = UURIFactory.getInstance("http://www.example.org"); CrawlURI curi = new CrawlURI(uuri); CharSequence cs = "<form name=\"testform\" method=\"POST\" action=\"redirect_me?form=true\"> " + " <INPUT TYPE=CHECKBOX NAME=\"checked[]\" VALUE=\"1\" CHECKED> " + " <INPUT TYPE=CHECKBOX NAME=\"unchecked[]\" VALUE=\"1\"> " + " <select name=\"selectBox\">" + " <option value=\"selectedOption\" selected>option1</option>" + " <option value=\"nonselectedOption\">option2</option>" + " </select>" + " <input type=\"submit\" name=\"test\" value=\"Go\">" + "</form>"; getExtractor().setExtractOnlyFormGets(false); getExtractor().extract(curi, cs); curi.getOutLinks(); assertTrue(CollectionUtils.exists(curi.getOutLinks(), new Predicate() { public boolean evaluate(Object object) { return ((CrawlURI) object).getURI().indexOf( "/redirect_me?form=true&checked[]=1&unchecked[]=&selectBox=selectedOption&test=Go") >= 0; } })); }
From source file:org.archive.modules.net.CrawlServer.java
/** Update the robotstxt * * @param curi the crawl URI containing the fetched robots.txt * @throws IOException//w w w .j a va2 s. c om */ public synchronized void updateRobots(CrawlURI curi) { robotsFetched = System.currentTimeMillis(); boolean gotSomething = curi.getFetchType() == HTTP_GET && (curi.getFetchStatus() > 0 || curi.getFetchStatus() == S_DEEMED_NOT_FOUND); if (!gotSomething && curi.getFetchAttempts() < MIN_ROBOTS_RETRIES) { // robots.txt lookup failed, still trying, no reason to consider IGNORE yet validRobots = false; return; } // special deeming for a particular kind of connection-lost (empty server response) if (curi.getFetchStatus() == S_CONNECT_LOST && CollectionUtils.exists(curi.getNonFatalFailures(), PredicateUtils.instanceofPredicate(NoHttpResponseException.class))) { curi.setFetchStatus(S_DEEMED_NOT_FOUND); gotSomething = true; } if (!gotSomething) { // robots.txt fetch failed and exceptions (ignore/deeming) don't apply; no valid robots info yet validRobots = false; return; } int fetchStatus = curi.getFetchStatus(); if (fetchStatus < 200 || fetchStatus >= 300) { // Not found or anything but a status code in the 2xx range is // treated as giving access to all of a sites' content. // This is the prevailing practice of Google, since 4xx // responses on robots.txt are usually indicative of a // misconfiguration or blanket-block, not an intentional // indicator of partial blocking. // TODO: consider handling server errors, redirects differently robotstxt = Robotstxt.NO_ROBOTS; validRobots = true; return; } InputStream contentBodyStream = null; try { BufferedReader reader; contentBodyStream = curi.getRecorder().getContentReplayInputStream(); reader = new BufferedReader(new InputStreamReader(contentBodyStream)); robotstxt = new Robotstxt(reader); validRobots = true; } catch (IOException e) { robotstxt = Robotstxt.NO_ROBOTS; logger.log(Level.WARNING, "problem reading robots.txt for " + curi, e); validRobots = true; curi.getNonFatalFailures().add(e); } finally { IOUtils.closeQuietly(contentBodyStream); } }
From source file:org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria.java
public boolean hasSpecialFilterValue() { // We want values that ARE special return CollectionUtils.exists(filterValues, getPredicateForSpecialValues(true)); }
From source file:org.codehaus.groovy.grails.commons.DefaultGrailsControllerClass.java
protected boolean doCheckIsHttpMethodAllowedForAction(GroovyObject controller, final String httpMethod, String actionName) {//from w w w .jav a2 s.co m Object methodRestrictionsProperty = null; MetaProperty metaProp = controller.getMetaClass().getMetaProperty(ALLOWED_HTTP_METHODS_PROPERTY); if (metaProp != null) { methodRestrictionsProperty = metaProp.getProperty(controller); } if (!(methodRestrictionsProperty instanceof Map)) { return true; } Map map = (Map) methodRestrictionsProperty; Object value = map.get(actionName); if (value instanceof String) { return ((String) value).equalsIgnoreCase(httpMethod); } if (!(value instanceof List)) { return true; } return CollectionUtils.exists((List) value, new Predicate() { public boolean evaluate(Object method) { return httpMethod.equalsIgnoreCase(method.toString()); } }); }
From source file:org.codehaus.groovy.grails.compiler.injection.GrailsASTUtils.java
/** * @param classNode a ClassNode to search * @param annotationsToLookFor Annotations to look for * @return true if classNode is marked with any of the annotations in annotationsToLookFor *//* ww w . j av a 2 s.c om*/ public static boolean hasAnyAnnotations(final ClassNode classNode, final Class<? extends Annotation>... annotationsToLookFor) { return CollectionUtils.exists(Arrays.asList(annotationsToLookFor), new Predicate() { @SuppressWarnings({ "unchecked", "rawtypes" }) public boolean evaluate(Object object) { return hasAnnotation(classNode, (Class) object); } }); }
From source file:org.dasein.cloud.azurepack.tests.HttpMethodAsserts.java
private static void assertHttpMethod(final HttpUriRequest actualHttpRequest, String expectedHttpMethod, String expectedUrl, Header[] expectedHeaders) { assertHttpMethod(actualHttpRequest, expectedHttpMethod, expectedUrl); assertNotNull(actualHttpRequest.getAllHeaders()); CollectionUtils.forAllDo(Arrays.asList(expectedHeaders), new Closure() { @Override/*from w w w . ja v a 2 s .c o m*/ public void execute(Object input) { final Header expectedHeader = (Header) input; boolean headerExists = CollectionUtils.exists(Arrays.asList(actualHttpRequest.getAllHeaders()), new Predicate() { @Override public boolean evaluate(Object object) { Header actualHeader = (Header) object; return expectedHeader.getName().equals(actualHeader.getName()) && expectedHeader.getValue().equals(actualHeader.getValue()); } }); assertTrue(String.format( "Expected %s header not found in the request or found with the wrong value in the request", expectedHeader.getName()), headerExists); } }); }
From source file:org.geoserver.jdbcconfig.internal.ConfigDatabase.java
/** * @param info//from ww w . jav a 2 s .com * */ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public <T extends Info> T save(T info) { checkNotNull(info); final String id = info.getId(); checkNotNull(id, "Can't modify an object with no id"); final ModificationProxy modificationProxy = ModificationProxy.handler(info); Preconditions.checkNotNull(modificationProxy, "Not a modification proxy: ", info); final Info oldObject = (Info) modificationProxy.getProxyObject(); cache.invalidate(id); // get changed properties before h.commit()s final Iterable<Property> changedProperties = dbMappings.changedProperties(oldObject, info); // see HACK block bellow final boolean updateResouceLayersName = info instanceof ResourceInfo && modificationProxy.getPropertyNames().contains("name"); final boolean updateResourceLayersKeywords = CollectionUtils.exists(modificationProxy.getPropertyNames(), new Predicate() { @Override public boolean evaluate(Object input) { return ((String) input).contains("keyword"); } }); modificationProxy.commit(); Map<String, ?> params; // get the object's internal id final Integer objectId = findObjectId(info); final String blob; try { byte[] value = binding.objectToEntry(info); blob = new String(value, "UTF-8"); } catch (UnsupportedEncodingException e) { throw Throwables.propagate(e); } String updateStatement = "update object set blob = :blob where oid = :oid"; params = params("blob", blob, "oid", objectId); logStatement(updateStatement, params); template.update(updateStatement, params); updateQueryableProperties(oldObject, objectId, changedProperties); cache.invalidate(id); Class<T> clazz = ClassMappings.fromImpl(oldObject.getClass()).getInterface(); // / <HACK> // we're explicitly changing the resourceinfo's layer name property here because // LayerInfo.getName() is a derived property. This can be removed once LayerInfo.name become // a regular JavaBean property if (info instanceof ResourceInfo) { if (updateResouceLayersName) { updateResourceLayerName((ResourceInfo) info); } if (updateResourceLayersKeywords) { updateResourceLayerKeywords((ResourceInfo) info); } } // / </HACK> return getById(id, clazz); }
From source file:org.jboss.dashboard.dataset.AbstractDataSet.java
protected Double calculateScalar(Interval interval, DataProperty property, ScalarFunction function) { Collection values = interval.getValues(property); if (!CollectionUtils.exists(values, NON_NULL_ELEMENTS)) { return new Double(0); } else {// w w w . ja va 2 s. co m double value = function.scalar(values); // Check constraints every time an scalar calculation is carried out. ProfilerHelper.checkRuntimeConstraints(); return new Double(value); } }
From source file:org.jboss.dashboard.dataset.index.DistinctValue.java
protected Double calculateScalar(int column, String functionCode) { DataSet dataSet = columnIndex.getDataSetIndex().dataSet; List targetValues = new ArrayList(); List columnValues = dataSet.getValuesAt(column); for (Integer targetRow : rows) { targetValues.add(columnValues.get(targetRow)); }//from w w w . j ava 2 s . c o m ScalarFunctionManager scalarFunctionManager = DataProviderServices.lookup().getScalarFunctionManager(); ScalarFunction function = scalarFunctionManager.getScalarFunctionByCode(functionCode); if (!CollectionUtils.exists(targetValues, NON_NULL_ELEMENTS)) { return new Double(0); } else { double value = function.scalar(targetValues); return new Double(value); } }
From source file:org.mifos.customers.personnel.persistence.LegacyPersonnelDao.java
@SuppressWarnings("unchecked") public List<PersonnelBO> getActiveBranchManagersUnderOffice(Short officeId, final RoleBO role) throws PersistenceException { Map<String, Object> params = new HashMap<String, Object>(); params.put(CustomerSearchConstants.OFFICEID, officeId); params.put(CustomerSearchConstants.PERSONNELSTATUSID, PersonnelStatus.ACTIVE.getValue()); List activeBranchManagers = executeNamedQuery(NamedQueryConstants.GET_ACTIVE_BRANCH_MANAGER_UNDER_OFFICE, params);//w ww .jav a 2s . co m return (List<PersonnelBO>) CollectionUtils.select(activeBranchManagers, new Predicate() { @Override public boolean evaluate(Object object) { Set<PersonnelRoleEntity> applicableRoles = ((PersonnelBO) object).getPersonnelRoles(); return CollectionUtils.exists(applicableRoles, new Predicate() { @Override public boolean evaluate(Object object) { return ((PersonnelRoleEntity) object).getRole().equals(role); } }); } }); }