/**
   * Retrieves the WMS's capabilities document.
   *
   * @param scaleHintUnitsPerDiaPixel true if the scalehint must be in units per diagonal of a pixel
   * @return Capabilities as {@link Document}
   */
  private Document findCapabilities(Boolean scaleHintUnitsPerDiaPixel) throws Exception {
    // set the Scalehint units per diagonal pixel setting.
    WMS wms = getWMS();
    WMSInfo info = wms.getServiceInfo();
    MetadataMap mm = info.getMetadata();
    mm.put(WMS.SCALEHINT_MAPUNITS_PIXEL, scaleHintUnitsPerDiaPixel);
    info.getGeoServer().save(info);

    GetCapabilitiesTransformer tr =
        new GetCapabilitiesTransformer(wms, BASE_URL, FORMATS, LEGEND_FORMAT, null);
    GetCapabilitiesRequest req = new GetCapabilitiesRequest();
    req.setBaseUrl(BASE_URL);
    req.setVersion(WMS.VERSION_1_1_1.toString());

    Document dom = WMSTestSupport.transform(req, tr);

    Element root = dom.getDocumentElement();
    Assert.assertEquals(WMS.VERSION_1_1_1.toString(), root.getAttribute("version"));

    return dom;
  }
  /**
   * @see
   *     org.geoserver.wms.ExtendedCapabilitiesProvider#encode(org.geoserver.wms.ExtendedCapabilitiesProvider.Translator,
   *     org.geoserver.wms.WMSInfo, org.geotools.util.Version)
   */
  public void encode(final Translator tx, final WMSInfo wms, final GetCapabilitiesRequest request)
      throws IOException {
    Version version = WMS.version(request.getVersion(), true);
    if (!WMS.VERSION_1_1_1.equals(version) || !isTiled(request)) {
      return;
    }

    String namespacePrefixFilter = request.getNamespace();
    Iterable<TileLayer> tileLayers = gwc.getTileLayersByNamespacePrefix(namespacePrefixFilter);

    for (TileLayer layer : tileLayers) {

      Set<String> layerGrids = layer.getGridSubsets();

      for (String gridId : layerGrids) {
        GridSubset grid = layer.getGridSubset(gridId);
        for (MimeType mime : layer.getMimeTypes()) {
          vendorSpecificTileset(tx, layer, grid, mime.getFormat());
        }
      }
    }
  }