-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GEOS-8245] Named layer validation for style groups
- Loading branch information
1 parent
5d839b3
commit 9972392
Showing
9 changed files
with
511 additions
and
257 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/main/src/main/java/org/geoserver/catalog/SLDNamedLayerValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,63 @@ | |||
package org.geoserver.catalog; | |||
|
|||
import org.geoserver.platform.ServiceException; | |||
import org.geotools.styling.NamedStyle; | |||
import org.geotools.styling.Style; | |||
import org.geotools.styling.StyledLayer; | |||
import org.geotools.styling.StyledLayerDescriptor; | |||
import org.opengis.referencing.crs.CoordinateReferenceSystem; | |||
|
|||
import java.io.IOException; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
|
|||
/** | |||
* Created by tbarsballe on 2017-08-21. | |||
*/ | |||
public class SLDNamedLayerValidator extends SLDVisitorAdapter { | |||
|
|||
public List<Exception> validationErrors = new ArrayList<>(); | |||
|
|||
public SLDNamedLayerValidator(Catalog catalog, CoordinateReferenceSystem fallbackCrs) { | |||
super(catalog, fallbackCrs); | |||
} | |||
|
|||
public List<Exception> getValidationErrors() { | |||
return validationErrors; | |||
} | |||
|
|||
@Override | |||
public SLDNamedLayerValidator apply(StyledLayerDescriptor sld) { | |||
try { | |||
super.apply(sld); | |||
} catch (Exception e) { | |||
validationErrors.add(e); | |||
} | |||
return this; | |||
} | |||
|
|||
@Override | |||
public PublishedInfo visitNamedLayer(StyledLayer namedLayer) { | |||
PublishedInfo p = catalog.getLayerGroupByName(namedLayer.getName()); | |||
if (p == null) { | |||
p = catalog.getLayerByName(namedLayer.getName()); | |||
} | |||
if (p == null) { | |||
validationErrors.add(new Exception("No layer or layer group named '" + namedLayer.getName()+ "' found in the catalog")); | |||
} | |||
return p; | |||
} | |||
|
|||
@Override | |||
public Style visitNamedStyle(StyledLayer layer, NamedStyle namedStyle, LayerInfo info) throws IOException { | |||
StyleInfo s = catalog.getStyleByName(namedStyle.getName()); | |||
if (s == null) { | |||
validationErrors.add(new Exception("No style named '" + namedStyle.getName()+ "' found in the catalog")); | |||
} | |||
return s.getStyle(); | |||
} | |||
|
|||
public static List<Exception> validate(Catalog catalog, StyledLayerDescriptor sld) { | |||
return new SLDNamedLayerValidator(catalog, null).apply(sld).getValidationErrors(); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.