Project

General

Profile

« Previous | Next » 

Revision 329a2264

Added by Andreas Müller over 12 years ago

add geoservice mapping functionality

View differences:

cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/geo/GeoServiceArea.java
12 12
import java.io.ByteArrayInputStream;
13 13
import java.io.IOException;
14 14
import java.io.InputStream;
15
import java.io.StringReader;
16 15
import java.io.StringWriter;
17 16
import java.util.ArrayList;
18 17
import java.util.HashMap;
......
24 23
import javax.xml.stream.XMLStreamException;
25 24
import javax.xml.stream.XMLStreamWriter;
26 25

  
26
import org.apache.log4j.Logger;
27 27
import org.jdom.Element;
28 28
import org.jdom.JDOMException;
29 29
import org.jdom.Namespace;
30
import org.xml.sax.InputSource;
31 30

  
32 31
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
33 32
import eu.etaxonomy.cdm.common.CdmUtils;
......
44 43
 *
45 44
 */
46 45
public class GeoServiceArea {
47
	
46
	@SuppressWarnings("unused")
47
	private static final Logger logger = Logger.getLogger(GeoServiceArea.class);
48

  
48 49
	private static final String VALUE = "value";
49 50
	private static final String FIELD = "field";
50 51
	private static final String LAYER = "layer";
51 52
	private static final String AREA = "area";
52 53
	private static final String MAP_SERVICE_NAMESPACE = "http://www.etaxonomy.eu/cdm";
53 54
	private static final String MAP_SERVICE = "mapService";
55

  
56
	
54 57
	TreeSet<SubArea> subAreas = new TreeSet<SubArea>(); 
55 58
	
56 59
	private class SubArea implements Comparable<SubArea>{
......
112 115
		subAreas.add(newArea);
113 116
	}
114 117
	
118
	/**
119
	 * Returns the areas as a layer, field, area nested map.
120
	 * @return
121
	 */
115 122
	public Map<String, Map<String, List<String>>> getAreas(){
116 123
		Map<String, Map<String, List<String>>> result = new HashMap<String, Map<String,List<String>>>();
117 124
				
......
137 144
		return result;
138 145
	}
139 146
	
147
	
148
	public static boolean isAreaMapping(String xml){
149
		//TODO check by parsing or only testing root + namespace
150
		GeoServiceArea mapping = valueOf(xml);
151
		if (mapping != null){
152
			return true;
153
		}else{
154
			return false;
155
		}
156
	}
157
	
140 158
	public static GeoServiceArea valueOf (String xml){
159
		if (xml == null){
160
			return null;
161
		}
162
		
141 163
//		StringReader reader = new StringReader (xml);
142 164
//		(new InputSource(reader));
143 165
//		InputStream is = new java.io.StringBufferInputStream(xml);
......
164 186
				}
165 187
				return result;	
166 188
			}
167
				
168
			
189
	
169 190
			
170 191
		} catch (JDOMException e) {
171 192
			throw new RuntimeException(e);
......
174 195
		}
175 196
	}
176 197
	
198
	/**
199
	 * @return
200
	 * @throws XMLStreamException
201
	 */
202
	//TODO use JAXB or other marshalling techniques
177 203
	public String toXml() throws XMLStreamException{
178 204
		XMLStreamWriter writer = null;
179 205
			XMLOutputFactory factory = XMLOutputFactory.newInstance();
......
231 257
		
232 258
	}
233 259

  
234
	/**
235
	 * Transforms the area to an geoservice area
236
	 * @param area the NamedArea
237
	 * @param appConfig for future use
238
	 * @return
239
	 */
240
	public static GeoServiceArea valueOf(NamedArea area, ICdmApplicationConfiguration appConfig) {
241
		for (Annotation annotation : area.getAnnotations()){
242
			if (AnnotationType.TECHNICAL().equals(annotation.getAnnotationType())){
243
				GeoServiceArea areas = valueOf(annotation.getText());
244
				return areas;
245
			}
246
		}
247
		
248
		return null;
249
	}
250

  
251
	/**
252
	 * Saves the mapping data to where ever necessary
253
	 * @param areaBangka
254
	 * @param geoServiceArea
255
	 * @throws XMLStreamException
256
	 */
257
	public static void set(NamedArea areaBangka, GeoServiceArea geoServiceArea) throws XMLStreamException {
258
		AnnotationType type = AnnotationType.TECHNICAL();
259
		Annotation annotation = Annotation.NewInstance(geoServiceArea.toXml(), type, Language.DEFAULT());
260
		areaBangka.addAnnotation(annotation);
261
	}
262 260

  
263 261
	public int size() {
264 262
		return this.subAreas.size();

Also available in: Unified diff