summaryrefslogtreecommitdiff
path: root/BKUCommonGUI/src/main/java/at/gv
diff options
context:
space:
mode:
Diffstat (limited to 'BKUCommonGUI/src/main/java/at/gv')
-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
-rw-r--r--BKUCommonGUI/src/main/java/at/gv/egiz/stal/impl/ByteArrayHashDataInput.java9
5 files changed, 74 insertions, 59 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));
diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/stal/impl/ByteArrayHashDataInput.java b/BKUCommonGUI/src/main/java/at/gv/egiz/stal/impl/ByteArrayHashDataInput.java
index 6ca9a0b2..b9416845 100644
--- a/BKUCommonGUI/src/main/java/at/gv/egiz/stal/impl/ByteArrayHashDataInput.java
+++ b/BKUCommonGUI/src/main/java/at/gv/egiz/stal/impl/ByteArrayHashDataInput.java
@@ -36,8 +36,9 @@ public class ByteArrayHashDataInput implements HashDataInput {
protected String id;
protected String mimeType;
protected String encoding;
+ protected String filename;
- public ByteArrayHashDataInput(byte[] hashData, String id, String mimeType, String encoding) {
+ public ByteArrayHashDataInput(byte[] hashData, String id, String mimeType, String encoding, String filename) {
if (hashData == null) {
throw new NullPointerException("HashDataInput not provided.");
}
@@ -45,6 +46,7 @@ public class ByteArrayHashDataInput implements HashDataInput {
this.id = id;
this.mimeType = mimeType;
this.encoding = encoding;
+ this.filename = filename;
}
/**
@@ -96,5 +98,10 @@ public class ByteArrayHashDataInput implements HashDataInput {
return encoding;
}
+ @Override
+ public String getFilename() {
+ return filename;
+ }
+
}