Subversion Repositories svn.mios

Rev

Rev 722 | Rev 729 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
709 adamjking 1
package org.midibox.mios.xml;
2
 
727 adamjking 3
import java.io.File;
4
 
721 adamjking 5
import org.midibox.mios.HexFileUpload;
727 adamjking 6
import org.w3c.dom.Element;
721 adamjking 7
import org.w3c.dom.Node;
709 adamjking 8
 
721 adamjking 9
public class HexFileUploadXML extends MIOSSysexSendReceiveXML {
10
 
11
    protected HexFileUpload hexFileUpload;
12
 
722 adamjking 13
    public final static String TAG_ROOT_ELEMENT = "hexFileUpload";
727 adamjking 14
 
15
    public final static String ATTR_FILE = "file";
721 adamjking 16
 
722 adamjking 17
    public final static String ATTR_WAIT_FOR_UPLOAD_REQUEST = "waitForUploadRequest";
721 adamjking 18
 
722 adamjking 19
    public final static String ATTR_UPLOAD_MODE = "uploadMode";
721 adamjking 20
 
722 adamjking 21
    public final static String ATTR_DELAY_TIME = "delayTime";
22
 
721 adamjking 23
    public HexFileUploadXML(HexFileUpload hexFileUpload, String rootElementTag) {
24
 
25
        super(hexFileUpload, rootElementTag);
26
 
27
        this.hexFileUpload = hexFileUpload;
28
    }
727 adamjking 29
 
30
    protected void parseElement(Element element) {
721 adamjking 31
 
727 adamjking 32
        super.parseElement(element);
33
 
34
        String name = element.getNodeName();
35
 
36
        if (name == rootElementTag) {
37
 
38
            File file = new File(element.getAttribute(ATTR_FILE));
39
 
40
            if (file.exists()) {
41
 
42
                hexFileUpload.setFile(file);
43
            }
44
 
45
            hexFileUpload.setMIOS32Mode(stringToBoolean(element.getAttribute(ATTR_MIOS32_MODE)));
46
 
47
            hexFileUpload.setDeviceID(stringToInt(element.getAttribute(ATTR_DEVICE_ID)));
48
 
49
            hexFileUpload.setDelayTime(stringToInt(element.getAttribute(ATTR_DELAY_TIME)));
50
 
51
            hexFileUpload.setUploadMode(stringToInt(element.getAttribute(ATTR_UPLOAD_MODE)));
52
 
53
            hexFileUpload.setWaitForUploadRequest(stringToBoolean(element.getAttribute(ATTR_WAIT_FOR_UPLOAD_REQUEST)));
54
        }
55
    }
56
 
57
 
58
 
721 adamjking 59
    public void saveXML(Node node) {
60
 
61
        super.saveXML(node);
62
 
727 adamjking 63
        File file = hexFileUpload.getFile();
64
 
65
        String fileAttr = (file != null) ? file.getAbsoluteFile().toString() : "";
66
 
67
        rootElement.setAttribute(ATTR_FILE, fileAttr);     
68
 
722 adamjking 69
        rootElement.setAttribute(ATTR_WAIT_FOR_UPLOAD_REQUEST,
70
                booleanToString(hexFileUpload.isWaitForUploadRequest()));
721 adamjking 71
 
722 adamjking 72
        rootElement.setAttribute(ATTR_UPLOAD_MODE, intToString(hexFileUpload
73
                .getUploadMode()));
721 adamjking 74
 
722 adamjking 75
        rootElement.setAttribute(ATTR_DELAY_TIME, intToString(hexFileUpload
76
                .getDelayTime()));
721 adamjking 77
    }
709 adamjking 78
}