summaryrefslogtreecommitdiff
path: root/BKUCommonGUI/src/main/java/at/gv/egiz/bku
diff options
context:
space:
mode:
authorclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-11-24 18:48:00 +0000
committerclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-11-24 18:48:00 +0000
commit5af9b75dccc1b52d1382fe0f2df30affd509f5b9 (patch)
tree8640f3e4f0446e85cbe34f2d87916e187f5b40ad /BKUCommonGUI/src/main/java/at/gv/egiz/bku
parent650732adaff82503b19a41b6c53d4299be9a1533 (diff)
downloadmocca-5af9b75dccc1b52d1382fe0f2df30affd509f5b9.tar.gz
mocca-5af9b75dccc1b52d1382fe0f2df30affd509f5b9.tar.bz2
mocca-5af9b75dccc1b52d1382fe0f2df30affd509f5b9.zip
Filenames derived from reference URI
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@553 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku')
-rw-r--r--BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java10
-rw-r--r--BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeFilter.java56
-rw-r--r--BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeTypes.java53
-rw-r--r--BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/SecureViewerSaveDialog.java5
4 files changed, 66 insertions, 58 deletions
diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java
index 16024fcc..6af22815 100644
--- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java
+++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java
@@ -39,10 +39,14 @@ public class HyperlinkRenderer extends DefaultTableCellRenderer {
@Override
protected void setValue(Object value) {
String hrefText;
- if (renderReferenceId) {
- hrefText = ((HashDataInput) value).getReferenceId();
+ if (((HashDataInput) value).getFilename() != null) {
+ hrefText = ((HashDataInput) value).getFilename();
} else {
- hrefText = ((HashDataInput) value).getMimeType();
+ if (renderReferenceId) {
+ hrefText = ((HashDataInput) value).getReferenceId();
+ } else {
+ hrefText = ((HashDataInput) value).getMimeType();
+ }
}
super.setText("<html><u>" + hrefText + "</u></html>");
setForeground(BKUGUIFacade.HYPERLINK_COLOR);
diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeFilter.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeFilter.java
index c0385dce..5d64eb4f 100644
--- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeFilter.java
+++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeFilter.java
@@ -26,14 +26,6 @@ import javax.swing.filechooser.FileFilter;
*/
class MimeFilter extends FileFilter {
- private static final String MIMETYPE_DESC_XML = "mimetype.desc.xml";
- private static final String MIMETYPE_DESC_HTML = "mimetype.desc.html";
- private static final String MIMETYPE_DESC_XHTML = "mimetype.desc.xhtml";
- private static final String MIMETYPE_DESC_TXT = "mimetype.desc.txt";
- private static final String MIMETYPE_DESC_PDF = "mimetype.desc.pdf";
- private static final String MIMETYPE_DESC_BIN = "mimetype.desc.bin";
- private static final String MIMETYPE_DESC_UNKNOWN = "mimetype.desc.unknown";
-
protected String mimeType;
protected ResourceBundle messages;
@@ -48,21 +40,7 @@ class MimeFilter extends FileFilter {
if (f.isDirectory()) {
return true;
}
-
- String ext = getExtension(f);
- if ("text/xml".equals(mimeType)) {
- return "xml".equalsIgnoreCase(ext);
- } else if ("text/html".equals(mimeType)) {
- return "html".equalsIgnoreCase(ext) || "htm".equalsIgnoreCase(ext);
- } else if ("application/xhtml+xml".equals(mimeType)) {
- return "xhtml".equalsIgnoreCase(ext);
- } else if ("text/plain".equals(mimeType)) {
- return "txt".equalsIgnoreCase(ext);
- } else if ("application/pdf".equals(mimeType)) {
- return "pdf".equalsIgnoreCase(ext);
- } else {
- return true;
- }
+ return MimeTypes.getExtension(mimeType).equalsIgnoreCase(getExtension(f));
}
private String getExtension(File f) {
@@ -78,38 +56,10 @@ class MimeFilter extends FileFilter {
@Override
public String getDescription() {
- if ("text/xml".equals(mimeType)) {
- return messages.getString(MIMETYPE_DESC_XML);
- } else if ("text/html".equals(mimeType)) {
- return messages.getString(MIMETYPE_DESC_HTML);
- } else if ("application/xhtml+xml".equals(mimeType)) {
- return messages.getString(MIMETYPE_DESC_XHTML);
- } else if ("text/plain".equals(mimeType)) {
- return messages.getString(MIMETYPE_DESC_TXT);
- } else if ("application/pdf".equals(mimeType)) {
- return messages.getString(MIMETYPE_DESC_PDF);
- } else if ("application/octet-stream".equals(mimeType)) {
- return messages.getString(MIMETYPE_DESC_BIN);
- } else {
- return messages.getString(MIMETYPE_DESC_UNKNOWN);
- }
+ return messages.getString(MimeTypes.getDescriptionKey(mimeType));
}
public static String getExtension(String mimeType) {
- if ("text/xml".equals(mimeType)) {
- return ".xml";
- } else if ("text/html".equals(mimeType)) {
- return ".html";
- } else if ("application/xhtml+xml".equals(mimeType)) {
- return ".xhtml";
- } else if ("text/plain".equals(mimeType)) {
- return ".txt";
- } else if ("application/pdf".equals(mimeType)) {
- return ".pdf";
- } else if ("application/octet-stream".equals(mimeType)) {
- return ".bin";
- } else {
- return "";
- }
+ return MimeTypes.getExtension(mimeType);
}
} \ No newline at end of file
diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeTypes.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeTypes.java
new file mode 100644
index 00000000..4500fa71
--- /dev/null
+++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeTypes.java
@@ -0,0 +1,53 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package at.gv.egiz.bku.gui.viewer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * @author clemens
+ */
+public class MimeTypes {
+
+ private static final Map<String , String> FILE_EXTENSIONS = new HashMap<String, String>() {{
+ put("application/msword", ".doc");
+ put("application/octet-stream", ".bin");
+ put("application/pdf", ".pdf");
+ put("application/xhtml+xml", ".xhtml");
+ put("text/html", ".html");
+ put("text/plain", ".txt");
+ put("text/xml", ".xml");
+ }};
+
+ private static final Map<String , String> DESCRIPTIONS = new HashMap<String, String>() {{
+ put("application/msword", "mimetype.desc.doc");
+ put("application/octet-stream", "mimetype.desc.bin");
+ put("application/pdf", "mimetype.desc.pdf");
+ put("application/xhtml+xml", "mimetype.desc.xhtml");
+ put("text/html", "mimetype.desc.html");
+ put("text/plain", "mimetype.desc.txt");
+ put("text/xml", "mimetype.desc.xml");
+ }};
+
+ public static String getExtension(String mimetype) {
+ if (FILE_EXTENSIONS.containsKey(mimetype)) {
+ return FILE_EXTENSIONS.get(mimetype);
+ }
+ return "";
+ }
+
+ /**
+ * @return bundle key to be resolved in message resource bundle
+ */
+ public static String getDescriptionKey(String mimetype) {
+ if (DESCRIPTIONS.containsKey(mimetype)) {
+ return DESCRIPTIONS.get(mimetype);
+ }
+ return "mimetype.desc.unknown";
+ }
+}
diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/SecureViewerSaveDialog.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/SecureViewerSaveDialog.java
index 40133f95..3303d4ef 100644
--- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/SecureViewerSaveDialog.java
+++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/SecureViewerSaveDialog.java
@@ -52,8 +52,9 @@ public class SecureViewerSaveDialog {
String mimeType = hashDataInput.getMimeType();
MimeFilter mimeFilter = new MimeFilter(mimeType, messages);
fileDialog.setFileFilter(mimeFilter);
- String filename = messages
- .getString(BKUGUIFacade.SAVE_HASHDATAINPUT_PREFIX)
+ String filename = (hashDataInput.getFilename() != null) ?
+ hashDataInput.getFilename() :
+ messages.getString(BKUGUIFacade.SAVE_HASHDATAINPUT_PREFIX)
+ MimeFilter.getExtension(mimeType);
fileDialog.setSelectedFile(new File(userHome, filename));