Mercurial > dive4elements > gnv-client
comparison gnv/src/main/java/de/intevation/gnv/action/mapviewer/parser/XMLExternalCallParser.java @ 681:15ac78a91d1b
Removed trailing whitespace.
gnv/trunk@852 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 29 Mar 2010 08:04:15 +0000 |
parents | b88e881e8e94 |
children | d49e8695786c |
comparison
equal
deleted
inserted
replaced
680:ba3370dbc8c5 | 681:15ac78a91d1b |
---|---|
22 /** | 22 /** |
23 * @author Tim Englich <tim.englich@intevation.de> | 23 * @author Tim Englich <tim.englich@intevation.de> |
24 * | 24 * |
25 */ | 25 */ |
26 public class XMLExternalCallParser implements ExternalCallParser { | 26 public class XMLExternalCallParser implements ExternalCallParser { |
27 | 27 |
28 /** | 28 /** |
29 * the logger, used to log exceptions and additonaly information | 29 * the logger, used to log exceptions and additonaly information |
30 */ | 30 */ |
31 private static Logger log = Logger.getLogger(XMLExternalCallParser.class); | 31 private static Logger log = Logger.getLogger(XMLExternalCallParser.class); |
32 | 32 |
33 private static String XPATH_GEOMETRY = "/gnviewer/location/data"; | 33 private static String XPATH_GEOMETRY = "/gnviewer/location/data"; |
34 private static String XPATH_SRS = "/gnviewer/location/srs"; | 34 private static String XPATH_SRS = "/gnviewer/location/srs"; |
35 private static String XPATH_MAPSERVICES_NODESET = "/gnviewer/mapservices/mapservice"; | 35 private static String XPATH_MAPSERVICES_NODESET = "/gnviewer/mapservices/mapservice"; |
36 private static String XPATH_LAYER = "layer"; | 36 private static String XPATH_LAYER = "layer"; |
37 private static String ATTRIBUTE_ID = "id"; | 37 private static String ATTRIBUTE_ID = "id"; |
38 private static String ATTRIBUTE_NAME = "name"; | 38 private static String ATTRIBUTE_NAME = "name"; |
39 private static String ATTRIBUTE_TYPE = "type"; | 39 private static String ATTRIBUTE_TYPE = "type"; |
40 private static String ATTRIBUTE_URL = "url"; | 40 private static String ATTRIBUTE_URL = "url"; |
41 | 41 |
42 private String geometry = null; | 42 private String geometry = null; |
43 private String srs = null; | 43 private String srs = null; |
44 | 44 |
45 private Collection<MapService> mapServices = null; | 45 private Collection<MapService> mapServices = null; |
46 | 46 |
47 private InputStream inputStream = null; | 47 private InputStream inputStream = null; |
48 | 48 |
49 /** | 49 /** |
50 * Constructor | 50 * Constructor |
51 */ | 51 */ |
73 public void parse() throws ExternalCallParserException { | 73 public void parse() throws ExternalCallParserException { |
74 if (inputStream != null){ | 74 if (inputStream != null){ |
75 XMLUtils xmlUtils = new XMLUtils(); | 75 XMLUtils xmlUtils = new XMLUtils(); |
76 Document document = xmlUtils.readDocument(this.inputStream); | 76 Document document = xmlUtils.readDocument(this.inputStream); |
77 if (document != null){ | 77 if (document != null){ |
78 | 78 |
79 this.geometry = xmlUtils.getStringXPath(document, XPATH_GEOMETRY); | 79 this.geometry = xmlUtils.getStringXPath(document, XPATH_GEOMETRY); |
80 this.srs = xmlUtils.getStringXPath(document, XPATH_SRS); | 80 this.srs = xmlUtils.getStringXPath(document, XPATH_SRS); |
81 NodeList mapservicesNodes = | 81 NodeList mapservicesNodes = |
82 xmlUtils.getNodeSetXPath(document, XPATH_MAPSERVICES_NODESET); | 82 xmlUtils.getNodeSetXPath(document, XPATH_MAPSERVICES_NODESET); |
83 if (mapservicesNodes != null){ | 83 if (mapservicesNodes != null){ |
84 this.mapServices = new ArrayList<MapService>(mapservicesNodes.getLength()); | 84 this.mapServices = new ArrayList<MapService>(mapservicesNodes.getLength()); |
85 for (int i = 0; i < mapservicesNodes.getLength(); i++){ | 85 for (int i = 0; i < mapservicesNodes.getLength(); i++){ |
86 Element mapserviceNode = (Element)mapservicesNodes.item(i); | 86 Element mapserviceNode = (Element)mapservicesNodes.item(i); |
93 layer = new ArrayList<Layer>(layerNodes.getLength()); | 93 layer = new ArrayList<Layer>(layerNodes.getLength()); |
94 layer = this.extractLayer(layer, null, layerNodes); | 94 layer = this.extractLayer(layer, null, layerNodes); |
95 }else{ | 95 }else{ |
96 log.debug("No Layer given for this Mapservice"); | 96 log.debug("No Layer given for this Mapservice"); |
97 } | 97 } |
98 MapService mapService = | 98 MapService mapService = |
99 new DefaultMapService(mapserviceID, layer, | 99 new DefaultMapService(mapserviceID, layer, |
100 mapserviceType, mapserviceUrl); | 100 mapserviceType, mapserviceUrl); |
101 this.mapServices.add(mapService); | 101 this.mapServices.add(mapService); |
102 } | 102 } |
103 | 103 |
104 }else{ | 104 }else{ |
105 String errMsg = "XML-Document does not contain any Mapservices which are required."; | 105 String errMsg = "XML-Document does not contain any Mapservices which are required."; |
106 log.error(errMsg); | 106 log.error(errMsg); |
107 throw new ExternalCallParserException(errMsg); | 107 throw new ExternalCallParserException(errMsg); |
108 } | 108 } |
109 | 109 |
110 }else{ | 110 }else{ |
111 String errMsg = "XML-Document could not be read from InputStream."; | 111 String errMsg = "XML-Document could not be read from InputStream."; |
112 log.error(errMsg); | 112 log.error(errMsg); |
113 throw new ExternalCallParserException(errMsg); | 113 throw new ExternalCallParserException(errMsg); |
114 } | 114 } |
116 String errMsg = "No InputStream given for parsing the Call."; | 116 String errMsg = "No InputStream given for parsing the Call."; |
117 log.error(errMsg); | 117 log.error(errMsg); |
118 throw new ExternalCallParserException(errMsg); | 118 throw new ExternalCallParserException(errMsg); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 /** | 122 /** |
123 * This Method extracts all Layers and put them into the Collection. | 123 * This Method extracts all Layers and put them into the Collection. |
124 * @param layer | 124 * @param layer |
125 * @param groupId | 125 * @param groupId |
126 * @param layerNodes | 126 * @param layerNodes |
131 for (int i = 0; i < layerNodes.getLength(); i++){ | 131 for (int i = 0; i < layerNodes.getLength(); i++){ |
132 Element layerNode = (Element)layerNodes.item(i); | 132 Element layerNode = (Element)layerNodes.item(i); |
133 String id = layerNode.getAttribute(ATTRIBUTE_ID); | 133 String id = layerNode.getAttribute(ATTRIBUTE_ID); |
134 String name = layerNode.getAttribute(ATTRIBUTE_NAME); | 134 String name = layerNode.getAttribute(ATTRIBUTE_NAME); |
135 NodeList localLayerNodes = xmlUtils.getNodeSetXPath(layerNode, XPATH_LAYER); | 135 NodeList localLayerNodes = xmlUtils.getNodeSetXPath(layerNode, XPATH_LAYER); |
136 Layer tmpLayer = new DefaultLayer(id, name, | 136 Layer tmpLayer = new DefaultLayer(id, name, |
137 (localLayerNodes != null && | 137 (localLayerNodes != null && |
138 localLayerNodes.getLength() > 0), | 138 localLayerNodes.getLength() > 0), |
139 groupId); | 139 groupId); |
140 layer.add(tmpLayer); | 140 layer.add(tmpLayer); |
141 if (localLayerNodes != null && localLayerNodes.getLength() > 0){ | 141 if (localLayerNodes != null && localLayerNodes.getLength() > 0){ |
142 layer = this.extractLayer(layer, id, localLayerNodes); | 142 layer = this.extractLayer(layer, id, localLayerNodes); |
143 } | 143 } |