@Test public void validate() throws IOException, ParseException { Reader reader = MapboxTestUtils.readerTestStyle("fillStyleTest.json"); List<Exception> problems = MapBoxStyle.validate(reader); assertTrue("fillStyleTest validate", problems.isEmpty()); reader = MapboxTestUtils.readerTestStyle("styleInvalidName.json"); problems = MapBoxStyle.validate(reader); assertEquals("styleInvalidName 1 failure", 1, problems.size()); reader = MapboxTestUtils.readerTestStyle("styleInvalidLayers.json"); problems = MapBoxStyle.validate(reader); assertEquals("styleInvalidLayers 2 failure", 2, problems.size()); }
public static List<Exception> validate(Reader reader) { List<Exception> problems = new ArrayList<Exception>(); MBStyleParser parser = new MBStyleParser(); MBStyle style; try { style = parser.parse(reader); } catch (Exception invalid) { problems.add(invalid); return problems; } List<MBLayer> layers = Collections.emptyList(); try { layers = style.layers(); if (layers.isEmpty()) { problems.add(new MBFormatException("No layers defined")); } } catch (MBFormatException layersUnavailable) { problems.add(layersUnavailable); } boolean hasVisibleLayer = false; for (MBLayer layer : layers) { if (!layer.visibility()) { continue; } try { List<FeatureTypeStyle> featureTypeStyle = layer.transform(style); if (featureTypeStyle != null) { hasVisibleLayer = true; } } catch (Exception invalid) { problems.add( (MBFormatException) new MBFormatException( "Layer " + layer.getId() + ":" + invalid.getMessage()) .initCause(invalid)); return problems; } } if (!hasVisibleLayer) { problems.add(new MBFormatException("No layers were visible")); } else { try { StyledLayerDescriptor sld = style.transform(); if (sld.getStyledLayers().length == 0) { problems.add( new MBFormatException( "Generated sld for " + sld.getName() + " is empty.")); } else { for (StyledLayer layer : sld.getStyledLayers()) { if (layer instanceof NamedLayer) { NamedLayer named = (NamedLayer) layer; if (named.styles().isEmpty()) { problems.add( new MBFormatException( "Generated named layer for " + named.getName() + " is empty.")); } else { for (Style layerStyle : named.styles()) { if (layerStyle instanceof FeatureTypeStyle) { FeatureTypeStyle fts = (FeatureTypeStyle) layerStyle; if (fts.rules().isEmpty()) { problems.add( new MBFormatException( "Generated feature type style " + fts.getName() + " is empty.")); } } } } } } } } catch (MBFormatException invalid) { problems.add(invalid); } catch (Exception problem) { problems.add( (MBFormatException) new MBFormatException( "Style " + style.getName() + ":" + problem.getMessage()) .initCause(problem)); } } return problems; }
MapBoxStyle { public static List<Exception> validate(Reader reader) { List<Exception> problems = new ArrayList<Exception>(); MBStyleParser parser = new MBStyleParser(); MBStyle style; try { style = parser.parse(reader); } catch (Exception invalid) { problems.add(invalid); return problems; } List<MBLayer> layers = Collections.emptyList(); try { layers = style.layers(); if (layers.isEmpty()) { problems.add(new MBFormatException("No layers defined")); } } catch (MBFormatException layersUnavailable) { problems.add(layersUnavailable); } boolean hasVisibleLayer = false; for (MBLayer layer : layers) { if (!layer.visibility()) { continue; } try { List<FeatureTypeStyle> featureTypeStyle = layer.transform(style); if (featureTypeStyle != null) { hasVisibleLayer = true; } } catch (Exception invalid) { problems.add( (MBFormatException) new MBFormatException( "Layer " + layer.getId() + ":" + invalid.getMessage()) .initCause(invalid)); return problems; } } if (!hasVisibleLayer) { problems.add(new MBFormatException("No layers were visible")); } else { try { StyledLayerDescriptor sld = style.transform(); if (sld.getStyledLayers().length == 0) { problems.add( new MBFormatException( "Generated sld for " + sld.getName() + " is empty.")); } else { for (StyledLayer layer : sld.getStyledLayers()) { if (layer instanceof NamedLayer) { NamedLayer named = (NamedLayer) layer; if (named.styles().isEmpty()) { problems.add( new MBFormatException( "Generated named layer for " + named.getName() + " is empty.")); } else { for (Style layerStyle : named.styles()) { if (layerStyle instanceof FeatureTypeStyle) { FeatureTypeStyle fts = (FeatureTypeStyle) layerStyle; if (fts.rules().isEmpty()) { problems.add( new MBFormatException( "Generated feature type style " + fts.getName() + " is empty.")); } } } } } } } } catch (MBFormatException invalid) { problems.add(invalid); } catch (Exception problem) { problems.add( (MBFormatException) new MBFormatException( "Style " + style.getName() + ":" + problem.getMessage()) .initCause(problem)); } } return problems; } }
MapBoxStyle { public static List<Exception> validate(Reader reader) { List<Exception> problems = new ArrayList<Exception>(); MBStyleParser parser = new MBStyleParser(); MBStyle style; try { style = parser.parse(reader); } catch (Exception invalid) { problems.add(invalid); return problems; } List<MBLayer> layers = Collections.emptyList(); try { layers = style.layers(); if (layers.isEmpty()) { problems.add(new MBFormatException("No layers defined")); } } catch (MBFormatException layersUnavailable) { problems.add(layersUnavailable); } boolean hasVisibleLayer = false; for (MBLayer layer : layers) { if (!layer.visibility()) { continue; } try { List<FeatureTypeStyle> featureTypeStyle = layer.transform(style); if (featureTypeStyle != null) { hasVisibleLayer = true; } } catch (Exception invalid) { problems.add( (MBFormatException) new MBFormatException( "Layer " + layer.getId() + ":" + invalid.getMessage()) .initCause(invalid)); return problems; } } if (!hasVisibleLayer) { problems.add(new MBFormatException("No layers were visible")); } else { try { StyledLayerDescriptor sld = style.transform(); if (sld.getStyledLayers().length == 0) { problems.add( new MBFormatException( "Generated sld for " + sld.getName() + " is empty.")); } else { for (StyledLayer layer : sld.getStyledLayers()) { if (layer instanceof NamedLayer) { NamedLayer named = (NamedLayer) layer; if (named.styles().isEmpty()) { problems.add( new MBFormatException( "Generated named layer for " + named.getName() + " is empty.")); } else { for (Style layerStyle : named.styles()) { if (layerStyle instanceof FeatureTypeStyle) { FeatureTypeStyle fts = (FeatureTypeStyle) layerStyle; if (fts.rules().isEmpty()) { problems.add( new MBFormatException( "Generated feature type style " + fts.getName() + " is empty.")); } } } } } } } } catch (MBFormatException invalid) { problems.add(invalid); } catch (Exception problem) { problems.add( (MBFormatException) new MBFormatException( "Style " + style.getName() + ":" + problem.getMessage()) .initCause(problem)); } } return problems; }  }
MapBoxStyle { public static List<Exception> validate(Reader reader) { List<Exception> problems = new ArrayList<Exception>(); MBStyleParser parser = new MBStyleParser(); MBStyle style; try { style = parser.parse(reader); } catch (Exception invalid) { problems.add(invalid); return problems; } List<MBLayer> layers = Collections.emptyList(); try { layers = style.layers(); if (layers.isEmpty()) { problems.add(new MBFormatException("No layers defined")); } } catch (MBFormatException layersUnavailable) { problems.add(layersUnavailable); } boolean hasVisibleLayer = false; for (MBLayer layer : layers) { if (!layer.visibility()) { continue; } try { List<FeatureTypeStyle> featureTypeStyle = layer.transform(style); if (featureTypeStyle != null) { hasVisibleLayer = true; } } catch (Exception invalid) { problems.add( (MBFormatException) new MBFormatException( "Layer " + layer.getId() + ":" + invalid.getMessage()) .initCause(invalid)); return problems; } } if (!hasVisibleLayer) { problems.add(new MBFormatException("No layers were visible")); } else { try { StyledLayerDescriptor sld = style.transform(); if (sld.getStyledLayers().length == 0) { problems.add( new MBFormatException( "Generated sld for " + sld.getName() + " is empty.")); } else { for (StyledLayer layer : sld.getStyledLayers()) { if (layer instanceof NamedLayer) { NamedLayer named = (NamedLayer) layer; if (named.styles().isEmpty()) { problems.add( new MBFormatException( "Generated named layer for " + named.getName() + " is empty.")); } else { for (Style layerStyle : named.styles()) { if (layerStyle instanceof FeatureTypeStyle) { FeatureTypeStyle fts = (FeatureTypeStyle) layerStyle; if (fts.rules().isEmpty()) { problems.add( new MBFormatException( "Generated feature type style " + fts.getName() + " is empty.")); } } } } } } } } catch (MBFormatException invalid) { problems.add(invalid); } catch (Exception problem) { problems.add( (MBFormatException) new MBFormatException( "Style " + style.getName() + ":" + problem.getMessage()) .initCause(problem)); } } return problems; }  static StyledLayerDescriptor parse(Reader reader); static StyledLayerDescriptor parse(InputStream stream); static List<Exception> validate(Reader reader); }
MapBoxStyle { public static List<Exception> validate(Reader reader) { List<Exception> problems = new ArrayList<Exception>(); MBStyleParser parser = new MBStyleParser(); MBStyle style; try { style = parser.parse(reader); } catch (Exception invalid) { problems.add(invalid); return problems; } List<MBLayer> layers = Collections.emptyList(); try { layers = style.layers(); if (layers.isEmpty()) { problems.add(new MBFormatException("No layers defined")); } } catch (MBFormatException layersUnavailable) { problems.add(layersUnavailable); } boolean hasVisibleLayer = false; for (MBLayer layer : layers) { if (!layer.visibility()) { continue; } try { List<FeatureTypeStyle> featureTypeStyle = layer.transform(style); if (featureTypeStyle != null) { hasVisibleLayer = true; } } catch (Exception invalid) { problems.add( (MBFormatException) new MBFormatException( "Layer " + layer.getId() + ":" + invalid.getMessage()) .initCause(invalid)); return problems; } } if (!hasVisibleLayer) { problems.add(new MBFormatException("No layers were visible")); } else { try { StyledLayerDescriptor sld = style.transform(); if (sld.getStyledLayers().length == 0) { problems.add( new MBFormatException( "Generated sld for " + sld.getName() + " is empty.")); } else { for (StyledLayer layer : sld.getStyledLayers()) { if (layer instanceof NamedLayer) { NamedLayer named = (NamedLayer) layer; if (named.styles().isEmpty()) { problems.add( new MBFormatException( "Generated named layer for " + named.getName() + " is empty.")); } else { for (Style layerStyle : named.styles()) { if (layerStyle instanceof FeatureTypeStyle) { FeatureTypeStyle fts = (FeatureTypeStyle) layerStyle; if (fts.rules().isEmpty()) { problems.add( new MBFormatException( "Generated feature type style " + fts.getName() + " is empty.")); } } } } } } } } catch (MBFormatException invalid) { problems.add(invalid); } catch (Exception problem) { problems.add( (MBFormatException) new MBFormatException( "Style " + style.getName() + ":" + problem.getMessage()) .initCause(problem)); } } return problems; }  static StyledLayerDescriptor parse(Reader reader); static StyledLayerDescriptor parse(InputStream stream); static List<Exception> validate(Reader reader);  }