You are viewing a plain text version of this content. The canonical link for it is here.
Posted to droids-commits@incubator.apache.org by ol...@apache.org on 2010/08/08 12:07:30 UTC

svn commit: r983395 - in /incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net: AlreadyVisitedFilter.java HostFilter.java

Author: olegk
Date: Sun Aug  8 12:07:30 2010
New Revision: 983395

URL: http://svn.apache.org/viewvc?rev=983395&view=rev
Log:
Two additional link filters: hostname based and already visited links

Added:
    incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/AlreadyVisitedFilter.java   (with props)
    incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/HostFilter.java   (with props)

Added: incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/AlreadyVisitedFilter.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/AlreadyVisitedFilter.java?rev=983395&view=auto
==============================================================================
--- incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/AlreadyVisitedFilter.java (added)
+++ incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/AlreadyVisitedFilter.java Sun Aug  8 12:07:30 2010
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.droids.net;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.droids.api.URLFilter;
+import org.apache.http.client.utils.URIUtils;
+
+/**
+ * 
+ * @version 1.0
+ */
+public class AlreadyVisitedFilter implements URLFilter {
+
+  private Set<URI> visited;
+
+  public AlreadyVisitedFilter() {
+    super();
+    this.visited = new HashSet<URI>();
+  }
+  
+  public String filter(final String url) {
+    try {
+      URI uri = new URI(url);
+      URI key = URIUtils.createURI(
+          uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), null, null);
+      synchronized (this.visited)
+      {
+        if (!this.visited.contains(key)) {
+          this.visited.add(key);
+          return url;
+        } else {
+          return null;
+        }
+      }
+    } catch (URISyntaxException ex) {
+      return null;
+    }
+  }
+
+}

Propchange: incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/AlreadyVisitedFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/AlreadyVisitedFilter.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/AlreadyVisitedFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/HostFilter.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/HostFilter.java?rev=983395&view=auto
==============================================================================
--- incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/HostFilter.java (added)
+++ incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/HostFilter.java Sun Aug  8 12:07:30 2010
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.droids.net;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.droids.api.URLFilter;
+
+/**
+ * Simple hostname based implementation of {@link URLFilter).
+ * 
+ * @version 1.0
+ */
+public class HostFilter implements URLFilter {
+
+  private Set<String> allowedHosts;
+
+  public HostFilter(final Set<String> allowedHosts) {
+    super();
+    this.allowedHosts = new HashSet<String>();
+    if (allowedHosts != null) {
+      this.allowedHosts.addAll(allowedHosts);
+    }
+  }
+  
+  public HostFilter(final String allowedHost) {
+    super();
+    this.allowedHosts = new HashSet<String>();
+    if (allowedHost != null) {
+      this.allowedHosts.add(allowedHost);
+    }
+  }
+  
+  public String filter(final String url) {
+    try {
+      URI uri = new URI(url);
+      if (this.allowedHosts.contains(uri.getHost())) {
+        return url;
+      } else {
+        return null;
+      }
+    } catch (URISyntaxException ex) {
+      return null;
+    }
+  }
+
+}

Propchange: incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/HostFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/HostFilter.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/net/HostFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain