View Javadoc

    1   /* Refinement
    2    *
    3    * $Id: Refinement.java 4663 2006-09-25 23:47:38Z paul_jack $
    4    *
    5    * Created on Apr 2, 2004
    6    *
    7    * Copyright (C) 2004 Internet Archive.
    8    *
    9    * This file is part of the Heritrix web crawler (crawler.archive.org).
    10   *
    11   * Heritrix is free software; you can redistribute it and/or modify
    12   * it under the terms of the GNU Lesser Public License as published by
    13   * the Free Software Foundation; either version 2.1 of the License, or
    14   * any later version.
    15   *
    16   * Heritrix is distributed in the hope that it will be useful,
    17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19   * GNU Lesser Public License for more details.
    20   *
    21   * You should have received a copy of the GNU Lesser Public License
    22   * along with Heritrix; if not, write to the Free Software
    23   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24   */
    25  package org.archive.crawler.settings.refinements;
    26
    27  import java.util.ArrayList;
    28  import java.util.Iterator;
    29  import java.util.List;
    30  import java.util.ListIterator;
    31
    32  import org.archive.crawler.settings.CrawlerSettings;
    33  import org.archive.net.UURI;
    34
    35
    36  /***
    37   * This class acts as a mapping between refinement criterias and a settings
    38   * object.
    39   *
    40   * @author John Erik Halse
    41   *
    42   */
    43  public class Refinement {
    44      private final CrawlerSettings owner;
    45      private String description;
    46      private String operator = "Admin";
    47      private String organization = "";
    48      private String audience = "";
    49      private String reference;
    50      private List<Criteria> criteria = new ArrayList<Criteria>();
    51
    52
    53      /***
    54       * Create a new instance of Refinement
    55       *
    56       * @param owner the settings object that owns the refinement.
    57       * @param reference a name that combined with the owner uniquely identifies
    58       *            the refinement.
    59       */
    60      public Refinement(CrawlerSettings owner, String reference) {
    61          this.owner = owner;
    62          this.reference = reference;
    63          owner.addRefinement(this);
    64      }
    65
    66      /*** Create a new instance of Refinement
    67       *
    68       * @param owner the settings object that owns the refinement.
    69       * @param reference a name that combined with the owner uniquely identifies
    70       *            the refinement.
    71       * @param descr A textual description of the refinement.
    72       */
    73      public Refinement(CrawlerSettings owner, String reference, String descr) {
    74          this(owner, reference);
    75          this.description = descr;
    76      }
    77
    78      /***
    79       * Check if a URI is within the bounds of every criteria set for this
    80       * refinement.
    81       *
    82       * @param uri the URI that shoulb be checked.
    83       * @return true if within bounds.
    84       */
    85      public boolean isWithinRefinementBounds(UURI uri) {
    86          if (uri == null || uri == null) {
    87              return false;
    88          }
    89          for (Iterator it = criteria.iterator(); it.hasNext();) {
    90              if (!((Criteria) it.next()).isWithinRefinementBounds(uri)) {
    91                  return false;
    92              }
    93          }
    94          return true;
    95      }
    96
    97      /***
    98       * Return the description of this refinement.
    99       *
    100      * @return Returns the description.
    101      */
    102     public String getDescription() {
    103         return description;
    104     }
    105
    106     /***
    107      * Set the description for this refinement.
    108      *
    109      * @param description The description to set.
    110      */
    111     public void setDescription(String description) {
    112         this.description = description;
    113     }
    114
    115     /***
    116      * Get an <code>ListIterator</code> over the criteria set for this
    117      * refinement.
    118      *
    119      * @return Returns an iterator over the criteria.
    120      */
    121     public ListIterator criteriaIterator() {
    122         return criteria.listIterator();
    123     }
    124
    125     /***
    126      * Add a new criterion to this refinement.
    127      *
    128      * @param criterion the criterion to add.
    129      */
    130     public void addCriteria(Criteria criterion) {
    131         if (!criteria.contains(criterion)) {
    132             criteria.add(criterion);
    133         }
    134     }
    135
    136     /***
    137      * Get the reference to this refinement's settings object.
    138      *
    139      * @return Returns the reference.
    140      */
    141     public String getReference() {
    142         return reference;
    143     }
    144
    145     /***
    146      * Set the reference to this refinement's settings object.
    147      *
    148      * @param reference The reference to set.
    149      */
    150     public void setReference(String reference) {
    151         this.reference = reference;
    152     }
    153
    154     /***
    155      * Get the <code>CrawlerSettings</code> object this refinement refers to.
    156      *
    157      * @return the settings object this refinement refers to.
    158      */
    159     public CrawlerSettings getSettings() {
    160         String parentScope = owner.getScope() == null ? "" : owner.getScope();
    161         CrawlerSettings settings = owner.getSettingsHandler()
    162                 .getOrCreateSettingsObject(parentScope, getReference());
    163         settings.setDescription((getDescription()));
    164         return settings;
    165     }
    166
    167     public boolean equals(Object o) {
    168         if (this == o
    169                 || (o instanceof Refinement && this.reference
    170                         .equals(((Refinement) o).reference))) {
    171             return true;
    172         }
    173         return false;
    174     }
    175
    176     /***
    177      * @return Returns the audience.
    178      */
    179     public String getAudience() {
    180         return this.audience;
    181     }
    182     /***
    183      * @param audience The audience to set.
    184      */
    185     public void setAudience(String audience) {
    186         this.audience = audience;
    187     }
    188     /***
    189      * @return Returns the operator.
    190      */
    191     public String getOperator() {
    192         return this.operator;
    193     }
    194     /***
    195      * @param operator The operator to set.
    196      */
    197     public void setOperator(String operator) {
    198         this.operator = operator;
    199     }
    200     /***
    201      * @return Returns the organziation.
    202      */
    203     public String getOrganization() {
    204         return this.organization;
    205     }
    206     /***
    207      * @param organization The organziation to set.
    208      */
    209     public void setOrganization(String organization) {
    210         this.organization = organization;
    211     }
    212 }