@author kreon
| 47 | * |
| 48 | */ |
| 49 | public class HttpdModule extends JnodeModule { |
| 50 | private static final String CONFIG_PORT = "port"; |
| 51 | private static final String CONFIG_LINK_REG = "linkreg"; |
| 52 | private static final String CONFIG_POINT_REG = "pointreg"; |
| 53 | private static final String CONFIG_HDG_REG = "hdgpointreg"; |
| 54 | private static final String CONFIG_EXTERNAL = "external"; |
| 55 | |
| 56 | public static final Logger logger = Logger.getLogger(HttpdModule.class); |
| 57 | private short port; |
| 58 | private boolean linkreg; |
| 59 | private boolean pointreg; |
| 60 | private boolean hdgpointreg; |
| 61 | private String external; |
| 62 | |
| 63 | public HttpdModule(String configFile) throws JnodeModuleException { |
| 64 | super(configFile); |
| 65 | port = Short.valueOf(properties.getProperty(CONFIG_PORT, "8080")); |
| 66 | linkreg = Boolean.valueOf(properties.getProperty(CONFIG_LINK_REG, |
| 67 | "false")); |
| 68 | pointreg = Boolean.valueOf(properties.getProperty(CONFIG_POINT_REG, |
| 69 | "false")); |
| 70 | external = properties.getProperty(CONFIG_EXTERNAL); |
| 71 | hdgpointreg = Boolean.valueOf(properties.getProperty(CONFIG_HDG_REG, |
| 72 | "false")); |
| 73 | HTML.setExternalPath(external); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public void handle(IEvent event) { |
| 78 | |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public void start() { |
| 83 | |
| 84 | Spark.setPort(port); |
| 85 | if (external != null) { |
| 86 | Spark.externalStaticFileLocation(external); |
| 87 | } |
| 88 | Spark.staticFileLocation("/www"); |
| 89 | |
| 90 | /**** PUBLIC LINKS *****/ |
| 91 | Spark.get(new SelfRoute()); |
| 92 | Spark.get(new SelfRoute("/")); |
| 93 | Spark.get(new SelfRoute("")); |
| 94 | Spark.get(new EchoareaCSVRoute()); |
| 95 | |
| 96 | Spark.post(new HDGPointRequestRoute(hdgpointreg)); |
| 97 | |
| 98 | if (pointreg) { |
| 99 | Spark.get(new BecomePointRoute(true)); |
| 100 | Spark.get(new PointRequestConfirmRoute()); |
| 101 | Spark.post(new PointRequestRoute()); |
| 102 | } else { |
| 103 | Spark.get(new BecomePointRoute(false)); |
| 104 | } |
| 105 | if (linkreg) { |
| 106 | Spark.get(new BecomeLinkRoute(true)); |