Revision 10627 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/gml/GMLFileCreator.java

View differences:

GMLFileCreator.java
7 7
import java.io.Writer;
8 8

  
9 9
import org.cresques.cts.IProjection;
10
import org.geotools.xml.gml.GMLSchema;
11 10

  
12 11
import com.hardcode.gdbms.engine.values.Value;
13
import com.iver.cit.gvsig.fmap.core.IFeature;
14 12
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
15
import com.iver.cit.gvsig.fmap.edition.EditionException;
16 13
import com.iver.utiles.StringUtilities;
17 14
import com.vividsolutions.jts.geom.Geometry;
18 15

  
......
60 57
 *
61 58
 * $Id$
62 59
 * $Log$
63
 * Revision 1.3  2006-11-20 08:12:41  jorpiell
60
 * Revision 1.4  2007-03-06 17:08:56  caballero
61
 * Exceptions
62
 *
63
 * Revision 1.3  2006/11/20 08:12:41  jorpiell
64 64
 * Se ha sustituido el car?cter & por &. El parser de XML lo requiere
65 65
 *
66 66
 * Revision 1.2  2006/08/10 12:03:43  jorpiell
......
83 83
	private Rectangle2D extent = null;
84 84
	private File m_File = null;
85 85
	private FieldDescription[] attributes = null;
86
		
86

  
87 87
	public GMLFileCreator(File file,String schemaFileName) throws IOException{
88 88
		this.m_File = file;
89 89
		this.schemaFileName = schemaFileName;
90 90
	}
91
	
91

  
92 92
	/**
93
	 * This method creates the GML head file. It must be 
93
	 * This method creates the GML head file. It must be
94 94
	 * called before start to add geometries.
95 95
	 * @throws IOException
96 96
	 */
97
	public void initialize() throws IOException{		
97
	public void initialize() throws IOException{
98 98
		writer = new FileWriter(m_File);
99 99
		writer.write(getInitFile());
100 100
		writer.write(getBoundedBy());
101 101
		featureWriter = new com.vividsolutions.jts.io.gml2.GMLWriter();
102 102
		featureWriter.setPrefix("gml");
103 103
	}
104
	
104

  
105 105
	/**
106 106
	 * Intert a new Feature
107 107
	 * @param geom
......
112 112
			writer.write(getInitGeomAttribute());
113 113
			featureWriter.write(geom,writer);
114 114
			writer.write(getEndGeomAttribute());
115
			
115

  
116 116
			for (int i=0 ; i<attributes.length ; i++){
117 117
				String attributeName = this.attributes[i].getFieldName();
118 118
				String attibuteValue = StringUtilities.replace(attributes[i].toString(),"&","&amp;");
119 119
				writer.write(getAttribute(attributeName,attibuteValue));
120 120
			}
121
			
122
			writer.write(getEndFeature());	
121

  
122
			writer.write(getEndFeature());
123 123
	}
124
	
125
	
126 124

  
125

  
126

  
127 127
	/**
128 128
	 * Writes the GML file
129
	 * @throws IOException 
129
	 * @throws IOException
130 130
	 *
131 131
	 */
132 132
	public void writeFile() throws IOException {
133 133
		writer.write(getEndFile());
134
		writer.close();		
134
		writer.close();
135 135
	}
136 136

  
137 137
	/**
......
141 141
	 */
142 142
	public void setBoundedBy(Rectangle2D extent, IProjection proj) {
143 143
		this.extent = extent;
144
		this.projection = proj;		
144
		this.projection = proj;
145 145
	}
146
	
146

  
147 147
	/**
148 148
	 * Sets the attributes collection
149 149
	 * @param attributes
......
151 151
	public void setAttibutes(FieldDescription[] attributes){
152 152
		this.attributes = attributes;
153 153
	}
154
	
154

  
155 155
	/**
156 156
	 *  Creates an init Tag for a feature member
157 157
	 * @return
......
161 161
		string.append("<gml:featureMember>\n");
162 162
		string.append("<" + GMLSchemaCreator.NAMESPACE + ":" + GMLSchemaCreator.getFeatureName() + ">");
163 163
		return string.toString();
164
		
164

  
165 165
	}
166
	
166

  
167 167
	/**
168 168
	 * Creates an end Tag for a feature member
169 169
	 * @return
......
174 174
		string.append("</gml:featureMember>");
175 175
		return string.toString();
176 176
	}
177
	
177

  
178 178
	/**
179 179
	 * Creates the GML File first line
180 180
	 * @param fileName
......
187 187
		string.append("<gml:FeatureCollection ");
188 188
		string.append("xmlns:" + GMLSchemaCreator.NAMESPACE + "=\"" + GMLSchemaCreator.TARGET_NAMESPACE + "\" ");
189 189
		string.append("xmlns:gml=\"http://www.opengis.net/gml\" ");
190
		string.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "); 
190
		string.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
191 191
		string.append("xsi:schemaLocation=\"" + GMLSchemaCreator.TARGET_NAMESPACE + " " + schemaFileName + "\"");
192 192
		string.append(">");
193 193
		return string.toString();
194 194
	}
195
	
195

  
196 196
	/**
197 197
	 * Creates the GML Attributes description
198 198
	 * @return
......
202 202
		string.append("<" + GMLSchemaCreator.NAMESPACE + ":" + GMLSchemaCreator.GML_GEOMETRY + ">");
203 203
		return string.toString();
204 204
	}
205
	
205

  
206 206
	/**
207 207
	 * Creates the GML attribute code
208 208
	 * @param attributeName
......
216 216
		string.append("</" + GMLSchemaCreator.NAMESPACE + ":" + attributeName + ">\n");
217 217
		return string.toString();
218 218
	}
219
	
219

  
220 220
	/**
221 221
	 * Creates the GML Attributes description
222 222
	 */
......
235 235
		string.append("</gml:FeatureCollection>");
236 236
		return string.toString();
237 237
	}
238
	
238

  
239 239
	/**
240 240
	 * Creates the boundedBy param
241 241
	 * @return
......
250 250
	    string.append(extent.getMaxX() + "," + extent.getMaxY() + "</gml:coordinates>");
251 251
	    string.append("</gml:Box>");
252 252
	    string.append("</gml:boundedBy>");
253
	    return string.toString();	    
253
	    return string.toString();
254 254
	}
255
	
256
	
257 255

  
256

  
257

  
258 258
}

Also available in: Unified diff