Search in sources :

Example 1 with SLDWriterInterface

use of com.sldeditor.common.output.SLDWriterInterface in project sldeditor by robward-scisys.

the class YSLDToolTest method getSLDDataFile.

/**
 * Gets the SLD/YSLD file.
 *
 * @param testfile the testfile
 * @return the SLD data file
 */
private static SLDData getSLDDataFile(String testfile) {
    SLDData sldData = null;
    InputStream inputStream = YSLDToolTest.class.getResourceAsStream(testfile);
    if (inputStream == null) {
        Assert.assertNotNull("Failed to find test file : " + testfile, inputStream);
    } else {
        File f = null;
        try {
            String fileExtension = ExternalFilenames.getFileExtension(testfile);
            f = stream2file(inputStream, ExternalFilenames.addFileExtensionSeparator(fileExtension));
            String sldContents = readFile(f.getAbsolutePath());
            if (fileExtension.compareTo("ysld") == 0) {
                StyledLayerDescriptor sld = Ysld.parse(sldContents);
                // Convert YSLD to SLD string
                SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
                sldContents = sldWriter.encodeSLD(null, sld);
            }
            sldData = new SLDData(new StyleWrapper(f.getName()), sldContents);
            sldData.setSLDFile(f);
            SelectedSymbol.getInstance().setSld(SLDUtils.createSLDFromString(sldData));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
    return sldData;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) InputStream(java.io.InputStream) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) IOException(java.io.IOException) File(java.io.File)

Example 2 with SLDWriterInterface

use of com.sldeditor.common.output.SLDWriterInterface in project sldeditor by robward-scisys.

the class YSLDTool method exportToSLD.

/**
 * Export to SLD.
 */
private void exportToSLD() {
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
    for (SLDDataInterface sldData : sldDataList) {
        StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
        String layerName = sldData.getLayerNameWithOutSuffix();
        if (sld != null) {
            String sldString = sldWriter.encodeSLD(sldData.getResourceLocator(), sld);
            String destinationFolder = sldData.getSLDFile().getParent();
            File fileToSave = GenerateFilename.findUniqueName(destinationFolder, layerName, SLDEditorFile.getSLDFileExtension());
            String sldFilename = fileToSave.getName();
            if (fileToSave.exists()) {
                ConsoleManager.getInstance().error(this, Localisation.getField(YSLDTool.class, "YSLDTool.destinationAlreadyExists") + " " + sldFilename);
            } else {
                ConsoleManager.getInstance().information(this, Localisation.getField(YSLDTool.class, "YSLDTool.exportToSLDMsg") + " " + sldFilename);
                BufferedWriter out;
                try {
                    out = new BufferedWriter(new FileWriter(fileToSave));
                    out.write(sldString);
                    out.close();
                } catch (IOException e) {
                    ConsoleManager.getInstance().exception(this, e);
                }
            }
        }
    }
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileWriter(java.io.FileWriter) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) IOException(java.io.IOException) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 3 with SLDWriterInterface

use of com.sldeditor.common.output.SLDWriterInterface in project sldeditor by robward-scisys.

the class SLDTextArea method outputText.

/**
 * Output text.
 */
private void outputText() {
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(outputFormat);
    String encodedSLD = sldWriter.encodeSLD(resourceLocator, displayedSld);
    sldSourceTextArea.setText(encodedSLD);
}
Also used : SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface)

Example 4 with SLDWriterInterface

use of com.sldeditor.common.output.SLDWriterInterface in project sldeditor by robward-scisys.

the class SLDWriterFactoryTest method testCreateSLDWriter.

/**
 * Test method for {@link com.sldeditor.common.output.impl.SLDWriterFactory#createWriter(java.lang.String)}.
 */
@Test
public void testCreateSLDWriter() {
    SLDWriterInterface writer = SLDWriterFactory.createWriter(null);
    assertNotNull(writer);
}
Also used : SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) Test(org.junit.Test)

Example 5 with SLDWriterInterface

use of com.sldeditor.common.output.SLDWriterInterface in project sldeditor by robward-scisys.

the class GeoServerClientTest method testInitialiseWithValidConnection.

/**
 * Only works if a default GeoServer instance is running
 *
 * <p>Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#initialise(com.sldeditor.extension.filesystem.geoserver.GeoServerReadProgressInterface, com.sldeditor.common.data.GeoServerConnection)}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#retrieveData()}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#connect()}. Test
 * method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#getStyle(com.sldeditor.common.data.StyleWrapper)}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#getStyle(com.sldeditor.common.data.StyleWrapper)}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#uploadSLD(com.sldeditor.common.data.StyleWrapper, java.lang.String)}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#getWorkspaceList()}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#refreshWorkspace(java.lang.String)}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#deleteStyle(com.sldeditor.common.data.StyleWrapper)}.
 * Test method for
 * {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#disconnect()}.
 */
@Ignore
@Test
public void testInitialiseWithValidConnection() {
    GeoServerClient client = new GeoServerClient();
    TestProgressClass progress = new TestProgressClass();
    client.initialise(progress, testConnection);
    assertTrue(client.connect());
    assertEquals(testConnection, client.getConnection());
    List<String> actualWorkspaceList = client.getWorkspaceList();
    assertTrue(actualWorkspaceList.size() > 0);
    client.retrieveData();
    int count = 0;
    while (!progress.hasFinished() && count < 50) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        count++;
    }
    assertTrue(progress.hasFinished());
    // CHECKSTYLE:OFF
    int actualNoOfStyles = progress.styleTotal;
    // CHECKSTYLE:ON
    // Retrieve style
    StyleWrapper styleWrapper = new StyleWrapper(client.getDefaultWorkspaceName(), "point");
    String sldContents = client.getStyle(styleWrapper);
    assertTrue(sldContents != null);
    SLDData sldData = new SLDData(styleWrapper, sldContents);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    assertEquals("default_point", sld.layers().get(0).getName());
    // Upload as new style
    String timeString = "" + System.currentTimeMillis();
    String styleName = "New_Test_style_" + timeString;
    styleWrapper.setStyle(styleName);
    assertTrue(client.uploadSLD(styleWrapper, sldContents));
    List<StyleWrapper> stylesToDeleteList = new ArrayList<StyleWrapper>();
    stylesToDeleteList.add(styleWrapper.clone());
    // Replace the existing style
    StyledLayer styledLayer = sld.layers().get(0);
    styledLayer.setName("test point sld");
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
    String updatedSLDBody = sldWriter.encodeSLD(null, sld);
    assertTrue(client.uploadSLD(styleWrapper, updatedSLDBody));
    // Change the workspace name - invalid
    styleWrapper.setWorkspace("Test workspace");
    assertFalse(client.uploadSLD(styleWrapper, updatedSLDBody));
    // Change the workspace name - valid
    String expectedWorkspace = "Test_workspace_" + timeString;
    styleWrapper.setWorkspace(expectedWorkspace);
    assertTrue(client.uploadSLD(styleWrapper, updatedSLDBody));
    stylesToDeleteList.add(styleWrapper.clone());
    actualWorkspaceList = client.getWorkspaceList();
    assertTrue(actualWorkspaceList.contains(expectedWorkspace));
    // Update the contents
    styledLayer.setName("updated test point sld");
    updatedSLDBody = sldWriter.encodeSLD(null, sld);
    assertTrue(client.uploadSLD(styleWrapper, updatedSLDBody));
    // Check refresh workspace works
    client.refreshWorkspace(client.getDefaultWorkspaceName());
    count = 0;
    while (!progress.hasFinished() && count < 50) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        count++;
    }
    assertTrue(progress.hasFinished());
    assertEquals(actualNoOfStyles + 1, progress.styleTotal);
    // 
    for (StyleWrapper styleToDelete : stylesToDeleteList) {
        System.out.println("Deleting style : " + styleToDelete.getWorkspace() + "/" + styleToDelete.getStyle());
        assertTrue(client.deleteStyle(styleToDelete));
    }
    assertFalse(client.deleteStyle(null));
    assertFalse(client.deleteStyle(new StyleWrapper()));
    StyleWrapper tmpStyle = styleWrapper.clone();
    tmpStyle.setStyle("invalid");
    assertFalse(client.deleteStyle(tmpStyle));
    tmpStyle = styleWrapper.clone();
    tmpStyle.setWorkspace("invalid");
    assertFalse(client.deleteStyle(tmpStyle));
    System.out.println("Deleting workspace : " + expectedWorkspace);
    assertTrue(client.deleteWorkspace(expectedWorkspace));
    client.disconnect();
    assertFalse(client.isConnected());
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayer(org.geotools.styling.StyledLayer) ArrayList(java.util.ArrayList) GeoServerClient(com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)11 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)8 File (java.io.File)6 SLDData (com.sldeditor.common.data.SLDData)5 StyleWrapper (com.sldeditor.common.data.StyleWrapper)5 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)5 IOException (java.io.IOException)5 Test (org.junit.Test)5 SLDDataInterface (com.sldeditor.common.SLDDataInterface)4 BufferedWriter (java.io.BufferedWriter)4 FileWriter (java.io.FileWriter)4 BatchUpdateFontData (com.sldeditor.tool.batchupdatefont.BatchUpdateFontData)3 Rule (org.geotools.styling.Rule)3 TextSymbolizer (org.geotools.styling.TextSymbolizer)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)2 Font (org.geotools.styling.Font)2 NamedLayer (org.geotools.styling.NamedLayer)2 Style (org.geotools.styling.Style)2