| Method from com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl Detail: |
void addElement(String rawname) {
if(fElementPointer < ELEMENT_ARRAY_LENGTH){
//storing element raw name in a linear list of array
fElementArray[fElementPointer] = rawname ;
//storing elemnetPointer for particular element depth
if(DEBUG_SKIP_ALGORITHM){
StringBuffer sb = new StringBuffer() ;
sb.append(" Storing element information ") ;
sb.append(" fElementPointer = " + fElementPointer) ;
sb.append(" fElementRawname = " + fElementQName.rawname) ;
sb.append(" fElementStack.fDepth = " + fElementStack.fDepth);
System.out.println(sb.toString()) ;
}
//store pointer information only when element depth is less MAX_DEPTH_LIMIT
if(fElementStack.fDepth < MAX_DEPTH_LIMIT){
short column = storePointerForADepth(fElementPointer);
if(column > 0){
short pointer = getElementPointer((short)fElementStack.fDepth, (short)(column - 1) );
//identity comparison shouldn't take much time and we can rely on this
//since its guaranteed to have same object id for same string.
if(rawname == fElementArray[pointer]){
fShouldSkip = true ;
fLastPointerLocation = pointer ;
//reset the things and return.
resetPointer((short)fElementStack.fDepth , column) ;
fElementArray[fElementPointer] = null ;
return ;
}else{
fShouldSkip = false ;
}
}
}
fElementPointer++ ;
}
}
|
boolean canStore(short depth,
short column) {
//colum = 0 , means first element at particular depth
//column = 1, means second element at particular depth
// calle should make sure that it doesn't call for value outside allowed co-ordinates
return fPointerInfo[depth][column] == 0 ? true : false ;
}
|
protected XMLDocumentFragmentScannerImpl.Driver createContentDriver() {
return new FragmentContentDriver();
}
Creates a content Driver. |
public void endEntity(String name,
Augmentations augs) throws IOException, XNIException {
/**
* // flush possible pending output buffer - see scanContent
* if (fInScanContent && fStringBuffer.length != 0
* && fDocumentHandler != null) {
* fDocumentHandler.characters(fStringBuffer, null);
* fStringBuffer.length = 0; // make sure we know it's been flushed
* }
*/
super.endEntity(name, augs);
// make sure markup is properly balanced
if (fMarkupDepth != fEntityStack[fEntityDepth]) {
reportFatalError("MarkupEntityMismatch", null);
}
/**/
// call handler
if (fDocumentHandler != null && !fScanningAttribute) {
if (!name.equals("[xml]")) {
fDocumentHandler.endGeneralEntity(name, null);
}
}
}
This method notifies the end of an entity. The DTD has the pseudo-name
of "[dtd]" parameter entity names start with '%'; and general entities
are just specified by their name. |
public XMLAttributesIteratorImpl getAttributeIterator() {
if(dtdGrammarUtil != null && fAddDefaultAttr){
dtdGrammarUtil.addDTDDefaultAttrs(fElementQName,fAttributes);
fAddDefaultAttr = false;
}
return fAttributes;
}
return the attribute iterator implementation |
public XMLString getCharacterData() {
if(fUsebuffer){
return fContentBuffer ;
}else{
return fTempString;
}
}
|
public String getComment() {
return fContentBuffer.toString();
}
|
public XMLDocumentHandler getDocumentHandler() {
return fDocumentHandler;
}
Returns the document handler |
public String getDriverName(XMLDocumentFragmentScannerImpl.Driver driver) {
if (DEBUG_DISPATCHER) {
if (driver != null) {
String name = driver.getClass().getName();
int index = name.lastIndexOf('.");
if (index != -1) {
name = name.substring(index + 1);
index = name.lastIndexOf('$");
if (index != -1) {
name = name.substring(index + 1);
}
}
return name;
}
}
return "null";
}
|
short getElementPointer(short depth,
short column) {
//colum = 0 , means first element at particular depth
//column = 1, means second element at particular depth
// calle should make sure that it doesn't call for value outside allowed co-ordinates
return fPointerInfo[depth][column] ;
}
|
public QName getElementQName() {
if(fScannerLastState == XMLEvent.END_ELEMENT){
fElementQName.setValues(fElementStack.getLastPoppedElement());
}
return fElementQName ;
}
|
public String getEntityName() {
//return the cached name
return fCurrentEntityName;
}
|
public Boolean getFeatureDefault(String featureId) {
for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) {
if (RECOGNIZED_FEATURES[i].equals(featureId)) {
return FEATURE_DEFAULTS[i];
}
}
return null;
}
Returns the default state for a feature, or null if this
component does not want to report a default value for this
feature. |
public XMLStringBuffer getPIData() {
return fContentBuffer ;
}
|
public String getPITarget() {
return fPITarget ;
}
|
public Object getPropertyDefault(String propertyId) {
for (int i = 0; i < RECOGNIZED_PROPERTIES.length; i++) {
if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) {
return PROPERTY_DEFAULTS[i];
}
}
return null;
}
Returns the default state for a property, or null if this
component does not want to report a default value for this
property. |
public String[] getRecognizedFeatures() {
return (String[])(RECOGNIZED_FEATURES.clone());
}
Returns a list of feature identifiers that are recognized by
this component. This method may return null if no features
are recognized by this component. |
public String[] getRecognizedProperties() {
return (String[])(RECOGNIZED_PROPERTIES.clone());
}
Returns a list of property identifiers that are recognized by
this component. This method may return null if no properties
are recognized by this component. |
protected String getScannerStateName(int state) {
switch (state) {
case SCANNER_STATE_DOCTYPE: return "SCANNER_STATE_DOCTYPE";
case SCANNER_STATE_ROOT_ELEMENT: return "SCANNER_STATE_ROOT_ELEMENT";
case SCANNER_STATE_START_OF_MARKUP: return "SCANNER_STATE_START_OF_MARKUP";
case SCANNER_STATE_COMMENT: return "SCANNER_STATE_COMMENT";
case SCANNER_STATE_PI: return "SCANNER_STATE_PI";
case SCANNER_STATE_CONTENT: return "SCANNER_STATE_CONTENT";
case SCANNER_STATE_REFERENCE: return "SCANNER_STATE_REFERENCE";
case SCANNER_STATE_END_OF_INPUT: return "SCANNER_STATE_END_OF_INPUT";
case SCANNER_STATE_TERMINATED: return "SCANNER_STATE_TERMINATED";
case SCANNER_STATE_CDATA: return "SCANNER_STATE_CDATA";
case SCANNER_STATE_TEXT_DECL: return "SCANNER_STATE_TEXT_DECL";
case SCANNER_STATE_ATTRIBUTE: return "SCANNER_STATE_ATTRIBUTE";
case SCANNER_STATE_ATTRIBUTE_VALUE: return "SCANNER_STATE_ATTRIBUTE_VALUE";
case SCANNER_STATE_START_ELEMENT_TAG: return "SCANNER_STATE_START_ELEMENT_TAG";
case SCANNER_STATE_END_ELEMENT_TAG: return "SCANNER_STATE_END_ELEMENT_TAG";
case SCANNER_STATE_CHARACTER_DATA: return "SCANNER_STATE_CHARACTER_DATA" ;
}
return "??? ("+state+')";
}
Returns the scanner state name. |
protected XMLString getString() {
if(fAttributeCacheUsedCount < initialCacheCount || fAttributeCacheUsedCount < attributeValueCache.size()){
return (XMLString)attributeValueCache.get(fAttributeCacheUsedCount++);
} else{
XMLString str = new XMLString();
fAttributeCacheUsedCount++;
attributeValueCache.add(str);
return str;
}
}
this function gets an XMLString (which is used to store the attribute value) from the special pool
maintained for attributes.
fAttributeCacheUsedCount tracks the number of attributes that has been consumed from the pool.
if all the attributes has been consumed, it adds a new XMLString inthe pool and returns the same
XMLString. |
public boolean hasAttributes() {
return fAttributes.getLength() > 0 ? true : false ;
}
|
public boolean isStandAlone() {
return fStandalone ;
}
return if the doucment is standalone |
public int next() throws IOException, XNIException {
return fDriver.next();
}
return the next state on the input |
static void pr(String str) {
System.out.println(str) ;
}
|
public void refresh() {
refresh(0);
}
Implements XMLBufferListener interface. |
public void refresh(int refreshPosition) {
//If you are reading attributes and you got a callback
//cache available attributes.
if(fReadingAttributes){
fAttributes.refresh();
}
if(fScannerState == SCANNER_STATE_CHARACTER_DATA){
//since fTempString directly matches to the underlying main buffer
//store the data into buffer
fContentBuffer.append(fTempString);
//clear the XMLString so that data can't be added again.
fTempString.length = 0;
fUsebuffer = true;
}
}
|
public void reset(XMLComponentManager componentManager) throws XMLConfigurationException {
super.reset(componentManager);
// other settings
// fDocumentSystemId = null;
// sax features
//fAttributes.setNamespaces(fNamespaces);
// xerces features
try{
fReportCdataEvent = componentManager.getFeature(Constants.STAX_REPORT_CDATA_EVENT);
} catch (XMLConfigurationException e) {
e.printStackTrace();
//note that default value of this feature is true in stax configuration
fReportCdataEvent = true;
}
try {
fSecurityManager = (SecurityManager)componentManager.getProperty(Constants.SECURITY_MANAGER);
} catch (XMLConfigurationException e) {
fSecurityManager = null;
}
fElementAttributeLimit = (fSecurityManager != null)?fSecurityManager.getElementAttrLimit():0;
try {
fNotifyBuiltInRefs = componentManager.getFeature(NOTIFY_BUILTIN_REFS);
} catch (XMLConfigurationException e) {
fNotifyBuiltInRefs = false;
}
try {
Object resolver = componentManager.getProperty(ENTITY_RESOLVER);
fExternalSubsetResolver = (resolver instanceof ExternalSubsetResolver) ?
(ExternalSubsetResolver) resolver : null;
} catch (XMLConfigurationException e) {
fExternalSubsetResolver = null;
}
// initialize vars
fMarkupDepth = 0;
fCurrentElement = null;
fElementStack.clear();
fHasExternalDTD = false;
fStandalone = false;
fInScanContent = false;
//skipping algorithm
fShouldSkip = false;
fAdd = false;
fSkip = false;
//attribute
fReadingAttributes = false;
//xxx: external entities are supported in Xerces
// it would be good to define feature for this case
fSupportExternalEntities = true;
fReplaceEntityReferences = true;
fIsCoalesce = false;
// setup Driver
setScannerState(SCANNER_STATE_CONTENT);
setDriver(fContentDriver);
fEntityStore = fEntityManager.getEntityStore();
dtdGrammarUtil = null;
//fEntityManager.test();
}
Resets the component. The component can query the component manager
about any features and properties that affect the operation of the
component. |
public void reset(PropertyManager propertyManager) {
super.reset(propertyManager);
// other settings
// fDocumentSystemId = null;
fNamespaces = ((Boolean)propertyManager.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE)).booleanValue();
fNotifyBuiltInRefs = false ;
// initialize vars
fMarkupDepth = 0;
fCurrentElement = null;
fShouldSkip = false;
fAdd = false;
fSkip = false;
fElementStack.clear();
//fElementStack2.clear();
fHasExternalDTD = false;
fStandalone = false;
//fReplaceEntityReferences = true;
//fSupportExternalEntities = true;
Boolean bo = (Boolean)propertyManager.getProperty(XMLInputFactoryImpl.IS_REPLACING_ENTITY_REFERENCES);
fReplaceEntityReferences = bo.booleanValue();
bo = (Boolean)propertyManager.getProperty(XMLInputFactoryImpl.IS_SUPPORTING_EXTERNAL_ENTITIES);
fSupportExternalEntities = bo.booleanValue();
Boolean cdata = (Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.STAX_REPORT_CDATA_EVENT) ;
if(cdata != null)
fReportCdataEvent = cdata.booleanValue() ;
Boolean coalesce = (Boolean)propertyManager.getProperty(XMLInputFactory.IS_COALESCING) ;
if(coalesce != null)
fIsCoalesce = coalesce.booleanValue();
fReportCdataEvent = fIsCoalesce ? false : (fReportCdataEvent && true) ;
//if fIsCoalesce is set to true, set the value of fReplaceEntityReferences to true,
//if fIsCoalesce is set to false, take the value of fReplaceEntityReferences as set by application
fReplaceEntityReferences = fIsCoalesce ? true : fReplaceEntityReferences;
// setup Driver
//we dont need to do this -- nb.
//setScannerState(SCANNER_STATE_CONTENT);
//setDriver(fContentDriver);
fEntityStore = fEntityManager.getEntityStore();
//fEntityManager.test();
dtdGrammarUtil = null;
}
|
void resetPointer(short depth,
short column) {
fPointerInfo[depth] [column] = (short)0;
}
|
protected void scanAttribute(XMLAttributes attributes) throws IOException, XNIException {
if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() +" > > > scanAttribute()");
// name
if (fNamespaces) {
fEntityScanner.scanQName(fAttributeQName);
} else {
String name = fEntityScanner.scanName();
fAttributeQName.setValues(null, name, name, null);
}
// equals
fEntityScanner.skipSpaces();
if (!fEntityScanner.skipChar('=")) {
reportFatalError("EqRequiredInAttribute",
new Object[] {fCurrentElement.rawname, fAttributeQName.rawname});
}
fEntityScanner.skipSpaces();
int attIndex = 0 ;
//REVISIT: one more case needs to be included: external PE and standalone is no
boolean isVC = fHasExternalDTD && !fStandalone;
//fTempString would store attribute value
///fTempString2 would store attribute non-normalized value
//this function doesn't use 'attIndex'. We are adding the attribute later
//after we have figured out that current attribute is not namespace declaration
//since scanAttributeValue doesn't use attIndex parameter therefore we
//can safely add the attribute later..
XMLString tmpStr = getString();
scanAttributeValue(tmpStr, fTempString2,
fAttributeQName.rawname, attributes,
attIndex, isVC);
// content
int oldLen = attributes.getLength();
//if the attribute name already exists.. new value is replaced with old value
attIndex = attributes.addAttribute(fAttributeQName, XMLSymbols.fCDATASymbol, null);
// WFC: Unique Att Spec
//attributes count will be same if the current attribute name already exists for this element name.
//this means there are two duplicate attributes.
if (oldLen == attributes.getLength()) {
reportFatalError("AttributeNotUnique",
new Object[]{fCurrentElement.rawname,
fAttributeQName.rawname});
}
//tmpString contains attribute value
//we are passing null as the attribute value
attributes.setValue(attIndex, null, tmpStr);
///xxx: nonNormalizedValue is not being set as it is not required by SAX & DOM
//attributes.setNonNormalizedValue(oldLen, fTempString2.toString());
attributes.setSpecified(attIndex, true);
if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() +"< < < scanAttribute()");
}
Scans an attribute name value pair.
[41] Attribute ::= Name Eq AttValue
Note: This method assumes that the next
character on the stream is the first character of the attribute
name.
Note: This method uses the fAttributeQName and
fQName variables. The contents of these variables will be
destroyed. |
protected boolean scanCDATASection(XMLStringBuffer contentBuffer,
boolean complete) throws IOException, XNIException {
// call handler
if (fDocumentHandler != null) {
//fDocumentHandler.startCDATA(null);
}
while (true) {
//scanData will fill the contentBuffer
if (!fEntityScanner.scanData("]] >", contentBuffer)) {
break ;
/** We dont need all this code if we pass ']] >' as delimeter..
* int brackets = 2;
* while (fEntityScanner.skipChar(']')) {
* brackets++;
* }
*
* //When we find more than 2 square brackets
* if (fDocumentHandler != null && brackets > 2) {
* //we dont need to clear the buffer..
* //contentBuffer.clear();
* for (int i = 2; i < brackets; i++) {
* contentBuffer.append(']');
* }
* fDocumentHandler.characters(contentBuffer, null);
* }
*
* if (fEntityScanner.skipChar(' >')) {
* break;
* }
* if (fDocumentHandler != null) {
* //we dont need to clear the buffer now..
* //contentBuffer.clear();
* contentBuffer.append("]]");
* fDocumentHandler.characters(contentBuffer, null);
* }
**/
} else {
int c = fEntityScanner.peekChar();
if (c != -1 && isInvalidLiteral(c)) {
if (XMLChar.isHighSurrogate(c)) {
//contentBuffer.clear();
//scan surrogates if any....
scanSurrogates(contentBuffer);
} else {
reportFatalError("InvalidCharInCDSect",
new Object[]{Integer.toString(c,16)});
fEntityScanner.scanChar();
}
}
//by this time we have also read surrogate contents if any...
if (fDocumentHandler != null) {
//fDocumentHandler.characters(contentBuffer, null);
}
}
}
fMarkupDepth--;
if (fDocumentHandler != null && contentBuffer.length > 0) {
//fDocumentHandler.characters(contentBuffer, null);
}
// call handler
if (fDocumentHandler != null) {
//fDocumentHandler.endCDATA(null);
}
return true;
}
|
protected void scanCharReference() throws IOException, XNIException {
fStringBuffer2.clear();
int ch = scanCharReferenceValue(fStringBuffer2, null);
fMarkupDepth--;
if (ch != -1) {
// call handler
if (fDocumentHandler != null) {
if (fNotifyCharRefs) {
fDocumentHandler.startGeneralEntity(fCharRefLiteral, null, null, null);
}
Augmentations augs = null;
if (fValidation && ch < = 0x20) {
if (fTempAugmentations != null) {
fTempAugmentations.removeAllItems();
}
else {
fTempAugmentations = new AugmentationsImpl();
}
augs = fTempAugmentations;
augs.putItem(Constants.CHAR_REF_PROBABLE_WS, Boolean.TRUE);
}
//xxx: How do we deal with this - how to return charReferenceValues
//now this is being commented because this is taken care in scanDocument()
//fDocumentHandler.characters(fStringBuffer2, null);
if (fNotifyCharRefs) {
fDocumentHandler.endGeneralEntity(fCharRefLiteral, null);
}
}
}
}
Scans a character reference.
[66] CharRef ::= '' [0-9]+ ';' | '' [0-9a-fA-F]+ ';'
|
protected void scanComment() throws IOException, XNIException {
fContentBuffer.clear();
scanComment(fContentBuffer);
//getTextCharacters can also be called for reading comments
fUsebuffer = true;
fMarkupDepth--;
}
[15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
Note: Called after scanning past '<!--' |
protected int scanContent(XMLStringBuffer content) throws IOException, XNIException {
//set the fTempString length to 0 before passing it on to scanContent
//scanContent sets the correct co-ordinates as per the content read
fTempString.length = 0;
int c = fEntityScanner.scanContent(fTempString);
content.append(fTempString);
fTempString.length = 0;
if (c == '\r") {
// happens when there is the character reference
//xxx: We know the next chracter.. we should just skip it and add ']' directlry
fEntityScanner.scanChar();
content.append((char)c);
c = -1;
} else if (c == ']") {
//fStringBuffer.clear();
//xxx: We know the next chracter.. we should just skip it and add ']' directlry
content.append((char)fEntityScanner.scanChar());
// remember where we are in case we get an endEntity before we
// could flush the buffer out - this happens when we're parsing an
// entity which ends with a ]
fInScanContent = true;
//
// We work on a single character basis to handle cases such as:
// ']]] >' which we might otherwise miss.
//
if (fEntityScanner.skipChar(']")) {
content.append(']");
while (fEntityScanner.skipChar(']")) {
content.append(']");
}
if (fEntityScanner.skipChar(' >")) {
reportFatalError("CDEndInContent", null);
}
}
fInScanContent = false;
c = -1;
}
if (fDocumentHandler != null && content.length > 0) {
//fDocumentHandler.characters(content, null);
}
return c;
}
|
public boolean scanDocument(boolean complete) throws IOException, XNIException {
// keep dispatching "events"
fEntityManager.setEntityHandler(this);
//System.out.println(" get Document Handler in NSDocumentHandler " + fDocumentHandler );
int event = next();
do {
switch (event) {
case XMLStreamConstants.START_DOCUMENT :
//fDocumentHandler.startDocument(fEntityManager.getEntityScanner(),fEntityManager.getEntityScanner().getVersion(),fNamespaceContext,null);// not able to get
break;
case XMLStreamConstants.START_ELEMENT :
//System.out.println(" in scann element");
//fDocumentHandler.startElement(getElementQName(),fAttributes,null);
break;
case XMLStreamConstants.CHARACTERS :
fDocumentHandler.characters(getCharacterData(),null);
break;
case XMLStreamConstants.SPACE:
//check if getCharacterData() is the right function to retrieve ignorableWhitespace information.
//System.out.println("in the space");
//fDocumentHandler.ignorableWhitespace(getCharacterData(), null);
break;
case XMLStreamConstants.ENTITY_REFERENCE :
//entity reference callback are given in startEntity
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION :
fDocumentHandler.processingInstruction(getPITarget(),getPIData(),null);
break;
case XMLStreamConstants.COMMENT :
//System.out.println(" in COMMENT of the XMLNSDocumentScannerImpl");
fDocumentHandler.comment(getCharacterData(),null);
break;
case XMLStreamConstants.DTD :
//all DTD related callbacks are handled in DTDScanner.
//1. Stax doesn't define DTD states as it does for XML Document.
//therefore we don't need to take care of anything here. So Just break;
break;
case XMLStreamConstants.CDATA:
fDocumentHandler.startCDATA(null);
//xxx: check if CDATA values comes from getCharacterData() function
fDocumentHandler.characters(getCharacterData(),null);
fDocumentHandler.endCDATA(null);
//System.out.println(" in CDATA of the XMLNSDocumentScannerImpl");
break;
case XMLStreamConstants.NOTATION_DECLARATION :
break;
case XMLStreamConstants.ENTITY_DECLARATION :
break;
case XMLStreamConstants.NAMESPACE :
break;
case XMLStreamConstants.ATTRIBUTE :
break;
case XMLStreamConstants.END_ELEMENT :
//do not give callback here.
//this callback is given in scanEndElement function.
//fDocumentHandler.endElement(getElementQName(),null);
break;
default :
throw new InternalError("processing event: " + event);
}
//System.out.println("here in before calling next");
event = next();
//System.out.println("here in after calling next");
} while (event!=XMLStreamConstants.END_DOCUMENT && complete);
if(event == XMLStreamConstants.END_DOCUMENT) {
fDocumentHandler.endDocument(null);
return false;
}
return true;
}
|
protected int scanEndElement() throws IOException, XNIException {
if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() +" > > > scanEndElement()");
// pop context
QName endElementName = fElementStack.popElement();
String rawname = endElementName.rawname;
if(DEBUG)System.out.println("endElementName = " + endElementName.toString());
// Take advantage of the fact that next string _should_ be "fElementQName.rawName",
//In scanners most of the time is consumed on checks done for XML characters, we can
// optimize on it and avoid the checks done for endElement,
//we will also avoid symbol table lookup - neeraj.bajaj@sun.com
// this should work both for namespace processing true or false...
//REVISIT: if the string is not the same as expected.. we need to do better error handling..
//We can skip this for now... In any case if the string doesn't match -- document is not well formed.
if (!fEntityScanner.skipString(endElementName.rawname)) {
reportFatalError("ETagRequired", new Object[]{rawname});
}
// end
fEntityScanner.skipSpaces();
if (!fEntityScanner.skipChar(' >")) {
reportFatalError("ETagUnterminated",
new Object[]{rawname});
}
fMarkupDepth--;
//we have increased the depth for two markup "< " characters
fMarkupDepth--;
// check that this element was opened in the same entity
if (fMarkupDepth < fEntityStack[fEntityDepth - 1]) {
reportFatalError("ElementEntityMismatch",
new Object[]{rawname});
}
//We should not be popping out the context here in endELement becaause the namespace context is still
//valid when parser is at the endElement state.
//if (fNamespaces) {
// fNamespaceContext.popContext();
//}
// call handler
if (fDocumentHandler != null ) {
//end element is scanned in this function so we can send a callback
//here.
//< strong >we shouldn't be sending callback in scanDocument()< /strong >
fDocumentHandler.endElement(endElementName, null);
}
if(dtdGrammarUtil != null)
dtdGrammarUtil.endElement(endElementName);
return fMarkupDepth;
}
[42] ETag ::= '</' Name S? '>'
Note: This method uses the fElementQName variable.
The contents of this variable will be destroyed. The caller should
copy the needed information out of this variable before calling
this method. |
protected void scanEntityReference(XMLStringBuffer content) throws IOException, XNIException {
String name = fEntityScanner.scanName();
if (name == null) {
reportFatalError("NameRequiredInReference", null);
}
if (!fEntityScanner.skipChar(';")) {
reportFatalError("SemicolonRequiredInReference", new Object []{name});
}
if (fEntityStore.isUnparsedEntity(name)) {
reportFatalError("ReferenceToUnparsedEntity", new Object[]{name});
}
fMarkupDepth--;
fCurrentEntityName = name;
// handle built-in entities
if (name == fAmpSymbol) {
handleCharacter('&", fAmpSymbol, content);
fScannerState = SCANNER_STATE_BUILT_IN_REFS;
return ;
} else if (name == fLtSymbol) {
handleCharacter('< ", fLtSymbol, content);
fScannerState = SCANNER_STATE_BUILT_IN_REFS;
return ;
} else if (name == fGtSymbol) {
handleCharacter(' >", fGtSymbol, content);
fScannerState = SCANNER_STATE_BUILT_IN_REFS;
return ;
} else if (name == fQuotSymbol) {
handleCharacter('"", fQuotSymbol, content);
fScannerState = SCANNER_STATE_BUILT_IN_REFS;
return ;
} else if (name == fAposSymbol) {
handleCharacter('\'", fAposSymbol, content);
fScannerState = SCANNER_STATE_BUILT_IN_REFS;
return ;
}
//1. if the entity is external and support to external entities is not required
// 2. or entities should not be replaced
//3. or if it is built in entity reference.
if((fEntityStore.isExternalEntity(name) && !fSupportExternalEntities) || (!fEntityStore.isExternalEntity(name) && !fReplaceEntityReferences) || foundBuiltInRefs){
fScannerState = SCANNER_STATE_REFERENCE;
return ;
}
// start general entity
if (!fEntityStore.isDeclaredEntity(name)) {
//REVISIT: one more case needs to be included: external PE and standalone is no
if ( fHasExternalDTD && !fStandalone) {
if (fValidation)
fErrorReporter.reportError(fEntityScanner, XMLMessageFormatter.XML_DOMAIN,"EntityNotDeclared",
new Object[]{name}, XMLErrorReporter.SEVERITY_ERROR);
} else
reportFatalError("EntityNotDeclared", new Object[]{name});
}
//we are starting the entity even if the entity was not declared
//if that was the case it its taken care in XMLEntityManager.startEntity()
//we immediately call the endEntity. Application gets to know if there was
//any entity that was not declared.
fEntityManager.startEntity(name, false);
//set the scaner state to content.. parser will automatically revive itself at any point of time.
//setScannerState(SCANNER_STATE_CONTENT);
//return true ;
}
Scans an entity reference. |
protected void scanPIData(String target,
XMLStringBuffer data) throws IOException, XNIException {
super.scanPIData(target, data);
//set the PI target and values
fPITarget = target ;
fMarkupDepth--;
}
Scans a processing data. This is needed to handle the situation
where a document starts with a processing instruction whose
target name starts with "xml". (e.g. xmlfoo) |
protected boolean scanStartElement() throws IOException, XNIException {
if (DEBUG_START_END_ELEMENT) System.out.println( this.getClass().toString() + " > > > scanStartElement()");
//when skipping is true and no more elements should be added
if(fSkip && !fAdd){
//get the stored element -- if everything goes right this should match the
//token in the buffer
QName name = fElementStack.getNext();
if(DEBUG_SKIP_ALGORITHM){
System.out.println("Trying to skip String = " + name.rawname);
}
//Be conservative -- if skipping fails -- stop.
fSkip = fEntityScanner.skipString(name.rawname);
if(fSkip){
if(DEBUG_SKIP_ALGORITHM){
System.out.println("Element SUCESSFULLY skipped = " + name.rawname);
}
fElementStack.push();
fElementQName = name;
}else{
//if skipping fails reposition the stack or fallback to normal way of processing
fElementStack.reposition();
if(DEBUG_SKIP_ALGORITHM){
System.out.println("Element was NOT skipped, REPOSITIONING stack" );
}
}
}
//we are still at the stage of adding elements
//the elements were not matched or
//fSkip is not set to true
if(!fSkip || fAdd){
//get the next element from the stack
fElementQName = fElementStack.nextElement();
// name
if (fNamespaces) {
fEntityScanner.scanQName(fElementQName);
} else {
String name = fEntityScanner.scanName();
fElementQName.setValues(null, name, name, null);
}
if(DEBUG)System.out.println("Element scanned in start element is " + fElementQName.toString());
if(DEBUG_SKIP_ALGORITHM){
if(fAdd){
System.out.println("Elements are being ADDED -- elemet added is = " + fElementQName.rawname + " at count = " + fElementStack.fCount);
}
}
}
//when the elements are being added , we need to check if we are set for skipping the elements
if(fAdd){
//this sets the value of fAdd variable
fElementStack.matchElement(fElementQName);
}
//xxx: We dont need another pointer, fCurrentElement, we can use fElementQName
fCurrentElement = fElementQName;
String rawname = fElementQName.rawname;
fEmptyElement = false;
fAttributes.removeAllAttributes();
if(!seekCloseOfStartTag()){
fReadingAttributes = true;
fAttributeCacheUsedCount =0;
fStringBufferIndex =0;
fAddDefaultAttr = true;
do {
scanAttribute(fAttributes);
if (fSecurityManager != null && fAttributes.getLength() > fElementAttributeLimit){
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
"ElementAttributeLimit",
new Object[]{rawname, new Integer(fAttributes.getLength()) },
XMLErrorReporter.SEVERITY_FATAL_ERROR );
}
} while (!seekCloseOfStartTag());
fReadingAttributes=false;
}
if (fEmptyElement) {
//decrease the markup depth..
fMarkupDepth--;
// check that this element was opened in the same entity
if (fMarkupDepth < fEntityStack[fEntityDepth - 1]) {
reportFatalError("ElementEntityMismatch",
new Object[]{fCurrentElement.rawname});
}
// call handler
if (fDocumentHandler != null) {
fDocumentHandler.emptyElement(fElementQName, fAttributes, null);
}
//We should not be popping out the context here in endELement becaause the namespace context is still
//valid when parser is at the endElement state.
//if (fNamespaces) {
// fNamespaceContext.popContext();
//}
//pop the element off the stack..
fElementStack.popElement();
} else {
if(dtdGrammarUtil != null)
dtdGrammarUtil.startElement(fElementQName, fAttributes);
if(fDocumentHandler != null){
//complete element and attributes are traversed in this function so we can send a callback
//here.
//< strong >we shouldn't be sending callback in scanDocument()< /strong >
fDocumentHandler.startElement(fElementQName, fAttributes, null);
}
}
if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() + "< < < scanStartElement(): "+fEmptyElement);
return fEmptyElement;
}
Scans a start element. This method will handle the binding of
namespace information and notifying the handler of the start
of the element.
[44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
[40] STag ::= '<' Name (S Attribute)* S? '>'
Note: This method assumes that the leading
'<' character has been consumed.
Note: This method uses the fElementQName and
fAttributes variables. The contents of these variables will be
destroyed. The caller should copy important information out of
these variables before calling this method.
NB: Content in fAttributes is valid only till the state of the parser is XMLEvent.START_ELEMENT |
protected void scanXMLDeclOrTextDecl(boolean scanningTextDecl) throws IOException, XNIException {
// scan decl
super.scanXMLDeclOrTextDecl(scanningTextDecl, fStrings);
fMarkupDepth--;
// pseudo-attribute values
String version = fStrings[0];
String encoding = fStrings[1];
String standalone = fStrings[2];
fDeclaredEncoding = encoding;
// set standalone
fStandalone = standalone != null && standalone.equals("yes");
///xxx see where its used.. this is not used anywhere. it may be useful for entity to store this information
//but this information is only related with Document Entity.
fEntityManager.setStandalone(fStandalone);
// call handler
if (fDocumentHandler != null) {
if (scanningTextDecl) {
fDocumentHandler.textDecl(version, encoding, null);
} else {
fDocumentHandler.xmlDecl(version, encoding, standalone, null);
}
}
if(version != null){
fEntityScanner.setVersion(version);
fEntityScanner.setXMLVersion(version);
}
// set encoding on reader, only if encoding was not specified by the application explicitly
if (encoding != null && !fEntityScanner.getCurrentEntity().isEncodingExternallySpecified()) {
fEntityScanner.setEncoding(encoding);
}
}
Scans an XML or text declaration.
[23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
[24] VersionInfo ::= S 'version' Eq (' VersionNum ' | " VersionNum ")
[80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" )
[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
[32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'")
| ('"' ('yes' | 'no') '"'))
[77] TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>'
|
protected boolean seekCloseOfStartTag() throws IOException, XNIException {
// spaces
boolean sawSpace = fEntityScanner.skipSpaces();
// end tag?
final int c = fEntityScanner.peekChar();
if (c == ' >") {
fEntityScanner.scanChar();
return true;
} else if (c == '/") {
fEntityScanner.scanChar();
if (!fEntityScanner.skipChar(' >")) {
reportFatalError("ElementUnterminated",
new Object[]{fElementQName.rawname});
}
fEmptyElement = true;
return true;
} else if (!isValidNameStartChar(c) || !sawSpace) {
reportFatalError("ElementUnterminated", new Object[]{fElementQName.rawname});
}
return false;
}
Looks for the close of start tag, i.e. if it finds '>' or '/>'
Characters are consumed. |
public void setDocumentHandler(XMLDocumentHandler documentHandler) {
fDocumentHandler = documentHandler;
//System.out.println(" In Set DOCUMENT HANDLER" + fDocumentHandler + " scanner =" + this);
}
|
protected final void setDriver(XMLDocumentFragmentScannerImpl.Driver driver) {
fDriver = driver;
if (DEBUG_DISPATCHER) {
System.out.print("%%% setDriver: ");
System.out.print(getDriverName(driver));
System.out.println();
}
}
|
public void setFeature(String featureId,
boolean state) throws XMLConfigurationException {
super.setFeature(featureId, state);
// Xerces properties
if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
String feature = featureId.substring(Constants.XERCES_FEATURE_PREFIX.length());
if (feature.equals(Constants.NOTIFY_BUILTIN_REFS_FEATURE)) {
fNotifyBuiltInRefs = state;
}
}
}
|
public void setInputSource(XMLInputSource inputSource) throws IOException {
fEntityManager.setEntityHandler(this);
fEntityManager.startEntity("$fragment$", inputSource, false, true);
// fDocumentSystemId = fEntityManager.expandSystemId(inputSource.getSystemId());
}
|
public void setProperty(String propertyId,
Object value) throws XMLConfigurationException {
super.setProperty(propertyId, value);
// Xerces properties
if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
if (suffixLength == Constants.ENTITY_MANAGER_PROPERTY.length() &&
propertyId.endsWith(Constants.ENTITY_MANAGER_PROPERTY)) {
fEntityManager = (XMLEntityManager)value;
return;
}
if (suffixLength == Constants.ENTITY_RESOLVER_PROPERTY.length() &&
propertyId.endsWith(Constants.ENTITY_RESOLVER_PROPERTY)) {
fExternalSubsetResolver = (value instanceof ExternalSubsetResolver) ?
(ExternalSubsetResolver) value : null;
return;
}
}
// Xerces properties
if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
String property = propertyId.substring(Constants.XERCES_PROPERTY_PREFIX.length());
if (property.equals(Constants.ENTITY_MANAGER_PROPERTY)) {
fEntityManager = (XMLEntityManager)value;
}
return;
}
}
Sets the value of a property. This method is called by the component
manager any time after reset when a property changes value.
Note: Components should silently ignore properties
that do not affect the operation of the component. |
protected final void setScannerState(int state) {
fScannerState = state;
if (DEBUG_SCANNER_STATE) {
System.out.print("### setScannerState: ");
//System.out.print(fScannerState);
System.out.print(getScannerStateName(state));
System.out.println();
}
}
|
protected boolean skipElement() throws IOException {
if(!fShouldSkip) return false ;
if(fLastPointerLocation != 0){
//Look at the next element stored in the array list.. we might just get a match.
String rawname = fElementArray[fLastPointerLocation + 1] ;
if(rawname != null && skipFromTheBuffer(rawname)){
fLastPointerLocation++ ;
if(DEBUG_SKIP_ALGORITHM){
System.out.println("Element " + fElementRawname + " was SKIPPED at pointer location = " + fLastPointerLocation);
}
return true ;
} else{
//reset it back to zero... we haven't got the correct subset yet.
fLastPointerLocation = 0 ;
}
}
//xxx: we can put some logic here as from what column it should start looking
//for now we always start at 0
//fallback to tolerant algorithm, it would look for differnt element stored at different
//depth and get us the pointer location.
return fShouldSkip && skipElement((short)0);
}
|
boolean skipElement(short column) throws IOException {
short depth = (short)fElementStack.fDepth ;
if(depth > MAX_DEPTH_LIMIT){
return fShouldSkip = false ;
}
for(short i = column ; i < MAX_POINTER_AT_A_DEPTH ; i++){
short pointer = getElementPointer(depth , i ) ;
if(pointer == 0){
return fShouldSkip = false ;
}
if(fElementArray[pointer] != null && skipFromTheBuffer(fElementArray[pointer])){
if(DEBUG_SKIP_ALGORITHM){
System.out.println();
System.out.println("Element " + fElementRawname + " was SKIPPED at depth = " + fElementStack.fDepth + " column = " + column );
System.out.println();
}
fLastPointerLocation = pointer ;
return fShouldSkip = true ;
}
}
return fShouldSkip = false ;
}
|
boolean skipFromTheBuffer(String rawname) throws IOException {
if(fEntityScanner.skipString(rawname)){
char c = (char)fEntityScanner.peekChar() ;
//If the start element was completely skipped we should encounter either ' '(space),
//or '/' (in case of empty element) or ' >'
if( c == ' " || c == '/" || c == ' >"){
fElementRawname = rawname ;
return true ;
} else{
return false;
}
} else
return false ;
}
|
boolean skipQElement(String rawname) throws IOException {
final int c = fEntityScanner.getChar(rawname.length());
//if this character is still valid element name -- this means string can't match
if(XMLChar.isName(c)){
return false;
}else{
return fEntityScanner.skipString(rawname);
}
}
|
public void startEntity(String name,
XMLResourceIdentifier identifier,
String encoding,
Augmentations augs) throws XNIException {
// keep track of this entity before fEntityDepth is increased
if (fEntityDepth == fEntityStack.length) {
int[] entityarray = new int[fEntityStack.length * 2];
System.arraycopy(fEntityStack, 0, entityarray, 0, fEntityStack.length);
fEntityStack = entityarray;
}
fEntityStack[fEntityDepth] = fMarkupDepth;
super.startEntity(name, identifier, encoding, augs);
// WFC: entity declared in external subset in standalone doc
if(fStandalone && fEntityStore.isEntityDeclInExternalSubset(name)) {
reportFatalError("MSG_REFERENCE_TO_EXTERNALLY_DECLARED_ENTITY_WHEN_STANDALONE",
new Object[]{name});
}
/** we are not calling the handlers yet.. */
// call handler
if (fDocumentHandler != null && !fScanningAttribute) {
if (!name.equals("[xml]")) {
fDocumentHandler.startGeneralEntity(name, identifier, encoding, null);
}
}
}
This method notifies of the start of an entity. The DTD has the
pseudo-name of "[dtd]" parameter entity names start with '%'; and
general entities are just specified by their name. |
short storePointerForADepth(short elementPointer) {
short depth = (short) fElementStack.fDepth ;
//Stores element pointer locations at particular depth , only 4 pointer locations
//are stored at particular depth for now.
for(short i = 0 ; i < MAX_POINTER_AT_A_DEPTH ; i++){
if(canStore(depth, i)){
fPointerInfo[depth][i] = elementPointer ;
if(DEBUG_SKIP_ALGORITHM){
StringBuffer sb = new StringBuffer() ;
sb.append(" Pointer information ") ;
sb.append(" fElementPointer = " + fElementPointer) ;
sb.append(" fElementStack.fDepth = " + fElementStack.fDepth);
sb.append(" column = " + i ) ;
System.out.println(sb.toString()) ;
}
return i;
}
//else
//pointer was not stored because we reached the limit
}
return -1 ;
}
|