001: //Parser.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, 2005
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.parser;
046:
047: import java.io.File;
048: import java.io.InputStream;
049: import java.util.Hashtable;
050:
051: import de.anomic.plasma.plasmaParserDocument;
052: import de.anomic.server.logging.serverLog;
053: import de.anomic.yacy.yacyURL;
054:
055: /**
056: * This interface defines a list of methods that needs to be implemented
057: * by each content parser class.
058: * @author Martin Thelian
059: * @version $LastChangedRevision$ / $LastChangedDate$
060: */
061: public interface Parser {
062:
063: public static long MAX_KEEP_IN_MEMORY_SIZE = 5 * 1024 * 1024;
064:
065: /**
066: * Parsing a document available as byte array
067: * @param location the origin of the document
068: * @param mimeType the mimetype of the document
069: * @param charset the supposed charset of the document or <code>null</code> if unkown
070: * @param source the content byte array
071: * @return a {@link plasmaParserDocument} containing the extracted plain text of the document
072: * and some additional metadata.
073: *
074: * @throws ParserException if the content could not be parsed properly
075: */
076: public plasmaParserDocument parse(yacyURL location,
077: String mimeType, String charset, byte[] source)
078: throws ParserException, InterruptedException;
079:
080: /**
081: * Parsing a document stored in a {@link File}
082: * @param location the origin of the document
083: * @param mimeType the mimetype of the document
084: * @param charset the supposed charset of the document or <code>null</code> if unkown
085: * @param sourceFile the file containing the content of the document
086: * @return a {@link plasmaParserDocument} containing the extracted plain text of the document
087: * and some additional metadata.
088: *
089: * @throws ParserException if the content could not be parsed properly
090: */
091: public plasmaParserDocument parse(yacyURL location,
092: String mimeType, String charset, File sourceFile)
093: throws ParserException, InterruptedException;
094:
095: /**
096: * Parsing a document available as {@link InputStream}
097: * @param location the origin of the document
098: * @param mimeType the mimetype of the document
099: * @param charset the supposed charset of the document or <code>null</code> if unkown
100: * @param source the {@link InputStream} containing the document content
101: * @return a {@link plasmaParserDocument} containing the extracted plain text of the document
102: * and some additional metadata.
103: *
104: * @throws ParserException if the content could not be parsed properly
105: */
106: public plasmaParserDocument parse(yacyURL location,
107: String mimeType, String charset, InputStream source)
108: throws ParserException, InterruptedException;
109:
110: /**
111: * Can be used to determine the MimeType(s) that are supported by the parser
112: * @return a {@link Hashtable} containing a list of MimeTypes that are supported by
113: * the parser
114: */
115: public Hashtable<String, String> getSupportedMimeTypes();
116:
117: /**
118: * This function should be called before reusing the parser object.
119: */
120: public void reset();
121:
122: public void setContentLength(long length);
123:
124: /**
125: * @return Returns a list of library names that are needed by this parser
126: */
127: public String[] getLibxDependences();
128:
129: /**
130: * Can be used to set the logger that should be used by the parser module
131: * @param log the {@link serverLog logger} that should be used
132: */
133: public void setLogger(serverLog log);
134:
135: /**
136: * Returns the version number of the current parser
137: * @return parser version number
138: */
139: public String getVersion();
140:
141: /**
142: * Returns the name of the parser
143: * @return parser name
144: */
145: public String getName();
146: }
|