// XXX: Consider doing more SLD when WMS post is a go
  public boolean canStyle(String SyleID, Object value) {
    if (value == null) return false;
    if (value instanceof Style) return !Double.isNaN(SLDs.rasterOpacity((Style) value));

    if (value instanceof StyleImpl && getRenderContext().getGeoResource().canResolve(Layer.class)) {
      try {
        Layer layer =
            getRenderContext()
                .getGeoResource()
                .resolve(Layer.class, ProgressManager.instance().get());
        if (layer.getStyles().contains(value)) {
          return true;
        } else {
          return false;
        }
      } catch (IOException e) {
        return false;
      }
    }

    return false;
  }
  private static void writeLayer(ILayer layer, BufferedWriter out) throws IOException {
    Layer wmsLayer = layer.getResource(Layer.class, null);
    WebMapServer wms = layer.getResource(WebMapServer.class, null);
    WMSCapabilities caps = wms.getCapabilities();
    String version = caps.getVersion();

    String title = wms.getCapabilities().getService().getTitle();
    int hidden = layer.isVisible() ? 1 : 0;
    int info = layer.isApplicable("info") ? 1 : 0; // $NON-NLS-1$
    String get = caps.getRequest().getGetCapabilities().getGet().toExternalForm();
    System.out.println(get);
    if (get.endsWith("&")) get = get.substring(0, get.length() - 1); // $NON-NLS-1$
    append(
        4,
        out,
        "<Layer hidden=\""
            + hidden
            + "\" queryable=\""
            + info
            + "\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    append(
        6,
        out,
        "<Server service=\"OGC:WMS\" title=\""
            + title
            + "\" version=\""
            + version
            + "\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    append(
        8,
        out,
        "<OnlineResource method=\"GET\" xlink:href=\""
            + get
            + "\" xlink:type=\"simple\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
    append(6, out, "</Server>"); // $NON-NLS-1$
    append(6, out, "<Name>" + wmsLayer.getName() + "</Name>"); // $NON-NLS-1$ //$NON-NLS-2$
    append(6, out, "<Title>" + wmsLayer.getTitle() + "</Title>"); // $NON-NLS-1$ //$NON-NLS-2$
    if (!Double.isNaN(wmsLayer.getScaleHintMin()))
      append(
          6,
          out,
          "<sld:MinScaleDenominator>"
              + wmsLayer.getScaleHintMin()
              + "</sld:MinScaleDenominator>"); //$NON-NLS-1$ //$NON-NLS-2$
    if (!Double.isNaN(wmsLayer.getScaleHintMax()))
      append(
          6,
          out,
          "<sld:MaxScaleDenominator>"
              + wmsLayer.getScaleHintMax()
              + "</sld:MaxScaleDenominator>"); //$NON-NLS-1$ //$NON-NLS-2$
    for (String srs : (Set<String>) wmsLayer.getSrs()) {
      append(6, out, "<SRS>" + srs + "</SRS>"); // $NON-NLS-1$ //$NON-NLS-2$
    }
    append(6, out, "<FormatList>"); // $NON-NLS-1$

    boolean first = true; // TODO: look up preferences?
    for (String format : caps.getRequest().getGetMap().getFormats()) {
      if (first) {
        append(
            8, out, "<Format current=\"1\">" + format + "</Format>"); // $NON-NLS-1$ //$NON-NLS-2$
        first = false;
      }
      append(8, out, "<Format>" + format + "</Format>"); // $NON-NLS-1$ //$NON-NLS-2$
    }
    append(6, out, "</FormatList>"); // $NON-NLS-1$

    first = true; // TODO: look up on styleblackboard?
    append(6, out, "<StyleList>"); // $NON-NLS-1$
    Object styles = wmsLayer.getStyles();
    List list;
    if (styles instanceof String) list = Collections.singletonList(styles);
    else if (styles instanceof List) list = (List) styles;
    else list = Collections.emptyList();
    for (Iterator<Object> iter = list.iterator(); iter.hasNext(); ) {
      Object next = iter.next();
      if (next instanceof String) {
        String style = (String) next;
        first = writeStyle(style, style, first, out);
      } else if (next instanceof StyleImpl) {
        StyleImpl style = (StyleImpl) next;
        writeStyle(style.getName(), style.getTitle().toString(), first, out);
      }
    }
    append(6, out, "</StyleList>"); // $NON-NLS-1$
    append(4, out, "</Layer>"); // $NON-NLS-1$
  }