1 23 24 package org.enhydra.xml.xmlc.dom.xerces; 25 26 import org.enhydra.xml.dom.DOMOps; 27 import org.enhydra.xml.xmlc.codegen.JavaCode; 28 import org.enhydra.xml.xmlc.codegen.JavaLang; 29 import org.enhydra.xml.xmlc.dom.XMLCDocument; 30 import org.enhydra.xml.xmlc.dom.generic.NodeCreateGenerator; 31 import org.w3c.dom.Entity ; 32 import org.w3c.dom.Notation ; 33 34 37 public class XercesNodeCreateGenerator extends NodeCreateGenerator { 38 41 public XercesNodeCreateGenerator(XMLCDocument xmlcDoc) { 42 super(xmlcDoc); 43 } 44 45 48 protected void genEntityCreate(Entity entity, 49 String docVar, 50 String varName, 51 JavaCode body) { 52 body.addln(varName + " = " + docVar + ".createEntity(" 53 + JavaLang.createStringConst(entity.getNodeName())); 54 body.addln(varName + ".setPublicId(" 55 + JavaLang.createStringConst(entity.getPublicId()) + ");"); 56 body.addln(varName + ".setSystemId(" 57 + JavaLang.createStringConst(entity.getSystemId()) + ");"); 58 try { 59 String encoding = DOMOps.getEncoding(entity); 60 body.addln( 61 "try { " + 62 "DOMOps.setEncoding(" + varName + ", " + encoding +"); " + 63 "} catch (UnsupportedOperationException e) { /* ignore */ }" 64 ); 65 } catch (UnsupportedOperationException e) { 66 } 69 70 body.addln(varName + ".setNotationName(" 71 + JavaLang.createStringConst(entity.getNotationName()) 72 + ");"); 73 } 74 75 78 protected void genNotationCreate(Notation notation, 79 String docVar, 80 String varName, 81 JavaCode body) { 82 body.addln(varName + " = " + docVar + ".createNotation(" 83 + JavaLang.createStringConst(notation.getNodeName())); 84 body.addln(varName + ".setPublicId(" 85 + JavaLang.createStringConst(notation.getPublicId()) + ");"); 86 body.addln(varName + ".setSystemId(" 87 + JavaLang.createStringConst(notation.getSystemId()) + ");"); 88 } 89 90 93 public void genAddEntity(String docTypeVar, 94 String entityVar, 95 Entity entity, 96 JavaCode body) { 97 if (entity.getNamespaceURI() != null) { 99 body.addln(docTypeVar + ".getEntities().setNamedItemNS(" 100 + entityVar + ");"); 101 } else { 102 body.addln(docTypeVar + ".getEntities().setNamedItem(" 103 + entityVar + ");"); 104 } 105 } 106 107 110 public void genAddNotation(String docTypeVar, 111 String notationVar, 112 Notation notation, 113 JavaCode body) { 114 if (notation.getNamespaceURI() != null) { 116 body.addln(docTypeVar + ".getNotations().setNamedItemNS(" 117 + notationVar + ");"); 118 } else { 119 body.addln(docTypeVar + ".getNotations().setNamedItem(" 120 + notationVar + ");"); 121 } 122 } 123 } 124 | Popular Tags |