private JSONObj storeDetails(JSONObj json, StoreInfo store, HttpServletRequest req) throws IOException { store(json, store); JSONObj connection = new JSONObj(); Map<String, Serializable> params = store.getConnectionParameters(); for (Entry<String, Serializable> param : params.entrySet()) { String key = param.getKey(); Object value = param.getValue(); String text = value == null ? null : value.toString(); connection.put(key, text); } if (store instanceof CoverageStoreInfo) { CoverageStoreInfo info = (CoverageStoreInfo) store; connection.put("raster", info.getURL()); } if (store instanceof WMSStoreInfo) { WMSStoreInfo info = (WMSStoreInfo) store; json.put("wms", info.getCapabilitiesURL()); } json.put("connection", connection); json.put("error", IO.error(new JSONObj(), store.getError())); if (store.isEnabled()) { resources(store, json.putArray("resources"), req); } json.put("layer-count", layerCount(store)); return json; }
private String source(StoreInfo store) { if (store instanceof CoverageStoreInfo) { CoverageStoreInfo coverage = (CoverageStoreInfo) store; return sourceURL(coverage.getURL()); } GeoServerResourceLoader resourceLoader = geoServer.getCatalog().getResourceLoader(); Map<String, Serializable> params = ResourcePool.getParams(store.getConnectionParameters(), resourceLoader); if (params.containsKey("dbtype")) { // See JDBCDataStoreFactory for details String host = Converters.convert(params.get("host"), String.class); String port = Converters.convert(params.get("port"), String.class); String dbtype = Converters.convert(params.get("dbtype"), String.class); String schema = Converters.convert(params.get("schema"), String.class); String database = Converters.convert(params.get("database"), String.class); StringBuilder source = new StringBuilder(); source.append(host); if (port != null) { source.append(':').append(port); } source.append('/').append(dbtype).append('/').append(database); if (schema != null) { source.append('/').append(schema); } return source.toString(); } else if (store instanceof WMSStoreInfo) { String url = ((WMSStoreInfo) store).getCapabilitiesURL(); return url; } else if (params.keySet().contains("directory")) { String directory = Converters.convert(params.get("directory"), String.class); return sourceFile(directory); } else if (params.keySet().contains("file")) { String file = Converters.convert(params.get("file"), String.class); return sourceFile(file); } if (params.containsKey("url")) { String url = Converters.convert(params.get("url"), String.class); return sourceURL(url); } for (Object value : params.values()) { if (value instanceof URL) { return source((URL) value); } if (value instanceof File) { return source((File) value); } if (value instanceof String) { String text = (String) value; if (text.startsWith("file:")) { return sourceURL(text); } else if (text.startsWith("http:") || text.startsWith("https:") || text.startsWith("ftp:")) { return text; } } } return "undertermined"; }