示例#1
0
 private void handleExternalSld(
     File file,
     String namedLayer,
     String layerName,
     Map<String, String> map,
     Map<String, Pair<File, URL>> legends,
     Map<String, Boolean> glgUrls)
     throws Throwable {
   LOG.info("Parsing SLD style file unavailable from style stores.");
   XMLInputFactory fac = XMLInputFactory.newInstance();
   FileInputStream is = new FileInputStream(file);
   try {
     XMLStreamReader in = fac.createXMLStreamReader(file.toURI().toURL().toString(), is);
     Pair<LinkedList<Filter>, LinkedList<StyleRef>> parsedStyles = getStyles(in, namedLayer, map);
     for (StyleRef s : parsedStyles.second) {
       if (!s.isResolved()) {
         continue;
       }
       registry.put(layerName, s.getStyle(), false);
       Pair<File, URL> p = legends.get(s.getName());
       if (p != null && p.first != null) {
         s.getStyle().setLegendFile(p.first);
       } else if (p != null) {
         s.getStyle().setLegendURL(p.second);
       }
       s.getStyle()
           .setPrefersGetLegendGraphicUrl(
               glgUrls.get(s.getStyle().getName()) != null && glgUrls.get(s.getStyle().getName()));
     }
   } finally {
     closeQuietly(is);
   }
 }
示例#2
0
  private void handleSldFromStyleStore(
      File file,
      String namedLayer,
      Map<String, String> map,
      String layerName,
      Map<String, Pair<File, URL>> legends,
      Map<String, Boolean> glgUrls) {
    // already loaded from workspace
    String styleId = file.getName().substring(0, file.getName().length() - 4);
    StyleStore store = styleManager.get(styleId);

    if (store != null) {
      LOG.info("Using SLD file loaded from style store.");
      for (Style s : store.getAll(namedLayer)) {
        s.setName(map.get(s.getName()));
        registry.put(layerName, s, false);
        Pair<File, URL> p = legends.get(s.getName());
        if (p != null && p.first != null) {
          s.setLegendFile(p.first);
        } else if (p != null) {
          s.setLegendURL(p.second);
        }
        s.setPrefersGetLegendGraphicUrl(
            glgUrls.get(s.getName()) != null && glgUrls.get(s.getName()));
      }
      return;
    }
  }
示例#3
0
 private Style findStyle(File legendFile, File stylesDir, String layerName) {
   Style style;
   if (legendFile.getParentFile().equals(stylesDir)) {
     // already loaded from style store
     String styleId = legendFile.getName().substring(0, legendFile.getName().length() - 4);
     StyleStore store = styleManager.get(styleId);
     if (store != null) {
       style = store.getStyle(null).copy();
     } else {
       LOG.warn("Style store {} was not available, trying to load directly.", styleId);
       style = registry.loadNoImport(layerName, legendFile, true);
     }
   } else {
     style = registry.loadNoImport(layerName, legendFile, true);
   }
   return style;
 }
示例#4
0
  private void extractFromSld(
      SLDStyleType sty,
      XMLAdapter adapter,
      File stylesDir,
      String layerName,
      Map<String, Pair<File, URL>> legends,
      Map<String, Boolean> glgUrls,
      Map<String, String> map)
      throws Throwable {
    String name = null, lastName = null;
    for (JAXBElement<?> elem : sty.getNameAndUserStyleAndLegendConfigurationFile()) {
      if (elem.getName().getLocalPart().equals("Name")) {
        name = elem.getValue().toString();
      } else if (elem.getName().getLocalPart().equals("LegendConfigurationFile")) {
        File legendFile = new File(adapter.resolve(elem.getValue().toString()).toURI());
        Style style = findStyle(legendFile, stylesDir, layerName);

        if (style != null) {
          if (name != null) {
            style.setName(name);
          }
          registry.putLegend(layerName, style, false);
        }
      } else if (elem.getName().getLocalPart().equals("LegendGraphicFile")) {
        LegendGraphicFile lgf = (LegendGraphicFile) elem.getValue();
        URL url = adapter.resolve(lgf.getValue());
        if (url.toURI().getScheme().equals("file")) {
          File legend = new File(url.toURI());
          legends.put(lastName, new Pair<File, URL>(legend, null));
        } else {
          legends.put(lastName, new Pair<File, URL>(null, url));
        }
        glgUrls.put(lastName, lgf.isOutputGetLegendGraphicUrl());
      } else if (elem.getName().getLocalPart().equals("UserStyle")) {
        if (name == null) {
          name = elem.getValue().toString();
        }
        LOG.debug(
            "Will load user style with name '{}', it will be known as '{}'.",
            elem.getValue(),
            name);
        map.put(elem.getValue().toString(), name);
        lastName = name;
        name = null;
      }
    }
  }