|
From: <jrb...@us...> - 2009-10-19 18:50:40
|
Revision: 971
http://cishell.svn.sourceforge.net/cishell/?rev=971&view=rev
Author: jrbibers
Date: 2009-10-19 18:50:27 +0000 (Mon, 19 Oct 2009)
Log Message:
-----------
The suggested filename in the file save dialog is now checked for invalid filename characters (like ? or *). Any found are replaced with a #.
Suggested filenames are produced from the item's label in the data manager. Since the label may contain characters which are not valid in filenames (like a quotation mark), previously the suggested filename could have been invalid and so the file save dialog would open with no suggestion. Now the user should always get a suggested filename.
Reviewed by Micah.
Modified Paths:
--------------
trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath
trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF
trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/FileUtil.java
trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java
Removed Paths:
-------------
trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.pde.core.prefs
Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath
===================================================================
--- trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath 2009-10-19 04:53:55 UTC (rev 970)
+++ trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath 2009-10-19 18:50:27 UTC (rev 971)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.pde.core.prefs
===================================================================
--- trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.pde.core.prefs 2009-10-19 04:53:55 UTC (rev 970)
+++ trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.pde.core.prefs 2009-10-19 18:50:27 UTC (rev 971)
@@ -1,3 +0,0 @@
-#Wed Sep 27 14:27:31 EDT 2006
-eclipse.preferences.version=1
-pluginProject.extensions=false
Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF
===================================================================
--- trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2009-10-19 04:53:55 UTC (rev 970)
+++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2009-10-19 18:50:27 UTC (rev 971)
@@ -24,3 +24,4 @@
Service-Component: OSGI-INF/load.xml, OSGI-INF/save.xml, OSGI-INF/view.xml, OSGI-INF/viewwith.xml
Require-Bundle: org.eclipse.swt,
org.eclipse.ui
+Bundle-RequiredExecutionEnvironment: J2SE-1.4
Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/FileUtil.java
===================================================================
--- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/FileUtil.java 2009-10-19 04:53:55 UTC (rev 970)
+++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/FileUtil.java 2009-10-19 18:50:27 UTC (rev 971)
@@ -2,10 +2,37 @@
import java.io.File;
import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
import org.osgi.service.log.LogService;
public class FileUtil {
+ public static final char FILENAME_CHARACTER_REPLACEMENT = '#';
+
+ /* Attempt to enumerate characters which cannot be used to name a file.
+ * For our purposes, this should be as aggressive as sensible.
+ * This includes all such characters for modern Windows systems, plus %.
+ * Please add any others.
+ */
+ public static final Collection INVALID_FILENAME_CHARACTERS;
+ static {
+ Collection s = new HashSet();
+ s.add(new Character('\\'));
+ s.add(new Character('/'));
+ s.add(new Character(':'));
+ s.add(new Character('*'));
+ s.add(new Character('?'));
+ s.add(new Character('"'));
+ s.add(new Character('<'));
+ s.add(new Character('>'));
+ s.add(new Character('|'));
+ s.add(new Character('%'));
+ INVALID_FILENAME_CHARACTERS = Collections.unmodifiableCollection(s);
+ }
+
private static int uniqueIntForTempFile = 1;
public static File getTempFile(String fileName, String extension, LogService logger) {
@@ -64,9 +91,22 @@
return extension;
}
-
- public static String extractFileName(String fileLabel) {
+
+ public static String replaceInvalidFilenameCharacters(String filename) {
+ String cleanedFilename = filename;
+ for (Iterator invalidCharacters = INVALID_FILENAME_CHARACTERS.iterator();
+ invalidCharacters.hasNext();) {
+ char invalidCharacter = ((Character) invalidCharacters.next()).charValue();
+
+ cleanedFilename =
+ cleanedFilename.replace(invalidCharacter, FILENAME_CHARACTER_REPLACEMENT);
+ }
+
+ return cleanedFilename;
+ }
+
+ public static String extractFileName(String fileLabel) {
//index variables will be -1 if index is not found.
int descriptionEndIndex = fileLabel.lastIndexOf(":");
int filePathEndIndex = fileLabel.lastIndexOf(File.separator);
@@ -75,9 +115,8 @@
//zero and none of the string will be cut off the front.
int startIndex = Math.max(descriptionEndIndex, filePathEndIndex) + 1;
- String fileNameWithExtension = fileLabel.substring(startIndex);
+ String fileNameWithExtension = fileLabel.substring(startIndex);
-
//find the first character of the file name extension.
int extensionBeginIndex = fileNameWithExtension.lastIndexOf(".");
@@ -93,8 +132,16 @@
}
String fileNameWithoutExtension = fileNameWithExtension.substring(0, endIndex);
-
- String fileName = fileNameWithoutExtension;
- return fileName;
+
+ return fileNameWithoutExtension;
}
+
+ public static void main(String[] args) {
+// String s = "Input data: CSV file: C:\\Documents and Settings\\katy\\Desktop\\NIH-Demo\\nih\\NIH-data\\NIH-NIGMS-PPBC-R01s,-FY08-Publications.csv";
+ String s = "a\\b/c:d*e?f\"g<h>i|j";
+
+ System.out.println(replaceInvalidFilenameCharacters(s));
+
+ System.exit(0);
+ }
}
Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java
===================================================================
--- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2009-10-19 04:53:55 UTC (rev 970)
+++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2009-10-19 18:50:27 UTC (rev 971)
@@ -119,7 +119,9 @@
String fileLabel = (String)data.getMetadata().get(DataProperty.LABEL);
String suggestedFileName = FileUtil.extractFileName(fileLabel);
- dialog.setFileName(suggestedFileName + "." + ext);
+ String cleanedSuggestedFileName =
+ FileUtil.replaceInvalidFilenameCharacters(suggestedFileName);
+ dialog.setFileName(cleanedSuggestedFileName + "." + ext);
// if (fileLabel == null) {
// dialog.setFileName("*." + ext);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|