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;
}
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;
}
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;
}
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();
}
}
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;
}
Aggregations