001: /*
002: * Copyright 2003-2004 Michael Franken, Zilverline.
003: *
004: * The contents of this file, or the files included with this file, are subject to
005: * the current version of ZILVERLINE Collaborative Source License for the
006: * Zilverline Search Engine (the "License"); You may not use this file except in
007: * compliance with the License.
008: *
009: * You may obtain a copy of the License at
010: *
011: * http://www.zilverline.org.
012: *
013: * See the License for the rights, obligations and
014: * limitations governing use of the contents of the file.
015: *
016: * The Original and Upgraded Code is the Zilverline Search Engine. The developer of
017: * the Original and Upgraded Code is Michael Franken. Michael Franken owns the
018: * copyrights in the portions it created. All Rights Reserved.
019: *
020: */
021:
022: package org.zilverline.core;
023:
024: import java.io.File;
025:
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028:
029: import org.apache.lucene.index.IndexWriter;
030:
031: /**
032: * Command pattern for providing Indexing process with parameters. The command contains a document that needs to be indexed, as well
033: * as the state within the indexing process. The state includes path (real and within possible zip), and the collection.
034: *
035: * <p>
036: * If the document was in an archive, the archive's name is realName, the name of the document itself is zipName
037: * </p>
038: *
039: * <p>
040: * If the document was <b>not </b> in an archive, the name of the document itself is realName
041: * </p>
042: *
043: * @author Michael Franken
044: * @version $Revision: 1.22 $
045: *
046: */
047: public class IndexCommand {
048: /** logger for Commons logging. */
049: private static Log log = LogFactory.getLog(IndexCommand.class);
050:
051: /** The collection of the document. */
052: private FileSystemCollection collection;
053:
054: /** The file of the document. */
055: private File file;
056:
057: /** The MD5 hash of the document. */
058: private String hash;
059:
060: /** Indicates whether document was originally in an archive. */
061: private boolean inZip;
062:
063: /** The name of the document. */
064: private String realName;
065:
066: /** The path of the document. */
067: private String realPath;
068:
069: /** Indicates whether the indexing process has just started. */
070: private boolean start;
071:
072: /** The {@link IndexWriter}of the indexing process. */
073: private IndexWriter writer;
074:
075: /** The name of the document within the zip. */
076: private String zipName;
077:
078: /** The path of the document within the zip. */
079: private String zipPath;
080:
081: /**
082: * Default constructor initializes all attributes to empty values, or false.
083: */
084: public IndexCommand() {
085: realName = "";
086: realPath = "";
087: zipName = "";
088: zipPath = "";
089: hash = "";
090: inZip = false;
091: start = false;
092: }
093:
094: /**
095: * Copy constructor initializes all attributes.
096: *
097: * @param otherCommand an IndexCommand to copy values from
098: */
099: public IndexCommand(final IndexCommand otherCommand) {
100: writer = otherCommand.getWriter();
101: file = otherCommand.getFile();
102: realName = otherCommand.getRealName();
103: hash = otherCommand.getHash();
104: realPath = otherCommand.getRealPath();
105: zipName = otherCommand.getZipName();
106: zipPath = otherCommand.getZipPath();
107: collection = otherCommand.getCollection();
108: inZip = otherCommand.isInZip();
109: start = otherCommand.isStart();
110: }
111:
112: /**
113: * Get the collection this document belongs to.
114: *
115: * @return the collection
116: */
117: public final FileSystemCollection getCollection() {
118: return collection;
119: }
120:
121: /**
122: * Get the file.
123: *
124: * @return the file that is being indexed
125: */
126: public final File getFile() {
127: return file;
128: }
129:
130: /**
131: * Get the MD5 hash of the file being indexed.
132: *
133: * @return the MD5hash of the file.
134: */
135: public final String getHash() {
136: return hash;
137: }
138:
139: /**
140: * Get the realname, the name of this file.
141: *
142: * @return String
143: */
144: public final String getRealName() {
145: return realName;
146: }
147:
148: /**
149: * Get the realpath, the path within the indexing process of this file.
150: *
151: * @return String the real path
152: */
153: public final String getRealPath() {
154: return realPath;
155: }
156:
157: /**
158: * Get the IndexWriter for this porcess.
159: *
160: * @return IndexWriter the indexwriter
161: */
162: public final IndexWriter getWriter() {
163: return writer;
164: }
165:
166: /**
167: * Get the name of the document within the Archive.
168: *
169: * <p>
170: * The document was in a archive (with name realName).
171: * </p>
172: *
173: * @return the name of the document.
174: */
175: public final String getZipName() {
176: return zipName;
177: }
178:
179: /**
180: * Get the path of the document within the Archive.
181: *
182: * <p>
183: * The document was in a archive (with name realName).
184: * </p>
185: *
186: * @return the path of the document within the archive.
187: */
188: public final String getZipPath() {
189: return zipPath;
190: }
191:
192: /**
193: * Indicates whether the document came from an archive.
194: *
195: * @return true or false
196: */
197: public final boolean isInZip() {
198: return inZip;
199: }
200:
201: /**
202: * Indicates whether the indexing process just started.
203: *
204: * <p>
205: * This is used to make up the entire path of the document, where the first directory (the collection's basedir, and the
206: * archive's expanded directory) is not include in the entire location.
207: * </p>
208: *
209: * @return true or false
210: */
211: public final boolean isStart() {
212: return start;
213: }
214:
215: /**
216: * Set the collection this document belongs to.
217: *
218: * @param col The collection of the document.
219: */
220: public final void setCollection(final FileSystemCollection col) {
221: collection = col;
222: }
223:
224: /**
225: * Set this file for this document.
226: *
227: * @param thisFile The File
228: */
229: public final void setFile(final File this File) {
230: this .file = this File;
231: }
232:
233: /**
234: * Set the MD5 hash for this document.
235: *
236: * @param string the MD5 hash
237: */
238: public final void setHash(final String string) {
239: hash = string;
240: }
241:
242: /**
243: * Set whether this document came from an archive.
244: *
245: * @param b true or false
246: */
247: public final void setInZip(final boolean b) {
248: inZip = b;
249: }
250:
251: /**
252: * Set the real name of the document.
253: *
254: * <p>
255: * This is the name of the original file provided to the indexing process; either a non-archive, or the archive itself.
256: * </p>
257: *
258: * <p>
259: * The path and name make up the location of the document.
260: * </p>
261: *
262: * @param string The name of the document
263: */
264: public final void setRealName(final String string) {
265: realName = string;
266: }
267:
268: /**
269: * Set the real path of the document.
270: *
271: * <p>
272: * This is the path of the original file provided to the indexing process; either a non-archive, or the archive itself.
273: * </p>
274: *
275: * <p>
276: * The path and name make up the location of the document.
277: * </p>
278: *
279: * @param string The path of the document
280: */
281: public final void setRealPath(final String string) {
282: realPath = string;
283: }
284:
285: /**
286: * Sets whether the indexing process just started.
287: *
288: * <p>
289: * This is used to make up the entire path of the document, where the first directory (the collection's basedir, and the
290: * archive's expanded directory) is not include in the entire location.
291: * </p>
292: *
293: * @param b true or false
294: */
295: public final void setStart(final boolean b) {
296: start = b;
297: }
298:
299: /**
300: * Set the {@link IndexWriter}of the indexing process.
301: *
302: * @param thisWriter the IndexWriter
303: */
304: public final void setWriter(final IndexWriter this Writer) {
305: this .writer = this Writer;
306: }
307:
308: /**
309: * Set the name of the document within the archive.
310: *
311: * <p>
312: * This is the name of the file within the archive;
313: * </p>
314: *
315: * <p>
316: * The zipPath and zipName make up the location of the document within the archive.
317: * </p>
318: *
319: * @param string The name of the document within the archive
320: */
321: public final void setZipName(final String string) {
322: zipName = string;
323: }
324:
325: /**
326: * Set the path of the document within the archive.
327: *
328: * <p>
329: * This is the path of the file within the archive;
330: * </p>
331: *
332: * <p>
333: * The zipPath and zipName make up the location of the document within the archive.
334: * </p>
335: *
336: * @param string The path of the document within the archive
337: */
338: public final void setZipPath(final String string) {
339: zipPath = string;
340: }
341:
342: /**
343: * Prints IndexCommand as String for logging.
344: *
345: * @see java.lang.Object#toString()
346: */
347: public final String toString() {
348: return "File: " + file + " in collection '"
349: + collection.getName() + "' with hash: " + hash
350: + "\n\tPath: " + realPath + "<" + realName + ">"
351: + "\n\tzipPath: " + zipPath + "<" + zipName
352: + ">, inZip: " + inZip + ", start: " + start;
353: }
354: }
|