Subversion Repositories svn.mios

Rev

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";
738 adamjking 14
 
729 adamjking 15
    public final static String TAG_FILE = "hexFile";
738 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;
738 adamjking 28
 
729 adamjking 29
        tags.add(TAG_FILE);
721 adamjking 30
    }
738 adamjking 31
 
727 adamjking 32
    protected void parseElement(Element element) {
721 adamjking 33
 
727 adamjking 34
        super.parseElement(element);
738 adamjking 35
 
727 adamjking 36
        String name = element.getNodeName();
738 adamjking 37
 
727 adamjking 38
        if (name == rootElementTag) {
738 adamjking 39
 
40
            hexFileUpload.setMIOS32Mode(stringToBoolean(element
41
                    .getAttribute(ATTR_MIOS32_MODE)));
42
 
43
            hexFileUpload.setDeviceID(stringToInt(element
44
                    .getAttribute(ATTR_DEVICE_ID)));
45
 
46
            hexFileUpload.setDelayTime(stringToInt(element
47
                    .getAttribute(ATTR_DELAY_TIME)));
48
 
49
            hexFileUpload.setUploadMode(stringToInt(element
50
                    .getAttribute(ATTR_UPLOAD_MODE)));
51
 
52
            hexFileUpload.setWaitForUploadRequest(stringToBoolean(element
53
                    .getAttribute(ATTR_WAIT_FOR_UPLOAD_REQUEST)));
54
 
55
        }
56
        if (name == TAG_FILE) {
57
 
729 adamjking 58
            File file = new File(element.getTextContent());
738 adamjking 59
 
729 adamjking 60
            if (file.exists()) {
738 adamjking 61
 
729 adamjking 62
                hexFileUpload.setFile(file);
63
            }
727 adamjking 64
        }
65
    }
66
 
721 adamjking 67
    public void saveXML(Node node) {
68
 
69
        super.saveXML(node);
738 adamjking 70
 
722 adamjking 71
        rootElement.setAttribute(ATTR_WAIT_FOR_UPLOAD_REQUEST,
72
                booleanToString(hexFileUpload.isWaitForUploadRequest()));
721 adamjking 73
 
722 adamjking 74
        rootElement.setAttribute(ATTR_UPLOAD_MODE, intToString(hexFileUpload
75
                .getUploadMode()));
721 adamjking 76
 
722 adamjking 77
        rootElement.setAttribute(ATTR_DELAY_TIME, intToString(hexFileUpload
78
                .getDelayTime()));
729 adamjking 79
 
80
        File file = hexFileUpload.getFile();
738 adamjking 81
 
729 adamjking 82
        if (file != null) {
738 adamjking 83
 
729 adamjking 84
            Element fileElement = document.createElement(TAG_FILE);
738 adamjking 85
 
729 adamjking 86
            rootElement.appendChild(fileElement);
738 adamjking 87
 
88
            fileElement.setTextContent(file.getAbsolutePath());
729 adamjking 89
        }
721 adamjking 90
    }
709 adamjking 91
}