Changeset 7488
- Timestamp:
- 11/24/06 14:19:51 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Res_Xalan/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
r7031 r7488 21 21 import java.util.Hashtable; 22 22 import java.util.Vector; 23 23 24 import javax.xml.transform.Source; 24 25 import javax.xml.transform.SourceLocator; 25 26 26 import org.apache.xml.dtm.*; 27 import org.apache.xml.dtm.ref.*; 28 import org.apache.xml.utils.StringVector; 29 import org.apache.xml.utils.IntVector; 27 import org.apache.xml.dtm.DTM; 28 import org.apache.xml.dtm.DTMManager; 29 import org.apache.xml.dtm.DTMWSFilter; 30 import org.apache.xml.dtm.ref.DTMDefaultBaseIterators; 31 import org.apache.xml.dtm.ref.DTMManagerDefault; 32 import org.apache.xml.dtm.ref.DTMStringPool; 33 import org.apache.xml.dtm.ref.DTMTreeWalker; 34 import org.apache.xml.dtm.ref.NodeLocator; 35 import org.apache.xml.res.XMLErrorResources; 36 import org.apache.xml.res.XMLMessages; 30 37 import org.apache.xml.utils.FastStringBuffer; 31 38 import org.apache.xml.utils.IntStack; 39 import org.apache.xml.utils.IntVector; 40 import org.apache.xml.utils.StringVector; 32 41 import org.apache.xml.utils.SuballocatedIntVector; 33 42 import org.apache.xml.utils.SystemIDResolver; 34 import org.apache.xml.utils.WrappedRuntimeException;35 43 import org.apache.xml.utils.XMLString; 36 44 import org.apache.xml.utils.XMLStringFactory; 37 import org.apache.xml.res.XMLErrorResources; 38 import org.apache.xml.res.XMLMessages; 39 import org.xml.sax.*; 40 import org.xml.sax.ext.*; 45 import org.xml.sax.Attributes; 46 import org.xml.sax.ContentHandler; 47 import org.xml.sax.DTDHandler; 48 import org.xml.sax.EntityResolver; 49 import org.xml.sax.ErrorHandler; 50 import org.xml.sax.InputSource; 51 import org.xml.sax.Locator; 52 import org.xml.sax.SAXException; 53 import org.xml.sax.SAXParseException; 54 import org.xml.sax.ext.DeclHandler; 55 import org.xml.sax.ext.LexicalHandler; 41 56 42 57 /** … … 50 65 /** Set true to monitor SAX events and similar diagnostic info. */ 51 66 private static final boolean DEBUG = false; 52 53 /**54 * If we're building the model incrementally on demand, we need to55 * be able to tell the source when to send us more data.56 *57 * Note that if this has not been set, and you attempt to read ahead58 * of the current build point, we'll probably throw a null-pointer59 * exception. We could try to wait-and-retry instead, as a very poor60 * fallback, but that has all the known problems with multithreading61 * on multiprocessors and we Don't Want to Go There.62 *63 * @see setIncrementalSAXSource64 */65 private IncrementalSAXSource m_incrementalSAXSource = null;66 67 67 68 /** … … 347 348 public void clearCoRoutine(boolean callDoTerminate) 348 349 { 349 350 if (null != m_incrementalSAXSource)351 {352 if (callDoTerminate)353 m_incrementalSAXSource.deliverMoreNodes(false);354 355 m_incrementalSAXSource = null;356 }357 }358 359 /**360 * Bind a IncrementalSAXSource to this DTM. If we discover we need nodes361 * that have not yet been built, we will ask this object to send us more362 * events, and it will manage interactions with its data sources.363 *364 * Note that we do not actually build the IncrementalSAXSource, since we don't365 * know what source it's reading from, what thread that source will run in,366 * or when it will run.367 *368 * @param incrementalSAXSource The parser that we want to recieve events from369 * on demand.370 * @param appCoRID The CoRoutine ID for the application.371 */372 public void setIncrementalSAXSource(IncrementalSAXSource incrementalSAXSource)373 {374 375 // Establish coroutine link so we can request more data376 //377 // Note: It's possible that some versions of IncrementalSAXSource may378 // not actually use a CoroutineManager, and hence may not require379 // that we obtain an Application Coroutine ID. (This relies on the380 // coroutine transaction details having been encapsulated in the381 // IncrementalSAXSource.do...() methods.)382 m_incrementalSAXSource = incrementalSAXSource;383 384 // Establish SAX-stream link so we can receive the requested data385 incrementalSAXSource.setContentHandler(this);386 incrementalSAXSource.setLexicalHandler(this);387 incrementalSAXSource.setDTDHandler(this);388 389 // Are the following really needed? incrementalSAXSource doesn't yet390 // support them, and they're mostly no-ops here...391 //incrementalSAXSource.setErrorHandler(this);392 //incrementalSAXSource.setDeclHandler(this);393 350 } 394 351 … … 407 364 public ContentHandler getContentHandler() 408 365 { 409 410 if (m_incrementalSAXSource instanceof IncrementalSAXSource_Filter)411 return (ContentHandler) m_incrementalSAXSource;412 else413 366 return this; 414 367 } … … 426 379 public LexicalHandler getLexicalHandler() 427 380 { 428 429 if (m_incrementalSAXSource instanceof IncrementalSAXSource_Filter)430 return (LexicalHandler) m_incrementalSAXSource;431 else432 381 return this; 433 382 } … … 481 430 public boolean needsTwoThreads() 482 431 { 483 return null != m_incrementalSAXSource;432 return false; 484 433 } 485 434 … … 519 468 int length = m_data.elementAt(dataIndex + 1); 520 469 521 if(normalize) 522 m_chars.sendNormalizedSAXcharacters(ch, offset, length); 523 else 524 m_chars.sendSAXcharacters(ch, offset, length); 470 //On n'envoie que si du texte doit etre envoyé (sinon xsl:attribute ne marche plus). 471 if(length > 0) { 472 if(normalize) 473 m_chars.sendNormalizedSAXcharacters(ch, offset, length); 474 else 475 m_chars.sendSAXcharacters(ch, offset, length); 476 } 525 477 } 526 478 else … … 718 670 identity += 1; 719 671 720 while (identity >= m_size) 721 { 722 if (null == m_incrementalSAXSource) 723 return DTM.NULL; 724 725 nextNode(); 672 if (identity >= m_size) 673 { 674 return DTM.NULL; 726 675 } 727 676 … … 780 729 protected boolean nextNode() 781 730 { 782 783 if (null == m_incrementalSAXSource) 784 return false; 785 786 if (m_endDocumentOccured) 787 { 788 clearCoRoutine(); 789 790 return false; 791 } 792 793 Object gotMore = m_incrementalSAXSource.deliverMoreNodes(true); 794 795 // gotMore may be a Boolean (TRUE if still parsing, FALSE if 796 // EOF) or an exception if IncrementalSAXSource malfunctioned 797 // (code error rather than user error). 798 // 799 // %REVIEW% Currently the ErrorHandlers sketched herein are 800 // no-ops, so I'm going to initially leave this also as a 801 // no-op. 802 if (!(gotMore instanceof Boolean)) 803 { 804 if(gotMore instanceof RuntimeException) 805 { 806 throw (RuntimeException)gotMore; 807 } 808 else if(gotMore instanceof Exception) 809 { 810 throw new WrappedRuntimeException((Exception)gotMore); 811 } 812 // for now... 813 clearCoRoutine(); 814 815 return false; 816 817 // %TBD% 818 } 819 820 if (gotMore != Boolean.TRUE) 821 { 822 823 // EOF reached without satisfying the request 824 clearCoRoutine(); // Drop connection, stop trying 825 826 // %TBD% deregister as its listener? 827 } 828 829 return true; 731 return false; 830 732 } 831 733
Note: See TracChangeset
for help on using the changeset viewer.