1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.magicproject.xml.action;
20
21 import java.io.IOException;
22 import java.io.OutputStream;
23
24 import net.sf.magicproject.action.Actiontype;
25 import net.sf.magicproject.test.TestOn;
26 import net.sf.magicproject.xml.XmlAction;
27 import net.sf.magicproject.xml.XmlToMDB;
28 import net.sf.magicproject.xml.XmlTools;
29 import net.sf.magicproject.xml.XmlParser.Node;
30
31 /***
32 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
33 * @since 0.94
34 */
35 public class Copycard implements XmlToMDB {
36
37 /***
38 * <ul>
39 * Structure of stream : Data[size]
40 * <li>idAction [1]</li>
41 * <li>card to copy [TestOn]</li>
42 * <li>card to apply copy [TestOn]</li>
43 * <li>excludes name [boolean]</li>
44 * <li>excludes colors [ListExpression]</li>
45 * <li>excludes idcards [ListExpression]</li>
46 * </ul>
47 *
48 * @param node
49 * the XML action structure
50 * @param out
51 * outputstream where the card structure will be saved.
52 * @return the amount of written action in the output.
53 * @throws IOException
54 * If some other I/O error occurs
55 */
56 public int buildMdb(Node node, OutputStream out) throws IOException {
57 XmlAction.buildMdb(Actiontype.COPY_CARD, node, out);
58 TestOn.serialize(out, node.getAttribute("card"));
59 TestOn.serialize(out, node.getAttribute("to"));
60 writeList(node.get("excludes"), out);
61 return 1;
62 }
63
64 private void writeList(Node node, OutputStream out) throws IOException {
65 out.write((node != null && "true".equals(node.getAttribute("name"))) ? 1
66 : 0);
67
68 XmlTools.writeList(out, node, "color");
69 XmlTools.writeList(out, node, "idcard");
70 }
71
72 }