001: //AbstractParser.java
002: //------------------------
003: //part of YaCy
004: //(C) by Michael Peter Christen; mc@anomic.de
005: //first published on http://www.anomic.de
006: //Frankfurt, Germany, 2007
007: //
008: //this file was contributed by Martin Thelian
009: //last major change: $LastChangedDate$ by $LastChangedBy$
010: //Revision: $LastChangedRevision$
011: //
012: //This program is free software; you can redistribute it and/or modify
013: //it under the terms of the GNU General Public License as published by
014: //the Free Software Foundation; either version 2 of the License, or
015: //(at your option) any later version.
016: //
017: //This program is distributed in the hope that it will be useful,
018: //but WITHOUT ANY WARRANTY; without even the implied warranty of
019: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: //GNU General Public License for more details.
021: //
022: //You should have received a copy of the GNU General Public License
023: //along with this program; if not, write to the Free Software
024: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
025: //
026: //Using this software in any meaning (reading, learning, copying, compiling,
027: //running) means that you agree that the Author(s) is (are) not responsible
028: //for cost, loss of data or any harm that may be caused directly or indirectly
029: //by usage of this softare or this documentation. The usage of this software
030: //is on your own risk. The installation and usage (starting/running) of this
031: //software may allow other people or application to access your computer and
032: //any attached devices and is highly dependent on the configuration of the
033: //software which must be done by the user of the software; the author(s) is
034: //(are) also not responsible for proper configuration and usage of the
035: //software, even if provoked by documentation provided together with
036: //the software.
037: //
038: //Any changes to this file according to the GPL as documented in the file
039: //gpl.txt aside this file in the shipment you received can be done to the
040: //lines that follows this copyright notice here, but changes must not be
041: //done inside the copyright notive above. A re-distribution must contain
042: //the intact and unchanged copyright notice.
043: //Contributions and changes to the program code must be marked as such.
044:
045: package de.anomic.plasma.dbImport;
046:
047: import java.util.HashMap;
048:
049: import de.anomic.data.SitemapParser;
050: import de.anomic.plasma.plasmaCrawlProfile;
051: import de.anomic.plasma.plasmaSwitchboard;
052: import de.anomic.yacy.yacyURL;
053:
054: public class SitemapImporter extends AbstractImporter implements
055: dbImporter {
056:
057: private SitemapParser parser = null;
058: private yacyURL sitemapURL = null;
059:
060: public SitemapImporter(plasmaSwitchboard switchboard) {
061: super ("sitemap", switchboard);
062: }
063:
064: public long getEstimatedTime() {
065: long t = getElapsedTime();
066: int p = getProcessingStatusPercent();
067: return (p == 0) ? 0 : (t / p) * (100 - p);
068: }
069:
070: /**
071: * @see dbImporter#getJobName()
072: */
073: public String getJobName() {
074: return this .sitemapURL.toString();
075: }
076:
077: /**
078: * @see dbImporter#getProcessingStatusPercent()
079: */
080: public int getProcessingStatusPercent() {
081: if (this .parser == null)
082: return 0;
083:
084: long total = this .parser.getTotalLength();
085: long processed = this .parser.getProcessedLength();
086:
087: if (total <= 1)
088: return 0;
089: return (int) ((processed * 100) / total);
090: }
091:
092: /**
093: * @see dbImporter#getStatus()
094: */
095: public String getStatus() {
096: StringBuffer theStatus = new StringBuffer();
097:
098: theStatus.append("#URLs=").append(
099: (this .parser == null) ? 0 : this .parser.getUrlcount());
100:
101: return theStatus.toString();
102: }
103:
104: /**
105: * @see dbImporter#init(HashMap)
106: * @see AbstractImporter#init(HashMap)
107: */
108: public void init(HashMap<String, String> initParams)
109: throws ImporterException {
110: super .init(initParams);
111:
112: if (initParams == null || initParams.size() == 0)
113: throw new IllegalArgumentException(
114: "Init parameters are missing");
115: if (!initParams.containsKey("crawlingProfile"))
116: throw new IllegalArgumentException(
117: "Init parameters 'crawlingProfile' is missing");
118: if (!initParams.containsKey("sitemapURL"))
119: throw new IllegalArgumentException(
120: "Init parameters 'sitemapURL' is missing");
121:
122: try {
123: // getting the sitemap URL
124: this .sitemapURL = new yacyURL((String) initParams
125: .get("sitemapURL"), null);
126:
127: // getting the crawling profile to use
128: plasmaCrawlProfile.entry profileEntry = this .sb.profilesActiveCrawls
129: .getEntry((String) initParams
130: .get("crawlingProfile"));
131:
132: // creating the sitemap parser
133: this .parser = new SitemapParser(this .sb, this .sitemapURL,
134: profileEntry);
135: } catch (Exception e) {
136: throw new ImporterException(
137: "Unable to initialize Importer", e);
138: }
139: }
140:
141: public void run() {
142: try {
143: this.parser.parse();
144: } finally {
145: this.globalEnd = System.currentTimeMillis();
146: this.sb.dbImportManager.finishedJobs.add(this);
147: }
148: }
149: }
|