Search in sources :

Example 1 with FileSystemInput

use of com.sldeditor.extension.filesystem.file.FileSystemInput in project sldeditor by robward-scisys.

the class FileSystemExtension method save.

/**
 * Save.
 *
 * @param sldData the sld data
 * @return true, if successful
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.extension.ExtensionInterface#save(java.net.URL, com.sldeditor.ui.iface.SLDDataInterface)
     */
@Override
public boolean save(SLDDataInterface sldData) {
    boolean saved = false;
    for (FileSystemInterface extension : extensionList) {
        if (saved == false) {
            saved = extension.save(sldData);
        }
    }
    if (saved) {
        FileSystemInput fileSystemInput = FileSystemExtensionFactory.getFileSystemInput();
        if (fileSystemInput != null) {
            fileSystemInput.setFolder(sldData.getSLDURL(), true);
        }
    }
    sldSaved = true;
    return saved;
}
Also used : FileSystemInterface(com.sldeditor.common.filesystem.FileSystemInterface) FileSystemInput(com.sldeditor.extension.filesystem.file.FileSystemInput)

Example 2 with FileSystemInput

use of com.sldeditor.extension.filesystem.file.FileSystemInput in project sldeditor by robward-scisys.

the class FileSystemExtensionFactory method populateExtensions.

/**
 * Populate default file extensions.
 *
 * @param toolMgr the tool manager
 */
private static void populateExtensions(ToolSelectionInterface toolMgr) {
    geoServerInput = new GeoServerInput(toolMgr);
    geoServerInput.readPropertyFile();
    extensionList.add(geoServerInput);
    databaseInput = new DatabaseInput(toolMgr);
    databaseInput.readPropertyFile();
    extensionList.add(databaseInput);
    fileSystemInput = new FileSystemInput(toolMgr);
    extensionList.add(fileSystemInput);
}
Also used : GeoServerInput(com.sldeditor.extension.filesystem.geoserver.GeoServerInput) DatabaseInput(com.sldeditor.extension.filesystem.database.DatabaseInput) FileSystemInput(com.sldeditor.extension.filesystem.file.FileSystemInput)

Example 3 with FileSystemInput

use of com.sldeditor.extension.filesystem.file.FileSystemInput in project sldeditor by robward-scisys.

the class FileSystemInputTest method testGetNodeTypes.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.file.FileSystemInput#getNodeTypes()}.
 */
@Test
public void testGetNodeTypes() {
    FileSystemInput input = new FileSystemInput(null);
    assertTrue(input.getNodeTypes().isEmpty());
}
Also used : FileSystemInput(com.sldeditor.extension.filesystem.file.FileSystemInput) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 4 with FileSystemInput

use of com.sldeditor.extension.filesystem.file.FileSystemInput in project sldeditor by robward-scisys.

the class FileSystemInputTest method testFileSystemInput.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.file.FileSystemInput#FileSystemInput(com.sldeditor.common.ToolSelectionInterface)}.
 */
@Test
public void testFileSystemInput() {
    FileSystemInput input = new FileSystemInput(null);
    FSTree tree = new FSTree();
    DefaultMutableTreeNode rootNode;
    try {
        rootNode = new DefaultMutableTreeNode("Root");
        DefaultTreeModel model = new DefaultTreeModel(rootNode);
        input.populate(tree, model, rootNode);
        URL url = SLDFileHandlerTest.class.getResource("/point/sld/point_attribute.sld");
        List<SLDDataInterface> sldDataList = input.open(url);
        assertEquals(1, sldDataList.size());
        File parent = null;
        try {
            parent = new File(url.toURI());
            parent = parent.getParentFile();
        } catch (URISyntaxException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
        FileTreeNode fileTreeNode = new FileTreeNode(parent, "point_attribute.sld");
        List<SLDDataInterface> sldDataContentsList = input.getSLDContents(fileTreeNode).getSldData();
        assertEquals(1, sldDataContentsList.size());
        // Changes where the file is to be saved to
        File saveFile = File.createTempFile(getClass().getSimpleName(), ".sld");
        SLDData sldData = (SLDData) sldDataContentsList.get(0);
        sldData.setSLDFile(saveFile);
        assertFalse(input.save(null));
        assertTrue(input.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) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) FileNotFoundException(java.io.FileNotFoundException) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URL(java.net.URL) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileSystemInput(com.sldeditor.extension.filesystem.file.FileSystemInput) File(java.io.File) Test(org.junit.Test) SLDFileHandlerTest(com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)

Example 5 with FileSystemInput

use of com.sldeditor.extension.filesystem.file.FileSystemInput 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)

Aggregations

FileSystemInput (com.sldeditor.extension.filesystem.file.FileSystemInput)5 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)3 Test (org.junit.Test)3 SLDDataInterface (com.sldeditor.common.SLDDataInterface)2 SLDData (com.sldeditor.common.data.SLDData)2 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)2 File (java.io.File)2 IOException (java.io.IOException)2 URL (java.net.URL)2 NodeInterface (com.sldeditor.common.NodeInterface)1 FileSystemInterface (com.sldeditor.common.filesystem.FileSystemInterface)1 FSTree (com.sldeditor.datasource.extension.filesystem.node.FSTree)1 DatabaseInput (com.sldeditor.extension.filesystem.database.DatabaseInput)1 GeoServerInput (com.sldeditor.extension.filesystem.geoserver.GeoServerInput)1 FileNotFoundException (java.io.FileNotFoundException)1 URISyntaxException (java.net.URISyntaxException)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 List (java.util.List)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1