From 0c15dac9e9985317de7f259da0e3ab90927aa32b Mon Sep 17 00:00:00 2001 From: buraq Date: Wed, 26 Nov 2003 09:04:20 +0000 Subject: adapted to new xml nodes --- sources/scala/tools/dtd2scala/DeclToScala.scala | 110 ++++++++++----------- .../dtd2scala/template/ObjectTemplate.scala.xml | 6 +- 2 files changed, 56 insertions(+), 60 deletions(-) diff --git a/sources/scala/tools/dtd2scala/DeclToScala.scala b/sources/scala/tools/dtd2scala/DeclToScala.scala index 048e1bfa58..55fbdf1619 100644 --- a/sources/scala/tools/dtd2scala/DeclToScala.scala +++ b/sources/scala/tools/dtd2scala/DeclToScala.scala @@ -28,70 +28,68 @@ class DeclToScala(fOut:PrintWriter, var curAttribs: Map[String,AttrDecl] = null ; /* of current elem */ def write:Unit = { - def writeNode( n:Node ):Unit = { - n.label match { - case "template" => { - lookup.update("objectName", objectName); - lookup.update("compressDefault", compress.toString()); - n.children.elements.foreach { n => writeNode(n) } - } - case "elementBinding" => { - for( val decl <- elemMap.values.elements ) { - fOut.println(); - printIndent(); - lookup += "elementName" -> decl.name; - lookup += "elementContainsText" -> decl.containsText.toString(); - lookup += "elementContentModel" -> decl.contentModel; - curAttribs = decl.attribs; - n.children.elements.foreach{ n => writeNode( n ) } + def writeNode( x:Node ):Unit = x match { + case Text(text) => + fOut.print( text ); + case n:AttributedNode => + n.label match { + case "template" => { + lookup.update("objectName", objectName); + lookup.update("compressDefault", compress.toString()); + n.children.elements.foreach { n => writeNode(n) } + } + case "elementBinding" => { + for( val decl <- elemMap.values.elements ) { + fOut.println(); + printIndent(); + lookup += "elementName" -> decl.name; + lookup += "elementContainsText" -> decl.containsText.toString(); + lookup += "elementContentModel" -> decl.contentModel; + curAttribs = decl.attribs; + n.children.elements.foreach{ n => writeNode( n ) } + } + curAttribs = null; + lookup -= "elementName"; + lookup -= "elementContainsText"; } - curAttribs = null; - lookup -= "elementName"; - lookup -= "elementContainsText"; - } - case "attributeAssign" => { - for( val aDecl <- curAttribs.keys.elements ) { - lookup += "attributeName" -> aDecl; - n.children.elements.foreach{ n => writeNode( n ) } + case "attributeAssign" => { + for( val aDecl <- curAttribs.keys.elements ) { + lookup += "attributeName" -> aDecl; + n.children.elements.foreach{ n => writeNode( n ) } + } + lookup -= "attributeName"; } - lookup -= "attributeName"; - } - case "attributeBinding" => { - for( val aDecl <- curAttribs.keys.elements ) { - lookup += "attributeName" -> aDecl; - //Console.println("attributeName is "+aDecl+" = "+lookup("attributeName")); - n.children.elements.foreach{ n => writeNode( n ) } + case "attributeBinding" => { + for( val aDecl <- curAttribs.keys.elements ) { + lookup += "attributeName" -> aDecl; + n.children.elements.foreach{ n => writeNode( n ) } + } + lookup -= "attributeName"; } - lookup -= "attributeName"; - } - case "ccstring" => { - //Console.println("ccstring ref=\""+n.attributes("ref")+"\""); - fOut.print( cookedCap( lookup( n.attributes("ref") ) )); - } - case "cstring" => { - //Console.println("ccstring ref=\""+n.attributes("ref")+"\""); - fOut.print( cooked( lookup( n.attributes("ref") ) )); - } - case "string" => { - //Console.println("string ref=\""+n.attributes("ref")+"\""); - fOut.print( lookup( n.attributes("ref") ) ); - } - case "qstring" => { - //Console.println("qstring ref=\""+n.attributes("ref")+"\""); + case "ccstring" => { + fOut.print( cookedCap( lookup( n("ref").get ) )); + } + case "cstring" => { + fOut.print( cooked( lookup( n("ref").get ) )); + } + case "string" => { + fOut.print( lookup( n("ref").get ) ); + } + case "qstring" => { - fOut.print("\""); - fOut.print( lookup( n.attributes("ref") ) ); - fOut.print("\""); + fOut.print("\""); + fOut.print( lookup( n("ref").get ) ); + fOut.print("\""); + } + case "br" => { fOut.println(); printIndent() } + case "inc" => fIndent = fIndent + IND_STEP + case "dec" => fIndent = fIndent - IND_STEP + case _ => error("what shall I do with a \""+n.label+"\" node ?") } - case "br" => { fOut.println(); printIndent() } - case "inc" => fIndent = fIndent + IND_STEP - case "dec" => fIndent = fIndent - IND_STEP - case "#PCDATA" => fOut.print( n.asInstanceOf[Text].text ) - case _ => error("what shall I do with a \""+n.label+"\" node ?") - } } + writeNode( tmpl ) } } diff --git a/sources/scala/tools/dtd2scala/template/ObjectTemplate.scala.xml b/sources/scala/tools/dtd2scala/template/ObjectTemplate.scala.xml index 2be3636760..f676893dc6 100644 --- a/sources/scala/tools/dtd2scala/template/ObjectTemplate.scala.xml +++ b/sources/scala/tools/dtd2scala/template/ObjectTemplate.scala.xml @@ -39,14 +39,12 @@ import scala.collection.mutable.HashMap ;
override def attributes : Map[String,String] = attrs;
override val &cAttributeName; = attrs.get(&qAttributeName;);
+ val attribHashCode: int = attrs.hashCode() ;
};
- case class &ccElementName;( ch:Node* ) extends scala.xml.Node {
+ case class &ccElementName;( ch:Node* ) extends scala.xml.AttributedNode {
def label = &qElementName;;
def children = ch;
- /* these methods are overridden at parse time */
- def attributes : Map[String,String] = new HashMap[String,String]();
- val attribHashCode: int = 0 ;
val &cAttributeName; : scala.Option[String] = scala.None; /* overridden at parse time */ -- cgit v1.2.3