Statistics
| Revision:

root / trunk / extensions / extPublish / src / org / gvsig / remoteservices / conf / geoserver / Catalog.java @ 8966

History | View | Annotate | Download (5.92 KB)

1
package org.gvsig.remoteservices.conf.geoserver;
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.RandomAccessFile;
8

    
9
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
10
 *
11
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version 2
16
 * of the License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
26
 *
27
 * For more information, contact:
28
 *
29
 *  Generalitat Valenciana
30
 *   Conselleria d'Infraestructures i Transport
31
 *   Av. Blasco Ib??ez, 50
32
 *   46010 VALENCIA
33
 *   SPAIN
34
 *
35
 *      +34 963862235
36
 *   gvsig@gva.es
37
 *      www.gvsig.gva.es
38
 *
39
 *    or
40
 *
41
 *   IVER T.I. S.A
42
 *   Salamanca 50
43
 *   46005 Valencia
44
 *   Spain
45
 *
46
 *   +34 963163400
47
 *   dac@iver.es
48
 */
49
/* CVS MESSAGES:
50
 *
51
 * $Id$
52
 * $Log$
53
 * Revision 1.4  2006-11-22 14:38:08  dagilgon
54
 * gets y sets de geoserver
55
 *
56
 * Revision 1.3  2006/11/22 12:48:21  jorpiell
57
 * Subidos algunos cambios para ver las capas en forma de ?rbol
58
 *
59
 * Revision 1.2  2006/10/06 10:33:09  dagilgon
60
 * varios cambios en los path de los .xml
61
 *
62
 * Revision 1.1  2006/10/05 16:33:48  jvhigon
63
 * Publica en geoserver. Falta depurar
64
 *
65
 *
66
 */
67
/**
68
 * @author Jos? Vicente Hig?n (higon_jos@gva.es)
69
 */
70
//creates catalog.xml
71

    
72
public class Catalog extends GeoserverConfiguration{
73
        
74
        String namespace = null;
75
        String name = null;
76
        String id = null;
77
        String url = null;
78
        String enabled = null;
79
        
80
        Catalog(String geopath,String namespace,String name,String id,String url,
81
                        String enabled){
82
                super(geopath);
83
                this.namespace=namespace;
84
                this.name=name;
85
                this.id=id;
86
                this.url=url;
87
                this.enabled=enabled;
88
                // forcing delete of catalog.xml
89
                File f = new File(geopath+"/WEB-INF/catalog.xml");
90
                if (f.exists()) f.delete();
91
                
92
                try{
93
                        catalog = new RandomAccessFile(geopath+"/WEB-INF/catalog.xml","rw");
94
                }catch(FileNotFoundException x){
95
                        System.out.println("Fichero catalog.xml no existe.");
96
                }
97
                catalog2 = new File(geopath+"/WEB-INF/catalog2.xml");
98
                try{
99
                        System.out.println("------------------");
100
                        outc = new FileWriter(catalog2);
101
                }catch(IOException x){
102
                        System.out.println("No se ha podido crear algun stream.");
103
                }
104
        }
105
        
106
        Catalog(String geopath,String namespace,String name,String id,String enabled){
107
                super(geopath);
108
                this.namespace=namespace;
109
                this.name=name;
110
                this.id=id;
111
                this.enabled=enabled;
112
                //forcing delete of catalog.xml
113
                File f = new File(geopath+ "/WEB-INF/catalog.xml");
114
                if (f.exists()) f.delete();
115
                
116
                try{
117
                        catalog = new RandomAccessFile(geopath+"/WEB-INF/catalog.xml","rw");
118
                }catch(FileNotFoundException x){
119
                        System.out.println("Fichero catalog.xml no existe.");
120
                }
121
                catalog2 = new File(geopath+"/WEB-INF/catalog2.xml");
122
                try{
123
                        System.out.println("------------------");
124
                        outc = new FileWriter(catalog2);
125
                }catch(IOException x){
126
                        System.out.println("No se ha podido crear algun stream.");
127
                }
128
        }
129
        
130
        void startCatalog(){
131
                writeln("<catalog>",1);
132
        }
133
        
134
        void startDatastores(){
135
                writeln("<datastores>",1);
136
        }
137
        
138
        void endCatalog(){
139
                writeln("</catalog>",1);
140
                writeln("",1);
141
        }
142
        
143
        void endDatastores(){
144
                writeln("</datastores>",1);
145
        }
146
        
147
        void startStyles(){
148
                writeln("<styles>",1);
149
                writeln("<style filename = \"default_line.sld\" id=\"line\" />",1);
150
        }
151
        
152
        void endStyles(){
153
                writeln("</styles>",1);
154
        }
155

    
156
        void startDatastore(){
157
        }
158

    
159
        void endDatastore(){
160
                writeln("</datastore>",1);
161
        }
162
        
163
        void startNamespace(){
164
                writeln("<namespaces>",1);
165
        }
166
        
167
        void setNamespace(){
168
                writeln("<namespace uri=\"http://www.gvsig.es\" prefix=\""+namespace+
169
                                "\" default=\"true\" />" ,1);
170
        }
171
        
172
        void endNamespace(){
173
                writeln("</namespaces>",1);
174
        }
175
        
176
        
177
        
178
        void startConnectionParams(){
179
                writeln("<connectionParams>",1);        
180
        }
181
        
182
        void endConnectionParams(){        
183
                writeln("</connectionParams>",1);
184
        }
185
        
186
        void parameter(String p1,String p2){
187
                writeln("<parameter value = \""+p1+"\" name = \""+p2+"\"  />",1);
188
        }
189
//        writes .xml file
190
        public void toXML(){        
191
                String s;
192
                s="";
193
                int cont=0;
194
                try{
195
                        s=catalog.readLine();
196
                        s=catalog.readLine();
197
                        s=catalog.readLine();
198
                }catch(IOException e){
199
                }
200
                s="";
201
                while(s!=null && s.compareTo("</datastores>")!=0){
202
                        try{
203
                                s=catalog.readLine();
204
                                if(s!=null){
205
                                        cont++;
206
                                        if(s!=null && s.compareTo("</datastores>")!=0){
207
                                                System.out.println("fichero----->"+s);
208
                                                outc.write(s);
209
                                                outc.write("\n");
210
                                        }
211
                                        
212
                                }
213
                                
214
                        }catch(IOException e){
215
                                System.out.println("No se ha podido leer de catalog.xml.");
216
                        }
217
                }
218
                endDatastores();
219
                startNamespace();
220
                setNamespace();
221
                endNamespace();
222
                startStyles();
223
                endStyles();
224
                endCatalog();
225
                try{
226
                        catalog.close();
227
                        outc.close();
228
                }catch(IOException e){
229
                        System.out.println("No se ha podido cerrar catalog.xml 1 o 2."); 
230
                }
231
                catalog3= new File(""+geopath+"/WEB-INF/catalog.xml");
232
                catalog3.delete();
233
                catalog2.renameTo(catalog3);
234
        }
235

    
236
        public String getEnabled() {
237
                return enabled;
238
        }
239

    
240
        public void setEnabled(String enabled) {
241
                this.enabled = enabled;
242
        }
243

    
244
        public String getId() {
245
                return id;
246
        }
247

    
248
        public void setId(String id) {
249
                this.id = id;
250
        }
251

    
252
        public String getName() {
253
                return name;
254
        }
255

    
256
        public void setName(String name) {
257
                this.name = name;
258
        }
259

    
260
        public String getNamespace() {
261
                return namespace;
262
        }
263

    
264
        public void setNamespace(String namespace) {
265
                this.namespace = namespace;
266
        }
267

    
268
        public String getUrl() {
269
                return url;
270
        }
271

    
272
        public void setUrl(String url) {
273
                this.url = url;
274
        }        
275
}