View Javadoc

1   /*
2    *   Magic-Project is a turn based strategy simulator
3    *   Copyright (C) 2003-2007 Fabrice Daugan
4    *
5    *   This program is free software; you can redistribute it and/or modify it 
6    * under the terms of the GNU General Public License as published by the Free 
7    * Software Foundation; either version 2 of the License, or (at your option) any
8    * later version.
9    *
10   *   This program is distributed in the hope that it will be useful, but WITHOUT 
11   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
13   * details.
14   *
15   *   You should have received a copy of the GNU General Public License along  
16   * with this program; if not, write to the Free Software Foundation, Inc., 
17   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  		// TODO Copycard action : XmlTools.writeList(out, node, "properties");
68  		XmlTools.writeList(out, node, "color");
69  		XmlTools.writeList(out, node, "idcard");
70  	}
71  
72  }