alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (Binder.scala)

This example Scala source code file (Binder.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

binder, boolean, comment, int, int, node, node, nodebuffer, nodebuffer, procinstr, string, string, text, validatingmarkuphandler

The Scala Binder.scala source code

/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2002-2011, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */



package scala.xml
package factory

import parsing.ValidatingMarkupHandler

/**
 *  @author Burak Emir
 */
abstract class Binder(val preserveWS: Boolean) extends ValidatingMarkupHandler {

  var result: NodeBuffer = new NodeBuffer()

  def reportSyntaxError(pos:Int, str:String) = {}

  final def procInstr(pos: Int, target: String, txt: String) =
    ProcInstr(target, txt)

  final def comment(pos: Int, txt: String) =
    Comment(txt)

  final def entityRef(pos: Int, n: String) =
    EntityRef(n)

  final def text(pos: Int, txt: String) =
    Text(txt)

  final def traverse(n:Node): Unit = n match {
    case x:ProcInstr =>
      result &+ procInstr(0, x.target, x.text)
    case x:Comment   =>
      result &+ comment(0, x.text)
    case x:Text      =>
      result &+ text(0, x.data)
    case x:EntityRef =>
      result &+ entityRef(0, x.entityName)
    case _ => 
      elemStart(0, n.prefix, n.label, n.attributes, n.scope)
      val old = result
      result = new NodeBuffer()
      for (m <- n.child) traverse(m)
      result = old &+ elem(0, n.prefix, n.label, n.attributes, n.scope, NodeSeq.fromSeq(result)).toList;
      elemEnd(0, n.prefix, n.label)
  }
  
  final def validate(n: Node): Node = {
    this.rootLabel = n.label
    traverse(n)
    result(0)
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala Binder.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.