svn-gvsig-desktop / branches / v10 / extensions / extPublishGeoserver / src / org / gvsig / publish / geoserver / conf / GSCatalog.java @ 19432
History | View | Annotate | Download (4.61 KB)
1 |
/* gvSIG. Sistema de Información Geográfica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004-2006 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ibañez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
|
43 |
package org.gvsig.publish.geoserver.conf; |
44 |
|
45 |
//Start of user code for imports
|
46 |
import java.io.File; |
47 |
import java.io.FileOutputStream; |
48 |
import java.io.IOException; |
49 |
import java.util.HashMap; |
50 |
import java.util.Iterator; |
51 |
import java.util.Map; |
52 |
|
53 |
import javax.xml.parsers.DocumentBuilder; |
54 |
import javax.xml.parsers.DocumentBuilderFactory; |
55 |
import javax.xml.parsers.ParserConfigurationException; |
56 |
|
57 |
import org.gvsig.publish.PublishLogger; |
58 |
import org.w3c.dom.Document; |
59 |
import org.w3c.dom.Element; |
60 |
|
61 |
import com.sun.org.apache.xml.internal.serialize.OutputFormat; |
62 |
import com.sun.org.apache.xml.internal.serialize.XMLSerializer; |
63 |
//End of user code for imports
|
64 |
/**
|
65 |
*
|
66 |
* @author
|
67 |
*/
|
68 |
public class GSCatalog { |
69 |
|
70 |
//Attributes from associations
|
71 |
private Map datastores = null; |
72 |
private Map namespaces = null; |
73 |
private Map formats = null; |
74 |
private Map styles = null; |
75 |
|
76 |
/**
|
77 |
* Default constructor
|
78 |
*/
|
79 |
public GSCatalog (){
|
80 |
this.datastores = new HashMap(); |
81 |
this.namespaces = new HashMap(); |
82 |
this.formats = new HashMap(); |
83 |
this.styles = new HashMap(); |
84 |
} |
85 |
|
86 |
/**
|
87 |
* Put an element into datastores
|
88 |
* @param datastores
|
89 |
*/
|
90 |
public void addDatastore(GSDatastore item){ |
91 |
this.datastores.put(item.getId(), item);
|
92 |
} |
93 |
/**
|
94 |
* Put an element into namespaces
|
95 |
* @param namespaces
|
96 |
*/
|
97 |
public void addNamespace(GSNamespace item){ |
98 |
this.namespaces.put(item.getPrefix() ,item);
|
99 |
} |
100 |
/**
|
101 |
* Put an element into styles
|
102 |
* @param namespaces
|
103 |
*/
|
104 |
public void addStyle(GSStyle item){ |
105 |
this.styles.put(item.getId() ,item);
|
106 |
} |
107 |
|
108 |
/**
|
109 |
* Writes the catalog.xml
|
110 |
* @param file where the catalog.xml is generated
|
111 |
*/
|
112 |
|
113 |
public void toXML(File file){ |
114 |
Document dom=null; |
115 |
//get an instance of factory
|
116 |
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
117 |
try {
|
118 |
//get an instance of builder
|
119 |
DocumentBuilder db = dbf.newDocumentBuilder();
|
120 |
|
121 |
//create an instance of DOM
|
122 |
dom = db.newDocument(); |
123 |
|
124 |
}catch(ParserConfigurationException pce) { |
125 |
PublishLogger.getLog().error("ERROR GSCatalog: Error while trying to instantiate DocumentBuilder " + pce);
|
126 |
} |
127 |
//create the root element <catalog>
|
128 |
Element rootEle = dom.createElement("catalog"); |
129 |
dom.appendChild(rootEle); |
130 |
//create datastore elements
|
131 |
Element rootDsEle = dom.createElement("datastores"); |
132 |
rootEle.appendChild(rootDsEle); |
133 |
Iterator i = datastores.values().iterator();
|
134 |
while (i.hasNext()){
|
135 |
GSDatastore d = (GSDatastore) i.next(); |
136 |
rootDsEle.appendChild(d.getXMLElement(dom)); |
137 |
} |
138 |
//create namespace elements
|
139 |
Element rootNsEle = dom.createElement("namespaces"); |
140 |
rootEle.appendChild(rootNsEle); |
141 |
i = namespaces.values().iterator(); |
142 |
while (i.hasNext()){
|
143 |
GSNamespace n = (GSNamespace) i.next(); |
144 |
rootNsEle.appendChild(n.getXMLElement(dom)); |
145 |
} |
146 |
//TODO: create style elements
|
147 |
Element rootStEle = dom.createElement("styles"); |
148 |
rootEle.appendChild(rootStEle); |
149 |
i = styles.values().iterator(); |
150 |
while (i.hasNext()){
|
151 |
GSStyle s = (GSStyle) i.next(); |
152 |
rootStEle.appendChild(s.getXMLElement(dom)); |
153 |
} |
154 |
//write files
|
155 |
try
|
156 |
{ |
157 |
OutputFormat format = new OutputFormat(dom);
|
158 |
format.setIndenting(true);
|
159 |
XMLSerializer serializer = new XMLSerializer(
|
160 |
new FileOutputStream(file), format); |
161 |
serializer.serialize(dom); |
162 |
} catch(IOException ioe) { |
163 |
PublishLogger.getLog().error("ERROR GSCatalog: I can't generate the catlog.xml", ioe);
|
164 |
} |
165 |
|
166 |
} |
167 |
|
168 |
} |