Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / persistence / xml / XMLPersistentConstants.java @ 1426

History | View | Annotate | Download (10.2 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 IVER T.I   {{Task}}
27
 */
28

    
29
package org.gvsig.tools.persistence.xml;
30

    
31
import java.util.Arrays;
32
import java.util.Collections;
33
import java.util.List;
34
import java.util.regex.Pattern;
35

    
36
public interface XMLPersistentConstants {
37

    
38
        /**
39
         * XML Header fomat.<br>
40
         * Parameters:
41
         *  <ol>
42
         *          <li>encoding</li>
43
         *  </ol>
44
         */
45
        public static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"{0}\"?>";
46

    
47
        // Indentations
48
        /**
49
         * Indentation string
50
         */
51
        public static final String INDENDT_1 = "  ";
52
        /**
53
         * Indentation string
54
         */
55
        public static final String INDENDT_2 = "    ";
56
        /**
57
         * Indentation string
58
         */
59
        public static final String INDENDT_3 = "      ";
60
        /**
61
         * Indentation string
62
         */
63
        public static final String INDENDT_4 = "        ";
64

    
65

    
66

    
67
        // XML ROOT ITEM
68
        /**
69
         * XML Root item tag name
70
         */
71
        public static final String ROOT_TAG = "XMLPersitence";
72

    
73
        /**
74
         * XML Root item format.<br>
75
         * Parameters:
76
         * <ol>
77
         * <li>domain notation (Ej. 'tools:')</li>
78
         * <li>additional definitions</li>
79
         * </ol>
80
         */
81
        public static final String ROOT_VALUE = "<{0}" + ROOT_TAG
82
                        + " xmlns:xlink=\"http://www.w3.org/1999/xlink\" {1}>";
83

    
84
        public static final String BASE_DOMIAN_URL = "http://www.gvsig.org/libTools";
85
        public static final String BASE_DOMIAN_NAME = "tools";
86

    
87
        /**
88
         * Schema File name format. <br>
89
         * Parameters:
90
         * <ol>
91
         * <li>schema name</li>
92
         * </ol>
93
         *
94
         */
95
        public static final String SCHEMA_FILE_NAME_VALUE = "{0}.xsd";
96

    
97
        /**
98
         * Schema definition format<br>
99
         * Parameters:
100
         * <ol>
101
         * <li>domain URL</li>
102
         * <li>domain name</li>
103
         * </ol>
104
         */
105
        public static final String SCHEMA_DEFINITON_VALUE = "{0} {1}.xsd \n";
106

    
107
        /**
108
         * SCHEMA attribute for ROOT tag.<br>
109
         * Parameters:
110
         * <ol>
111
         * <li>Schema definition list</li>
112
         * </ol>
113
         */
114
        public static final String DEFAULT_SCHEMA_ATTRIBUTE_VALUE = INDENDT_3
115
                        + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
116
                        + "xsi:SchemaLocation=\"{0}\"";
117

    
118

    
119
        /**
120
         * domain Name definition format. Parameters:
121
         * <ol>
122
         * <li>domain name</li>
123
         * <li>domain URL</li>
124
         * </ol>
125
         */
126
        public static final String DOMAIN_NAME_ATTRIBUTE_VALUE = INDENDT_3
127
                        + "xmlns:{0}=\"{1}\"";
128

    
129
        /**
130
         * XML Root item end.<br>
131
         * <ol>
132
         * <li>domain definition (Ej.: "tools:")</li>
133
         * </ol>
134
         */
135
        public static final String ROOT_END_VALUE = "</{0}" + ROOT_TAG + ">";
136

    
137

    
138
        // Version definition
139
        /**
140
         * Persistence library version tag name
141
         */
142
        public static final String VERSION_TAG = "persistence_xml_version";
143
        /**
144
         * Persistence library version item format.<br>
145
         * Parameters:
146
         * <ol>
147
         * <li>id root state</li>
148
         * </ol>
149
         */
150
        public static final String VERSION_VALUE = "<" + VERSION_TAG + ">{0}</"
151
                        + VERSION_TAG + ">";
152

    
153

    
154
        // Root state item definition
155
        /**
156
         * Root state tag name
157
         */
158
        public static final String ROOTSTATE_TAG = "rootState";
159

    
160
        /**
161
         * Root state id attribute name
162
         */
163
        public static final String ROOSTATE_ID_ATTR = "id_state";
164

    
165
        /**
166
         * States tag name
167
         */
168
        public static final String STATES_TAG = "states";
169

    
170
        /**
171
         * Root state item format.<br>
172
         * Parameters:
173
         *  <ol>
174
         *          <li>id root state</li>
175
         *  </ol>
176
         */
177
        public static final String ROOTSTATE_VALUE = INDENDT_1 + "<"
178
                        + ROOTSTATE_TAG + " " + ROOSTATE_ID_ATTR
179
                        + "=\"{0}\" xlink:type=\"simple\""
180
                        + " xlink:href=\"" + STATES_TAG
181
                        + "#id(''{0}'')\" />";
182

    
183

    
184

    
185

    
186
        // State item definition
187

    
188
        /**
189
         * States item start
190
         */
191
        public static final String STATES_START = "<" + STATES_TAG + ">";
192
        /**
193
         * States item end
194
         */
195
        public static final String STATES_END = "</" + STATES_TAG + ">";
196

    
197
        /**
198
         * State id attribute name
199
         */
200
        public static final String STATE_ID_ATTR = "id";
201

    
202
        /**
203
         * State item start format.<br>
204
         * Parameters:
205
         * <ol>
206
         * <li>domain prefix (ex: 'aDomain:')</li>
207
         * <li>theClassName</li>
208
         * <li>id state</li>
209
         * </ol>
210
         */
211
        public static final String STATE_START = INDENDT_1 + "<{0}{1} "
212
                        + STATE_ID_ATTR + "=\"{2}\">";
213

    
214
        /**
215
         * State item end format.<br>
216
         * Parameters:
217
         * <ol>
218
         * <li>domain prefix (ex: 'aDomain:')</li>
219
         * <li>theClassName</li>
220
         * <li>id state</li>
221
         * </ol>
222
         */
223
        public static final String STATE_END = INDENDT_1 + "</{0}{1}>";
224

    
225

    
226

    
227
        // Value item definition
228
        /**
229
         * Value item tag name for generic (when name of value is not a valid xml
230
         * tag name)
231
         */
232
        public static final String VALUE_TAG = "value";
233
        /**
234
         * type attribute name for value item
235
         */
236
        public static final String VALUE_TYPE_ATTR = "type";
237
        /**
238
         * name item tag name of Value item for generic (when name of value is
239
         * not a valid xml tag name)
240
         */
241
        public static final String NAMEVALUE_TAG = "name";
242
        /**
243
         * data item tag name of Value item for generic (when name of value is
244
         * not a valid xml tag name)
245
         */
246
        public static final String DATAVALUE_TAG = "data";
247
        /**
248
         * Value format.<br>
249
         * Parameters:
250
         *  <ol>
251
         *          <li>name</li>
252
         *          <li>typeName</li>
253
         *      <li>string representation of data</li>
254
         *  </ol>
255
         */
256
        public static final String VALUE_ITEM = INDENDT_2
257
                        + "<{0} "
258
                        + VALUE_TYPE_ATTR + "=\"{1}\">{2}</{0}>";
259
        /**
260
         * Value format for generic (when name of value is
261
         * not a valid xml tag name).<br>
262
         * Parameters:
263
         *  <ol>
264
         *          <li>name</li>
265
         *          <li>typeName</li>
266
         *      <li>string representation of data</li>
267
         *  </ol>
268
         */
269
        public static final String VALUE_ITEM_GENERIC = INDENDT_2 + "<" + VALUE_TAG
270
                        + " " + VALUE_TYPE_ATTR + "=\"{1}\">\n" + INDENDT_3 + "<"
271
                        + NAMEVALUE_TAG + ">{0}</"
272
                        + NAMEVALUE_TAG + ">\n" + INDENDT_3 + "<" + DATAVALUE_TAG
273
                        + ">{2}</" + DATAVALUE_TAG + ">\n" + INDENDT_2 + "</" + VALUE_TAG
274
                        + ">";
275

    
276

    
277

    
278

    
279
        // Final Value data formating
280
        /**
281
         * reference item tag name of data of Value item for references values.
282
         */
283
        public static final String REFERENCE_TAG = "reference";
284
        /**
285
         * type attribute name for value item
286
         */
287
        public static final String REFERENCE_ID_ATTR = "id_state";
288
        /**
289
         * ReferenceValue format.<br>
290
         * Parameters:
291
         *  <ol>
292
         *          <li>id reference</li>
293
         *  </ol>
294
         */
295
        public static final String REFERENCE_VALUE = "\n" + INDENDT_4 + "<"
296
                        + REFERENCE_TAG + " " + REFERENCE_ID_ATTR
297
                        + "=\"{0}\" xlink:type=\"simple\""
298
                        + " xlink:href=\"" + STATES_TAG
299
                        + "#id(''{0}'')\" />";
300
        /**
301
         * list item tag name of data of Value item for list values.
302
         */
303
        public static final String LISTITEM_TAG = "item";
304
        /**
305
         * List value item format.<br>
306
         * Parameters:
307
         * <ol>
308
         * <li>typeName</li>
309
         * <li>string representation of data</li>
310
         * </ol>
311
         */
312
        public static final String LISTITEM_VALUE = INDENDT_3 + "<"
313
                        + LISTITEM_TAG
314
                        + " " + VALUE_TYPE_ATTR + "=\"{0}\">{1}</" + LISTITEM_TAG + ">";
315
        /**
316
         * set item tag name of data of Value item for list values.
317
         */
318
        public static final String SETITEM_TAG = "item";
319
        /**
320
         * Set value item format.<br>
321
         * Parameters:
322
         * <ol>
323
         * <li>typeName</li>
324
         * <li>string representation of data</li>
325
         * </ol>
326
         */
327
        public static final String SETITEM_VALUE = INDENDT_3 + "<"
328
                        + SETITEM_TAG
329
                        + " " + VALUE_TYPE_ATTR + "=\"{0}\">{1}</" + SETITEM_TAG + ">";
330
        /**
331
         * Map item tag name of data of Value item for list values.
332
         */
333
        public static final String MAPITEM_TAG = "mapitem";
334
        /**
335
         * Key Map item tag name of data of Value item for list values.
336
         */
337
        public static final String MAPKEY_TAG = "key";
338
        /**
339
         * Value Map item tag name of data of Value item for list values.
340
         */
341
        public static final String MAPVALUE_TAG = "value";
342
        /**
343
         * Map item format.<br>
344
         * Parameters:
345
         * <ol>
346
         * *
347
         * <li>key typeName</li>
348
         * <li>string representation of key</li>
349
         * <li>value typeName</li>
350
         * <li>string representation of value</li>
351
         * </ol>
352
         */
353
        public static final String MAPITEM_VALUE = "\n" + INDENDT_3 + "<"
354
                        + MAPITEM_TAG
355
                        + ">\n" + INDENDT_4 + "<" + MAPKEY_TAG + " type=\"{0}\">{1}</"
356
                        + MAPKEY_TAG + ">\n" + INDENDT_4 + "<" + MAPVALUE_TAG
357
                        + " type=\"{2}\">{3}</"
358
                        + MAPVALUE_TAG + ">\n" + INDENDT_3 + "</" + MAPITEM_TAG
359
                        + ">\n";
360

    
361

    
362
        public static final String TYPE_NULL = "null";
363
        public static final String TYPE_STRING = "string";
364
        public static final String TYPE_MAP = "map";
365
        public static final String TYPE_SET = "set";
366
        public static final String TYPE_LIST = "list";
367
        public static final String TYPE_REFERENCE = "reference";
368
        public static final String TYPE_BOOLEAN = "boolean";
369
        public static final String TYPE_INTEGER = "integer";
370
        public static final String TYPE_LONG = "long";
371
        public static final String TYPE_FLOAT = "float";
372
        public static final String TYPE_DOUBLE = "double";
373
        public static final String TYPE_DATE = "date";
374
        public static final String TYPE_FILE = "file";
375
        public static final String TYPE_URL = "url";
376
        public static final String TYPE_URI = "uri";
377
        public static final String TYPE_BIGDECIMAL = "bigdecimal";
378
        public static final List TYPES_NUMBER = Collections.unmodifiableList(Arrays
379
                        .asList(new String[] { TYPE_INTEGER, TYPE_LONG, TYPE_FLOAT,
380
                                        TYPE_DOUBLE, TYPE_BIGDECIMAL }));
381

    
382

    
383
        // Validation patters of xml elements
384
        /**
385
         * Pattern matches with valid xml item names (tag name)
386
         */
387
        public static final Pattern VALID_TAG_PATTERN = Pattern
388
                        .compile("[\\w][\\d\\w_]*");
389
        /**
390
         * Pattern matches with valid xml item text values (text content between tag)
391
         */
392
        public static final Pattern VALID_VALUE_PATTERN = Pattern.compile("[^<&]*");
393

    
394

    
395
        // CDATA constants
396
        /**
397
         * CDATA element start
398
         */
399
        public static final String CDATA_START = "<![CDATA[";
400
        /**
401
         * CDATA element end
402
         */
403
        public static final String CDATA_END = "]]>";
404

    
405

    
406
}