Subversion Repositories svn.mios

Rev

Rev 800 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
800 adamjking 1
package org.midibox.midi.xml;
2
 
850 adamjking 3
import java.io.File;
4
 
800 adamjking 5
import org.midibox.midi.SysexSendReceive;
6
import org.midibox.utils.xml.XMLUtils;
850 adamjking 7
import org.w3c.dom.Element;
800 adamjking 8
import org.w3c.dom.Node;
9
 
10
public class SysexSendReceiveXML extends XMLUtils {
11
 
12
    public final static String TAG_ROOT_ELEMENT = "sysexSendReceive";
13
 
850 adamjking 14
    public final static String TAG_SEND_FILE = "sendSysexFile";
15
 
16
    public final static String ATTR_SEND_DELAY_TIME = "sendDelayTime";
17
 
800 adamjking 18
    protected SysexSendReceive sysexSendReceive;
19
 
20
    public SysexSendReceiveXML(SysexSendReceive sysexSendReceive,
21
            String rootElementTag) {
22
 
23
        super(rootElementTag);
24
 
25
        this.sysexSendReceive = sysexSendReceive;
850 adamjking 26
 
27
        addTag(TAG_SEND_FILE);
800 adamjking 28
    }
29
 
850 adamjking 30
    protected void parseElement(Element element) {
31
 
32
        super.parseElement(element);
33
 
34
        String name = element.getNodeName();
35
 
36
        if (name == rootElementTag) {
37
 
38
            if (element.getAttribute(ATTR_SEND_DELAY_TIME) != "") {
39
 
40
                sysexSendReceive.setSendDelayTime(stringToInt(element
41
                        .getAttribute(ATTR_SEND_DELAY_TIME)));
42
            }
43
        }
44
 
45
        if (name == TAG_SEND_FILE) {
46
 
47
            File file = new File(element.getTextContent());
48
 
49
            if (file.exists()) {
50
 
51
                sysexSendReceive.setSendFile(file);
52
            }
53
        }
54
    }
55
 
800 adamjking 56
    public void saveXML(Node node) {
57
 
58
        super.saveXML(node);
850 adamjking 59
 
60
        rootElement.setAttribute(ATTR_SEND_DELAY_TIME,
61
                intToString(sysexSendReceive.getSendDelayTime()));
62
 
63
        File file = sysexSendReceive.getSendFile();
64
 
65
        if (file != null) {
66
 
67
            Element fileElement = document.createElement(TAG_SEND_FILE);
68
 
69
            rootElement.appendChild(fileElement);
70
 
71
            fileElement.setTextContent(file.getAbsolutePath());
72
        }
800 adamjking 73
    }
74
}