1 | package de.ugoe.cs.eventbench.web.commands;
|
---|
2 |
|
---|
3 | import java.io.FileNotFoundException;
|
---|
4 | import java.io.IOException;
|
---|
5 | import java.security.InvalidParameterException;
|
---|
6 | import java.text.ParseException;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
10 | import de.ugoe.cs.eventbench.web.WeblogParser;
|
---|
11 | import de.ugoe.cs.util.console.Command;
|
---|
12 | import de.ugoe.cs.util.console.Console;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * <p>
|
---|
16 | * Command to load sessions from a web log.
|
---|
17 | * </p>
|
---|
18 | * @author Steffen Herbold
|
---|
19 | * @version 1.0
|
---|
20 | */
|
---|
21 | public class CMDloadSessionsFromClickstream implements Command {
|
---|
22 |
|
---|
23 | /* (non-Javadoc)
|
---|
24 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
25 | */
|
---|
26 | @Override
|
---|
27 | public void run(List<Object> parameters) {
|
---|
28 | if( parameters.size() < 1 ) {
|
---|
29 | throw new InvalidParameterException();
|
---|
30 | }
|
---|
31 | String source = (String) parameters.get(0);
|
---|
32 | int timeout = -1;
|
---|
33 | int minLength = -1;
|
---|
34 | if( parameters.size() ==3 ) {
|
---|
35 | timeout = Integer.parseInt((String) parameters.get(1));
|
---|
36 | minLength = Integer.parseInt((String) parameters.get(2));
|
---|
37 | }
|
---|
38 |
|
---|
39 | WeblogParser parser = new WeblogParser();
|
---|
40 | if( timeout!=-1 ) {
|
---|
41 | parser.setTimeout(timeout);
|
---|
42 | parser.setMinLength(minLength);
|
---|
43 | }
|
---|
44 | try {
|
---|
45 | parser.parseFile(source);
|
---|
46 | } catch (FileNotFoundException e) {
|
---|
47 | Console.println(e.getMessage());
|
---|
48 | } catch (IOException e) {
|
---|
49 | Console.println(e.getMessage());
|
---|
50 | } catch (ParseException e) {
|
---|
51 | Console.println("Invalid format of date stamps.");
|
---|
52 | Console.println(e.getMessage());
|
---|
53 | }
|
---|
54 |
|
---|
55 | if( GlobalDataContainer.getInstance().addData("sequences", parser.getSequences()) ) {
|
---|
56 | Console.traceln("Old data \"" + "sequences" + "\" overwritten");
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | /* (non-Javadoc)
|
---|
61 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
62 | */
|
---|
63 | @Override
|
---|
64 | public void help() {
|
---|
65 | Console.println("Usage: loadSessionsFromClickstream <filename> {<timeout> <minSessionLength>}");
|
---|
66 | }
|
---|
67 |
|
---|
68 | }
|
---|