Search in sources :

Example 41 with SLDDataInterface

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

the class SLDFileHandlerTest method testGetSLDContentsFolder.

/**
 * Supply a folder name and retrieve all the sld files in it
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.sld.SLDFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDContentsFolder() {
    assertNull(new SLDFileHandler().getSLDContents(null));
    URL url = SLDFileHandlerTest.class.getResource("/point/sld");
    String folderName = "";
    File parent = null;
    try {
        parent = new File(url.toURI());
        folderName = parent.getName();
        parent = parent.getParentFile();
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        FileTreeNode fileTreeNode = new FileTreeNode(parent, folderName);
        SLDFileHandler handler = new SLDFileHandler();
        List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
        List<String> expectedLayerNameList = Arrays.asList("point_attribute.sld", "point_pointasgraphic.sld", "point_pointasgraphichttp.sld", "point_pointwithdefaultlabel.sld", "point_pointwithrotatedlabel.sld", "point_pointwithstyledlabel.sld", "point_rotatedsquare.sld", "point_simplepoint.sld", "point_simplepointwithstroke.sld", "point_transparenttriangle.sld", "point_zoom.sld", "point_wkt.sld", "point_pointwithenhancedlabel.sld");
        assertEquals(expectedLayerNameList.size(), sldDataList.size());
        for (SLDDataInterface sldData : sldDataList) {
            assertTrue(expectedLayerNameList.contains(sldData.getLayerName()));
        }
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) 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 42 with SLDDataInterface

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

the class SLDFileEditorHandlerTest method testGetSLDContents.

/**
 * Test method for {@link com.sldeditor.extension.filesystem.file.sldeditor.SLDEditorFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDContents() {
    assertNull(new SLDEditorFileHandler().getSLDContents(null));
    URL url = SLDFileEditorHandlerTest.class.getResource("/point/sld");
    File parent = null;
    try {
        parent = new File(url.toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    System.out.println(url.toString());
    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 sldEditorFile = File.createTempFile(getClass().getSimpleName(), ".sldeditor");
        SLDData sldData = (SLDData) sldDataList.get(0);
        sldData.setSldEditorFile(sldEditorFile);
        SLDEditorFileHandler editorFileHandler = new SLDEditorFileHandler();
        assertFalse(handler.save(null));
        assertTrue(editorFileHandler.save(sldData));
        SLDEditorFileHandler editorFileHandler2 = new SLDEditorFileHandler();
        List<SLDDataInterface> actualSldDataList = editorFileHandler2.open(sldEditorFile);
        assertEquals(1, actualSldDataList.size());
        FileTreeNode editorFileTreeNode = new FileTreeNode(sldEditorFile.getParentFile(), sldEditorFile.getName());
        List<SLDDataInterface> actualSldDataList2 = editorFileHandler2.getSLDContents(editorFileTreeNode);
        assertEquals(1, actualSldDataList2.size());
        sldEditorFile.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) SLDEditorFileHandler(com.sldeditor.extension.filesystem.file.sldeditor.SLDEditorFileHandler) 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 43 with SLDDataInterface

use of com.sldeditor.common.SLDDataInterface 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 44 with SLDDataInterface

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

the class YSLDFileHandlerTest method testGetSLDContentsFolder.

/**
 * Supply a folder name and retrieve all the ysld files in it
 *
 * <p>Test method for {@link com.sldeditor.extension.filesystem.file.ysld.YSLDFileHandler#getSLDContents(com.sldeditor.common.NodeInterface)}.
 */
@Test
public void testGetSLDContentsFolder() {
    assertNull(new YSLDFileHandler().getSLDContents(null));
    URL url = SLDFileHandlerTest.class.getResource("/point/ysld");
    String folderName = "";
    File parent = null;
    try {
        parent = new File(url.toURI());
        folderName = parent.getName();
        parent = parent.getParentFile();
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        FileTreeNode fileTreeNode = new FileTreeNode(parent, folderName);
        YSLDFileHandler handler = new YSLDFileHandler();
        List<SLDDataInterface> sldDataList = handler.getSLDContents(fileTreeNode);
        List<String> expectedLayerNameList = Arrays.asList("point_simplepoint.ysld");
        assertEquals(expectedLayerNameList.size(), sldDataList.size());
        for (SLDDataInterface sldData : sldDataList) {
            assertTrue(expectedLayerNameList.contains(sldData.getLayerName()));
        }
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileNotFoundException(java.io.FileNotFoundException) YSLDFileHandler(com.sldeditor.extension.filesystem.file.ysld.YSLDFileHandler) URISyntaxException(java.net.URISyntaxException) 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 45 with SLDDataInterface

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

the class SLDEditorFileHandler method getSLDContents.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.extension.input.FileHandlerInterface#getSLDContents(com.sldeditor.extension.input.NodeInterface)
     */
@Override
public List<SLDDataInterface> getSLDContents(NodeInterface node) {
    if (node instanceof FileTreeNode) {
        FileTreeNode fileTreeNode = (FileTreeNode) node;
        File f = fileTreeNode.getFile();
        if (f != null) {
            if (FileSystemUtils.isFileExtensionSupported(f, getFileExtensionList())) {
                List<SLDDataInterface> list = new ArrayList<SLDDataInterface>();
                SLDDataInterface sldData = readSLDEditorFile(f);
                list.add(sldData);
                return list;
            }
        }
    }
    return null;
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) ArrayList(java.util.ArrayList) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

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