Search in sources :

Example 1 with FileHandlerInterface

use of com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface in project sldeditor by robward-scisys.

the class FileSystemInput method getSLDContents.

/**
 * Gets the SLD contents.
 *
 * @param node the node
 * @return the SLD contents
 */
@Override
public SelectedFiles getSLDContents(NodeInterface node) {
    SelectedFiles selectedFiles = new SelectedFiles();
    if (node instanceof FileTreeNode) {
        FileTreeNode fileTreeNode = (FileTreeNode) node;
        selectedFiles.setIsFolder(fileTreeNode.isDir());
        File f = fileTreeNode.getFile();
        String folderName = f.isFile() ? f.getParent() : f.getAbsolutePath();
        selectedFiles.setFolderName(folderName);
    }
    for (FileHandlerInterface handler : fileHandlerMap.values()) {
        List<SLDDataInterface> sldContentList = handler.getSLDContents(node);
        if (sldContentList != null) {
            selectedFiles.setSldData(sldContentList);
            selectedFiles.setDataSource(handler.isDataSource());
            return selectedFiles;
        }
    }
    return selectedFiles;
}
Also used : FileHandlerInterface(com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface) SLDDataInterface(com.sldeditor.common.SLDDataInterface) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) File(java.io.File) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 2 with FileHandlerInterface

use of com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface in project sldeditor by robward-scisys.

the class FileSystemInput method open.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.extension.input.FileSystemInterface#open(java.net.URL)
     */
@Override
public List<SLDDataInterface> open(URL url) {
    if (url != null) {
        try {
            String urlString = URLDecoder.decode(url.getFile(), "UTF-8");
            File file = new File(urlString);
            FileHandlerInterface fileHandler = getFileHandler(file.getAbsolutePath());
            if (fileHandler != null) {
                return fileHandler.open(file);
            }
        } catch (UnsupportedEncodingException e) {
            ConsoleManager.getInstance().exception(this, e);
        }
    }
    return null;
}
Also used : FileHandlerInterface(com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface) UnsupportedEncodingException(java.io.UnsupportedEncodingException) File(java.io.File)

Example 3 with FileHandlerInterface

use of com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface in project sldeditor by robward-scisys.

the class FileSystemInput method copyNodes.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.extension.input.FileSystemInterface#drop(com.sldeditor.extension.input.
     * NodeInterface, java.util.Map)
     */
@Override
public boolean copyNodes(NodeInterface destinationTreeNode, Map<NodeInterface, List<SLDDataInterface>> copyDataMap) {
    if ((destinationTreeNode == null) || (copyDataMap == null)) {
        return false;
    }
    FileTreeNode destinationNode = (FileTreeNode) destinationTreeNode;
    if (!destinationNode.isDir()) {
        destinationNode = (FileTreeNode) destinationNode.getParent();
    }
    File destinationFolder = destinationNode.getFile();
    for (NodeInterface key : copyDataMap.keySet()) {
        List<SLDDataInterface> sldDataList = copyDataMap.get(key);
        for (SLDDataInterface sldData : sldDataList) {
            String sldFilename = sldData.getSLDFile().getAbsolutePath();
            FileHandlerInterface handler = getFileHandler(sldFilename);
            if (handler != null) {
                String sldName = handler.getSLDName(sldData);
                File existingFolder = new File(sldFilename).getParentFile();
                if (existingFolder.equals(destinationFolder)) {
                    sldName = "Copy of " + sldName;
                }
                File updateFile = new File(destinationFolder, sldName);
                sldData.setSLDFile(updateFile);
                save(sldData);
            }
        }
        destinationNode.refreshFolder();
        if (treeModel != null) {
            treeModel.reload(destinationNode);
        }
    }
    return true;
}
Also used : FileHandlerInterface(com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface) SLDDataInterface(com.sldeditor.common.SLDDataInterface) File(java.io.File) NodeInterface(com.sldeditor.common.NodeInterface) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 4 with FileHandlerInterface

use of com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface in project sldeditor by robward-scisys.

the class FileTreeNodeTest method test.

/**
 * Test.
 */
@Ignore
@Test
public void test() {
    Map<String, FileHandlerInterface> fileHandlerMap = new LinkedHashMap<String, FileHandlerInterface>();
    FileHandlerInterface fileHandler = new DummyFileHandler();
    for (String fileExtension : fileHandler.getFileExtensionList()) {
        fileHandlerMap.put(fileExtension, fileHandler);
    }
    Path tmpFolder = null;
    try {
        tmpFolder = Files.createTempDirectory(getClass().getSimpleName());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    File folder = tmpFolder.toFile();
    File parent = folder.getParentFile();
    String name = folder.getName();
    try {
        FileTreeNode.setFileHandlerMap(fileHandlerMap);
        FileTreeNode node = new FileTreeNode(parent, name);
        assertTrue(node.isDir());
        assertTrue(node.getAllowsChildren());
        assertFalse(node.isLeaf());
        assertNull(node.getHandler());
        assertEquals(name, node.getName());
        assertEquals(DataFlavourManager.FOLDER_DATAITEM_FLAVOR, node.getDataFlavour());
        // CHECKSTYLE:OFF
        File tmpFile1 = File.createTempFile("sldeditor", ".abc", folder);
        // CHECKSTYLE:ON
        Thread.sleep(1000);
        // Has a file extension not expecting
        assertEquals(0, node.getChildCount());
        File tmpFile2 = File.createTempFile("sldeditor", ".test", folder);
        Thread.sleep(10000);
        assertEquals(1, node.getChildCount());
        tmpFile2.delete();
        Thread.sleep(10000);
        assertEquals(0, node.getChildCount());
        assertEquals(folder.getAbsolutePath(), node.getDestinationText());
        tmpFile1.delete();
        folder.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());
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) FileHandlerInterface(com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with FileHandlerInterface

use of com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface in project sldeditor by robward-scisys.

the class FileSystemInput method save.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.extension.input.FileSystemInterface#save(com.sldeditor.ui.iface.
     * SLDDataInterface)
     */
@Override
public boolean save(SLDDataInterface sldData) {
    if (sldData == null) {
        return false;
    }
    boolean result1 = false;
    boolean result2 = false;
    // Save SLD file
    String sldFilename = sldData.getSLDFile().getAbsolutePath();
    FileHandlerInterface fileHandler = getFileHandler(sldFilename);
    if (fileHandler != null) {
        result1 = fileHandler.save(sldData);
        if (result1) {
            ConsoleManager.getInstance().information(this, Localisation.getField(FileSystemInput.class, "FileSystemInput.sldfilesaved") + sldFilename);
        }
    }
    // Save SLD editor file
    File sldEditorFile = sldData.getSldEditorFile();
    if (sldEditorFile != null) {
        fileHandler = getFileHandler(sldEditorFile.getAbsolutePath());
        if (fileHandler != null) {
            result2 = fileHandler.save(sldData);
            if (result2) {
                ;
                ConsoleManager.getInstance().information(this, Localisation.getField(FileSystemInput.class, "FileSystemInput.sldeditorfilesaved") + sldEditorFile.getAbsolutePath());
            }
        }
    }
    return result1 || result2;
}
Also used : FileHandlerInterface(com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface) File(java.io.File)

Aggregations

FileHandlerInterface (com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface)6 File (java.io.File)5 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)3 SLDDataInterface (com.sldeditor.common.SLDDataInterface)2 NodeInterface (com.sldeditor.common.NodeInterface)1 DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)1 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1