|
1 /* |
|
2 * Copyright 2011 Tomas Zeman <tzeman@volny.cz> |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 package bootstrap.liftweb |
|
17 |
|
18 import net.liftweb.common._ |
|
19 import net.liftweb.http._ |
|
20 import net.liftweb.mapper._ |
|
21 import net.liftweb.sitemap._ |
|
22 import net.liftweb.sitemap.Loc._ |
|
23 import net.liftweb.util._ |
|
24 import net.liftweb.widgets.menu.MenuWidget |
|
25 import net.tz.lift.snippet.ActionLinks |
|
26 import net.tz.lift.util.YmdDateTimeConverter |
|
27 import radview.model._ |
|
28 import radview.snippet._ |
|
29 import scala.xml.NodeSeq |
|
30 |
|
31 class Boot extends Logger { |
|
32 |
|
33 def boot = { |
|
34 /* DB stuff */ |
|
35 initDb("radacct", RadAcctConnectionIdentifier) |
|
36 initDb("radius", RadiusConnectionIdentifier) |
|
37 initDb("syslog", SyslogConnectionIdentifier) |
|
38 S.addAround(DB.buildLoanWrapper(List(RadAcctConnectionIdentifier, |
|
39 RadiusConnectionIdentifier, SyslogConnectionIdentifier))) |
|
40 |
|
41 if (Props.mode == Props.RunModes.Development) |
|
42 DB.addLogFunc { (dbLog, l) => dbLog.statementEntries.foreach { e => |
|
43 debug("Query: " + e.statement) |
|
44 }} |
|
45 |
|
46 /* Date format */ |
|
47 LiftRules.dateTimeConverter.default.set { () => YmdDateTimeConverter } |
|
48 |
|
49 /* Handle end slash and drop it (except for home page) */ |
|
50 LiftRules.statelessRewrite.append { |
|
51 case RewriteRequest(ParsePath(xs,_,_,true),_,_) if (xs.size > 1) && |
|
52 (xs.lastOption == Some("index")) => |
|
53 RewriteResponse(xs dropRight 1) |
|
54 } |
|
55 |
|
56 /* Snippet dispatch */ |
|
57 LiftRules.snippetDispatch.append { |
|
58 case "Menubar" => new AnyRef with DispatchSnippet { |
|
59 def dispatch: DispatchIt = { |
|
60 case _ => { xhtml => MenuWidget() } |
|
61 } |
|
62 } |
|
63 case "action-links" => ActionLinks |
|
64 } |
|
65 |
|
66 /* Sitemap */ |
|
67 SiteMap.enforceUniqueLinks = false |
|
68 |
|
69 LiftRules.setSiteMap(SiteMap( |
|
70 Menu.i("Home") / "index" >> Hidden, |
|
71 Menu(CellSnippet), |
|
72 Menu.i("Cells") / "cell", |
|
73 Menu(SessionSnippet), |
|
74 Menu(AccountSnippet), |
|
75 Menu.i("Accounts") / "account" |
|
76 )) |
|
77 |
|
78 /* Menu widget */ |
|
79 MenuWidget.init() |
|
80 |
|
81 /* Http conf */ |
|
82 LiftRules.logServiceRequestTiming = false |
|
83 LiftRules.early.append(_.setCharacterEncoding("UTF-8")) |
|
84 } |
|
85 |
|
86 def initDb(ident: String, connId: ConnectionIdentifier) = { |
|
87 val driver = "com.mysql.jdbc.Driver" |
|
88 val vendor = new StandardDBVendor(driver, |
|
89 Props.get("db."+ident+".url") openOr ("jdbc:mysql://localhost/"+ident), |
|
90 Props.get("db."+ident+".user"), Props.get("db."+ident+".pass")) |
|
91 //LiftRules.unloadHooks.append(vendor.closeAllConnections_! _) |
|
92 DB.defineConnectionManager(connId, vendor) |
|
93 vendor.newConnection(connId) |
|
94 } |
|
95 } |
|
96 |
|
97 // vim: set ts=2 sw=2 et: |