001: /*
002: * Project: Lius
003: * Package: de.teamskill.lius.index.application
004: *
005: * Copyright (c) 2004 by Jens Fendler <jf@teamskill.de>
006: *
007: * This program is a free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License as
009: * published by the Free Software Foundation; either version 2 of
010: * the License, or (at your option) any later version.
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License for more details.
015: * You should have received a copy of the GNU General Public License
016: * along with this program; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package de.teamskill.lius.index.application;
021:
022: import java.io.IOException;
023: import java.util.ArrayList;
024: import java.util.Collection;
025: import java.util.Iterator;
026:
027: import org.apache.lucene.document.Document;
028:
029: import ca.ulaval.bibl.lius.config.LiusConfig;
030: import ca.ulaval.bibl.lius.config.LiusField;
031: import ca.ulaval.bibl.lius.index.Indexer;
032: import de.teamskill.util.parser.TexParser;
033:
034: /**
035: * Class: TexIndexer <br>
036: *
037: * Changelog:
038: * <ul>
039: * <li>01.06.2005: Initial implementation</li>
040: * </ul>
041: *
042: * @author <a href="mailto:jf@teamskill.de">Jens Fendler </a>
043: */
044: public class TexIndexer extends Indexer {
045:
046: /**
047: * @see ca.ulaval.bibl.lius.index.Indexer#createLuceneDocument(java.lang.String,
048: * ca.ulaval.bibl.lius.config.LiusConfig)
049: */
050: public Document createLuceneDocument(String file, LiusConfig lc) {
051: return createLuceneDocument(file, lc.getMP3Fields());
052: }
053:
054: /**
055: * @see ca.ulaval.bibl.lius.index.Indexer#getLiusFields(ca.ulaval.bibl.lius.config.LiusConfig)
056: */
057: public Collection getLiusFields(LiusConfig lc) {
058: return lc.getTexFields();
059: }
060:
061: /**
062: * @see ca.ulaval.bibl.lius.index.Indexer#getPopulatedCollection(java.lang.Object,
063: * java.util.Collection)
064: */
065: public Collection getPopulatedCollection(Object file,
066: Collection liusFields) {
067: Collection c = new ArrayList();
068: TexParser tp;
069: try {
070: tp = new TexParser((String) file);
071: for (Iterator i = liusFields.iterator(); i.hasNext();) {
072: Object next = i.next();
073: if (next instanceof LiusField) {
074: LiusField lf = (LiusField) next;
075: if ("documentclass".equalsIgnoreCase(lf.getGet())) {
076: lf.setValue("" + tp.getDocumentclass());
077: c.add(lf);
078: } else if ("title".equalsIgnoreCase(lf.getGet())) {
079: lf.setValue(tp.getTitle());
080: c.add(lf);
081: } else if ("author".equalsIgnoreCase(lf.getGet())) {
082: lf.setValue(tp.getAuthor());
083: c.add(lf);
084: } else if ("content".equalsIgnoreCase(lf.getGet())) {
085: lf.setValue(tp.getContent());
086: c.add(lf);
087: } else if ("abstract".equalsIgnoreCase(lf.getGet())) {
088: lf.setValue(tp.getAbstract());
089: c.add(lf);
090: }
091: } else
092: c.add(next);
093: }
094: } catch (IOException e) {
095: // I/O-Error from TexParser. Ignore for now and return empty
096: // collection.
097: }
098:
099: return c;
100: }
101:
102: /**
103: * @see ca.ulaval.bibl.lius.index.Indexer#getPopulatedCollection(java.lang.Object,
104: * java.lang.String)
105: */
106: public Collection getPopulatedCollection(Object file,
107: String liusConfig) {
108: return getPopulatedCollection(file, liusConfig);
109: }
110:
111: /**
112: * @see ca.ulaval.bibl.lius.index.Indexer#getPopulatedCollection(java.lang.Object,
113: * ca.ulaval.bibl.lius.config.LiusConfig)
114: */
115: public Collection getPopulatedCollection(Object file,
116: LiusConfig liusConfig) {
117: return getPopulatedCollection(file, liusConfig.getTexFields());
118: }
119:
120: }
|