Exemplo n.º 1
0
  /**
   * This transforms all external graphics references that are relative to absolute. This is a
   * workaround to be able to visualize png and svg in relative mode, which doesn't work right now
   * in geotools. See: http://jira.codehaus.org/browse/GEOT-3235
   *
   * <p>This will not be necessary any more as soon as the geotools bug is fixed.
   *
   * @param relatedFile the related shapefile.
   * @param style the style to check.
   */
  private void makeGraphicsAbsolute(File relatedFile, Style style) {
    File parentFolder = relatedFile.getParentFile();
    Rule[] rules = SLDs.rules(style);
    for (Rule rule : rules) {
      Symbolizer[] onlineResource = rule.getSymbolizers();

      for (Symbolizer symbolizer : onlineResource) {
        if (symbolizer instanceof PointSymbolizer) {
          PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
          Graphic graphic = SLDs.graphic(pointSymbolizer);
          List<GraphicalSymbol> graphicalSymbols = graphic.graphicalSymbols();
          for (GraphicalSymbol graphicalSymbol : graphicalSymbols) {
            if (graphicalSymbol instanceof ExternalGraphic) {
              ExternalGraphic externalGraphic = (ExternalGraphic) graphicalSymbol;
              try {
                URL location = externalGraphic.getLocation();
                File urlToFile = URLUtils.urlToFile(location);
                if (urlToFile != null && !urlToFile.exists()) {
                  File newFile = new File(parentFolder, urlToFile.getPath());
                  if (newFile.exists()) {
                    externalGraphic.setLocation(newFile.toURI().toURL());
                  }
                }
              } catch (MalformedURLException e) {
                e.printStackTrace();
              }
            }
          }
        }
      }
    }
  }
 public Object[] getChildren(Object parentElement) {
   if (parentElement == null) return EMPTY_ARRAY;
   if (parentElement instanceof Style) {
     Style style = (Style) parentElement;
     Rule[] rule = SLDs.rules(style);
     return rule; // return rules
   } else if (parentElement instanceof FeatureTypeStyle) {
     FeatureTypeStyle fts = (FeatureTypeStyle) parentElement;
     List<Rule> rules = fts.rules();
     Rule[] rulesArray = (Rule[]) rules.toArray(new Rule[rules.size()]);
     return rulesArray;
   }
   return EMPTY_ARRAY;
 }