Mercurial Hosting > luan
comparison src/luan/host/WebHandler.java @ 1335:e0cf0d108a77
major cleanup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 14 Feb 2019 03:10:45 -0700 |
parents | 25746915a241 |
children | 7483108154bb |
comparison
equal
deleted
inserted
replaced
1334:c88b486a9511 | 1335:e0cf0d108a77 |
---|---|
10 import luan.Luan; | 10 import luan.Luan; |
11 import luan.LuanException; | 11 import luan.LuanException; |
12 import luan.LuanTable; | 12 import luan.LuanTable; |
13 import luan.LuanFunction; | 13 import luan.LuanFunction; |
14 import luan.LuanClosure; | 14 import luan.LuanClosure; |
15 import luan.LuanRuntimeException; | |
15 import luan.modules.BasicLuan; | 16 import luan.modules.BasicLuan; |
16 import luan.modules.http.LuanHandler; | 17 import luan.modules.http.LuanHandler; |
17 import luan.modules.logging.Log4j; | 18 import luan.modules.logging.Log4j; |
18 | 19 |
19 | 20 |
20 public class WebHandler implements Handler { | 21 public class WebHandler implements Handler { |
21 private static final Logger logger = LoggerFactory.getLogger(WebHandler.class); | 22 private static final Logger logger = LoggerFactory.getLogger(WebHandler.class); |
22 | |
23 private static final class LuanRuntimeException extends RuntimeException { | |
24 final LuanException e; | |
25 | |
26 LuanRuntimeException(LuanException e) { | |
27 this.e = e; | |
28 } | |
29 } | |
30 | 23 |
31 private static final DomainHandler.Factory factory = new DomainHandler.Factory() { | 24 private static final DomainHandler.Factory factory = new DomainHandler.Factory() { |
32 public Handler newHandler(String domain) { | 25 public Handler newHandler(String domain) { |
33 File dir = new File(sitesDir,domain); | 26 File dir = new File(sitesDir,domain); |
34 if( !dir.exists() /* && !recover(dir) */ ) | 27 if( !dir.exists() /* && !recover(dir) */ ) |
101 */ | 94 */ |
102 static void initLuan(Luan luan,String dir,String domain,boolean logging) { | 95 static void initLuan(Luan luan,String dir,String domain,boolean logging) { |
103 security(luan,dir); | 96 security(luan,dir); |
104 try { | 97 try { |
105 LuanFunction fn = BasicLuan.load_file(luan,"classpath:luan/host/init.luan"); | 98 LuanFunction fn = BasicLuan.load_file(luan,"classpath:luan/host/init.luan"); |
106 fn.call(luan,new Object[]{dir,domain,logging}); | 99 fn.call(dir,domain,logging); |
107 } catch(LuanException e) { | 100 } catch(LuanException e) { |
108 throw new LuanRuntimeException(e); | 101 throw new LuanRuntimeException(e); |
109 } | 102 } |
110 } | 103 } |
111 | 104 |
115 | 108 |
116 public static void loadHandler(String domain) throws LuanException { | 109 public static void loadHandler(String domain) throws LuanException { |
117 try { | 110 try { |
118 domainHandler.getHandler(domain); | 111 domainHandler.getHandler(domain); |
119 } catch(LuanRuntimeException e) { | 112 } catch(LuanRuntimeException e) { |
120 throw e.e; | 113 throw (LuanException)e.getCause(); |
121 } | 114 } |
122 } | 115 } |
123 | 116 |
124 private static final void security(Luan luan,String dir) { | 117 private static final void security(Luan luan,String dir) { |
125 final String siteUri = "file:" + dir + "/site"; | 118 final String siteUri = "file:" + dir + "/site"; |