(empty log message)
@@ -0,0 +1,69 @@ | ||
1 | +package org.alinous; | |
2 | + | |
3 | +import java.io.IOException; | |
4 | +import java.io.InputStream; | |
5 | +import java.util.HashMap; | |
6 | +import java.util.Iterator; | |
7 | +import java.util.List; | |
8 | +import java.util.Map; | |
9 | + | |
10 | +import org.alinous.expections.AlinousException; | |
11 | +import org.jdom.Document; | |
12 | +import org.jdom.Element; | |
13 | +import org.jdom.JDOMException; | |
14 | +import org.jdom.input.SAXBuilder; | |
15 | + | |
16 | +public class MimeManager | |
17 | +{ | |
18 | + private Map<String, String> contentTypes = new HashMap<String, String>(); | |
19 | + | |
20 | + | |
21 | + | |
22 | + public MimeManager(InputStream stream) throws AlinousException | |
23 | + { | |
24 | + Document doc = null; | |
25 | + try { | |
26 | + doc = new SAXBuilder().build(stream); | |
27 | + } catch (JDOMException e) { | |
28 | + throw new AlinousException(e, null); | |
29 | + } catch (IOException e) { | |
30 | + throw new AlinousException(e, "mimetypes.xml is broken"); | |
31 | + } | |
32 | + | |
33 | + | |
34 | + Element root = doc.getRootElement(); | |
35 | + | |
36 | + AlinousDebug.debugOut("root name" + root.getName()); | |
37 | + | |
38 | + try{ | |
39 | + parseElements(root); | |
40 | + }finally{ | |
41 | + doc.clone(); | |
42 | + } | |
43 | + } | |
44 | + | |
45 | + @SuppressWarnings("unchecked") | |
46 | + private void parseElements(Element root) | |
47 | + { | |
48 | + List<Element> mimeMappings = root.getChildren("mime-mapping"); | |
49 | + Iterator<Element> it = mimeMappings.iterator(); | |
50 | + while(it.hasNext()){ | |
51 | + Element el = it.next(); | |
52 | + | |
53 | + Element extEl = el.getChild("extension"); | |
54 | + Element contEl = el.getChild("mime-type"); | |
55 | + | |
56 | + if(extEl != null && contEl != null){ | |
57 | + String extention = extEl.getText(); | |
58 | + String content = contEl.getText(); | |
59 | + | |
60 | + this.contentTypes.put(extention, content); | |
61 | + | |
62 | + // TODO: debug | |
63 | + AlinousDebug.debugOut("Accepted contentType: " + extention + " -> " + content); | |
64 | + } | |
65 | + | |
66 | + } | |
67 | + } | |
68 | + | |
69 | +} |
@@ -70,6 +70,9 @@ | ||
70 | 70 | // Singleton instance |
71 | 71 | private static AlinousCore instance = null; |
72 | 72 | |
73 | + // MIME types | |
74 | + private MimeManager mime; | |
75 | + | |
73 | 76 | public static String EXT_HTML = "html"; |
74 | 77 | public static String EXT_ALNS = "alns"; |
75 | 78 |
@@ -145,7 +148,11 @@ | ||
145 | 148 | // maintain service start |
146 | 149 | this.maintainanceService = new AlinousMaintainThreadManager(this.systemRepository, this.logger); |
147 | 150 | this.maintainanceService.start(); |
148 | - | |
151 | + | |
152 | + // mime | |
153 | + if(stream != null){ | |
154 | + this.mime = new MimeManager(stream); | |
155 | + } | |
149 | 156 | } |
150 | 157 | |
151 | 158 | public void registerAlinousObject(String dsPath, String acPath) throws AlinousException |
@@ -232,6 +239,12 @@ | ||
232 | 239 | return logger; |
233 | 240 | } |
234 | 241 | |
242 | + | |
243 | + public MimeManager getMime() | |
244 | + { | |
245 | + return mime; | |
246 | + } | |
247 | + | |
235 | 248 | @Override |
236 | 249 | protected void finalize() throws Throwable |
237 | 250 | { |