Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sdlscala
- import java.io.File
- import xml._
- import transform.{RuleTransformer, RewriteRule}
- object App {
- implicit def addGoodCopyToAttribute(attr: Attribute) = new {
- def goodcopy(key: String = attr.key, value: Any = attr.value): Attribute =
- Attribute(attr.pre, key, Text(value.toString), attr.next)
- }
- implicit def iterableToMetaData(items: Iterable[MetaData]): MetaData = {
- items match {
- case Nil => Null
- case head :: tail => head.copy(next = iterableToMetaData(tail))
- }
- }
- def main(args: Array[String]) {
- val from = "Tridion"
- val to = "SDL Tridion"
- def replace(s: String) = s.replace(to, from).replace(from, to)
- val transformation = new RewriteRule {
- override def transform(n: Node): NodeSeq = n match {
- case elem: Elem => elem.copy(attributes =
- for (attr <- elem.attributes) yield attr match {
- case attr@Attribute("title", _, _) =>
- attr.goodcopy(value=attr.value.text+"ddd")
- case other => other
- }
- )
- case Text(text) if text.contains(from) => new Text(replace(text))
- case other => other
- }
- }
- val dir = new File(".")
- val files = dir.listFiles.filter(f => f.isFile &&
- (f.getName.endsWith(".xml") || f.getName.endsWith(".xls")) &&
- !f.getName.endsWith("pom.xml"))
- files.foreach(f => {
- try {
- val xml = XML.loadFile(f)
- println(new RuleTransformer(transformation).transform(xml))
- } catch {
- case e: Exception => {}
- }
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement