timperrett (owner)

Forks

Revisions

gist: 137066 Download_button fork
public
Public Clone URL: git://gist.github.com/137066.git
Embed All Files: show embed
Java #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  /**
* api helpers
*/
  
   implicit def boxNodeSeqToNodeSeq(in: Box[NodeSeq]): NodeSeq = {
     in match {
       case Full(n) => n
       case Failure(msg, _, _) => <error>{msg}</error>
       case _ => <error></error>
     }
   }
 
  implicit def tupleSeqNodeToResponse(in: (String, Seq[Node])): LiftResponse = {
    buildResponse(true, in._1, Empty, in._2)
  }
 
  implicit def putResponseInBox(in: LiftResponse): Box[LiftResponse] = Full(in)
  
  
  def buildResponse(success: Boolean, rootname: String, msg: Box[NodeSeq], body: NodeSeq): LiftResponse = {
    XmlResponse(
      wrapXmlBody(rootname, body)
    )
  }
  
  def wrapXmlBody(in: String, elems: NodeSeq): Elem = {
    Elem(null,in,Null,TopScope,elems:_*)
  }
  
  /**
* The attribute name for success
*/
  def successAttrName: String = "success"
 
  /**
* The attribute name for operation
*/
  def operationAttrName: String = "operation"
 
  /**
* The attribute name for any msg attribute
*/
  def msgAttrName: String = "msg"
  
  protected def operation: Option[NodeSeq] =
  (for (req <- S.request) yield req.path.partPath match {
      case _ :: name :: _ => name
      case _ => ""
    }).map(Text)