1 16 19 package com.sun.org.apache.xml.internal.dtm.ref.sax2dtm; 20 21 import javax.xml.transform.Source ; 22 23 import com.sun.org.apache.xml.internal.dtm.DTM; 24 import com.sun.org.apache.xml.internal.dtm.DTMManager; 25 import com.sun.org.apache.xml.internal.dtm.DTMWSFilter; 26 import com.sun.org.apache.xml.internal.utils.IntStack; 27 import com.sun.org.apache.xml.internal.utils.IntVector; 28 import com.sun.org.apache.xml.internal.utils.StringVector; 29 import com.sun.org.apache.xml.internal.utils.XMLStringFactory; 30 31 import org.xml.sax.SAXException ; 32 33 60 public class SAX2RTFDTM extends SAX2DTM 61 { 62 63 private static final boolean DEBUG = false; 64 65 66 private int m_currentDocumentNode=NULL; 67 68 69 IntStack mark_size=new IntStack(); 70 71 IntStack mark_data_size=new IntStack(); 72 73 IntStack mark_char_size=new IntStack(); 74 75 IntStack mark_doq_size=new IntStack(); 76 81 IntStack mark_nsdeclset_size=new IntStack(); 82 87 IntStack mark_nsdeclelem_size=new IntStack(); 88 89 92 int m_emptyNodeCount; 93 94 97 int m_emptyNSDeclSetCount; 98 99 102 int m_emptyNSDeclSetElemsCount; 103 104 107 int m_emptyDataCount; 108 109 112 int m_emptyCharsCount; 113 114 117 int m_emptyDataQNCount; 118 119 public SAX2RTFDTM(DTMManager mgr, Source source, int dtmIdentity, 120 DTMWSFilter whiteSpaceFilter, 121 XMLStringFactory xstringfactory, 122 boolean doIndexing) 123 { 124 super(mgr, source, dtmIdentity, whiteSpaceFilter, 125 xstringfactory, doIndexing); 126 127 m_useSourceLocationProperty=false; 131 m_sourceSystemId = (m_useSourceLocationProperty) ? new StringVector() 132 : null; 133 m_sourceLine = (m_useSourceLocationProperty) ? new IntVector() : null; 134 m_sourceColumn = (m_useSourceLocationProperty) ? new IntVector() : null; 135 136 m_emptyNodeCount = m_size; 140 m_emptyNSDeclSetCount = (m_namespaceDeclSets == null) 141 ? 0 : m_namespaceDeclSets.size(); 142 m_emptyNSDeclSetElemsCount = (m_namespaceDeclSetElements == null) 143 ? 0 : m_namespaceDeclSetElements.size(); 144 m_emptyDataCount = m_data.size(); 145 m_emptyCharsCount = m_chars.size(); 146 m_emptyDataQNCount = m_dataOrQName.size(); 147 } 148 149 163 public int getDocument() 164 { 165 return makeNodeHandle(m_currentDocumentNode); 166 } 167 168 179 public int getDocumentRoot(int nodeHandle) 180 { 181 for (int id=makeNodeIdentity(nodeHandle); id!=NULL; id=_parent(id)) { 182 if (_type(id)==DTM.DOCUMENT_NODE) { 183 return makeNodeHandle(id); 184 } 185 } 186 187 return DTM.NULL; } 189 190 198 protected int _documentRoot(int nodeIdentifier) 199 { 200 if(nodeIdentifier==NULL) return NULL; 201 202 for (int parent=_parent(nodeIdentifier); 203 parent!=NULL; 204 nodeIdentifier=parent,parent=_parent(nodeIdentifier)) 205 ; 206 207 return nodeIdentifier; 208 } 209 210 222 public void startDocument() throws SAXException 223 { 224 m_endDocumentOccured = false; 226 m_prefixMappings = new java.util.Vector (); 227 m_contextIndexes = new IntStack(); 228 m_parents = new IntStack(); 229 230 m_currentDocumentNode=m_size; 231 super.startDocument(); 232 } 233 234 246 public void endDocument() throws SAXException 247 { 248 charactersFlush(); 249 250 m_nextsib.setElementAt(NULL,m_currentDocumentNode); 251 252 if (m_firstch.elementAt(m_currentDocumentNode) == NOTPROCESSED) 253 m_firstch.setElementAt(NULL,m_currentDocumentNode); 254 255 if (DTM.NULL != m_previous) 256 m_nextsib.setElementAt(DTM.NULL,m_previous); 257 258 m_parents = null; 259 m_prefixMappings = null; 260 m_contextIndexes = null; 261 262 m_currentDocumentNode= NULL; m_endDocumentOccured = true; 264 } 265 266 267 277 public void pushRewindMark() 278 { 279 if(m_indexing || m_elemIndexes!=null) 280 throw new java.lang.NullPointerException ("Coding error; Don't try to mark/rewind an indexed DTM"); 281 282 mark_size.push(m_size); 285 mark_nsdeclset_size.push((m_namespaceDeclSets==null) 286 ? 0 287 : m_namespaceDeclSets.size()); 288 mark_nsdeclelem_size.push((m_namespaceDeclSetElements==null) 289 ? 0 290 : m_namespaceDeclSetElements.size()); 291 292 mark_data_size.push(m_data.size()); 294 mark_char_size.push(m_chars.size()); 295 mark_doq_size.push(m_dataOrQName.size()); 296 } 297 298 323 public boolean popRewindMark() 324 { 325 boolean top=mark_size.empty(); 326 327 m_size=top ? m_emptyNodeCount : mark_size.pop(); 328 m_exptype.setSize(m_size); 329 m_firstch.setSize(m_size); 330 m_nextsib.setSize(m_size); 331 m_prevsib.setSize(m_size); 332 m_parent.setSize(m_size); 333 334 m_elemIndexes=null; 335 336 int ds= top ? m_emptyNSDeclSetCount : mark_nsdeclset_size.pop(); 337 if (m_namespaceDeclSets!=null) { 338 m_namespaceDeclSets.setSize(ds); 339 } 340 341 int ds1= top ? m_emptyNSDeclSetElemsCount : mark_nsdeclelem_size.pop(); 342 if (m_namespaceDeclSetElements!=null) { 343 m_namespaceDeclSetElements.setSize(ds1); 344 } 345 346 m_data.setSize(top ? m_emptyDataCount : mark_data_size.pop()); 348 m_chars.setLength(top ? m_emptyCharsCount : mark_char_size.pop()); 349 m_dataOrQName.setSize(top ? m_emptyDataQNCount : mark_doq_size.pop()); 350 351 return m_size==0; 353 } 354 355 357 public boolean isTreeIncomplete() 358 { 359 return !m_endDocumentOccured; 360 } 361 } 362 | Popular Tags |