1 package org.exoplatform.services.xml.querying.impl.xtas.xml; 2 3 import org.xml.sax.SAXException ; 4 import org.xml.sax.ext.DeclHandler ; 5 import org.xml.sax.ext.LexicalHandler ; 6 7 11 public class DtdTracer 12 implements LexicalHandler ,DeclHandler 13 { 14 15 private String name; 16 private String publicId; 17 private String systemId; 18 19 private String text=""; 20 private boolean isInternal = false; 21 22 26 public DtdTracer() 27 { 28 name=null; 29 publicId=null; 30 systemId=null; 31 32 text=""; 33 isInternal = false; 34 35 } 36 37 38 public void startDTD(String name, String publicId, String systemId) 39 throws SAXException { 40 41 this.name = name; 44 this.systemId = systemId; 45 this.publicId = publicId; 46 47 48 if (systemId == null) 49 isInternal = true; 51 else { 52 isInternal = false; 53 text = "<!DOCTYPE "+name+" SYSTEM \""+systemId+"\">"; 54 } 55 56 57 } 58 59 60 public void startEntity(String name) throws SAXException 61 { } 62 63 64 public void startCDATA() throws SAXException 65 { } 66 67 68 public void endCDATA() throws SAXException 69 { } 70 71 72 public void comment(char[] ch, int offset, int length) 73 throws SAXException 74 { } 75 76 77 public void endEntity(String name) throws SAXException 78 { } 79 80 81 public void endDTD() throws SAXException { 82 if ( isInternal ) 83 text+="]>"; 84 } 85 86 90 91 public void elementDecl(String name, String contentModel) 92 throws SAXException { 93 94 if( isInternal ) 96 text+="<!ELEMENT "+name+"("+contentModel+")>\n"; 97 } 98 99 100 public void attributeDecl(String elementName, String attributeName, 101 String type, String valueDefault, 102 String value) throws SAXException { 103 104 if( isInternal ) 106 text+="<!ATTLIST "+elementName+" "+attributeName+" "+ 107 type+" "+valueDefault+" "+value+">\n"; 108 109 110 } 111 112 113 public void internalEntityDecl(String name, String text) 114 throws SAXException { 115 116 if( isInternal ) 118 text+="<!ENTITY "+name+"\""+text+"\">\n"; 119 120 } 121 122 123 public void externalEntityDecl(String name, 124 String publicId, String systemId) 125 throws SAXException { 126 127 String publicStr=(publicId==null)?"":" PUBLIC "+"\""+publicId+"\""; 129 String systemStr=(systemId==null)?"":" SYSTEM "+"\""+systemId+"\""; 130 131 if( isInternal ) 132 text+="<!ENTITY "+name+"\""+name+"\">"+systemStr+publicStr+"\n"; 133 134 } 135 136 public String getSystemId() 137 { 138 return systemId; 139 } 140 141 public String getPublicId() 142 { 143 return publicId; 144 } 145 146 public String getText() 147 { 148 return text; 149 } 150 151 } | Popular Tags |