Search in sources :

Example 66 with SLDDataInterface

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

the class FileSystemInputTest method testCopyNodes.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.file.FileSystemInput#copyNodes(com.sldeditor.common.NodeInterface, java.util.Map)}.
 */
@Test
public void testCopyNodes() {
    FileSystemInput input = new FileSystemInput(null);
    URL url = SLDFileHandlerTest.class.getResource("/point/sld/point_attribute.sld");
    List<SLDDataInterface> sldDataList = input.open(url);
    assertEquals(1, sldDataList.size());
    try {
        Path tempFolder = Files.createTempDirectory(getClass().getSimpleName());
        File tempFolderFile = tempFolder.toFile();
        FileTreeNode destinationTreeNode = new FileTreeNode(tempFolderFile.getParentFile(), tempFolderFile.getName());
        Map<NodeInterface, List<SLDDataInterface>> copyDataMap = new HashMap<NodeInterface, List<SLDDataInterface>>();
        copyDataMap.put(destinationTreeNode, sldDataList);
        assertTrue(input.copyNodes(destinationTreeNode, copyDataMap));
        SLDData sldData = (SLDData) sldDataList.get(0);
        sldData.setSLDFile(new File(tempFolderFile, "point_attribute.sld"));
        input.deleteNodes(destinationTreeNode, sldDataList);
        tempFolderFile.deleteOnExit();
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) SLDData(com.sldeditor.common.data.SLDData) HashMap(java.util.HashMap) IOException(java.io.IOException) URL(java.net.URL) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) List(java.util.List) FileSystemInput(com.sldeditor.extension.filesystem.file.FileSystemInput) File(java.io.File) NodeInterface(com.sldeditor.common.NodeInterface) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 67 with SLDDataInterface

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

the class RasterFileHandlerTest method testGetSLDContentsFile.

/**
 * Single file
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.raster.RasterFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDContentsFile() {
    assertNull(new RasterFileHandler().getSLDContents(null));
    URL url = RasterFileHandlerTest.class.getResource("/point/sld");
    File parent = null;
    try {
        parent = new File(url.toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
        RasterFileHandler handler = new RasterFileHandler();
        List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
        assertNull(sldDataList);
        // Try with valid vector file
        FileTreeNode fileTreeNode2 = new FileTreeNode(parent, "point_attribute.tif");
        sldDataList = handler.getSLDContents(fileTreeNode2);
        assertTrue(sldDataList.isEmpty());
        // Changes where the file is to be saved to
        File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
        SLDData sldData = new SLDData(null, "");
        sldData.setSLDFile(saveFile);
        assertFalse(handler.save(null));
        assertFalse(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) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RasterFileHandler(com.sldeditor.extension.filesystem.file.raster.RasterFileHandler) File(java.io.File) URL(java.net.URL) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) Test(org.junit.Test)

Example 68 with SLDDataInterface

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

the class SLDFileHandlerTest method testGetSLDContentsFile.

/**
 * Single file
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.sld.SLDFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDContentsFile() {
    assertNull(new SLDFileHandler().getSLDContents(null));
    URL url = SLDFileHandlerTest.class.getResource("/point/sld");
    File parent = null;
    try {
        parent = new File(url.toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
        SLDFileHandler handler = new SLDFileHandler();
        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(), ".sld");
        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) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) SLDFileHandler(com.sldeditor.extension.filesystem.file.sld.SLDFileHandler) File(java.io.File) URL(java.net.URL) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) Test(org.junit.Test)

Example 69 with SLDDataInterface

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

the class VectorFileHandlerTest method testGetSLDContentsFile.

/**
 * Single file
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.vector.VectorFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDContentsFile() {
    assertNull(new VectorFileHandler().getSLDContents(null));
    URL url = VectorFileHandlerTest.class.getResource("/point/sld");
    File parent = null;
    try {
        parent = new File(url.toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
        VectorFileHandler handler = new VectorFileHandler();
        List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
        assertNull(sldDataList);
        // Try with valid vector file
        FileTreeNode fileTreeNode2 = new FileTreeNode(parent, "point_attribute.shp");
        sldDataList = handler.getSLDContents(fileTreeNode2);
        assertTrue(sldDataList.isEmpty());
        // Changes where the file is to be saved to
        File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
        SLDData sldData = new SLDData(null, "");
        sldData.setSLDFile(saveFile);
        assertFalse(handler.save(null));
        assertFalse(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) VectorFileHandler(com.sldeditor.extension.filesystem.file.vector.VectorFileHandler) FileNotFoundException(java.io.FileNotFoundException) 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)

Example 70 with SLDDataInterface

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

the class YSLDToolTest method testSetSelectedItems.

/**
 * Test sld file.
 */
@Test
public void testSetSelectedItems() {
    YSLDTool tool = new YSLDTool();
    JPanel panel = tool.getPanel();
    ToolButton toSLD = null;
    ToolButton toYSLD = null;
    for (Component c : panel.getComponents()) {
        if (c instanceof ToolButton) {
            ToolButton button = (ToolButton) c;
            String toolTipText = button.getToolTipText();
            if (toolTipText.compareTo(Localisation.getString(YSLDTool.class, "YSLDTool.exportToSLD")) == 0) {
                toSLD = button;
            } else if (toolTipText.compareTo(Localisation.getString(YSLDTool.class, "YSLDTool.exportToYSLD")) == 0) {
                toYSLD = button;
            }
        }
    }
    File testFile1 = null;
    File testFile3 = null;
    try {
        testFile1 = File.createTempFile("invalid", ".tst");
        testFile3 = File.createTempFile("valid", ".ysld");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    // Should both be disabled
    assertFalse(toSLD.isEnabled());
    assertFalse(toYSLD.isEnabled());
    tool.setSelectedItems(null, null);
    // Invalid file
    List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
    SLDData sldData1 = new SLDData(null, null);
    sldData1.setSLDFile(testFile1);
    sldDataList.add(sldData1);
    tool.setSelectedItems(null, sldDataList);
    // Should both be disabled
    assertFalse(toSLD.isEnabled());
    assertFalse(toYSLD.isEnabled());
    // Try with valid sld file
    sldDataList = new ArrayList<SLDDataInterface>();
    SLDData sldData2 = getSLDDataFile("/point/sld/point_simplepoint.sld");
    sldDataList.add(sldData2);
    tool.setSelectedItems(null, sldDataList);
    // YSLD should be enabled
    assertTrue(toYSLD.isEnabled());
    assertFalse(toSLD.isEnabled());
    toYSLD.doClick();
    // Try with valid ysld file
    sldDataList = new ArrayList<SLDDataInterface>();
    SLDData sldData3 = getSLDDataFile("/point/ysld/point_simplepoint.ysld");
    sldDataList.add(sldData3);
    tool.setSelectedItems(null, sldDataList);
    // SLD should be enabled
    assertTrue(toSLD.isEnabled());
    assertFalse(toYSLD.isEnabled());
    toSLD.doClick();
    // Try with valid sld and ysld files
    sldDataList = new ArrayList<SLDDataInterface>();
    sldDataList.add(sldData2);
    sldDataList.add(sldData3);
    tool.setSelectedItems(null, sldDataList);
    // SLD and YSLD should be enabled
    assertTrue(toSLD.isEnabled());
    assertTrue(toYSLD.isEnabled());
    testFile1.delete();
    testFile3.delete();
    tidyUpTempFiles(sldData2.getSLDFile());
    tidyUpTempFiles(sldData3.getSLDFile());
}
Also used : JPanel(javax.swing.JPanel) SLDData(com.sldeditor.common.data.SLDData) ToolButton(com.sldeditor.tool.ToolButton) SLDDataInterface(com.sldeditor.common.SLDDataInterface) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Component(java.awt.Component) File(java.io.File) YSLDTool(com.sldeditor.tool.ysld.YSLDTool) Test(org.junit.Test)

Aggregations

SLDDataInterface (com.sldeditor.common.SLDDataInterface)72 File (java.io.File)34 IOException (java.io.IOException)21 SLDData (com.sldeditor.common.data.SLDData)20 ArrayList (java.util.ArrayList)20 Test (org.junit.Test)20 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)17 URL (java.net.URL)17 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)14 StyleWrapper (com.sldeditor.common.data.StyleWrapper)12 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)12 FileNotFoundException (java.io.FileNotFoundException)12 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)12 URISyntaxException (java.net.URISyntaxException)10 NodeInterface (com.sldeditor.common.NodeInterface)9 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)7 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)5 FSTree (com.sldeditor.datasource.extension.filesystem.node.FSTree)5 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)5