| 83 | | |
| 84 | | String remainingString = (String) request.getResourceRef().getRemainingPart(); |
| 85 | | String myReqLayerName = null; |
| 86 | | if (remainingString == null) { |
| 87 | | // request was made to ...rest/layers/ |
| | 85 | // TODO this is really the kind of stuff RESTlet.org could do for us |
| | 86 | //String remainingString = (String) request.getResourceRef().getRemainingPart(); |
| | 87 | |
| | 88 | String lastSegment = request.getResourceRef().getLastSegment(); |
| | 89 | String layerName = null; |
| | 90 | String format = null; |
| | 91 | if(0 < lastSegment.lastIndexOf(".")) { |
| | 92 | String[] splitStr = lastSegment.split("\\."); |
| | 93 | layerName = splitStr[0]; |
| | 94 | format = splitStr[1]; |
| | 95 | } else { |
| | 96 | layerName = lastSegment; |
| | 97 | } |
| | 98 | |
| | 99 | if(format != null && format.equalsIgnoreCase("json")) { |
| | 100 | getVariants().add(new Variant(MediaType.APPLICATION_JSON)); |
| | 101 | } else { |
| 89 | | currentLayer = null; |
| 90 | | } else if (remainingString.indexOf('.') == -1) { |
| 91 | | // no extension provided, default to xml |
| 92 | | getVariants().add(new Variant(MediaType.TEXT_XML)); |
| 93 | | myReqLayerName = remainingString; |
| 94 | | currentLayer = tlDispatcher.getLayers().get(myReqLayerName); |
| 95 | | } else if (remainingString.indexOf('.') != -1) { |
| 96 | | myReqLayerName = remainingString.substring(0, remainingString |
| 97 | | .indexOf('.')); |
| 98 | | String format = remainingString.substring(remainingString |
| 99 | | .indexOf('.') + 1); |
| 100 | | if (format.equals("xml")) { |
| 101 | | getVariants().add(new Variant(MediaType.TEXT_XML)); |
| 102 | | } else if (format.equals("json")) { |
| 103 | | getVariants().add(new Variant(MediaType.APPLICATION_JSON)); |
| 104 | | } else if (format.equals("text")) { |
| 105 | | getVariants().add(new Variant(MediaType.TEXT_PLAIN)); |
| 106 | | } |
| 107 | | currentLayer = tlDispatcher.getLayers().get(myReqLayerName); |
| 108 | | } |
| 109 | | |
| | 103 | } |
| | 104 | |
| | 105 | if(layerName != null && ! layerName.equalsIgnoreCase("layers")) { |
| | 106 | currentLayer = tlDispatcher.getLayers().get(layerName); |
| | 107 | } |
| 118 | | TileLayer tl = currentLayer; |
| 119 | | if (variant.getMediaType().equals(MediaType.TEXT_PLAIN)) { |
| 120 | | // create a text representation of the current layer |
| 121 | | result = getStringRepresentation(currentLayer); |
| 122 | | } else if (tl == null |
| 123 | | && variant.getMediaType().equals(MediaType.TEXT_XML)) { |
| 124 | | // create a dom representation that will list of all available layers |
| 125 | | result = getDomRepresentationAsListOfLayers(); |
| 126 | | } else if (tl != null && variant.getMediaType().equals(MediaType.TEXT_XML)) { |
| 127 | | // create xml representation of the currentLayer |
| 128 | | result = getXMLRepresentation(currentLayer); |
| 129 | | } else if (variant.getMediaType().equals(MediaType.APPLICATION_JSON)) { |
| 130 | | // create JSONRepresentation of the currentLayer |
| 131 | | result = getJsonRepresentation(currentLayer); |
| | 116 | |
| | 117 | if(currentLayer == null) { |
| | 118 | //if(variant.getMediaType() == MediaType.APPLICATION_JSON) { |
| | 119 | // result = getJSONRepresentationAsListOfLayers(); |
| | 120 | //} else { |
| | 121 | result = getDomRepresentationAsListOfLayers(); |
| | 122 | //} |
| | 123 | } else { |
| | 124 | if(variant.getMediaType() == MediaType.APPLICATION_JSON) { |
| | 125 | result = getXMLRepresentation(currentLayer); |
| | 126 | } else { |
| | 127 | result = getJsonRepresentation(currentLayer); |
| | 128 | } |