Skip to content

Instantly share code, notes, and snippets.

@casualjim
Created November 3, 2010 21:30
Show Gist options
  • Save casualjim/661753 to your computer and use it in GitHub Desktop.
Save casualjim/661753 to your computer and use it in GitHub Desktop.
object Stream {
sealed trait XMPPStreamError
object BadFormatError {
def apply( text: Option[String] = None, applicationCondition: Seq[Node]) = {
<stream:error>
<bad-format xmlns={XMPP_STREAMS_NS} />
{text.map(t => <text xmlns={XMPP_STREAMS_NS}>{t}</text>) getOrElse Nil}
{applicationCondition getOrElse Nil}
</stream:error>
}
def unapply(stanza: NodeSeq) = stanza match {
case err @ <stream:error>{ ch @ _*}</stream:error> if !(err \ "bad-format").isEmpty => {
val txt = (err \ "text").text
val text = if(txt.isNotBlank) Some(txt) else None
val appCond = ch.filterNot(n => ("bad-format" :: "text" :: Nil).contains(n))
Some((text, appCond))
}
case _ => None
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment