2 // Author: Berlin Brown
6 package org
.spirit
.lift
.agents
.util
8 import java
.text
.MessageFormat
12 // @see KeywordProcessor
13 def formatTextAscii(str
: String
): String
= {
14 val val_bytes
= str
.getBytes("US-ASCII")
15 val val_text
= new java
.lang
.String(val_bytes
)
18 def filterNonAscii(value
: String
): String
= {
19 // Filter out non alphanumeric chars
20 val output
= value
.replaceAll("\\P{ASCII}+", "")
23 def createKeywords(value
: String
): String
= {
24 // Filter out non alphanumeric chars
25 val output
= value
.replaceAll("[^\\s0-9a-zA-Z]", "")
26 return output
.trim().toLowerCase
28 def formatDescription(value
: String
): String
= {
29 val postfix
= if (value
.length
> maxDescrLen
) "..." else ""
30 return formatTextAscii(value
).take(maxDescrLen
) + postfix
32 def formatKeywords(value
: String
): String
= {
33 return createKeywords(formatTextAscii(value
))
35 def msgFormatStr(text
: String
, args
: Any
*): String
= {
37 else MessageFormat
.format(text
, textParams(args
))
39 private def textParams(s
: Seq
[Any
]): Array
[AnyRef
] = {
40 val res
= new Array
[AnyRef
](s
.length
)
43 while (iter
.hasNext
) {
44 res(i
) = iter
.next
match {
45 case x
: Boolean
=> new java
.lang
.Boolean(x
)
46 case x
: Byte
=> new java
.lang
.Byte(x
)
47 case x
: Short
=> new java
.lang
.Short(x
)
48 case x
: Char
=> new java
.lang
.Character(x
)
49 case x
: Int
=> new java
.lang
.Integer(x
)
50 case x
: Long
=> new java
.lang
.Long(x
)
51 case x
: Float
=> new java
.lang
.Float(x
)
52 case x
: Double
=> new java
.lang
.Double(x
)