1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.magicproject.database.propertyconfig;
20
21 import net.sf.magicproject.database.Proxy;
22 import net.sf.magicproject.database.data.StringData;
23 import net.sf.magicproject.database.data.TranslatableData;
24 import net.sf.magicproject.ui.i18n.LanguageManagerMDB;
25 import net.sf.magicproject.xml.XmlParser.Node;
26
27 /***
28 * Abstract class that holds information about a property name and its
29 * translation in the selected language in the <code>LanguageManager</code>
30 * class.
31 *
32 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
33 * @since 0.90
34 */
35 public abstract class PropertyConfig {
36
37 /***
38 * The translated name of this property.
39 */
40 private String translatedName;
41
42 /***
43 * The name of this property.
44 */
45 private String name;
46
47 /***
48 * Default protected constructor.
49 *
50 * @param name
51 * the identifier or name of this property
52 */
53 protected PropertyConfig(String name) {
54 this.name = name;
55 }
56
57 /***
58 * Indicates if the value of this property is translated or not.
59 *
60 * @return <code>true</code> if the value of this property is translated,
61 * <code>false</code> either
62 */
63 abstract boolean isTranslated();
64
65 /***
66 * Returns the translated property name.
67 *
68 * @return the translated property name
69 */
70 public String getTranslatedName() {
71 if (translatedName == null) {
72 translatedName = LanguageManagerMDB.getString(name);
73 }
74 return translatedName;
75 }
76
77 /***
78 * Returns the name of this property.
79 *
80 * @return the name of this property
81 */
82 public String getName() {
83 return name;
84 }
85
86 @Override
87 public final int hashCode() {
88 return name.hashCode();
89 }
90
91 @Override
92 public String toString() {
93 return "[name=" + name + ",local=" + translatedName + "]";
94 }
95
96 /***
97 * Parse the given stream to build the associated TranslatableData object to
98 * the specified card name.
99 *
100 * @param cardName
101 * the card name.
102 * @param node
103 * the node containing the data used to build the
104 * {@link TranslatableData} object.
105 * @return the {@link TranslatableData} object built from the given node.
106 */
107 public TranslatableData parseProperty(String cardName, Node node) {
108 return new StringData(this, node.getAttribute("value"));
109 }
110
111 /***
112 * Parse the given stream to build the associated TranslatableData object to
113 * the specified card name.
114 *
115 * @param cardName
116 * the card name.
117 * @param stream
118 * the stream containing the data used to build the
119 * {@link TranslatableData} object.
120 * @param proxy
121 * is the proxy this data come from. Is used to translate from
122 * private-proxy to public-tbs value.
123 * @return the {@link TranslatableData} object built from the given stream.
124 */
125 public TranslatableData parseProperty(String cardName, String stream,
126 Proxy proxy) {
127 return new StringData(this, proxy
128 .getGlobalValueFromLocal(getName(), stream));
129 }
130 }