Subversion Repositories public

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
85 luk 1
/*
2
 * ICRow.java - jIncron table row class
3
 *
4
 * Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz
5
 *
6
 * ==========================================================================
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License Version 2 as
10
 * published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
 *
21
 * ==========================================================================
22
 */
23
 
24
package cz.aiken.util.jincron;
25
 
26
import java.util.regex.*;
27
 
28
/**
29
 *
30
 * @author luk
31
 */
32
public class ICRow {
33
 
34
    protected static final Pattern splitter = Pattern.compile("[^\\\\](\\s)+");
35
 
36
    private String path = "";
37
    private InotifyEvent event = null;
38
    private String command = "";
39
 
40
    ICRow(String path, InotifyEvent event, String command) {
41
        this.path = path;
42
        this.event = event;
43
        this.command = command;
44
    }
45
 
46
    String getPath() {
47
        return path;
48
    }
49
 
50
    void setPath(String path) {
51
        this.path = path;
52
    }
53
 
54
    InotifyEvent getEvent() {
55
        return event;
56
    }
57
 
58
    void setEvent(InotifyEvent event) {
59
        this.event = event;
60
    }
61
 
62
    String getCommand() {
63
        return command;
64
    }
65
 
66
    void setCommand(String command) {
67
        this.command = command;
68
    }
69
 
70
    static int getFieldCount() {
71
        return 3;
72
    }
73
 
74
    static ICRow parse(String text) {
75
        if (text == null || text.equals(""))
76
            return null;
77
 
78
        Matcher m = splitter.matcher(text);
79
 
80
        if (!m.find())
81
            return null;
82
        int pos = m.start() + 1;
83
        String path = text.substring(0, pos).trim().replace("\\ ", " ").replace("\\\\", "\\");
84
 
85
        if (!m.find())
86
            return null;
87
        int oldpos = pos;
88
        pos = m.start() + 1;
89
 
90
        InotifyEvent evt = InotifyEvent.parse(text.substring(oldpos, pos));
91
        if (evt == null)
92
            return null;
93
 
94
        String cmd = text.substring(pos).trim();
95
 
96
        return new ICRow(path, evt, cmd);
97
    }
98
 
99
    public String toString() {
100
        StringBuilder sb = new StringBuilder();
101
        sb.append(getPath().replace("\\", "\\\\").replace(" ", "\\ "));
102
        sb.append(' ');
103
        sb.append(getEvent().toString());
104
        sb.append(' ');
105
        sb.append(getCommand());        
106
        return sb.toString();
107
    }
108
}