Statistics
| Revision:

root / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / xml / writer / GPEXmlWriterHandler.java @ 11210

History | View | Annotate | Download (3.49 KB)

1
package org.gvsig.gpe.xml.writer;
2

    
3
import java.io.File;
4
import java.io.FileNotFoundException;
5
import java.io.FileWriter;
6
import java.io.IOException;
7
import java.io.InputStream;
8
import java.io.OutputStream;
9
import org.gvsig.gpe.xml.writer.Writer;
10

    
11
import org.apache.xml.utils.NameSpace;
12
import org.gvsig.gpe.GPEDefaults;
13
import org.gvsig.gpe.GPEErrorHandler;
14
import org.gvsig.gpe.writers.GPEWriterHandler;
15

    
16
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
17
 *
18
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
19
 *
20
 * This program is free software; you can redistribute it and/or
21
 * modify it under the terms of the GNU General Public License
22
 * as published by the Free Software Foundation; either version 2
23
 * of the License, or (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with this program; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
33
 *
34
 * For more information, contact:
35
 *
36
 *  Generalitat Valenciana
37
 *   Conselleria d'Infraestructures i Transport
38
 *   Av. Blasco Ib??ez, 50
39
 *   46010 VALENCIA
40
 *   SPAIN
41
 *
42
 *      +34 963862235
43
 *   gvsig@gva.es
44
 *      www.gvsig.gva.es
45
 *
46
 *    or
47
 *
48
 *   IVER T.I. S.A
49
 *   Salamanca 50
50
 *   46005 Valencia
51
 *   Spain
52
 *
53
 *   +34 963163400
54
 *   dac@iver.es
55
 */
56
/* CVS MESSAGES:
57
 *
58
 * $Id: GPEXmlWriterHandler.java 11210 2007-04-14 16:07:30Z jorpiell $
59
 * $Log$
60
 * Revision 1.4  2007-04-14 16:07:30  jorpiell
61
 * The writer has been created
62
 *
63
 * Revision 1.3  2007/04/13 07:17:57  jorpiell
64
 * Add the writting tests for the simple geometries
65
 *
66
 * Revision 1.2  2007/04/12 17:06:44  jorpiell
67
 * First GML writing tests
68
 *
69
 * Revision 1.1  2007/04/12 10:23:41  jorpiell
70
 * Add some writers and the GPEXml parser
71
 *
72
 *
73
 */
74
/**
75
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
76
 */
77
public abstract class GPEXmlWriterHandler extends GPEWriterHandler {
78
        protected Writer writer = null;
79
        private String targetNamespace = null;
80
        
81
        public GPEXmlWriterHandler(String format, GPEErrorHandler errorHandler) {
82
                super(format, errorHandler);
83
                try {
84
                        writer = createWriter();
85
                        initXmlHeader();
86
                } catch (IOException e) {
87
                        errorHandler.addError(e);
88
                }                
89
        }        
90
        
91
        /**
92
         * Writes the XML header
93
         * @throws IOException
94
         */
95
        private void initXmlHeader() throws IOException{
96
                writer.write("<?xml version=\"");
97
                writer.write(GPEDefaults.getProperty(GPEDefaults.XML_VERSION).toString());
98
                writer.write("\" encoding=\"");
99
                writer.write(GPEDefaults.getProperty(GPEDefaults.XML_ENCODING).toString());
100
                writer.write("\"?>");
101
        }
102
        
103
        /**
104
         * Creates an input stream from a file. 
105
         * @param file
106
         * @return
107
         * @throws FileNotFoundException 
108
         * @throws FileNotFoundException 
109
         */
110
        protected abstract Writer createWriter() throws IOException;
111
        
112
        /**
113
         * @return the outputStream
114
         */
115
        protected Writer getWriter() {
116
                return writer;
117
        }
118

    
119
        /**
120
         * Returns the selected target namespace. If
121
         * the namespace doesn't exists it returns the 
122
         * default Namespace (cit); 
123
         * @return the namespace
124
         */
125
        public String getNamespacePrefix() {
126
                if (targetNamespace == null){
127
                        String prefix = GPEDefaults.getProperty(GPEDefaults.NAMESPACE_PREFIX);
128
                        if (prefix != null){
129
                                targetNamespace = prefix + ":";
130
                        }else{
131
                                targetNamespace = "";
132
                        }
133
                }
134
                return targetNamespace;
135
        }
136
        
137
        
138
}
139
        
140