public ServiceMetadata getMetadataInfoFromWMS(String urlServer) { ServiceMetadata servMetadata = new ServiceMetadata(); try { WMSClient wms = new WMSClient(urlServer); wms.connect(null); // set server information WMSServiceInformation serviceInfo = wms.getServiceInformation(); servMetadata.setAbstractStr(serviceInfo.abstr); servMetadata.setFees(serviceInfo.fees); servMetadata.setKeywords(serviceInfo.keywords); servMetadata.setName(serviceInfo.name); servMetadata.setTitle(serviceInfo.title); servMetadata.setUrl(urlServer); servMetadata.setVersion(serviceInfo.version); // I can't get from service the accessConstraints value // servMetadata.setAccessConstraints(accessConstraints); // get layers TreeMap layers = wms.getLayers(); if (layers != null) { List<Layer> lstLayers = new ArrayList<Layer>(); Set<String> keys = layers.keySet(); for (String key : keys) { WMSLayer wmsLayer = (WMSLayer) layers.get(key); Layer layer = new Layer(); layer.setName(wmsLayer.getName()); layer.setTitle(wmsLayer.getTitle()); lstLayers.add(layer); } servMetadata.setLayers(lstLayers); } // get operations Hashtable supportedOperations = serviceInfo.getSupportedOperationsByName(); if (supportedOperations != null) { List<OperationsMetadata> lstOperations = new ArrayList<OperationsMetadata>(); Set<String> keys = supportedOperations.keySet(); for (String key : keys) { OperationsMetadata opMetadata = new OperationsMetadata(); opMetadata.setName(key); opMetadata.setUrl((String) supportedOperations.get(key)); lstOperations.add(opMetadata); } servMetadata.setOperations(lstOperations); } // get contact address ContactAddressMetadata contactAddress = null; if (StringUtils.isNotEmpty(serviceInfo.address) || StringUtils.isNotEmpty(serviceInfo.addresstype) || StringUtils.isNotEmpty(serviceInfo.place) || StringUtils.isNotEmpty(serviceInfo.country) || StringUtils.isNotEmpty(serviceInfo.postcode) || StringUtils.isNotEmpty(serviceInfo.province)) { contactAddress = new ContactAddressMetadata(); contactAddress.setAddress(serviceInfo.address); contactAddress.setAddressType(serviceInfo.addresstype); contactAddress.setCity(serviceInfo.place); contactAddress.setCountry(serviceInfo.country); contactAddress.setPostCode(serviceInfo.postcode); contactAddress.setStateProvince(serviceInfo.province); } // get contact info ContactMetadata contactMetadata = null; if (contactAddress != null || StringUtils.isNotEmpty(serviceInfo.email) || StringUtils.isNotEmpty(serviceInfo.fax) || StringUtils.isNotEmpty(serviceInfo.organization) || StringUtils.isNotEmpty(serviceInfo.personname) || StringUtils.isNotEmpty(serviceInfo.function) || StringUtils.isNotEmpty(serviceInfo.phone)) { contactMetadata = new ContactMetadata(); contactMetadata.setContactAddress(contactAddress); contactMetadata.setEmail(serviceInfo.email); contactMetadata.setFax(serviceInfo.fax); contactMetadata.setOrganization(serviceInfo.organization); contactMetadata.setPerson(serviceInfo.personname); contactMetadata.setPosition(serviceInfo.function); contactMetadata.setTelephone(serviceInfo.phone); } servMetadata.setContact(contactMetadata); } catch (Exception exc) { // Show exception in log logger.error("Exception on getMetadataInfoFromWMS", exc); throw new ServerGeoException(); } return servMetadata; }
/* * (non-Javadoc) * @see es.gva.dgti.gvgeoportal.service.ogc.OGCInfoService * #getCapabilitiesFromWMS(String, String, String, boolean) */ public WMSInfo getCapabilitiesFromWMS( String urlServerWMS, TreeSet<String> listCrs, String format, boolean isCalledByWizard) throws ServerGeoException { WMSInfo wmsInfo = new WMSInfo(); // put url on object WMSInfo wmsInfo.setServiceUrl(urlServerWMS); // Create hashmap to add the layers getted to the WMSInfo object Map<String, org.gvsig.framework.web.ogc.WMSLayer> layersMap = new HashMap<String, org.gvsig.framework.web.ogc.WMSLayer>(); // Create conexion with server WMS try { WMSClient wms = new WMSClient(urlServerWMS); wms.connect(null); // set server information WMSServiceInformation serviceInfo = wms.getServiceInformation(); wmsInfo.setServiceAbstract(serviceInfo.abstr); wmsInfo.setServiceName(serviceInfo.name); wmsInfo.setServiceTitle(serviceInfo.title); // set id of the request wmsinfo (service name + calendar) int hashCode = (serviceInfo.name + Calendar.getInstance()).hashCode(); wmsInfo.setId(hashCode); // get and set version String version = wms.getVersion(); wmsInfo.setVersion(version); // get and set formats Vector formatVector = wms.getFormats(); TreeSet<String> formatSet = new TreeSet<String>(); formatSet.addAll(formatVector); wmsInfo.setFormatsSupported(formatSet); if (StringUtils.isEmpty(format)) { format = getFirstFormatSupported(formatSet); wmsInfo.setFormatSelected(format); } // check format if (isCalledByWizard || (!isCalledByWizard && formatVector.contains(format))) { wmsInfo.setFormatSelected(format); // get root layer WMSLayer rootLayer = wms.getRootLayer(); // get crs (srs) (belong to layer) Vector crsVector = rootLayer.getAllSrs(); // get and set all common crs supported TreeSet<String> crsTreeSet = new TreeSet<String>(); crsTreeSet.addAll(crsVector); wmsInfo.setCrsSupported(crsTreeSet); // Create tree with layer values List<TreeNode> tree = new ArrayList<TreeNode>(); // Create root node ArrayList<WMSLayer> children = rootLayer.getChildren(); TreeNode rootNode = new TreeNode("rootLayer_" + rootLayer.getName()); rootNode.setTitle(rootLayer.getTitle()); if (children.isEmpty()) { rootNode.setFolder(false); } else { rootNode.setFolder(true); rootNode.setExpanded(true); generateWMSChildrenNodes(children, tree, listCrs, rootNode, layersMap, wmsInfo); } // Set childrenLayers paramrootLayer.getChildren() wmsInfo.setChildrenCount(children.size()); // Only register the tree if it has a layer with crs defined if (rootNode.hasChildren()) { tree.add(rootNode); wmsInfo.setLayersTree(tree); } TreeSet<String> selCrs = new TreeSet<String>(); if (listCrs.isEmpty()) { selCrs.addAll(wmsInfo.getCrsSupported()); } else { selCrs.addAll(CollectionUtils.intersection(listCrs, wmsInfo.getCrsSupported())); } wmsInfo.setCrsSelected(selCrs); // Add map that contains info of all layers wmsInfo.setLayers(layersMap); } } catch (Exception exc) { // Show exception in log and create ServerGeoException which is // captured on controller and puts message to ajax response logger.error("Exception on getCapabilitiesFromWMS", exc); throw new ServerGeoException(); } return wmsInfo; }