
net.liftweb.http.LiftMerge.scala Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2009-2011 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.liftweb
package http
import scala.collection.mutable.{HashMap, ArrayBuffer, ListBuffer}
import scala.xml._
import net.liftweb.util._
import net.liftweb.common._
import net.liftweb.http.js._
import Helpers._
private[http] trait LiftMerge {
self: LiftSession =>
/**
* Manages the merge phase of the rendering pipeline
*/
def merge(xhtml: NodeSeq, req: Req): Node = {
val snippetHashs: HashMap[String, Box[NodeSeq]] = this.deferredSnippets.is
val waitUntil = millis + LiftRules.lazySnippetTimeout.vend.millis
val stripComments: Boolean = LiftRules.stripComments.vend
def waitUntilSnippetsDone() {
val myMillis = millis
snippetHashs.synchronized {
if (myMillis >= waitUntil || snippetHashs.isEmpty || !snippetHashs.values.toIterator.contains(Empty)) ()
else {
snippetHashs.wait(waitUntil - myMillis)
waitUntilSnippetsDone()
}
}
}
waitUntilSnippetsDone()
val processedSnippets: Map[String, NodeSeq] = Map(snippetHashs.toList.flatMap {
case (name, Full(value)) => List((name, value))
case (name, f: Failure) => List((name, LiftRules.deferredSnippetFailure.vend(f)))
case (name, Empty) => List((name, LiftRules.deferredSnippetTimeout.vend))
case _ => Nil
}: _*)
val hasHtmlHeadAndBody: Boolean = xhtml.find {
case e: Elem if e.label == "html" =>
e.child.find {
case e: Elem if e.label == "head" => true
case _ => false
}.isDefined &&
e.child.find {
case e: Elem if e.label == "body" => true
case _ => false
}.isDefined
case _ => false
}.isDefined
var htmlTag =
var headTag =
var bodyTag = XHTML Validation error:{e.msg}at line{e.line + 1}and column{e.col}
)
val rule = new RewriteRule {
override def transform(n: Node) = n match {
case e: Elem if e.label == "body" =>
Elem(e.prefix, e.label, e.attributes, e.scope, e.child ++ errors: _*)
case x => super.transform(x)
}
}
(new RuleTransformer(rule)).transform(tmpRet)(0)
}
} else tmpRet
ret
}
}
}