• R/O
  • SSH
  • HTTPS

alinous-core: Commit


Commit MetaInfo

Revision120 (tree)
Time2007-11-25 18:47:08
Authori-zuka

Log Message

(empty log message)

Change Summary

Incremental Difference

--- AlinousCoreIDE1.0/AlinousCore/src/org/alinous/MimeManager.java (nonexistent)
+++ AlinousCoreIDE1.0/AlinousCore/src/org/alinous/MimeManager.java (revision 120)
@@ -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+}
--- AlinousCoreIDE1.0/AlinousCore/src/org/alinous/AlinousCore.java (revision 119)
+++ AlinousCoreIDE1.0/AlinousCore/src/org/alinous/AlinousCore.java (revision 120)
@@ -70,6 +70,9 @@
7070 // Singleton instance
7171 private static AlinousCore instance = null;
7272
73+ // MIME types
74+ private MimeManager mime;
75+
7376 public static String EXT_HTML = "html";
7477 public static String EXT_ALNS = "alns";
7578
@@ -145,7 +148,11 @@
145148 // maintain service start
146149 this.maintainanceService = new AlinousMaintainThreadManager(this.systemRepository, this.logger);
147150 this.maintainanceService.start();
148-
151+
152+ // mime
153+ if(stream != null){
154+ this.mime = new MimeManager(stream);
155+ }
149156 }
150157
151158 public void registerAlinousObject(String dsPath, String acPath) throws AlinousException
@@ -232,6 +239,12 @@
232239 return logger;
233240 }
234241
242+
243+ public MimeManager getMime()
244+ {
245+ return mime;
246+ }
247+
235248 @Override
236249 protected void finalize() throws Throwable
237250 {
Show on old repository browser