001: /* Refinement
002: *
003: * $Id: Refinement.java 4663 2006-09-25 23:47:38Z paul_jack $
004: *
005: * Created on Apr 2, 2004
006: *
007: * Copyright (C) 2004 Internet Archive.
008: *
009: * This file is part of the Heritrix web crawler (crawler.archive.org).
010: *
011: * Heritrix is free software; you can redistribute it and/or modify
012: * it under the terms of the GNU Lesser Public License as published by
013: * the Free Software Foundation; either version 2.1 of the License, or
014: * any later version.
015: *
016: * Heritrix is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
019: * GNU Lesser Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser Public License
022: * along with Heritrix; if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: */
025: package org.archive.crawler.settings.refinements;
026:
027: import java.util.ArrayList;
028: import java.util.Iterator;
029: import java.util.List;
030: import java.util.ListIterator;
031:
032: import org.archive.crawler.settings.CrawlerSettings;
033: import org.archive.net.UURI;
034:
035: /**
036: * This class acts as a mapping between refinement criterias and a settings
037: * object.
038: *
039: * @author John Erik Halse
040: *
041: */
042: public class Refinement {
043: private final CrawlerSettings owner;
044: private String description;
045: private String operator = "Admin";
046: private String organization = "";
047: private String audience = "";
048: private String reference;
049: private List<Criteria> criteria = new ArrayList<Criteria>();
050:
051: /**
052: * Create a new instance of Refinement
053: *
054: * @param owner the settings object that owns the refinement.
055: * @param reference a name that combined with the owner uniquely identifies
056: * the refinement.
057: */
058: public Refinement(CrawlerSettings owner, String reference) {
059: this .owner = owner;
060: this .reference = reference;
061: owner.addRefinement(this );
062: }
063:
064: /** Create a new instance of Refinement
065: *
066: * @param owner the settings object that owns the refinement.
067: * @param reference a name that combined with the owner uniquely identifies
068: * the refinement.
069: * @param descr A textual description of the refinement.
070: */
071: public Refinement(CrawlerSettings owner, String reference,
072: String descr) {
073: this (owner, reference);
074: this .description = descr;
075: }
076:
077: /**
078: * Check if a URI is within the bounds of every criteria set for this
079: * refinement.
080: *
081: * @param uri the URI that shoulb be checked.
082: * @return true if within bounds.
083: */
084: public boolean isWithinRefinementBounds(UURI uri) {
085: if (uri == null || uri == null) {
086: return false;
087: }
088: for (Iterator it = criteria.iterator(); it.hasNext();) {
089: if (!((Criteria) it.next()).isWithinRefinementBounds(uri)) {
090: return false;
091: }
092: }
093: return true;
094: }
095:
096: /**
097: * Return the description of this refinement.
098: *
099: * @return Returns the description.
100: */
101: public String getDescription() {
102: return description;
103: }
104:
105: /**
106: * Set the description for this refinement.
107: *
108: * @param description The description to set.
109: */
110: public void setDescription(String description) {
111: this .description = description;
112: }
113:
114: /**
115: * Get an <code>ListIterator</code> over the criteria set for this
116: * refinement.
117: *
118: * @return Returns an iterator over the criteria.
119: */
120: public ListIterator criteriaIterator() {
121: return criteria.listIterator();
122: }
123:
124: /**
125: * Add a new criterion to this refinement.
126: *
127: * @param criterion the criterion to add.
128: */
129: public void addCriteria(Criteria criterion) {
130: if (!criteria.contains(criterion)) {
131: criteria.add(criterion);
132: }
133: }
134:
135: /**
136: * Get the reference to this refinement's settings object.
137: *
138: * @return Returns the reference.
139: */
140: public String getReference() {
141: return reference;
142: }
143:
144: /**
145: * Set the reference to this refinement's settings object.
146: *
147: * @param reference The reference to set.
148: */
149: public void setReference(String reference) {
150: this .reference = reference;
151: }
152:
153: /**
154: * Get the <code>CrawlerSettings</code> object this refinement refers to.
155: *
156: * @return the settings object this refinement refers to.
157: */
158: public CrawlerSettings getSettings() {
159: String parentScope = owner.getScope() == null ? "" : owner
160: .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: /**
184: * @param audience The audience to set.
185: */
186: public void setAudience(String audience) {
187: this .audience = audience;
188: }
189:
190: /**
191: * @return Returns the operator.
192: */
193: public String getOperator() {
194: return this .operator;
195: }
196:
197: /**
198: * @param operator The operator to set.
199: */
200: public void setOperator(String operator) {
201: this .operator = operator;
202: }
203:
204: /**
205: * @return Returns the organziation.
206: */
207: public String getOrganization() {
208: return this .organization;
209: }
210:
211: /**
212: * @param organization The organziation to set.
213: */
214: public void setOrganization(String organization) {
215: this.organization = organization;
216: }
217: }
|