001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.ubt.report.data.file;
006:
007: import com.sun.portal.ubt.report.data.*;
008: import com.sun.portal.ubt.report.data.file.parser.BadDelimiterException;
009: import com.sun.portal.ubt.report.data.file.parser.CSVParser;
010: import com.sun.portal.ubt.report.data.file.parser.LabeledCSVParser;
011: import com.sun.portal.log.common.PortalLogger;
012:
013: import java.io.File;
014: import java.io.FileInputStream;
015: import java.lang.reflect.InvocationTargetException;
016: import java.util.Vector;
017: import java.util.logging.Logger;
018: import java.util.logging.Level;
019:
020: /**
021: *
022: */
023: public class FileDataMiner implements DataMiner {
024:
025: private static Logger logger = PortalLogger
026: .getLogger(FileDataMiner.class);
027:
028: File inputFile;
029: MinerCollection collection;
030: String portalID;
031:
032: public FileDataMiner(File inputFile) {
033: this .inputFile = inputFile;
034: }
035:
036: public FileDataMiner() {
037:
038: }
039:
040: public void setPortalID(String portalID) {
041: this .portalID = portalID;
042: }
043:
044: public void setData(Object data) {
045: }
046:
047: public String getPortalID() {
048: return this .portalID;
049: }
050:
051: public void setInputFile(File inputFile) {
052: this .inputFile = inputFile;
053: }
054:
055: public void setMinerCollection(MinerCollection collection) {
056: this .collection = collection;
057: }
058:
059: public void mine(UBTLogLine logLine) throws Exception,
060: IllegalAccessException, InvocationTargetException,
061: BadDelimiterException {
062: LabeledCSVParser lparser = new LabeledCSVParser(new CSVParser(
063: new FileInputStream(inputFile), '\t', "\r", "\r", "#"));
064: String[] line;
065: Vector miners = collection.getCollection();
066: for (int i = 0; i < miners.size(); i++) {
067: ((DataMiner) miners.get(i)).setPortalID(this .portalID);
068: }
069: while ((line = lparser.getLine()) != null) {
070: UBTLogFileLine uline;
071: try {
072: uline = new UBTLogFileLine(line);
073: if (uline.getUserID() == null
074: || (this .portalID != null && !this .portalID
075: .equals(uline.getPortalID())))
076: continue;
077: } catch (LabelsNoDataException e) {
078: continue;
079: }
080: for (int i = 0; i < miners.size(); i++) {
081: try {
082: ((DataMiner) miners.get(i)).mine(uline);
083: } catch (Exception e) {
084:
085: String minerClassName = miners.get(i).getClass()
086: .getName();
087: logger.log(Level.SEVERE, "PSUB_CSPU0024",
088: new Object[] { minerClassName, line });
089: logger.throwing("FileDataMiner", "mine", e);
090:
091: throw e;
092: }
093: }
094: }
095:
096: }
097:
098: public Object getData() {
099: return null;
100: }
101: }
|