Пример #1
0
  public StyleDTO(StyleImpl style) {
    assert (style != null) : "StyleImpl is NULL";

    this.name = style.getName();
    this.title = style.getTitle() == null ? "" : style.getTitle().toString();
    this.abstractText = style.getAbstract() == null ? "" : style.getAbstract().toString();
    // TODO: FIX StyleDTO(StyleImpl style) and DEL
    //        this.legendURL = style.getLegendURLs() == null ? "" :
    // style.getLegendURLs().toArray().toString();
    //        //
    //        if (style.getLegendURLs() != null) {
    //            System.out.println("\n\nURL#K\n" + style.getLegendURLs().size());
    //            for (Object o : style.getLegendURLs()) {
    //                System.out.println("\n\nURL#K\n" + o);
    //            }
    //        }
    //        if (style.getStyleSheetURL() != null) {
    //            System.out.println("\n\nURL#1\n" + style.getStyleSheetURL().toString());
    //        }
    //        if (style.getStyleURL() != null) {
    //            System.out.println("\n\nURL#2\n" + style.getStyleURL().toString());
    //        }
  }
  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$
  }