Changeset 732


Ignore:
Timestamp:
05/03/11 18:59:05 (8 years ago)
Author:
philsmart
Message:
 
Location:
raptor-parse/trunk
Files:
5 added
6 edited

Legend:

Unmodified
Added
Removed
  • raptor-parse/trunk/.classpath

    r716 r732  
    66        <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/> 
    77        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> 
    8         <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> 
     8        <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"> 
     9                <attributes> 
     10                        <attribute name="org.eclipse.jst.component.nondependency" value=""/> 
     11                </attributes> 
     12        </classpathentry> 
     13        <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> 
    914        <classpathentry kind="output" path="target/classes"/> 
    1015</classpath> 
  • raptor-parse/trunk/.project

    r716 r732  
    66        </projects> 
    77        <buildSpec> 
     8                <buildCommand> 
     9                        <name>org.eclipse.wst.common.project.facet.core.builder</name> 
     10                        <arguments> 
     11                        </arguments> 
     12                </buildCommand> 
    813                <buildCommand> 
    914                        <name>org.eclipse.jdt.core.javabuilder</name> 
     
    1621                        </arguments> 
    1722                </buildCommand> 
     23                <buildCommand> 
     24                        <name>org.eclipse.wst.validation.validationbuilder</name> 
     25                        <arguments> 
     26                        </arguments> 
     27                </buildCommand> 
    1828        </buildSpec> 
    1929        <natures> 
     30                <nature>org.eclipse.jem.workbench.JavaEMFNature</nature> 
     31                <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> 
    2032                <nature>org.eclipse.jdt.core.javanature</nature> 
    2133                <nature>org.maven.ide.eclipse.maven2Nature</nature> 
     34                <nature>org.eclipse.wst.common.project.facet.core.nature</nature> 
    2235        </natures> 
    2336</projectDescription> 
  • raptor-parse/trunk/.settings/org.eclipse.jdt.core.prefs

    r717 r732  
    1 #Mon May 02 20:28:51 BST 2011 
     1#Tue May 03 10:53:11 BST 2011 
    22eclipse.preferences.version=1 
    33org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 
  • raptor-parse/trunk/src/main/java/uk/ac/cardiff/raptor/parse/BaseEventParser.java

    r717 r732  
    1919package uk.ac.cardiff.raptor.parse; 
    2020 
     21import java.io.BufferedInputStream; 
    2122import java.util.List; 
    2223import java.util.Set; 
     
    5253    private InclusionList inclusionList; 
    5354 
     55    /** The fully qualified name of the event type class */ 
     56    protected String eventType; 
     57 
     58    /** A human readable name of the types of events this parser handles*/ 
     59    private String eventTypeFriendlyName; 
     60 
    5461    /** 
    5562     * Default constructor 
     
    5966 
    6067    /** 
    61      * The method that must be provided to parse events from a particular datasource 
     68     * The method that must be provided to parse events from the <code>bytes</code> parameter 
     69     * 
     70     * @throws ParserException 
     71     */ 
     72    public abstract void parse(byte[] bytes) throws ParserException; 
     73 
     74    /** 
     75     * The method that must be provided to parse events from the internally configured 
     76     * log file location e.g. <code>logfile</code> 
    6277     * 
    6378     * @throws ParserException 
     
    164179    } 
    165180 
     181    /** 
     182     * @param eventType 
     183     *            the eventType to set 
     184     */ 
     185    public void setEventType(String eventType) { 
     186            this.eventType = eventType; 
     187    } 
     188 
     189    /** 
     190     * @return the eventType 
     191     */ 
     192    public String getEventType() { 
     193            return eventType; 
     194    } 
     195 
     196    /** 
     197     * @param eventTypeFriendlyName the eventTypeFriendlyName to set 
     198     */ 
     199    public void setEventTypeFriendlyName(String eventTypeFriendlyName) { 
     200        this.eventTypeFriendlyName = eventTypeFriendlyName; 
     201    } 
     202 
     203    /** 
     204     * @return the eventTypeFriendlyName 
     205     */ 
     206    public String getEventTypeFriendlyName() { 
     207        return eventTypeFriendlyName; 
     208    } 
     209 
    166210 
    167211 
  • raptor-parse/trunk/src/main/java/uk/ac/cardiff/raptor/parse/DataAccessRegister.java

    r717 r732  
    2727 
    2828 
     29import uk.ac.cardiff.model.event.ShibbolethIdpAuthenticationEvent; 
    2930import uk.ac.cardiff.raptor.parse.BaseEventParser; 
    3031 
     
    5657        public void setParsingModules(List<BaseEventParser> parsingModules) { 
    5758                for (BaseEventParser parser : parsingModules) 
    58                     log.info("Registering: "+parser.getClass()); 
     59                    log.info("Registering parsing module {} for Event Type {}",parser.getClass(),parser.getEventType()); 
    5960                this.parsingModules = parsingModules; 
    6061        } 
     
    6970        } 
    7071 
     72    /** 
     73     * Returns the first parsing module whos <code>eventType</code> matches the 
     74     * <code>eventType</code> parameter 
     75     * 
     76     * @param eventTypeFriendlyName the <code>friendlyName</code> of the event parser to find 
     77     * @return returns the matching parsing module if found, or throws a <code>EventParserNotFoundException</code> if not found 
     78     */ 
     79    public BaseEventParser getParsingModuleForType(String eventTypeFriendlyName) throws EventParserNotFoundException{ 
     80        if (eventTypeFriendlyName==null) 
     81            throw new EventParserNotFoundException("No event type supplied to the data register, hence parsing module could not be found"); 
     82        for (BaseEventParser baseEventParser : parsingModules){ 
     83            if (baseEventParser.getEventTypeFriendlyName().equals(eventTypeFriendlyName)) 
     84                return baseEventParser; 
     85        } 
     86 
     87        throw new EventParserNotFoundException("No parser could be found for the event type "+eventTypeFriendlyName); 
     88 
     89    } 
     90 
    7191 
    7292 
  • raptor-parse/trunk/src/main/java/uk/ac/cardiff/raptor/parse/external/file/LogFileParser.java

    r717 r732  
    1717 
    1818import java.io.BufferedReader; 
     19import java.io.ByteArrayInputStream; 
    1920import java.io.IOException; 
    2021import java.io.InputStream; 
     
    6970        private LogFileFormat format; 
    7071 
    71         /** The fully qualified path of the log file */ 
     72        /** The fully qualified path of the log file. Not required if <code>parse(bytes[])</code> 
     73         * is used 
     74         */ 
    7275        private String logfile; 
    73  
    74         /** The fully qualified name of the event type class */ 
    75         private String eventType; 
    7676 
    7777        /** 
     
    9191        } 
    9292 
    93  
     93        @Override 
     94        public void parse(byte[] bytes) throws ParserException{ 
     95            try{ 
     96                log.info("Parsing log file as byte array with length {}",bytes.length); 
     97                BufferedReader bf = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytes))); 
     98                int totalNoLines = count(bytes); 
     99                doParse(bf, totalNoLines); 
     100            } 
     101            catch (MalformedURLException e1) { 
     102                throw new ParserException("Could not find the source file [" + logfile + "] for parsing", e1); 
     103            } catch (IOException e2) { 
     104                throw new ParserException("Could not read from the source file [" + logfile + "] during parsing", e2); 
     105            } 
     106 
     107        } 
     108 
     109        @Override 
    94110        public void parse() throws ParserException { 
    95                 log.info("parsing: {} instance: {}", logfile, this); 
    96  
    97                 try { 
    98                         URL logfileURL = new URL(logfile); 
    99  
    100                         URLConnection logfileconnection = logfileURL.openConnection(); 
    101  
    102                         BufferedReader in = new BufferedReader(new InputStreamReader(logfileconnection.getInputStream())); 
     111            try{ 
     112                log.info("parsing log file: {}", logfile); 
     113                URL logfileURL = new URL(logfile); 
     114                URLConnection logfileconnection = logfileURL.openConnection(); 
     115                BufferedReader in = new BufferedReader(new InputStreamReader(logfileconnection.getInputStream())); 
     116                int totalNoLines = count(logfileURL); 
     117                doParse(in, totalNoLines); 
     118            } 
     119            catch (MalformedURLException e1) { 
     120                throw new ParserException("Could not find the source file [" + logfile + "] for parsing", e1); 
     121            } catch (IOException e2) { 
     122                throw new ParserException("Could not read from the source file [" + logfile + "] during parsing", e2); 
     123            } 
     124 
     125        } 
     126 
     127 
     128 
     129        private void doParse(BufferedReader in, int totalNoLines) throws ParserException { 
     130                try { 
    103131                        int lineCount = 0; 
    104132                        String inputLine; 
    105                         int totalNoLines = count(logfileURL); 
    106  
    107                         log.debug("Parsing file with {} lines", totalNoLines); 
     133 
     134                        //log.debug("Parsing file with {} lines", totalNoLines); 
    108135                        while ((inputLine = in.readLine()) != null) { 
    109136                                lineCount++; 
     
    152179                        log.debug("LogFileParser currently has: {} entries, latestEntry: {}", entryHandler.getNumberOfEntries(), entryHandler.getLatestEntryTime()); 
    153180                        //entryHandler.endTransaction(); 
    154                 } catch (MalformedURLException e1) { 
    155                         throw new ParserException("Could not find the source file [" + logfile + "] for parsing", e1); 
    156181                } catch (IOException e2) { 
    157182                        throw new ParserException("Could not read from the source file [" + logfile + "] during parsing", e2); 
     
    350375 
    351376        /** 
    352          * Efficient method for finding the number of lines in a logfile 
     377         * Efficient method for finding the number of lines in a logfile. Where each line is denoted by the line break character \n 
    353378         * 
    354379         * @param logfileURL the location, as a URL, of the logfile that is to be processed 
     
    373398 
    374399        /** 
     400         * Counts the number of lines (where each line is denoted by the line break character \n) stored by a buffered reader. 
     401         * Maybe not such an efficient method 
     402         * 
     403         * @param reader the <code>BufferedReader</code> that the line count is performed on 
     404         * @return the number of lines in the <code>reader</code> input parameter 
     405         * @throws IOException 
     406         */ 
     407        private int count(byte[] bytes) throws IOException  { 
     408            BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytes))); 
     409            int lineCount=0; 
     410            while (reader.readLine()!=null){ 
     411                lineCount++; 
     412            } 
     413            return lineCount; 
     414 
     415        } 
     416 
     417        /** 
    375418         * Converts the <code>value</code> into a list delimited by the <code> delimeter</code> input, 
    376419         * and adds the list of string values to the <code>fieldName</code> of the <code>object</code> using 
     
    533576        } 
    534577 
    535         /** 
    536          * @param eventType 
    537          *            the eventType to set 
    538          */ 
    539         public void setEventType(String eventType) { 
    540                 this.eventType = eventType; 
    541         } 
    542  
    543         /** 
    544          * @return the eventType 
    545          */ 
    546         public String getEventType() { 
    547                 return eventType; 
    548         } 
    549578 
    550579        /** 
Note: See TracChangeset for help on using the changeset viewer.