Search in sources :

Example 36 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class YSLDFileHandlerTest method testGetSLDContentsFile.

/**
 * Single file
 * Test method for {@link com.sldeditor.extension.filesystem.file.ysld.YSLDFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDContentsFile() {
    assertNull(new YSLDFileHandler().getSLDContents(null));
    URL url = YSLDFileHandlerTest.class.getResource("/point/ysld");
    File parent = null;
    try {
        parent = new File(url.toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_simplepoint.ysld");
        YSLDFileHandler handler = new YSLDFileHandler();
        List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
        assertEquals(1, sldDataList.size());
        // Changes where the file is to be saved to
        File saveFile = File.createTempFile(getClass().getSimpleName(), ".ysld");
        SLDData sldData = (SLDData) sldDataList.get(0);
        sldData.setSLDFile(saveFile);
        assertFalse(handler.save(null));
        assertTrue(handler.save(sldData));
        saveFile.delete();
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileNotFoundException(java.io.FileNotFoundException) YSLDFileHandler(com.sldeditor.extension.filesystem.file.ysld.YSLDFileHandler) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 37 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class BatchUpdateFontModelTest method testLoadData.

/**
 * Test method for {@link com.sldeditor.tool.batchupdatefont.BatchUpdateFontModel#loadData(java.util.List)}.
 */
@Test
public void testLoadData() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    fts.rules().add(rule);
    String expectedRule = "rule";
    rule.setName(expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    rule.symbolizers().add(symbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
    symbolizer.setFont(font);
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
    String sldContents = sldWriter.encodeSLD(null, sld);
    String expectedWorkspace = "workspace";
    String expectedStyle = "layer.sld";
    StyleWrapper styleWrapper = new StyleWrapper(expectedWorkspace, expectedStyle);
    SLDData data = new SLDData(styleWrapper, sldContents);
    File testFile = new File("test.sld");
    data.setSLDFile(testFile);
    SLDEditorFile.getInstance().setSldFile(testFile);
    SLDEditorFile.getInstance().setSLDData(data);
    BatchUpdateFontData testObj = new BatchUpdateFontData(sld, data);
    SelectedSymbol.getInstance().setSld(sld);
    testObj.setNamedLayer(expectedNamedLayer);
    testObj.setStyle(expectedStyleLayer);
    testObj.setFeatureTypeStyle(expectedFeatureTypeStyleLayer);
    testObj.setRule(rule);
    testObj.setSymbolizer(symbolizer);
    testObj.setFont(font);
    List<BatchUpdateFontData> dataList = new ArrayList<BatchUpdateFontData>();
    dataList.add(testObj);
    BatchUpdateFontModel model = new BatchUpdateFontModel();
    model.loadData(dataList);
    for (int col = 0; col < model.getColumnCount(); col++) {
        assertFalse(model.hasValueBeenUpdated(0, col));
    }
    assertFalse(model.anyChanges());
    assertFalse(model.saveData(null));
    List<Font> actualFontlist = model.getFontEntries(new int[] { 0 });
    assertEquals(1, actualFontlist.size());
    assertEquals(1, model.getRowCount());
    // Update font
    String originalFontname = "New Font";
    String originalFontStyle = "italic";
    String originalFontWeight = "bold";
    int originalFontSize = 16;
    font = styleFactory.createFont(ff.literal(originalFontname), ff.literal(originalFontStyle), ff.literal(originalFontWeight), ff.literal(originalFontSize));
    model.applyData(new int[] { 0 }, font);
    assertTrue(model.hasValueBeenUpdated(0, 7));
    assertTrue(model.hasValueBeenUpdated(0, 8));
    assertTrue(model.hasValueBeenUpdated(0, 9));
    assertTrue(model.hasValueBeenUpdated(0, 10));
    assertTrue(model.anyChanges());
    assertEquals(originalFontname, model.getValueAt(0, 7));
    assertEquals(originalFontStyle, model.getValueAt(0, 8));
    assertEquals(originalFontWeight, model.getValueAt(0, 9));
    assertEquals(String.valueOf(originalFontSize), model.getValueAt(0, 10));
    model.revertData();
    assertFalse(model.anyChanges());
    int expectedFontSize = 99;
    model.applyData(new int[] { 0 }, expectedFontSize);
    // Font size
    assertTrue(model.hasValueBeenUpdated(0, 10));
    assertEquals(expectedWorkspace, model.getValueAt(0, 0));
    assertEquals(expectedStyle, model.getValueAt(0, 1));
    assertEquals(expectedNamedLayer, model.getValueAt(0, 2));
    assertEquals(expectedStyleLayer, model.getValueAt(0, 3));
    assertEquals(expectedFeatureTypeStyleLayer, model.getValueAt(0, 4));
    assertEquals(expectedRule, model.getValueAt(0, 5));
    assertEquals(expectedSymbolizer, model.getValueAt(0, 6));
    assertEquals("abc", model.getValueAt(0, 7));
    assertEquals("normal", model.getValueAt(0, 8));
    assertEquals("normal", model.getValueAt(0, 9));
    assertEquals(String.valueOf(10 + expectedFontSize), model.getValueAt(0, 10));
    assertNull(model.getValueAt(0, 42));
    assertTrue(model.saveData(null));
    SelectedSymbol.destroyInstance();
    SLDEditorFile.destroyInstance();
    model.setColumnRenderer(null);
    JTable table = new JTable();
    table.setModel(model);
    model.setColumnRenderer(table.getColumnModel());
    assertFalse(model.isCellEditable(0, 0));
    assertEquals(Localisation.getString(BatchUpdateFontModel.class, "BatchUpdateFontModel.workspace"), model.getColumnName(0));
}
Also used : SLDData(com.sldeditor.common.data.SLDData) ArrayList(java.util.ArrayList) BatchUpdateFontModel(com.sldeditor.tool.batchupdatefont.BatchUpdateFontModel) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) StyleWrapper(com.sldeditor.common.data.StyleWrapper) JTable(javax.swing.JTable) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) Rule(org.geotools.styling.Rule) BatchUpdateFontData(com.sldeditor.tool.batchupdatefont.BatchUpdateFontData) NamedLayer(org.geotools.styling.NamedLayer) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) Test(org.junit.Test)

Example 38 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class RenderSymbolTest method createSLD.

/**
 * Creates the sld.
 *
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createSLD() {
    String sldContents = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<StyledLayerDescriptor version=\"1.0.0\" " + "    xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" " + "    xmlns=\"http://www.opengis.net/sld\" " + "    xmlns:ogc=\"http://www.opengis.net/ogc\" " + "    xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "  <NamedLayer>" + "    <Name>Attribute-based point</Name>" + "    <UserStyle>" + "      <Title>GeoServer SLD Cook Book: Attribute-based point</Title>" + "      <FeatureTypeStyle>" + "        <Rule>" + "          <Name>SmallPop</Name>" + "          <Title>1 to 50000</Title>" + "          <ogc:Filter>" + "            <ogc:PropertyIsLessThan>" + "              <ogc:PropertyName>pop</ogc:PropertyName>" + "              <ogc:Literal>50000</ogc:Literal>" + "            </ogc:PropertyIsLessThan>" + "          </ogc:Filter>" + "          <PointSymbolizer>" + "            <Graphic>" + "              <Mark>" + "                <WellKnownName>star</WellKnownName>" + "                <Fill>" + "                  <CssParameter name=\"fill\">#0033CC</CssParameter>" + "                </Fill>" + "              </Mark>" + "              <Rotation>" + "                <ogc:PropertyName>angle</ogc:PropertyName>" + "              </Rotation>" + "              <Size>" + "                <ogc:PropertyName>size</ogc:PropertyName>" + "              </Size>" + "            </Graphic>" + "          </PointSymbolizer>" + "        </Rule>" + "        <Rule>" + "          <Name>MediumPop</Name>" + "          <Title>50000 to 500000</Title>" + "          <ogc:Filter>" + "            <ogc:PropertyIsLessThan>" + "              <ogc:PropertyName>pop</ogc:PropertyName>" + "              <ogc:Literal>500000</ogc:Literal>" + "            </ogc:PropertyIsLessThan>" + "          </ogc:Filter>" + "          <PointSymbolizer>" + "            <Graphic>" + "              <Mark>" + "                <WellKnownName>star</WellKnownName>" + "                <Fill>" + "                  <CssParameter name=\"fill\">#0033CC</CssParameter>" + "                </Fill>" + "              </Mark>" + "              <Rotation>" + "                <ogc:PropertyName>angle</ogc:PropertyName>" + "              </Rotation>" + "              <Size>" + "                <ogc:PropertyName>size</ogc:PropertyName>" + "              </Size>" + "            </Graphic>" + "          </PointSymbolizer>" + "          <PointSymbolizer>" + "            <Graphic>" + "              <Mark>" + "                <WellKnownName>circle</WellKnownName>" + "                <Fill>" + "                  <CssParameter name=\"fill\">#123456</CssParameter>" + "                </Fill>" + "              </Mark>" + "              <Rotation>" + "                <ogc:PropertyName>angle</ogc:PropertyName>" + "              </Rotation>" + "              <Size>" + "                <ogc:PropertyName>size</ogc:PropertyName>" + "              </Size>" + "            </Graphic>" + "          </PointSymbolizer>" + "        </Rule>" + "        <Rule>" + "          <Name>LargePop</Name>" + "          <Title>500000 to 900000</Title>" + "          <ogc:Filter>" + "            <ogc:PropertyIsLessThan>" + "              <ogc:PropertyName>pop</ogc:PropertyName>" + "              <ogc:Literal>900000</ogc:Literal>" + "            </ogc:PropertyIsLessThan>" + "          </ogc:Filter>" + "          <PointSymbolizer>" + "            <Graphic>" + "              <Mark>" + "                <WellKnownName>star</WellKnownName>" + "                <Fill>" + "                  <CssParameter name=\"fill\">#0033CC</CssParameter>" + "                </Fill>" + "              </Mark>" + "              <Rotation>" + "                <ogc:PropertyName>angle</ogc:PropertyName>" + "              </Rotation>" + "              <Size>" + "                <ogc:PropertyName>size</ogc:PropertyName>" + "              </Size>" + "            </Graphic>" + "          </PointSymbolizer>" + "        </Rule>" + "      </FeatureTypeStyle>" + "    </UserStyle>" + "  </NamedLayer>" + "</StyledLayerDescriptor>";
    SLDData sldData = new SLDData(new StyleWrapper(null, "test.sld"), sldContents);
    sldData.setDataSourceProperties(DataSourceConnectorFactory.getNoDataSource());
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    return sld;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper)

Example 39 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class RuleRenderVisitorTest method createSLD.

/**
 * Creates the sld.
 *
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createSLD() {
    String sldContents = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<StyledLayerDescriptor version=\"1.0.0\" " + "    xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" " + "    xmlns=\"http://www.opengis.net/sld\" " + "    xmlns:ogc=\"http://www.opengis.net/ogc\" " + "    xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "  <NamedLayer>" + "    <Name>Attribute-based point</Name>" + "    <UserStyle>" + "      <Title>GeoServer SLD Cook Book: Attribute-based point</Title>" + "      <FeatureTypeStyle>" + "        <Rule>" + "          <Name>SmallPop</Name>" + "          <Title>1 to 50000</Title>" + "          <ogc:Filter>" + "            <ogc:PropertyIsLessThan>" + "              <ogc:PropertyName>pop</ogc:PropertyName>" + "              <ogc:Literal>50000</ogc:Literal>" + "            </ogc:PropertyIsLessThan>" + "          </ogc:Filter>" + "          <PointSymbolizer>" + "            <Graphic>" + "              <Mark>" + "                <WellKnownName>star</WellKnownName>" + "                <Fill>" + "                  <CssParameter name=\"fill\">#0033CC</CssParameter>" + "                </Fill>" + "              </Mark>" + "              <Rotation>" + "                <ogc:PropertyName>angle</ogc:PropertyName>" + "              </Rotation>" + "              <Size>" + "                <ogc:PropertyName>size</ogc:PropertyName>" + "              </Size>" + "            </Graphic>" + "          </PointSymbolizer>" + "        </Rule>" + "        <Rule>" + "          <Name>MediumPop</Name>" + "          <Title>50000 to 500000</Title>" + "          <ogc:Filter>" + "            <ogc:PropertyIsLessThan>" + "              <ogc:PropertyName>pop</ogc:PropertyName>" + "              <ogc:Literal>500000</ogc:Literal>" + "            </ogc:PropertyIsLessThan>" + "          </ogc:Filter>" + "          <PointSymbolizer>" + "            <Graphic>" + "              <Mark>" + "                <WellKnownName>star</WellKnownName>" + "                <Fill>" + "                  <CssParameter name=\"fill\">#0033CC</CssParameter>" + "                </Fill>" + "              </Mark>" + "              <Rotation>" + "                <ogc:PropertyName>angle</ogc:PropertyName>" + "              </Rotation>" + "              <Size>" + "                <ogc:PropertyName>size</ogc:PropertyName>" + "              </Size>" + "            </Graphic>" + "          </PointSymbolizer>" + "          <PointSymbolizer>" + "            <Graphic>" + "              <Mark>" + "                <WellKnownName>circle</WellKnownName>" + "                <Fill>" + "                  <CssParameter name=\"fill\">#123456</CssParameter>" + "                </Fill>" + "              </Mark>" + "              <Rotation>" + "                <ogc:PropertyName>angle</ogc:PropertyName>" + "              </Rotation>" + "              <Size>" + "                <ogc:PropertyName>size</ogc:PropertyName>" + "              </Size>" + "            </Graphic>" + "          </PointSymbolizer>" + "        </Rule>" + "        <Rule>" + "          <Name>LargePop</Name>" + "          <Title>500000 to 900000</Title>" + "          <ogc:Filter>" + "            <ogc:PropertyIsLessThan>" + "              <ogc:PropertyName>pop</ogc:PropertyName>" + "              <ogc:Literal>900000</ogc:Literal>" + "            </ogc:PropertyIsLessThan>" + "          </ogc:Filter>" + "          <PointSymbolizer>" + "            <Graphic>" + "              <Mark>" + "                <WellKnownName>star</WellKnownName>" + "                <Fill>" + "                  <CssParameter name=\"fill\">#0033CC</CssParameter>" + "                </Fill>" + "              </Mark>" + "              <Rotation>" + "                <ogc:PropertyName>angle</ogc:PropertyName>" + "              </Rotation>" + "              <Size>" + "                <ogc:PropertyName>size</ogc:PropertyName>" + "              </Size>" + "            </Graphic>" + "          </PointSymbolizer>" + "        </Rule>" + "      </FeatureTypeStyle>" + "    </UserStyle>" + "  </NamedLayer>" + "</StyledLayerDescriptor>";
    SLDData sldData = new SLDData(new StyleWrapper(null, "test.sld"), sldContents);
    sldData.setDataSourceProperties(DataSourceConnectorFactory.getNoDataSource());
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    return sld;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper)

Example 40 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class SLDUtilsTest method testCreateSLDFromStringGeoServer.

@Test
public void testCreateSLDFromStringGeoServer() {
    SLDData sldData = new SLDData(null, expectedSld);
    String geoserverUrl = "http://localhost:8080/geoserver";
    GeoServerConnection connectionData = new GeoServerConnection();
    try {
        connectionData.setUrl(new URL(geoserverUrl));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    sldData.setConnectionData(connectionData);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(null);
    assertNull(sld);
    sld = SLDUtils.createSLDFromString(sldData);
    StyledLayer[] styledLayers = sld.getStyledLayers();
    NamedLayer namedLayer = (NamedLayer) styledLayers[0];
    Style[] actualStyles = namedLayer.getStyles();
    PointSymbolizer pointSymbolizer = (PointSymbolizer) actualStyles[0].featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
    MarkImpl mark = (MarkImpl) pointSymbolizer.getGraphic().graphicalSymbols().get(0);
    assertEquals("circle", mark.getWellKnownName().toString());
    // Check resource locator
    geoserverUrl = geoserverUrl + "/styles/";
    assertTrue(geoserverUrl.compareTo(sldData.getResourceLocator().toExternalForm()) == 0);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) PointSymbolizer(org.geotools.styling.PointSymbolizer) MalformedURLException(java.net.MalformedURLException) StyledLayer(org.geotools.styling.StyledLayer) MarkImpl(org.geotools.styling.MarkImpl) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) URL(java.net.URL) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Aggregations

SLDData (com.sldeditor.common.data.SLDData)68 Test (org.junit.Test)54 StyleWrapper (com.sldeditor.common.data.StyleWrapper)35 File (java.io.File)27 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)24 SLDDataInterface (com.sldeditor.common.SLDDataInterface)20 IOException (java.io.IOException)20 URL (java.net.URL)16 ArrayList (java.util.ArrayList)14 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)8 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)8 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)7 FileNotFoundException (java.io.FileNotFoundException)7 URISyntaxException (java.net.URISyntaxException)7 MalformedURLException (java.net.MalformedURLException)6 NamedLayer (org.geotools.styling.NamedLayer)6 Style (org.geotools.styling.Style)6 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)5 VersionData (com.sldeditor.common.vendoroption.VersionData)4