8170556: Warnings cleanup related to JDK-8167340

Reviewed-by: dfuchs, lancea, clanger
This commit is contained in:
Joe Wang 2016-12-15 13:57:04 -08:00
parent ea6028f37e
commit 95f72fe86a
54 changed files with 1414 additions and 1376 deletions

@ -218,8 +218,8 @@ public class XMLDocumentFragmentScannerImpl
}; };
private static final char [] cdata = {'[','C','D','A','T','A','['}; private static final char [] CDATA = {'[','C','D','A','T','A','['};
static final char [] xmlDecl = {'<','?','x','m','l'}; static final char [] XMLDECL = {'<','?','x','m','l'};
// private static final char [] endTag = {'<','/'}; // private static final char [] endTag = {'<','/'};
// debugging // debugging
@ -232,13 +232,9 @@ public class XMLDocumentFragmentScannerImpl
/** Debug content driver scanning. */ /** Debug content driver scanning. */
protected static final boolean DEBUG_START_END_ELEMENT = false; protected static final boolean DEBUG_START_END_ELEMENT = false;
/** Debug driver next */
protected static final boolean DEBUG_NEXT = false ;
/** Debug driver next */ /** Debug driver next */
protected static final boolean DEBUG = false; protected static final boolean DEBUG = false;
protected static final boolean DEBUG_COALESCE = false;
// //
// Data // Data
// //
@ -371,16 +367,16 @@ public class XMLDocumentFragmentScannerImpl
protected XMLString fTempString2 = new XMLString(); protected XMLString fTempString2 = new XMLString();
/** Array of 3 strings. */ /** Array of 3 strings. */
private String[] fStrings = new String[3]; private final String[] fStrings = new String[3];
/** Making the buffer accesible to derived class -- String buffer. */ /** Making the buffer accessible to derived class -- String buffer. */
protected XMLStringBuffer fStringBuffer = new XMLStringBuffer(); protected XMLStringBuffer fStringBuffer = new XMLStringBuffer();
/** Making the buffer accesible to derived class -- String buffer. */ /** Making the buffer accessible to derived class -- String buffer. */
protected XMLStringBuffer fStringBuffer2 = new XMLStringBuffer(); protected XMLStringBuffer fStringBuffer2 = new XMLStringBuffer();
/** stores character data. */ /** stores character data. */
/** Making the buffer accesible to derived class -- stores PI data */ /** Making the buffer accessible to derived class -- stores PI data */
protected XMLStringBuffer fContentBuffer = new XMLStringBuffer(); protected XMLStringBuffer fContentBuffer = new XMLStringBuffer();
/** Single character array. */ /** Single character array. */
@ -633,22 +629,23 @@ public class XMLDocumentFragmentScannerImpl
// other settings // other settings
// fDocumentSystemId = null; // fDocumentSystemId = null;
fNamespaces = ((Boolean)propertyManager.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE)).booleanValue(); fNamespaces = ((Boolean)propertyManager.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE));
fNotifyBuiltInRefs = false ; fNotifyBuiltInRefs = false ;
//fElementStack2.clear(); //fElementStack2.clear();
//fReplaceEntityReferences = true; //fReplaceEntityReferences = true;
//fSupportExternalEntities = true; //fSupportExternalEntities = true;
Boolean bo = (Boolean)propertyManager.getProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES); Boolean bo = (Boolean)propertyManager.getProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES);
fReplaceEntityReferences = bo.booleanValue(); fReplaceEntityReferences = bo;
bo = (Boolean)propertyManager.getProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES); bo = (Boolean)propertyManager.getProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES);
fSupportExternalEntities = bo.booleanValue(); fSupportExternalEntities = bo;
Boolean cdata = (Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.STAX_REPORT_CDATA_EVENT) ; Boolean cdata = (Boolean)propertyManager.getProperty(
Constants.ZEPHYR_PROPERTY_PREFIX + Constants.STAX_REPORT_CDATA_EVENT) ;
if(cdata != null) if(cdata != null)
fReportCdataEvent = cdata.booleanValue() ; fReportCdataEvent = cdata ;
Boolean coalesce = (Boolean)propertyManager.getProperty(XMLInputFactory.IS_COALESCING) ; Boolean coalesce = (Boolean)propertyManager.getProperty(XMLInputFactory.IS_COALESCING) ;
if(coalesce != null) if(coalesce != null)
fIsCoalesce = coalesce.booleanValue(); fIsCoalesce = coalesce;
fReportCdataEvent = fIsCoalesce ? false : (fReportCdataEvent && true) ; fReportCdataEvent = fIsCoalesce ? false : (fReportCdataEvent && true) ;
//if fIsCoalesce is set to true, set the value of fReplaceEntityReferences to 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 //if fIsCoalesce is set to false, take the value of fReplaceEntityReferences as set by application
@ -703,7 +700,7 @@ public class XMLDocumentFragmentScannerImpl
* are recognized by this component. * are recognized by this component.
*/ */
public String[] getRecognizedFeatures() { public String[] getRecognizedFeatures() {
return (String[])(RECOGNIZED_FEATURES.clone()); return RECOGNIZED_FEATURES.clone();
} // getRecognizedFeatures():String[] } // getRecognizedFeatures():String[]
/** /**
@ -742,7 +739,7 @@ public class XMLDocumentFragmentScannerImpl
* are recognized by this component. * are recognized by this component.
*/ */
public String[] getRecognizedProperties() { public String[] getRecognizedProperties() {
return (String[])(RECOGNIZED_PROPERTIES.clone()); return RECOGNIZED_PROPERTIES.clone();
} // getRecognizedProperties():String[] } // getRecognizedProperties():String[]
/** /**
@ -990,7 +987,8 @@ public class XMLDocumentFragmentScannerImpl
// set standalone // set standalone
fStandaloneSet = standalone != null; fStandaloneSet = standalone != null;
fStandalone = fStandaloneSet && standalone.equals("yes"); fStandalone = fStandaloneSet && standalone.equals("yes");
///xxx see where its used.. this is not used anywhere. it may be useful for entity to store this information ///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. //but this information is only related with Document Entity.
fEntityManager.setStandalone(fStandalone); fEntityManager.setStandalone(fStandalone);
@ -1199,7 +1197,8 @@ public class XMLDocumentFragmentScannerImpl
if(rawname != null && skipFromTheBuffer(rawname)){ if(rawname != null && skipFromTheBuffer(rawname)){
fLastPointerLocation++ ; fLastPointerLocation++ ;
if(DEBUG_SKIP_ALGORITHM){ if(DEBUG_SKIP_ALGORITHM){
System.out.println("Element " + fElementRawname + " was SKIPPED at pointer location = " + fLastPointerLocation); System.out.println("Element " + fElementRawname +
" was SKIPPED at pointer location = " + fLastPointerLocation);
} }
return true ; return true ;
} else{ } else{
@ -1233,7 +1232,8 @@ public class XMLDocumentFragmentScannerImpl
if(fElementArray[pointer] != null && skipFromTheBuffer(fElementArray[pointer])){ if(fElementArray[pointer] != null && skipFromTheBuffer(fElementArray[pointer])){
if(DEBUG_SKIP_ALGORITHM){ if(DEBUG_SKIP_ALGORITHM){
System.out.println(); System.out.println();
System.out.println("Element " + fElementRawname + " was SKIPPED at depth = " + fElementStack.fDepth + " column = " + column ); System.out.println("Element " + fElementRawname + " was SKIPPED at depth = " +
fElementStack.fDepth + " column = " + column );
System.out.println(); System.out.println();
} }
fLastPointerLocation = pointer ; fLastPointerLocation = pointer ;
@ -1317,7 +1317,8 @@ public class XMLDocumentFragmentScannerImpl
if(DEBUG)System.out.println("Element scanned in start element is " + fElementQName.toString()); if(DEBUG)System.out.println("Element scanned in start element is " + fElementQName.toString());
if(DEBUG_SKIP_ALGORITHM){ if(DEBUG_SKIP_ALGORITHM){
if(fAdd){ if(fAdd){
System.out.println("Elements are being ADDED -- elemet added is = " + fElementQName.rawname + " at count = " + fElementStack.fCount); System.out.println("Elements are being ADDED -- elemet added is = " +
fElementQName.rawname + " at count = " + fElementStack.fCount);
} }
} }
@ -1395,7 +1396,8 @@ public class XMLDocumentFragmentScannerImpl
} }
if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() + "<<< scanStartElement(): "+fEmptyElement); if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() +
"<<< scanStartElement(): "+fEmptyElement);
return fEmptyElement; return fEmptyElement;
} // scanStartElement():boolean } // scanStartElement():boolean
@ -1434,84 +1436,9 @@ public class XMLDocumentFragmentScannerImpl
} }
public boolean hasAttributes(){ public boolean hasAttributes(){
return fAttributes.getLength() > 0 ? true : false ; return fAttributes.getLength() > 0;
} }
/**
* Scans an attribute.
* <p>
* <pre>
* [41] Attribute ::= Name Eq AttValue
* </pre>
* <p>
* <strong>Note:</strong> This method assumes that the next
* character on the stream is the first character of the attribute
* name.
* <p>
* <strong>Note:</strong> This method uses the fAttributeQName and
* fQName variables. The contents of these variables will be
* destroyed.
*
* @param attributes The attributes list for the scanned attribute.
*/
/**
* protected void scanAttribute(AttributeIteratorImpl attributes)
* throws IOException, XNIException {
* if (DEBUG_START_END_ELEMENT) System.out.println(">>> 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[]{fAttributeQName.rawname});
* }
* fEntityScanner.skipSpaces();
*
*
* // content
* int oldLen = attributes.getLength();
*/
/**xxx there is one check of duplicate attribute that has been removed.
* attributes.addAttribute(fAttributeQName, XMLSymbols.fCDATASymbol, null);
*
* // WFC: Unique Att Spec
* if (oldLen == attributes.getLength()) {
* reportFatalError("AttributeNotUnique",
* new Object[]{fCurrentElement.rawname,
* fAttributeQName.rawname});
* }
*/
/*
//REVISIT: one more case needs to be included: external PE and standalone is no
boolean isVC = fHasExternalDTD && !fStandalone;
scanAttributeValue(fTempString, fTempString2,
fAttributeQName.rawname, attributes,
oldLen, isVC);
//attributes.setValue(oldLen, fTempString.toString());
//attributes.setNonNormalizedValue(oldLen, fTempString2.toString());
//attributes.setSpecified(oldLen, true);
AttributeImpl attribute = new AttributeImpl(fAttributeQName.prefix,fAttributeQName.localpart,fAttributeQName.uri,fTempString.toString(),fTempString2.toString(),XMLSymbols.fCDATASymbol,true);
fAttributes.addAttribute(attribute);
if (DEBUG_START_END_ELEMENT) System.out.println("<<< scanAttribute()");
} // scanAttribute(XMLAttributes)
*/
/** return the attribute iterator implementation */ /** return the attribute iterator implementation */
public XMLAttributesIteratorImpl getAttributeIterator(){ public XMLAttributesIteratorImpl getAttributeIterator(){
if(dtdGrammarUtil != null && fAddDefaultAttr){ if(dtdGrammarUtil != null && fAddDefaultAttr){
@ -2624,7 +2551,7 @@ public class XMLDocumentFragmentScannerImpl
null); null);
} }
setScannerState(SCANNER_STATE_COMMENT); setScannerState(SCANNER_STATE_COMMENT);
} else if (fEntityScanner.skipString(cdata)) { } else if (fEntityScanner.skipString(CDATA)) {
fCDataStart = true; fCDataStart = true;
setScannerState(SCANNER_STATE_CDATA ); setScannerState(SCANNER_STATE_CDATA );
} else if (!scanForDoctypeHook()) { } else if (!scanForDoctypeHook()) {
@ -2710,62 +2637,56 @@ public class XMLDocumentFragmentScannerImpl
public int next() throws IOException, XNIException { public int next() throws IOException, XNIException {
while (true) { while (true) {
try { try {
if(DEBUG_NEXT){
System.out.println("NOW IN FragmentContentDriver");
System.out.println("Entering the FragmentContentDriver with = " + getScannerStateName(fScannerState));
}
//decide the actual sub state of the scanner.For more information refer to the javadoc of //decide the actual sub state of the scanner.For more information refer to the javadoc of
//decideSubState. //decideSubState.
switch (fScannerState) { if (fScannerState == SCANNER_STATE_CONTENT) {
case SCANNER_STATE_CONTENT: { final int ch = fEntityScanner.peekChar();
final int ch = fEntityScanner.peekChar(); if (ch == '<') {
if (ch == '<') { fEntityScanner.scanChar(null);
fEntityScanner.scanChar(null); setScannerState(SCANNER_STATE_START_OF_MARKUP);
setScannerState(SCANNER_STATE_START_OF_MARKUP); } else if (ch == '&') {
} else if (ch == '&') { fEntityScanner.scanChar(NameType.REFERENCE);
fEntityScanner.scanChar(NameType.REFERENCE); setScannerState(SCANNER_STATE_REFERENCE) ;
setScannerState(SCANNER_STATE_REFERENCE) ; //XMLEvent.ENTITY_REFERENCE ); //SCANNER_STATE_REFERENCE } else {
break; //element content is there..
} else { setScannerState(SCANNER_STATE_CHARACTER_DATA);
//element content is there..
setScannerState(SCANNER_STATE_CHARACTER_DATA);
break;
}
} }
}
case SCANNER_STATE_START_OF_MARKUP: { if (fScannerState == SCANNER_STATE_START_OF_MARKUP) {
startOfMarkup(); startOfMarkup();
break; }
}//case: SCANNER_STATE_START_OF_MARKUP
}//end of switch
//decideSubState() ; //decideSubState() ;
//do some special handling if isCoalesce is set to true. //do some special handling if isCoalesce is set to true.
if(fIsCoalesce){ if (fIsCoalesce) {
fUsebuffer = true ; fUsebuffer = true ;
//if the last section was character data //if the last section was character data
if(fLastSectionWasCharacterData){ if (fLastSectionWasCharacterData) {
//if we dont encounter any CDATA or ENTITY REFERENCE and current state is also not SCANNER_STATE_CHARACTER_DATA //if we dont encounter any CDATA or ENTITY REFERENCE and
//current state is also not SCANNER_STATE_CHARACTER_DATA
//return the last scanned charactrer data. //return the last scanned charactrer data.
if((fScannerState != SCANNER_STATE_CDATA) && (fScannerState != SCANNER_STATE_REFERENCE) if ((fScannerState != SCANNER_STATE_CDATA)
&& (fScannerState != SCANNER_STATE_CHARACTER_DATA)){ && (fScannerState != SCANNER_STATE_REFERENCE)
&& (fScannerState != SCANNER_STATE_CHARACTER_DATA)) {
fLastSectionWasCharacterData = false; fLastSectionWasCharacterData = false;
return XMLEvent.CHARACTERS; return XMLEvent.CHARACTERS;
} }
}//if last section was CDATA or ENTITY REFERENCE }//if last section was CDATA or ENTITY REFERENCE
//xxx: there might be another entity reference or CDATA after this //xxx: there might be another entity reference or CDATA after this
//<foo>blah blah &amp;&lt;<![CDATA[[aa]]>blah blah</foo> //<foo>blah blah &amp;&lt;<![CDATA[[aa]]>blah blah</foo>
else if((fLastSectionWasCData || fLastSectionWasEntityReference)){ else if ((fLastSectionWasCData || fLastSectionWasEntityReference)) {
//and current state is not SCANNER_STATE_CHARACTER_DATA //and current state is not SCANNER_STATE_CHARACTER_DATA
//or SCANNER_STATE_CDATA or SCANNER_STATE_REFERENCE //or SCANNER_STATE_CDATA or SCANNER_STATE_REFERENCE
//this means there is nothing more to be coalesced. //this means there is nothing more to be coalesced.
//return the CHARACTERS event. //return the CHARACTERS event.
if((fScannerState != SCANNER_STATE_CDATA) && (fScannerState != SCANNER_STATE_REFERENCE) if ((fScannerState != SCANNER_STATE_CDATA)
&& (fScannerState != SCANNER_STATE_CHARACTER_DATA)){ && (fScannerState != SCANNER_STATE_REFERENCE)
&& (fScannerState != SCANNER_STATE_CHARACTER_DATA)){
fLastSectionWasCData = false; fLastSectionWasCData = false;
fLastSectionWasEntityReference = false; fLastSectionWasEntityReference = false;
@ -2774,11 +2695,6 @@ public class XMLDocumentFragmentScannerImpl
} }
} }
if(DEBUG_NEXT){
System.out.println("Actual scanner state set by decideSubState is = " + getScannerStateName(fScannerState));
}
switch(fScannerState){ switch(fScannerState){
case XMLEvent.START_DOCUMENT : case XMLEvent.START_DOCUMENT :
@ -2786,7 +2702,6 @@ public class XMLDocumentFragmentScannerImpl
case SCANNER_STATE_START_ELEMENT_TAG :{ case SCANNER_STATE_START_ELEMENT_TAG :{
//xxx this function returns true when element is empty.. can be linked to end element event.
//returns true if the element is empty //returns true if the element is empty
fEmptyElement = scanStartElement() ; fEmptyElement = scanStartElement() ;
//if the element is empty the next event is "end element" //if the element is empty the next event is "end element"
@ -2800,15 +2715,16 @@ public class XMLDocumentFragmentScannerImpl
} }
case SCANNER_STATE_CHARACTER_DATA: { case SCANNER_STATE_CHARACTER_DATA: {
if(DEBUG_COALESCE){
System.out.println("fLastSectionWasCData = " + fLastSectionWasCData);
System.out.println("fIsCoalesce = " + fIsCoalesce);
}
//if last section was either entity reference or cdata or character data we should be using buffer
fUsebuffer = fLastSectionWasEntityReference || fLastSectionWasCData || fLastSectionWasCharacterData ;
//When coalesce is set to true and last state was REFERENCE or CDATA or CHARACTER_DATA, buffer should not be cleared. //if last section was either entity reference or cdata or
if( fIsCoalesce && (fLastSectionWasEntityReference || fLastSectionWasCData || fLastSectionWasCharacterData) ){ //character data we should be using buffer
fUsebuffer = fLastSectionWasEntityReference || fLastSectionWasCData
|| fLastSectionWasCharacterData ;
//When coalesce is set to true and last state was REFERENCE or
//CDATA or CHARACTER_DATA, buffer should not be cleared.
if( fIsCoalesce && (fLastSectionWasEntityReference ||
fLastSectionWasCData || fLastSectionWasCharacterData) ){
fLastSectionWasEntityReference = false; fLastSectionWasEntityReference = false;
fLastSectionWasCData = false; fLastSectionWasCData = false;
fLastSectionWasCharacterData = true ; fLastSectionWasCharacterData = true ;
@ -2822,9 +2738,7 @@ public class XMLDocumentFragmentScannerImpl
//scanContent sets the correct co-ordinates as per the content read //scanContent sets the correct co-ordinates as per the content read
fTempString.length = 0; fTempString.length = 0;
int c = fEntityScanner.scanContent(fTempString); int c = fEntityScanner.scanContent(fTempString);
if(DEBUG){
System.out.println("fTempString = " + fTempString);
}
if(fEntityScanner.skipChar('<', null)){ if(fEntityScanner.skipChar('<', null)){
//check if we have reached end of element //check if we have reached end of element
if(fEntityScanner.skipChar('/', NameType.ELEMENTEND)){ if(fEntityScanner.skipChar('/', NameType.ELEMENTEND)){
@ -2841,21 +2755,17 @@ public class XMLDocumentFragmentScannerImpl
setScannerState(SCANNER_STATE_START_OF_MARKUP); setScannerState(SCANNER_STATE_START_OF_MARKUP);
//there can be cdata ahead if coalesce is true we should call again //there can be cdata ahead if coalesce is true we should call again
if(fIsCoalesce){ if(fIsCoalesce){
fUsebuffer = true;
fLastSectionWasCharacterData = true; fLastSectionWasCharacterData = true;
fContentBuffer.append(fTempString); bufferContent();
fTempString.length = 0;
continue; continue;
} }
} }
//in case last section was either entity reference or cdata or character data -- we should be using buffer //in case last section was either entity reference or
//cdata or character data -- we should be using buffer
if(fUsebuffer){ if(fUsebuffer){
fContentBuffer.append(fTempString); bufferContent();
fTempString.length = 0;
}
if(DEBUG){
System.out.println("NOT USING THE BUFFER, STRING = " + fTempString.toString());
} }
if(dtdGrammarUtil!= null && dtdGrammarUtil.isIgnorableWhiteSpace(fContentBuffer)){ if(dtdGrammarUtil!= null && dtdGrammarUtil.isIgnorableWhiteSpace(fContentBuffer)){
if(DEBUG)System.out.println("Return SPACE EVENT"); if(DEBUG)System.out.println("Return SPACE EVENT");
return XMLEvent.SPACE; return XMLEvent.SPACE;
@ -2863,13 +2773,7 @@ public class XMLDocumentFragmentScannerImpl
return XMLEvent.CHARACTERS; return XMLEvent.CHARACTERS;
} else{ } else{
fUsebuffer = true ; bufferContent();
if(DEBUG){
System.out.println("fContentBuffer = " + fContentBuffer);
System.out.println("fTempString = " + fTempString);
}
fContentBuffer.append(fTempString);
fTempString.length = 0;
} }
if (c == '\r') { if (c == '\r') {
if(DEBUG){ if(DEBUG){
@ -2969,7 +2873,8 @@ public class XMLDocumentFragmentScannerImpl
setScannerState(SCANNER_STATE_CONTENT); setScannerState(SCANNER_STATE_CONTENT);
//check the case when there is comment after single element document //check the case when there is comment after single element document
//<foo/> and some comment after this //<foo/> and some comment after this
return (fMarkupDepth == 0 && elementDepthIsZeroHook() ) ? XMLEvent.END_ELEMENT : XMLEvent.END_ELEMENT ; return (fMarkupDepth == 0 && elementDepthIsZeroHook() ) ?
XMLEvent.END_ELEMENT : XMLEvent.END_ELEMENT ;
} else if(scanEndElement() == 0) { } else if(scanEndElement() == 0) {
//It is last element of the document //It is last element of the document
@ -3093,7 +2998,8 @@ public class XMLDocumentFragmentScannerImpl
if(fScannerState == SCANNER_STATE_REFERENCE){ if(fScannerState == SCANNER_STATE_REFERENCE){
setScannerState(SCANNER_STATE_CONTENT); setScannerState(SCANNER_STATE_CONTENT);
if (fReplaceEntityReferences && fEntityStore.isDeclaredEntity(fCurrentEntityName)) { if (fReplaceEntityReferences &&
fEntityStore.isDeclaredEntity(fCurrentEntityName)) {
// Skip the entity reference, we don't care // Skip the entity reference, we don't care
continue; continue;
} }
@ -3126,7 +3032,8 @@ public class XMLDocumentFragmentScannerImpl
fStringBuffer.append((char)fEntityScanner.scanChar(null)); fStringBuffer.append((char)fEntityScanner.scanChar(null));
} }
} }
String target = fSymbolTable.addSymbol(fStringBuffer.ch, fStringBuffer.offset, fStringBuffer.length); String target = fSymbolTable.addSymbol(fStringBuffer.ch,
fStringBuffer.offset, fStringBuffer.length);
fContentBuffer.clear(); fContentBuffer.clear();
scanPIData(target, fContentBuffer); scanPIData(target, fContentBuffer);
} }
@ -3269,7 +3176,8 @@ public class XMLDocumentFragmentScannerImpl
*/ */
protected XMLString getString(){ protected XMLString getString(){
if(fAttributeCacheUsedCount < initialCacheCount || fAttributeCacheUsedCount < attributeValueCache.size()){ if(fAttributeCacheUsedCount < initialCacheCount ||
fAttributeCacheUsedCount < attributeValueCache.size()){
return attributeValueCache.get(fAttributeCacheUsedCount++); return attributeValueCache.get(fAttributeCacheUsedCount++);
} else{ } else{
XMLString str = new XMLString(); XMLString str = new XMLString();
@ -3299,13 +3207,20 @@ public class XMLDocumentFragmentScannerImpl
fAttributes.refresh(); fAttributes.refresh();
} }
if(fScannerState == SCANNER_STATE_CHARACTER_DATA){ if(fScannerState == SCANNER_STATE_CHARACTER_DATA){
//since fTempString directly matches to the underlying main buffer bufferContent();
//store the data into buffer
fContentBuffer.append(fTempString);
//clear the XMLString so that data can't be added again.
fTempString.length = 0;
fUsebuffer = true;
} }
} }
/**
* Since 'TempString' shares the buffer (a char array) with the CurrentEntity,
* when the cursor position reaches the end, that is, before the buffer is
* being loaded with new data, the content in the TempString needs to be
* copied into the ContentBuffer.
*/
private void bufferContent() {
fContentBuffer.append(fTempString);
//clear the XMLString so that data can't be added again.
fTempString.length = 0;
fUsebuffer = true;
}
} // class XMLDocumentFragmentScannerImpl } // class XMLDocumentFragmentScannerImpl

@ -733,9 +733,6 @@ public class XMLDocumentScannerImpl
public int next() throws IOException, XNIException { public int next() throws IOException, XNIException {
if(DEBUG_NEXT){
System.out.println("NOW IN XMLDeclDriver");
}
// next driver is prolog regardless of whether there // next driver is prolog regardless of whether there
// is an XMLDecl in this document // is an XMLDecl in this document
@ -745,7 +742,7 @@ public class XMLDocumentScannerImpl
//System.out.println("fEntityScanner = " + fEntityScanner); //System.out.println("fEntityScanner = " + fEntityScanner);
// scan XMLDecl // scan XMLDecl
try { try {
if (fEntityScanner.skipString(xmlDecl)) { if (fEntityScanner.skipString(XMLDECL)) {
if (fEntityScanner.peekChar() == ' ') { if (fEntityScanner.peekChar() == ' ') {
fMarkupDepth++; fMarkupDepth++;
scanXMLDeclOrTextDecl(false); scanXMLDeclOrTextDecl(false);
@ -797,11 +794,7 @@ public class XMLDocumentScannerImpl
*/ */
public int next() throws IOException, XNIException { public int next() throws IOException, XNIException {
//System.out.println("here in next");
if(DEBUG_NEXT){
System.out.println("NOW IN PrologDriver");
}
try { try {
do { do {
switch (fScannerState) { switch (fScannerState) {
@ -1014,17 +1007,9 @@ public class XMLDocumentScannerImpl
// //
public int next() throws IOException, XNIException{ public int next() throws IOException, XNIException{
// throw new XNIException("DTD Parsing is currently not supported");
if(DEBUG_NEXT){
System.out.println("Now in DTD Driver");
}
dispatch(true); dispatch(true);
if(DEBUG_NEXT){
System.out.println("After calling dispatch(true) -- At this point whole DTD is read.");
}
//xxx: remove this hack and align this with reusing DTD components //xxx: remove this hack and align this with reusing DTD components
//currently this routine will only be executed from Stax //currently this routine will only be executed from Stax
if(fPropertyManager != null){ if(fPropertyManager != null){
@ -1380,10 +1365,9 @@ public class XMLDocumentScannerImpl
break; break;
} }
} }
}while(fScannerState == SCANNER_STATE_START_OF_MARKUP || fScannerState == SCANNER_STATE_TRAILING_MISC); } while(fScannerState == SCANNER_STATE_START_OF_MARKUP ||
if(DEBUG_NEXT){ fScannerState == SCANNER_STATE_TRAILING_MISC);
System.out.println("State set by deciding while loop [TrailingMiscellaneous] is = " + getScannerStateName(fScannerState));
}
switch (fScannerState){ switch (fScannerState){
case SCANNER_STATE_PI: { case SCANNER_STATE_PI: {
fContentBuffer.clear(); fContentBuffer.clear();

@ -967,7 +967,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
*/ */
public void setEntityHandler(com.sun.org.apache.xerces.internal.impl.XMLEntityHandler entityHandler) { public void setEntityHandler(com.sun.org.apache.xerces.internal.impl.XMLEntityHandler entityHandler) {
fEntityHandler = (XMLEntityHandler) entityHandler; fEntityHandler = entityHandler;
} // setEntityHandler(XMLEntityHandler) } // setEntityHandler(XMLEntityHandler)
//this function returns StaxXMLInputSource //this function returns StaxXMLInputSource
@ -1266,11 +1266,11 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
for (int i = size; i >= 0; i--) { for (int i = size; i >= 0; i--) {
Entity activeEntity = i == size Entity activeEntity = i == size
? fCurrentEntity ? fCurrentEntity
: (Entity)fEntityStack.elementAt(i); : fEntityStack.elementAt(i);
if (activeEntity.name == entityName) { if (activeEntity.name == entityName) {
String path = entityName; String path = entityName;
for (int j = i + 1; j < size; j++) { for (int j = i + 1; j < size; j++) {
activeEntity = (Entity)fEntityStack.elementAt(j); activeEntity = fEntityStack.elementAt(j);
path = path + " -> " + activeEntity.name; path = path + " -> " + activeEntity.name;
} }
path = path + " -> " + fCurrentEntity.name; path = path + " -> " + fCurrentEntity.name;
@ -1704,7 +1704,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
* are recognized by this component. * are recognized by this component.
*/ */
public String[] getRecognizedFeatures() { public String[] getRecognizedFeatures() {
return (String[])(RECOGNIZED_FEATURES.clone()); return RECOGNIZED_FEATURES.clone();
} // getRecognizedFeatures():String[] } // getRecognizedFeatures():String[]
/** /**
@ -1824,7 +1824,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
* are recognized by this component. * are recognized by this component.
*/ */
public String[] getRecognizedProperties() { public String[] getRecognizedProperties() {
return (String[])(RECOGNIZED_PROPERTIES.clone()); return RECOGNIZED_PROPERTIES.clone();
} // getRecognizedProperties():String[] } // getRecognizedProperties():String[]
/** /**
* Returns the default state for a feature, or null if this * Returns the default state for a feature, or null if this
@ -2952,7 +2952,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
public CharacterBuffer getBuffer(boolean external) { public CharacterBuffer getBuffer(boolean external) {
if (external) { if (external) {
if (fExternalTop > -1) { if (fExternalTop > -1) {
return (CharacterBuffer)fExternalBufferPool[fExternalTop--]; return fExternalBufferPool[fExternalTop--];
} }
else { else {
return new CharacterBuffer(true, fExternalBufferSize); return new CharacterBuffer(true, fExternalBufferSize);
@ -2960,7 +2960,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
} }
else { else {
if (fInternalTop > -1) { if (fInternalTop > -1) {
return (CharacterBuffer)fInternalBufferPool[fInternalTop--]; return fInternalBufferPool[fInternalTop--];
} }
else { else {
return new CharacterBuffer(false, fInternalBufferSize); return new CharacterBuffer(false, fInternalBufferSize);

@ -35,8 +35,6 @@ import com.sun.org.apache.xerces.internal.util.XMLResourceIdentifierImpl;
import com.sun.org.apache.xerces.internal.utils.SecuritySupport; import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -142,16 +140,8 @@ public class XMLEntityStorage {
return fEntities.get(name); return fEntities.get(name);
} // getEntity(String) } // getEntity(String)
public boolean hasEntities() { public Map<String, Entity> getEntities() {
return (fEntities!=null); return fEntities;
} // getEntity(String)
public int getEntitySize() {
return fEntities.size();
} // getEntity(String)
public Enumeration getEntityKeys() {
return Collections.enumeration(fEntities.keySet());
} }
/** /**
* Adds an internal entity declaration. * Adds an internal entity declaration.
@ -310,9 +300,9 @@ public class XMLEntityStorage {
fCurrentEntity = fEntityManager.getCurrentEntity(); fCurrentEntity = fEntityManager.getCurrentEntity();
if (!fEntities.containsKey(name)) { if (!fEntities.containsKey(name)) {
Entity entity = new Entity.ExternalEntity(name, new XMLResourceIdentifierImpl(publicId, systemId, baseSystemId, null), notation, fInExternalSubset); Entity entity = new Entity.ExternalEntity(name,
// (fCurrentEntity == null) ? fasle : fCurrentEntity.isEntityDeclInExternalSubset()); new XMLResourceIdentifierImpl(publicId, systemId, baseSystemId, null),
// fCurrentEntity.isEntityDeclInExternalSubset()); notation, fInExternalSubset);
fEntities.put(name, entity); fEntities.put(name, entity);
} }
else{ else{
@ -438,7 +428,7 @@ public class XMLEntityStorage {
userDir = userDir.replace(separator, '/'); userDir = userDir.replace(separator, '/');
int len = userDir.length(), ch; int len = userDir.length(), ch;
StringBuffer buffer = new StringBuffer(len*3); StringBuilder buffer = new StringBuilder(len*3);
// change C:/blah to /C:/blah // change C:/blah to /C:/blah
if (len >= 2 && userDir.charAt(1) == ':') { if (len >= 2 && userDir.charAt(1) == ':') {
ch = Character.toUpperCase(userDir.charAt(0)); ch = Character.toUpperCase(userDir.charAt(0));

@ -1,15 +1,16 @@
/* /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
*/ */
/* /*
* Copyright 2005 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * http://www.apache.org/licenses/LICENSE-2.0
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
@ -24,8 +25,6 @@ import com.sun.xml.internal.stream.dtd.nonvalidating.XMLAttributeDecl;
import com.sun.xml.internal.stream.dtd.nonvalidating.XMLElementDecl; import com.sun.xml.internal.stream.dtd.nonvalidating.XMLElementDecl;
import com.sun.xml.internal.stream.dtd.nonvalidating.XMLSimpleType; import com.sun.xml.internal.stream.dtd.nonvalidating.XMLSimpleType;
import com.sun.org.apache.xerces.internal.impl.Constants; import com.sun.org.apache.xerces.internal.impl.Constants;
import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
import com.sun.org.apache.xerces.internal.util.SymbolTable; import com.sun.org.apache.xerces.internal.util.SymbolTable;
import com.sun.org.apache.xerces.internal.util.XMLChar; import com.sun.org.apache.xerces.internal.util.XMLChar;
import com.sun.org.apache.xerces.internal.util.XMLSymbols; import com.sun.org.apache.xerces.internal.util.XMLSymbols;
@ -33,13 +32,10 @@ import com.sun.org.apache.xerces.internal.xni.Augmentations;
import com.sun.org.apache.xerces.internal.xni.QName; import com.sun.org.apache.xerces.internal.xni.QName;
import com.sun.org.apache.xerces.internal.xni.NamespaceContext; import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
import com.sun.org.apache.xerces.internal.xni.XMLAttributes; import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
import com.sun.org.apache.xerces.internal.xni.XMLLocator;
import com.sun.org.apache.xerces.internal.xni.XMLString; import com.sun.org.apache.xerces.internal.xni.XMLString;
import com.sun.org.apache.xerces.internal.xni.XNIException; import com.sun.org.apache.xerces.internal.xni.XNIException;
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;
import javax.xml.XMLConstants; import javax.xml.XMLConstants;
/* /*
@ -96,7 +92,7 @@ public class DTDGrammarUtil {
private QName fTempQName = new QName(); private QName fTempQName = new QName();
/** Temporary string buffers. */ /** Temporary string buffers. */
private StringBuffer fBuffer = new StringBuffer(); private StringBuilder fBuffer = new StringBuilder();
private NamespaceContext fNamespaceContext = null; private NamespaceContext fNamespaceContext = null;
@ -396,7 +392,7 @@ public class DTDGrammarUtil {
XMLSymbols.fENTITYSymbol; XMLSymbols.fENTITYSymbol;
} }
case XMLSimpleType.TYPE_ENUMERATION: { case XMLSimpleType.TYPE_ENUMERATION: {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
buffer.append('('); buffer.append('(');
for (int i = 0; i < attrDecl.simpleType.enumeration.length; i++) { for (int i = 0; i < attrDecl.simpleType.enumeration.length; i++) {
if (i > 0) { if (i > 0) {

@ -1,15 +1,16 @@
/* /*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
*/ */
/* /*
* Copyright 2005 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * http://www.apache.org/licenses/LICENSE-2.0
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
@ -34,7 +35,6 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random;
/** /**
* A DTD grammar. This class implements the XNI handler interfaces * A DTD grammar. This class implements the XNI handler interfaces
@ -95,8 +95,8 @@ public class DTDGrammar {
protected boolean fReadingExternalDTD = false; protected boolean fReadingExternalDTD = false;
/** Symbol table. */ /** Symbol table. */
private SymbolTable fSymbolTable; private final SymbolTable fSymbolTable;
private ArrayList notationDecls = new ArrayList(); private final ArrayList<XMLNotationDecl> notationDecls = new ArrayList<>();
// element declarations // element declarations
@ -334,18 +334,19 @@ public class DTDGrammar {
fSimpleType.clear(); fSimpleType.clear();
if ( defaultType != null ) { if ( defaultType != null ) {
if ( defaultType.equals( "#FIXED") ) { if ( defaultType.equals( "#FIXED") ) {
fSimpleType.defaultType = fSimpleType.DEFAULT_TYPE_FIXED; fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_FIXED;
} else if ( defaultType.equals( "#IMPLIED") ) { } else if ( defaultType.equals( "#IMPLIED") ) {
fSimpleType.defaultType = fSimpleType.DEFAULT_TYPE_IMPLIED; fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_IMPLIED;
} else if ( defaultType.equals( "#REQUIRED") ) { } else if ( defaultType.equals( "#REQUIRED") ) {
fSimpleType.defaultType = fSimpleType.DEFAULT_TYPE_REQUIRED; fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_REQUIRED;
} }
} }
if ( DEBUG ) { if ( DEBUG ) {
System.out.println("defaultvalue = " + defaultValue.toString() ); System.out.println("defaultvalue = " + defaultValue.toString() );
} }
fSimpleType.defaultValue = defaultValue!=null ? defaultValue.toString() : null; fSimpleType.defaultValue = defaultValue!=null ? defaultValue.toString() : null;
fSimpleType.nonNormalizedDefaultValue = nonNormalizedDefaultValue!=null ? nonNormalizedDefaultValue.toString() : null; fSimpleType.nonNormalizedDefaultValue = nonNormalizedDefaultValue!=null ?
nonNormalizedDefaultValue.toString() : null;
fSimpleType.enumeration = enumeration; fSimpleType.enumeration = enumeration;
if (type.equals("CDATA")) { if (type.equals("CDATA")) {
@ -731,7 +732,7 @@ public class DTDGrammar {
notationDecls.add(notationDecl); notationDecls.add(notationDecl);
} }
public List getNotationDecls(){ public List<XMLNotationDecl> getNotationDecls() {
return notationDecls; return notationDecls;
} }

@ -3,13 +3,14 @@
*/ */
/* /*
* Copyright 2005 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * http://www.apache.org/licenses/LICENSE-2.0
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,

@ -3,13 +3,14 @@
*/ */
/* /*
* Copyright 2005 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * http://www.apache.org/licenses/LICENSE-2.0
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,

@ -3,13 +3,14 @@
*/ */
/* /*
* Copyright 2005 The Apache Software Foundation. * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * http://www.apache.org/licenses/LICENSE-2.0
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,80 +25,88 @@
package com.sun.xml.internal.stream.events; package com.sun.xml.internal.stream.events;
import java.util.List;
import javax.xml.stream.events.DTD; import javax.xml.stream.events.DTD;
import javax.xml.stream.events.EntityDeclaration;
import javax.xml.stream.events.NotationDeclaration;
import javax.xml.stream.events.XMLEvent; import javax.xml.stream.events.XMLEvent;
/** /**
* *
* @author Neeraj Bajaj, Sun Microsystesm. * @author Neeraj Bajaj, Sun Microsystesm.
* *
*/ */
public class DTDEvent extends DummyEvent implements DTD{ public class DTDEvent extends DummyEvent implements DTD {
private String fDoctypeDeclaration; private String fDoctypeDeclaration;
private java.util.List fNotations; private List<NotationDeclaration> fNotations;
private java.util.List fEntities; private List<EntityDeclaration> fEntities;
/** Creates a new instance of DTDEvent */ /**
* Creates a new instance of DTDEvent
*/
public DTDEvent() { public DTDEvent() {
init(); init();
} }
public DTDEvent(String doctypeDeclaration){ public DTDEvent(String doctypeDeclaration) {
init(); init();
fDoctypeDeclaration = doctypeDeclaration; fDoctypeDeclaration = doctypeDeclaration;
} }
public void setDocumentTypeDeclaration(String doctypeDeclaration){ public void setDocumentTypeDeclaration(String doctypeDeclaration) {
fDoctypeDeclaration = doctypeDeclaration; fDoctypeDeclaration = doctypeDeclaration;
} }
@Override
public String getDocumentTypeDeclaration() { public String getDocumentTypeDeclaration() {
return fDoctypeDeclaration; return fDoctypeDeclaration;
} }
//xxx: we can change the signature if the implementation doesn't store the entities in List Datatype. //xxx: we can change the signature if the implementation doesn't store the entities in List Datatype.
//and then convert that DT to list format here. That way callee dont need to bother about conversion //and then convert that DT to list format here. That way callee dont need to bother about conversion
public void setEntities(List<EntityDeclaration> entites) {
public void setEntities(java.util.List entites){
fEntities = entites; fEntities = entites;
} }
public java.util.List getEntities() { @Override
public List<EntityDeclaration> getEntities() {
return fEntities; return fEntities;
} }
//xxx: we can change the signature if the implementation doesn't store the entities in List Datatype. //xxx: we can change the signature if the implementation doesn't store the entities in List Datatype.
//and then convert that DT to list format here. That way callee dont need to bother about conversion //and then convert that DT to list format here. That way callee dont need to bother about conversion
public void setNotations(List<NotationDeclaration> notations) {
public void setNotations(java.util.List notations){
fNotations = notations; fNotations = notations;
} }
public java.util.List getNotations() { @Override
public List<NotationDeclaration> getNotations() {
return fNotations; return fNotations;
} }
/** /**
*Returns an implementation defined representation of the DTD. * Returns an implementation defined representation of the DTD. This method
* This method may return null if no representation is available. * may return null if no representation is available.
* *
*/ */
@Override
public Object getProcessedDTD() { public Object getProcessedDTD() {
return null; return null;
} }
protected void init(){ protected final void init() {
setEventType(XMLEvent.DTD); setEventType(XMLEvent.DTD);
} }
public String toString(){ @Override
return fDoctypeDeclaration ; public String toString() {
return fDoctypeDeclaration;
} }
@Override
protected void writeAsEncodedUnicodeEx(java.io.Writer writer) protected void writeAsEncodedUnicodeEx(java.io.Writer writer)
throws java.io.IOException throws java.io.IOException {
{
writer.write(fDoctypeDeclaration); writer.write(fDoctypeDeclaration);
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,8 +22,7 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package com.sun.xml.internal.stream.events;
package com.sun.xml.internal.stream.events ;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
@ -31,35 +30,33 @@ import java.util.ArrayList;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
import javax.xml.stream.events.EndElement; import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.Namespace; import javax.xml.stream.events.Namespace;
import java.io.Writer;
import java.util.Iterator; import java.util.Iterator;
import javax.xml.stream.events.XMLEvent; import javax.xml.stream.events.XMLEvent;
import com.sun.xml.internal.stream.util.ReadOnlyIterator; import com.sun.xml.internal.stream.util.ReadOnlyIterator;
/** Implementation of EndElement event. /**
* Implementation of EndElement event.
* *
* @author Neeraj Bajaj Sun Microsystems,Inc. * @author Neeraj Bajaj Sun Microsystems,Inc.
* @author K.Venugopal Sun Microsystems,Inc. * @author K.Venugopal Sun Microsystems,Inc.
*/ */
public class EndElementEvent extends DummyEvent public class EndElementEvent extends DummyEvent
implements EndElement { implements EndElement {
List fNamespaces = null; List<Namespace> fNamespaces = null;
QName fQName ; QName fQName;
public EndElementEvent() { public EndElementEvent() {
init(); init();
} }
protected void init() { protected final void init() {
setEventType(XMLEvent.END_ELEMENT); setEventType(XMLEvent.END_ELEMENT);
fNamespaces = new ArrayList(); fNamespaces = new ArrayList<>();
} }
public EndElementEvent(String prefix, String uri, String localpart) {
public EndElementEvent(String prefix, String uri, String localpart) { this(new QName(uri, localpart, prefix));
this(new QName(uri,localpart,prefix));
} }
public EndElementEvent(QName qname) { public EndElementEvent(QName qname) {
@ -67,6 +64,7 @@ implements EndElement {
init(); init();
} }
@Override
public QName getName() { public QName getName() {
return fQName; return fQName;
} }
@ -75,34 +73,36 @@ implements EndElement {
this.fQName = qname; this.fQName = qname;
} }
@Override
protected void writeAsEncodedUnicodeEx(java.io.Writer writer) protected void writeAsEncodedUnicodeEx(java.io.Writer writer)
throws java.io.IOException throws java.io.IOException {
{
writer.write("</"); writer.write("</");
String prefix = fQName.getPrefix(); String prefix = fQName.getPrefix();
if (prefix != null && prefix.length() > 0) { if (prefix != null && prefix.length() > 0) {
writer.write(prefix); writer.write(prefix);
writer.write(':'); writer.write(':');
} }
writer.write(fQName.getLocalPart()); writer.write(fQName.getLocalPart());
writer.write('>'); writer.write('>');
} }
/** Returns an Iterator of namespaces that have gone out /**
* of scope. Returns an empty iterator if no namespaces have gone * Returns an Iterator of namespaces that have gone out of scope. Returns an
* out of scope. * empty iterator if no namespaces have gone out of scope.
* @return an Iterator over Namespace interfaces, or an *
* empty iterator * @return an Iterator over Namespace interfaces, or an empty iterator
*/ */
public Iterator getNamespaces() { @Override
if(fNamespaces != null) public Iterator<Namespace> getNamespaces() {
if (fNamespaces != null) {
fNamespaces.iterator(); fNamespaces.iterator();
return new ReadOnlyIterator(); }
return new ReadOnlyIterator<>();
} }
void addNamespace(Namespace attr){ void addNamespace(Namespace ns) {
if(attr != null){ if (ns != null) {
fNamespaces.add(attr); fNamespaces.add(ns);
} }
} }
@ -113,12 +113,15 @@ implements EndElement {
} }
public String nameAsString() { public String nameAsString() {
if("".equals(fQName.getNamespaceURI())) if ("".equals(fQName.getNamespaceURI())) {
return fQName.getLocalPart(); return fQName.getLocalPart();
if(fQName.getPrefix() != null) }
if (fQName.getPrefix() != null) {
return "['" + fQName.getNamespaceURI() + "']:" + fQName.getPrefix() + ":" + fQName.getLocalPart(); return "['" + fQName.getNamespaceURI() + "']:" + fQName.getPrefix() + ":" + fQName.getLocalPart();
else } else {
return "['" + fQName.getNamespaceURI() + "']:" + fQName.getLocalPart(); return "['" + fQName.getNamespaceURI() + "']:" + fQName.getLocalPart();
}
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,35 +23,33 @@
* questions. * questions.
*/ */
package com.sun.xml.internal.stream.events ; package com.sun.xml.internal.stream.events;
import java.util.List; import com.sun.xml.internal.stream.util.ReadOnlyIterator;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import javax.xml.namespace.QName; import java.util.Iterator;
import javax.xml.stream.events.StartElement; import java.util.List;
import javax.xml.stream.events.Attribute; import java.util.Map;
import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.NamespaceContext;
import java.io.Writer; import javax.xml.namespace.QName;
import com.sun.xml.internal.stream.util.ReadOnlyIterator;
import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.Namespace; import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.StartElement;
/** Implementation of StartElementEvent. /**
* Implementation of StartElementEvent.
* *
* @author Neeraj Bajaj Sun Microsystems,Inc. * @author Neeraj Bajaj Sun Microsystems,Inc.
* @author K.Venugopal Sun Microsystems,Inc. * @author K.Venugopal Sun Microsystems,Inc.
*/ */
public class StartElementEvent extends DummyEvent public class StartElementEvent extends DummyEvent
implements StartElement { implements StartElement {
private Map fAttributes; private Map<QName, Attribute> fAttributes;
private List fNamespaces; private List<Namespace> fNamespaces;
private NamespaceContext fNamespaceContext = null; private NamespaceContext fNamespaceContext = null;
private QName fQName; private QName fQName;
@ -70,12 +68,13 @@ implements StartElement {
addNamespaceAttributes(startelement.getNamespaces()); addNamespaceAttributes(startelement.getNamespaces());
} }
protected void init() { protected final void init() {
setEventType(XMLStreamConstants.START_ELEMENT); setEventType(XMLStreamConstants.START_ELEMENT);
fAttributes = new HashMap(); fAttributes = new HashMap<>();
fNamespaces = new ArrayList(); fNamespaces = new ArrayList<>();
} }
@Override
public QName getName() { public QName getName() {
return fQName; return fQName;
} }
@ -84,50 +83,60 @@ implements StartElement {
this.fQName = qname; this.fQName = qname;
} }
public Iterator getAttributes() { @Override
if(fAttributes != null){ public Iterator<Attribute> getAttributes() {
Collection coll = fAttributes.values(); if (fAttributes != null) {
return new ReadOnlyIterator(coll.iterator()); Collection<Attribute> coll = fAttributes.values();
return new ReadOnlyIterator<>(coll.iterator());
} }
return new ReadOnlyIterator(); return new ReadOnlyIterator<>();
} }
public Iterator getNamespaces() { @Override
if(fNamespaces != null){ public Iterator<Namespace> getNamespaces() {
return new ReadOnlyIterator(fNamespaces.iterator()); if (fNamespaces != null) {
return new ReadOnlyIterator<>(fNamespaces.iterator());
} }
return new ReadOnlyIterator(); return new ReadOnlyIterator<>();
} }
@Override
public Attribute getAttributeByName(QName qname) { public Attribute getAttributeByName(QName qname) {
if(qname == null) if (qname == null) {
return null; return null;
return (Attribute)fAttributes.get(qname); }
return fAttributes.get(qname);
} }
public String getNamespace(){ public String getNamespace() {
return fQName.getNamespaceURI(); return fQName.getNamespaceURI();
} }
@Override
public String getNamespaceURI(String prefix) { public String getNamespaceURI(String prefix) {
//check that URI was supplied when creating this startElement event and prefix matches //check that URI was supplied when creating this startElement event and prefix matches
if( getNamespace() != null && fQName.getPrefix().equals(prefix)) return getNamespace(); if (getNamespace() != null && fQName.getPrefix().equals(prefix)) {
return getNamespace();
}
//else check the namespace context //else check the namespace context
if(fNamespaceContext != null) if (fNamespaceContext != null) {
return fNamespaceContext.getNamespaceURI(prefix); return fNamespaceContext.getNamespaceURI(prefix);
}
return null; return null;
} }
/** /**
* <p>Return a <code>String</code> representation of this * <p>
* Return a <code>String</code> representation of this
* <code>StartElement</code> formatted as XML.</p> * <code>StartElement</code> formatted as XML.</p>
* *
* @return <code>String</code> representation of this * @return <code>String</code> representation of this
* <code>StartElement</code> formatted as XML. * <code>StartElement</code> formatted as XML.
*/ */
@Override
public String toString() { public String toString() {
StringBuffer startElement = new StringBuffer(); StringBuilder startElement = new StringBuilder();
// open element // open element
startElement.append("<"); startElement.append("<");
@ -135,10 +144,10 @@ implements StartElement {
// add any attributes // add any attributes
if (fAttributes != null) { if (fAttributes != null) {
Iterator it = this.getAttributes(); Iterator<Attribute> it = this.getAttributes();
Attribute attr = null; Attribute attr;
while (it.hasNext()) { while (it.hasNext()) {
attr = (Attribute) it.next(); attr = it.next();
startElement.append(" "); startElement.append(" ");
startElement.append(attr.toString()); startElement.append(attr.toString());
} }
@ -146,12 +155,12 @@ implements StartElement {
// add any namespaces // add any namespaces
if (fNamespaces != null) { if (fNamespaces != null) {
Iterator it = fNamespaces.iterator(); Iterator<Namespace> it = fNamespaces.iterator();
Namespace attr = null; Namespace ns;
while (it.hasNext()) { while (it.hasNext()) {
attr = (Namespace) it.next(); ns = it.next();
startElement.append(" "); startElement.append(" ");
startElement.append(attr.toString()); startElement.append(ns.toString());
} }
} }
@ -162,26 +171,31 @@ implements StartElement {
return startElement.toString(); return startElement.toString();
} }
/** Return this event as String /**
* Return this event as String
*
* @return String Event returned as string. * @return String Event returned as string.
*/ */
public String nameAsString() { public String nameAsString() {
if("".equals(fQName.getNamespaceURI())) if ("".equals(fQName.getNamespaceURI())) {
return fQName.getLocalPart(); return fQName.getLocalPart();
if(fQName.getPrefix() != null) }
return "['" + fQName.getNamespaceURI() + "']:" + fQName.getPrefix() + ":" + fQName.getLocalPart(); if (fQName.getPrefix() != null) {
else return "['" + fQName.getNamespaceURI() + "']:" + fQName.getPrefix()
+ ":" + fQName.getLocalPart();
} else {
return "['" + fQName.getNamespaceURI() + "']:" + fQName.getLocalPart(); return "['" + fQName.getNamespaceURI() + "']:" + fQName.getLocalPart();
}
} }
/**
/** Gets a read-only namespace context. If no context is * Gets a read-only namespace context. If no context is available this
* available this method will return an empty namespace context. * method will return an empty namespace context. The NamespaceContext
* The NamespaceContext contains information about all namespaces * contains information about all namespaces in scope for this StartElement.
* in scope for this StartElement.
* *
* @return the current namespace context * @return the current namespace context
*/ */
@Override
public NamespaceContext getNamespaceContext() { public NamespaceContext getNamespaceContext() {
return fNamespaceContext; return fNamespaceContext;
} }
@ -190,40 +204,43 @@ implements StartElement {
fNamespaceContext = nc; fNamespaceContext = nc;
} }
@Override
protected void writeAsEncodedUnicodeEx(java.io.Writer writer) protected void writeAsEncodedUnicodeEx(java.io.Writer writer)
throws java.io.IOException throws java.io.IOException {
{
writer.write(toString()); writer.write(toString());
} }
void addAttribute(Attribute attr){ void addAttribute(Attribute attr) {
if(attr.isNamespace()){ if (attr.isNamespace()) {
fNamespaces.add(attr); fNamespaces.add((Namespace) attr);
}else{ } else {
fAttributes.put(attr.getName(),attr); fAttributes.put(attr.getName(), attr);
} }
} }
void addAttributes(Iterator attrs){ final void addAttributes(Iterator<? extends Attribute> attrs) {
if(attrs == null) if (attrs == null) {
return; return;
while(attrs.hasNext()){ }
Attribute attr = (Attribute)attrs.next(); while (attrs.hasNext()) {
fAttributes.put(attr.getName(),attr); Attribute attr = attrs.next();
fAttributes.put(attr.getName(), attr);
} }
} }
void addNamespaceAttribute(Namespace attr){ void addNamespaceAttribute(Namespace attr) {
if(attr == null) if (attr == null) {
return; return;
}
fNamespaces.add(attr); fNamespaces.add(attr);
} }
void addNamespaceAttributes(Iterator attrs){ final void addNamespaceAttributes(Iterator<? extends Namespace> attrs) {
if(attrs == null) if (attrs == null) {
return; return;
while(attrs.hasNext()){ }
Namespace attr = (Namespace)attrs.next(); while (attrs.hasNext()) {
Namespace attr = attrs.next();
fNamespaces.add(attr); fNamespaces.add(attr);
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,7 +22,6 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package com.sun.xml.internal.stream.events; package com.sun.xml.internal.stream.events;
import com.sun.org.apache.xerces.internal.impl.PropertyManager; import com.sun.org.apache.xerces.internal.impl.PropertyManager;
@ -34,29 +33,36 @@ import javax.xml.XMLConstants;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
import com.sun.org.apache.xerces.internal.util.NamespaceContextWrapper; import com.sun.org.apache.xerces.internal.util.NamespaceContextWrapper;
import com.sun.org.apache.xerces.internal.util.NamespaceSupport; import com.sun.org.apache.xerces.internal.util.NamespaceSupport;
import javax.xml.stream.util.XMLEventConsumer;
/** /**
* Implementation of XMLEvent Allocator. * Implementation of XMLEvent Allocator.
*
* @author Neeraj.bajaj@sun.com, k.venugopal@sun.com * @author Neeraj.bajaj@sun.com, k.venugopal@sun.com
*/ */
public class XMLEventAllocatorImpl implements XMLEventAllocator { public class XMLEventAllocatorImpl implements XMLEventAllocator {
/** Creates a new instance of XMLEventAllocator */ /**
* Creates a new instance of XMLEventAllocator
*/
public XMLEventAllocatorImpl() { public XMLEventAllocatorImpl() {
} }
public javax.xml.stream.events.XMLEvent allocate(javax.xml.stream.XMLStreamReader xMLStreamReader) throws javax.xml.stream.XMLStreamException { public XMLEvent allocate(XMLStreamReader xMLStreamReader) throws XMLStreamException {
if(xMLStreamReader == null ) if (xMLStreamReader == null) {
throw new XMLStreamException("Reader cannot be null"); throw new XMLStreamException("Reader cannot be null");
}
// allocate is not supposed to change the state of the reader so we shouldn't be calling next. // allocate is not supposed to change the state of the reader so we shouldn't be calling next.
// return getNextEvent(xMLStreamReader); // return getNextEvent(xMLStreamReader);
return getXMLEvent(xMLStreamReader); return getXMLEvent(xMLStreamReader);
} }
public void allocate(javax.xml.stream.XMLStreamReader xMLStreamReader, javax.xml.stream.util.XMLEventConsumer xMLEventConsumer) throws javax.xml.stream.XMLStreamException { public void allocate(XMLStreamReader xMLStreamReader, XMLEventConsumer xMLEventConsumer)
throws XMLStreamException {
XMLEvent currentEvent = getXMLEvent(xMLStreamReader); XMLEvent currentEvent = getXMLEvent(xMLStreamReader);
if(currentEvent != null ) if (currentEvent != null) {
xMLEventConsumer.add(currentEvent); xMLEventConsumer.add(currentEvent);
}
return; return;
} }
@ -66,141 +72,149 @@ public class XMLEventAllocatorImpl implements XMLEventAllocator {
} }
//REVISIT: shouldn't we be using XMLEventFactory to create events. //REVISIT: shouldn't we be using XMLEventFactory to create events.
XMLEvent getXMLEvent(XMLStreamReader streamReader){ XMLEvent getXMLEvent(XMLStreamReader streamReader) {
XMLEvent event = null; XMLEvent event = null;
//returns the current event //returns the current event
int eventType = streamReader.getEventType(); int eventType = streamReader.getEventType();
switch(eventType){ switch (eventType) {
case XMLEvent.START_ELEMENT:{ case XMLEvent.START_ELEMENT: {
StartElementEvent startElementEvent = new StartElementEvent(getQName(streamReader)); StartElementEvent startElementEvent = new StartElementEvent(getQName(streamReader));
fillAttributes(startElementEvent,streamReader); fillAttributes(startElementEvent, streamReader);
//we might have different XMLStreamReader so check every time for the namespace aware property //we might have different XMLStreamReader so check every time for
//we should be setting namespace related values only when isNamespaceAware is 'true' //the namespace aware property. we should be setting namespace
if( ((Boolean)streamReader.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE)).booleanValue() ){ //related values only when isNamespaceAware is 'true'
if (((Boolean) streamReader.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE))) {
fillNamespaceAttributes(startElementEvent, streamReader); fillNamespaceAttributes(startElementEvent, streamReader);
setNamespaceContext(startElementEvent,streamReader); setNamespaceContext(startElementEvent, streamReader);
} }
startElementEvent.setLocation(streamReader.getLocation()); startElementEvent.setLocation(streamReader.getLocation());
event = startElementEvent ; event = startElementEvent;
break; break;
} }
case XMLEvent.END_ELEMENT:{ case XMLEvent.END_ELEMENT: {
EndElementEvent endElementEvent = new EndElementEvent(getQName(streamReader)); EndElementEvent endElementEvent = new EndElementEvent(getQName(streamReader));
endElementEvent.setLocation(streamReader.getLocation()); endElementEvent.setLocation(streamReader.getLocation());
if( ((Boolean)streamReader.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE)).booleanValue() ){ if (((Boolean) streamReader.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE))) {
fillNamespaceAttributes(endElementEvent,streamReader); fillNamespaceAttributes(endElementEvent, streamReader);
} }
event = endElementEvent ; event = endElementEvent;
break; break;
} }
case XMLEvent.PROCESSING_INSTRUCTION:{ case XMLEvent.PROCESSING_INSTRUCTION: {
ProcessingInstructionEvent piEvent = new ProcessingInstructionEvent(streamReader.getPITarget(),streamReader.getPIData()); ProcessingInstructionEvent piEvent = new ProcessingInstructionEvent(
streamReader.getPITarget(), streamReader.getPIData());
piEvent.setLocation(streamReader.getLocation()); piEvent.setLocation(streamReader.getLocation());
event = piEvent ; event = piEvent;
break; break;
} }
case XMLEvent.CHARACTERS:{ case XMLEvent.CHARACTERS: {
CharacterEvent cDataEvent = new CharacterEvent(streamReader.getText()); CharacterEvent cDataEvent = new CharacterEvent(streamReader.getText());
cDataEvent.setLocation(streamReader.getLocation()); cDataEvent.setLocation(streamReader.getLocation());
event = cDataEvent ; event = cDataEvent;
break; break;
} }
case XMLEvent.COMMENT:{ case XMLEvent.COMMENT: {
CommentEvent commentEvent = new CommentEvent(streamReader.getText()); CommentEvent commentEvent = new CommentEvent(streamReader.getText());
commentEvent.setLocation(streamReader.getLocation()); commentEvent.setLocation(streamReader.getLocation());
event = commentEvent ; event = commentEvent;
break; break;
} }
case XMLEvent.START_DOCUMENT:{ case XMLEvent.START_DOCUMENT: {
StartDocumentEvent sdEvent = new StartDocumentEvent(); StartDocumentEvent sdEvent = new StartDocumentEvent();
sdEvent.setVersion(streamReader.getVersion()); sdEvent.setVersion(streamReader.getVersion());
sdEvent.setEncoding(streamReader.getEncoding()); sdEvent.setEncoding(streamReader.getEncoding());
if(streamReader.getCharacterEncodingScheme() != null){ if (streamReader.getCharacterEncodingScheme() != null) {
sdEvent.setDeclaredEncoding(true); sdEvent.setDeclaredEncoding(true);
}else{ } else {
sdEvent.setDeclaredEncoding(false); sdEvent.setDeclaredEncoding(false);
} }
sdEvent.setStandalone(streamReader.isStandalone()); sdEvent.setStandalone(streamReader.isStandalone());
sdEvent.setLocation(streamReader.getLocation()); sdEvent.setLocation(streamReader.getLocation());
event = sdEvent ; event = sdEvent;
break; break;
} }
case XMLEvent.END_DOCUMENT:{ case XMLEvent.END_DOCUMENT: {
EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ; EndDocumentEvent endDocumentEvent = new EndDocumentEvent();
endDocumentEvent.setLocation(streamReader.getLocation()); endDocumentEvent.setLocation(streamReader.getLocation());
event = endDocumentEvent ; event = endDocumentEvent;
break; break;
} }
case XMLEvent.ENTITY_REFERENCE:{ case XMLEvent.ENTITY_REFERENCE: {
EntityReferenceEvent entityEvent = new EntityReferenceEvent(streamReader.getLocalName(), new EntityDeclarationImpl(streamReader.getLocalName(),streamReader.getText())); EntityReferenceEvent entityEvent = new EntityReferenceEvent(streamReader.getLocalName(),
new EntityDeclarationImpl(streamReader.getLocalName(), streamReader.getText()));
entityEvent.setLocation(streamReader.getLocation()); entityEvent.setLocation(streamReader.getLocation());
event = entityEvent; event = entityEvent;
break; break;
} }
case XMLEvent.ATTRIBUTE:{ case XMLEvent.ATTRIBUTE: {
event = null ; event = null;
break; break;
} }
case XMLEvent.DTD:{ case XMLEvent.DTD: {
DTDEvent dtdEvent = new DTDEvent(streamReader.getText()); DTDEvent dtdEvent = new DTDEvent(streamReader.getText());
dtdEvent.setLocation(streamReader.getLocation()); dtdEvent.setLocation(streamReader.getLocation());
List entities = (List)streamReader.getProperty(PropertyManager.STAX_ENTITIES); @SuppressWarnings("unchecked")
if (entities != null && entities.size() != 0) dtdEvent.setEntities(entities); List<EntityDeclaration> entities = (List<EntityDeclaration>)
List notations = (List)streamReader.getProperty(PropertyManager.STAX_NOTATIONS); streamReader.getProperty(PropertyManager.STAX_ENTITIES);
if (notations != null && notations.size() != 0) dtdEvent.setNotations(notations); if (entities != null && entities.size() != 0) {
dtdEvent.setEntities(entities);
}
@SuppressWarnings("unchecked")
List<NotationDeclaration> notations = (List<NotationDeclaration>)
streamReader.getProperty(PropertyManager.STAX_NOTATIONS);
if (notations != null && !notations.isEmpty()) {
dtdEvent.setNotations(notations);
}
event = dtdEvent; event = dtdEvent;
break; break;
} }
case XMLEvent.CDATA:{ case XMLEvent.CDATA: {
CharacterEvent cDataEvent = new CharacterEvent(streamReader.getText(),true); CharacterEvent cDataEvent = new CharacterEvent(streamReader.getText(), true);
cDataEvent.setLocation(streamReader.getLocation()); cDataEvent.setLocation(streamReader.getLocation());
event = cDataEvent ; event = cDataEvent;
break; break;
} }
case XMLEvent.SPACE:{ case XMLEvent.SPACE: {
CharacterEvent spaceEvent = new CharacterEvent(streamReader.getText(),false,true); CharacterEvent spaceEvent = new CharacterEvent(streamReader.getText(), false, true);
spaceEvent.setLocation(streamReader.getLocation()); spaceEvent.setLocation(streamReader.getLocation());
event = spaceEvent ; event = spaceEvent;
break; break;
} }
} }
return event ; return event;
} }
//this function is not used.. //this function is not used..
protected XMLEvent getNextEvent(XMLStreamReader streamReader) throws XMLStreamException{ protected XMLEvent getNextEvent(XMLStreamReader streamReader) throws XMLStreamException {
//advance the reader to next event. //advance the reader to next event.
streamReader.next(); streamReader.next();
return getXMLEvent(streamReader); return getXMLEvent(streamReader);
} }
protected void fillAttributes(StartElementEvent event,XMLStreamReader xmlr){ protected void fillAttributes(StartElementEvent event, XMLStreamReader xmlr) {
int len = xmlr.getAttributeCount(); int len = xmlr.getAttributeCount();
QName qname = null; QName qname = null;
AttributeImpl attr = null; AttributeImpl attr = null;
NamespaceImpl nattr = null; NamespaceImpl nattr = null;
for(int i=0; i<len ;i++){ for (int i = 0; i < len; i++) {
qname = xmlr.getAttributeName(i); qname = xmlr.getAttributeName(i);
//this method doesn't include namespace declarations //this method doesn't include namespace declarations
//so we can be sure that there wont be any namespace declaration as part of this function call //so we can be sure that there wont be any namespace declaration as part of this function call
//we can avoid this check - nb. //we can avoid this check - nb.
/** /**
* prefix = qname.getPrefix(); * prefix = qname.getPrefix(); localpart = qname.getLocalPart(); if
* localpart = qname.getLocalPart(); * (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE) ) { attr = new
* if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE) ) { * NamespaceImpl(localpart,xmlr.getAttributeValue(i)); }else if
* attr = new NamespaceImpl(localpart,xmlr.getAttributeValue(i)); * (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)){ attr = new
* }else if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)){ * NamespaceImpl(xmlr.getAttributeValue(i)); }else{ attr = new
* attr = new NamespaceImpl(xmlr.getAttributeValue(i)); * AttributeImpl(); attr.setName(qname); }
* }else{ *
* attr = new AttributeImpl(); */
* attr.setName(qname);
* }
**/
attr = new AttributeImpl(); attr = new AttributeImpl();
attr.setName(qname); attr.setName(qname);
attr.setAttributeType(xmlr.getAttributeType(i)); attr.setAttributeType(xmlr.getAttributeType(i));
@ -210,42 +224,42 @@ public class XMLEventAllocatorImpl implements XMLEventAllocator {
} }
} }
protected void fillNamespaceAttributes(StartElementEvent event,XMLStreamReader xmlr){ protected void fillNamespaceAttributes(StartElementEvent event, XMLStreamReader xmlr) {
int count = xmlr.getNamespaceCount(); int count = xmlr.getNamespaceCount();
String uri = null; String uri = null;
String prefix = null; String prefix = null;
NamespaceImpl attr = null; NamespaceImpl attr = null;
for(int i=0;i< count;i++){ for (int i = 0; i < count; i++) {
uri = xmlr.getNamespaceURI(i); uri = xmlr.getNamespaceURI(i);
prefix = xmlr.getNamespacePrefix(i); prefix = xmlr.getNamespacePrefix(i);
if(prefix == null){ if (prefix == null) {
prefix = XMLConstants.DEFAULT_NS_PREFIX; prefix = XMLConstants.DEFAULT_NS_PREFIX;
} }
attr = new NamespaceImpl(prefix,uri); attr = new NamespaceImpl(prefix, uri);
event.addNamespaceAttribute(attr); event.addNamespaceAttribute(attr);
} }
} }
protected void fillNamespaceAttributes(EndElementEvent event,XMLStreamReader xmlr){ protected void fillNamespaceAttributes(EndElementEvent event, XMLStreamReader xmlr) {
int count = xmlr.getNamespaceCount(); int count = xmlr.getNamespaceCount();
String uri = null; String uri = null;
String prefix = null; String prefix = null;
NamespaceImpl attr = null; NamespaceImpl attr = null;
for(int i=0;i< count;i++){ for (int i = 0; i < count; i++) {
uri = xmlr.getNamespaceURI(i); uri = xmlr.getNamespaceURI(i);
prefix = xmlr.getNamespacePrefix(i); prefix = xmlr.getNamespacePrefix(i);
if(prefix == null){ if (prefix == null) {
prefix = XMLConstants.DEFAULT_NS_PREFIX; prefix = XMLConstants.DEFAULT_NS_PREFIX;
} }
attr = new NamespaceImpl(prefix,uri); attr = new NamespaceImpl(prefix, uri);
event.addNamespace(attr); event.addNamespace(attr);
} }
} }
//Revisit : Creating a new Namespacecontext for now. //Revisit : Creating a new Namespacecontext for now.
//see if we can do better job. //see if we can do better job.
private void setNamespaceContext(StartElementEvent event , XMLStreamReader xmlr){ private void setNamespaceContext(StartElementEvent event, XMLStreamReader xmlr) {
NamespaceContextWrapper contextWrapper =(NamespaceContextWrapper) xmlr.getNamespaceContext(); NamespaceContextWrapper contextWrapper = (NamespaceContextWrapper) xmlr.getNamespaceContext();
NamespaceSupport ns = new NamespaceSupport(contextWrapper.getNamespaceContext()); NamespaceSupport ns = new NamespaceSupport(contextWrapper.getNamespaceContext());
event.setNamespaceContext(new NamespaceContextWrapper(ns)); event.setNamespaceContext(new NamespaceContextWrapper(ns));
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,10 +25,19 @@
package com.sun.xml.internal.stream.events; package com.sun.xml.internal.stream.events;
import java.util.Iterator;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventFactory; import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.Location; import javax.xml.stream.Location;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.Characters;
import javax.xml.stream.events.ProcessingInstruction;
import javax.xml.stream.events.Namespace; import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.EntityDeclaration; import javax.xml.stream.events.EntityDeclaration;
import javax.xml.stream.events.EntityReference;
import javax.xml.stream.events.StartDocument;
import javax.xml.stream.events.StartElement;
/** /**
@ -42,23 +51,27 @@ public class XMLEventFactoryImpl extends XMLEventFactory {
public XMLEventFactoryImpl() { public XMLEventFactoryImpl() {
} }
public javax.xml.stream.events.Attribute createAttribute(String localName, String value) { @Override
public Attribute createAttribute(String localName, String value) {
AttributeImpl attr = new AttributeImpl(localName, value); AttributeImpl attr = new AttributeImpl(localName, value);
if(location != null)attr.setLocation(location); if(location != null)attr.setLocation(location);
return attr; return attr;
} }
public javax.xml.stream.events.Attribute createAttribute(javax.xml.namespace.QName name, String value) { @Override
public Attribute createAttribute(QName name, String value) {
return createAttribute(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), value); return createAttribute(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), value);
} }
public javax.xml.stream.events.Attribute createAttribute(String prefix, String namespaceURI, String localName, String value) { @Override
public Attribute createAttribute(String prefix, String namespaceURI, String localName, String value) {
AttributeImpl attr = new AttributeImpl(prefix, namespaceURI, localName, value, null); AttributeImpl attr = new AttributeImpl(prefix, namespaceURI, localName, value, null);
if(location != null)attr.setLocation(location); if(location != null)attr.setLocation(location);
return attr; return attr;
} }
public javax.xml.stream.events.Characters createCData(String content) { @Override
public Characters createCData(String content) {
//stax doesn't have separate CDATA event. This is taken care by //stax doesn't have separate CDATA event. This is taken care by
//CHRACTERS event setting the cdata flag to true. //CHRACTERS event setting the cdata flag to true.
CharacterEvent charEvent = new CharacterEvent(content, true); CharacterEvent charEvent = new CharacterEvent(content, true);
@ -66,126 +79,156 @@ public class XMLEventFactoryImpl extends XMLEventFactory {
return charEvent; return charEvent;
} }
public javax.xml.stream.events.Characters createCharacters(String content) { @Override
public Characters createCharacters(String content) {
CharacterEvent charEvent = new CharacterEvent(content); CharacterEvent charEvent = new CharacterEvent(content);
if(location != null)charEvent.setLocation(location); if(location != null)charEvent.setLocation(location);
return charEvent; return charEvent;
} }
@Override
public javax.xml.stream.events.Comment createComment(String text) { public javax.xml.stream.events.Comment createComment(String text) {
CommentEvent charEvent = new CommentEvent(text); CommentEvent charEvent = new CommentEvent(text);
if(location != null)charEvent.setLocation(location); if(location != null)charEvent.setLocation(location);
return charEvent; return charEvent;
} }
@Override
public javax.xml.stream.events.DTD createDTD(String dtd) { public javax.xml.stream.events.DTD createDTD(String dtd) {
DTDEvent dtdEvent = new DTDEvent(dtd); DTDEvent dtdEvent = new DTDEvent(dtd);
if(location != null)dtdEvent.setLocation(location); if(location != null)dtdEvent.setLocation(location);
return dtdEvent; return dtdEvent;
} }
@Override
public javax.xml.stream.events.EndDocument createEndDocument() { public javax.xml.stream.events.EndDocument createEndDocument() {
EndDocumentEvent event =new EndDocumentEvent(); EndDocumentEvent event =new EndDocumentEvent();
if(location != null)event.setLocation(location); if(location != null)event.setLocation(location);
return event; return event;
} }
public javax.xml.stream.events.EndElement createEndElement(javax.xml.namespace.QName name, java.util.Iterator namespaces) { @Override
public javax.xml.stream.events.EndElement createEndElement(QName name,
Iterator<? extends Namespace> namespaces) {
return createEndElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart()); return createEndElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart());
} }
public javax.xml.stream.events.EndElement createEndElement(String prefix, String namespaceUri, String localName) { @Override
public javax.xml.stream.events.EndElement createEndElement(
String prefix, String namespaceUri, String localName) {
EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName); EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName);
if(location != null)event.setLocation(location); if(location != null)event.setLocation(location);
return event; return event;
} }
public javax.xml.stream.events.EndElement createEndElement(String prefix, String namespaceUri, String localName, java.util.Iterator namespaces) { @Override
public javax.xml.stream.events.EndElement createEndElement(String prefix, String namespaceUri,
String localName, Iterator<? extends Namespace> namespaces) {
EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName); EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName);
if(namespaces!=null){ if(namespaces!=null){
while(namespaces.hasNext()) while(namespaces.hasNext())
event.addNamespace((Namespace)namespaces.next()); event.addNamespace(namespaces.next());
} }
if(location != null)event.setLocation(location); if(location != null)event.setLocation(location);
return event; return event;
} }
public javax.xml.stream.events.EntityReference createEntityReference(String name, EntityDeclaration entityDeclaration) { @Override
public EntityReference createEntityReference(String name, EntityDeclaration entityDeclaration) {
EntityReferenceEvent event = new EntityReferenceEvent(name, entityDeclaration); EntityReferenceEvent event = new EntityReferenceEvent(name, entityDeclaration);
if(location != null)event.setLocation(location); if(location != null)event.setLocation(location);
return event; return event;
} }
public javax.xml.stream.events.Characters createIgnorableSpace(String content) { @Override
public Characters createIgnorableSpace(String content) {
CharacterEvent event = new CharacterEvent(content, false, true); CharacterEvent event = new CharacterEvent(content, false, true);
if(location != null)event.setLocation(location); if(location != null)event.setLocation(location);
return event; return event;
} }
public javax.xml.stream.events.Namespace createNamespace(String namespaceURI) { @Override
public Namespace createNamespace(String namespaceURI) {
NamespaceImpl event = new NamespaceImpl(namespaceURI); NamespaceImpl event = new NamespaceImpl(namespaceURI);
if(location != null)event.setLocation(location); if(location != null)event.setLocation(location);
return event; return event;
} }
public javax.xml.stream.events.Namespace createNamespace(String prefix, String namespaceURI) { @Override
public Namespace createNamespace(String prefix, String namespaceURI) {
NamespaceImpl event = new NamespaceImpl(prefix, namespaceURI); NamespaceImpl event = new NamespaceImpl(prefix, namespaceURI);
if(location != null)event.setLocation(location); if(location != null)event.setLocation(location);
return event; return event;
} }
public javax.xml.stream.events.ProcessingInstruction createProcessingInstruction(String target, String data) { @Override
public ProcessingInstruction createProcessingInstruction(String target, String data) {
ProcessingInstructionEvent event = new ProcessingInstructionEvent(target, data); ProcessingInstructionEvent event = new ProcessingInstructionEvent(target, data);
if(location != null)event.setLocation(location); if(location != null)event.setLocation(location);
return event; return event;
} }
public javax.xml.stream.events.Characters createSpace(String content) { @Override
public Characters createSpace(String content) {
CharacterEvent event = new CharacterEvent(content); CharacterEvent event = new CharacterEvent(content);
if(location != null)event.setLocation(location); if(location != null)event.setLocation(location);
return event; return event;
} }
public javax.xml.stream.events.StartDocument createStartDocument() { @Override
public StartDocument createStartDocument() {
StartDocumentEvent event = new StartDocumentEvent(); StartDocumentEvent event = new StartDocumentEvent();
if(location != null)event.setLocation(location); if(location != null)event.setLocation(location);
return event; return event;
} }
public javax.xml.stream.events.StartDocument createStartDocument(String encoding) { @Override
public StartDocument createStartDocument(String encoding) {
StartDocumentEvent event = new StartDocumentEvent(encoding); StartDocumentEvent event = new StartDocumentEvent(encoding);
if(location != null)event.setLocation(location); if(location != null)event.setLocation(location);
return event; return event;
} }
public javax.xml.stream.events.StartDocument createStartDocument(String encoding, String version) { @Override
public StartDocument createStartDocument(String encoding, String version) {
StartDocumentEvent event = new StartDocumentEvent(encoding, version); StartDocumentEvent event = new StartDocumentEvent(encoding, version);
if(location != null)event.setLocation(location); if(location != null)event.setLocation(location);
return event; return event;
} }
public javax.xml.stream.events.StartDocument createStartDocument(String encoding, String version, boolean standalone) { @Override
public StartDocument createStartDocument(String encoding, String version, boolean standalone) {
StartDocumentEvent event = new StartDocumentEvent(encoding, version, standalone); StartDocumentEvent event = new StartDocumentEvent(encoding, version, standalone);
if(location != null)event.setLocation(location); if(location != null)event.setLocation(location);
return event; return event;
} }
public javax.xml.stream.events.StartElement createStartElement(javax.xml.namespace.QName name, java.util.Iterator attributes, java.util.Iterator namespaces) { @Override
return createStartElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), attributes, namespaces); public StartElement createStartElement(QName name, Iterator<? extends Attribute> attributes,
Iterator<? extends Namespace> namespaces) {
return createStartElement(name.getPrefix(), name.getNamespaceURI(),
name.getLocalPart(), attributes, namespaces);
} }
public javax.xml.stream.events.StartElement createStartElement(String prefix, String namespaceUri, String localName) { @Override
public StartElement createStartElement(String prefix, String namespaceUri, String localName) {
StartElementEvent event = new StartElementEvent(prefix, namespaceUri, localName); StartElementEvent event = new StartElementEvent(prefix, namespaceUri, localName);
if(location != null)event.setLocation(location); if(location != null)event.setLocation(location);
return event; return event;
} }
public javax.xml.stream.events.StartElement createStartElement(String prefix, String namespaceUri, String localName, java.util.Iterator attributes, java.util.Iterator namespaces) { @Override
public StartElement createStartElement(String prefix, String namespaceUri,
String localName, Iterator<? extends Attribute> attributes,
Iterator<? extends Namespace> namespaces) {
return createStartElement(prefix, namespaceUri, localName, attributes, namespaces, null); return createStartElement(prefix, namespaceUri, localName, attributes, namespaces, null);
} }
public javax.xml.stream.events.StartElement createStartElement(String prefix, String namespaceUri, String localName, java.util.Iterator attributes, java.util.Iterator namespaces, javax.xml.namespace.NamespaceContext context) { @Override
public StartElement createStartElement(String prefix, String namespaceUri,
String localName, Iterator<? extends Attribute> attributes,
Iterator<? extends Namespace> namespaces, NamespaceContext context) {
StartElementEvent elem = new StartElementEvent(prefix, namespaceUri, localName); StartElementEvent elem = new StartElementEvent(prefix, namespaceUri, localName);
elem.addAttributes(attributes); elem.addAttributes(attributes);
elem.addNamespaceAttributes(namespaces); elem.addNamespaceAttributes(namespaces);
@ -194,6 +237,7 @@ public class XMLEventFactoryImpl extends XMLEventFactory {
return elem; return elem;
} }
@Override
public void setLocation(javax.xml.stream.Location location) { public void setLocation(javax.xml.stream.Location location) {
this.location = location; this.location = location;
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -31,35 +31,32 @@ package com.sun.xml.internal.stream.util;
import java.util.Iterator; import java.util.Iterator;
public class ReadOnlyIterator implements Iterator { public class ReadOnlyIterator<T> implements Iterator<T> {
Iterator iterator = null; Iterator<T> iterator = null;
public ReadOnlyIterator(){ public ReadOnlyIterator(){
} }
public ReadOnlyIterator(Iterator itr){ public ReadOnlyIterator(Iterator<T> itr){
iterator = itr; iterator = itr;
} }
/** @Override
* @return
*/
public boolean hasNext() { public boolean hasNext() {
if(iterator != null) if(iterator != null)
return iterator.hasNext(); return iterator.hasNext();
return false; return false;
} }
/** @Override
* @return public T next() {
*/
public Object next() {
if(iterator != null) if(iterator != null)
return iterator.next(); return iterator.next();
return null; return null;
} }
@Override
public void remove() { public void remove() {
throw new UnsupportedOperationException("Remove operation is not supported"); throw new UnsupportedOperationException("Remove operation is not supported");
} }

@ -39,15 +39,15 @@ import java.lang.ref.*;
* @author Santiago.PericasGeertsen@sun.com * @author Santiago.PericasGeertsen@sun.com
*/ */
public class ThreadLocalBufferAllocator { public class ThreadLocalBufferAllocator {
private static ThreadLocal tlba = new ThreadLocal(); private static ThreadLocal<SoftReference> tlba = new ThreadLocal<>();
public static BufferAllocator getBufferAllocator() { public static BufferAllocator getBufferAllocator() {
SoftReference bAllocatorRef = (SoftReference) tlba.get(); SoftReference<BufferAllocator> bAllocatorRef = tlba.get();
if (bAllocatorRef == null || bAllocatorRef.get() == null) { if (bAllocatorRef == null || bAllocatorRef.get() == null) {
bAllocatorRef = new SoftReference(new BufferAllocator()); bAllocatorRef = new SoftReference(new BufferAllocator());
tlba.set(bAllocatorRef); tlba.set(bAllocatorRef);
} }
return (BufferAllocator) bAllocatorRef.get(); return bAllocatorRef.get();
} }
} }

@ -89,7 +89,7 @@ public final class UTF8OutputStreamWriter extends Writer {
// Otherwise, encode char as defined in UTF-8 // Otherwise, encode char as defined in UTF-8
if (c < 0x80) { if (c < 0x80) {
// 1 byte, 7 bits // 1 byte, 7 bits
out.write((int) c); out.write(c);
} }
else if (c < 0x800) { else if (c < 0x800) {
// 2 bytes, 11 bits // 2 bytes, 11 bits

@ -26,9 +26,12 @@
package com.sun.xml.internal.stream.writers; package com.sun.xml.internal.stream.writers;
import java.util.Iterator; import java.util.Iterator;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter; import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.events.Attribute; import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.Characters; import javax.xml.stream.events.Characters;
import javax.xml.stream.events.Comment; import javax.xml.stream.events.Comment;
@ -39,24 +42,24 @@ import javax.xml.stream.events.ProcessingInstruction;
import javax.xml.stream.events.StartDocument; import javax.xml.stream.events.StartDocument;
import javax.xml.stream.events.StartElement; import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent; import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.XMLStreamWriter;
/** /**
* *
* @author Neeraj Bajaj, Sun Microsystems. * @author Neeraj Bajaj, Sun Microsystems.
* *
*/ */
public class XMLEventWriterImpl implements XMLEventWriter{ public class XMLEventWriterImpl implements XMLEventWriter {
//delegate everything to XMLStreamWriter.. //delegate everything to XMLStreamWriter..
private final XMLStreamWriterBase fStreamWriter ; private final XMLStreamWriterBase fStreamWriter;
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
/** /**
* *
* @param streamWriter * @param streamWriter
*/ */
public XMLEventWriterImpl(XMLStreamWriter streamWriter){ public XMLEventWriterImpl(XMLStreamWriter streamWriter) {
fStreamWriter = (XMLStreamWriterBase)streamWriter; fStreamWriter = (XMLStreamWriterBase) streamWriter;
} }
/** /**
@ -64,9 +67,11 @@ public class XMLEventWriterImpl implements XMLEventWriter{
* @param xMLEventReader * @param xMLEventReader
* @throws XMLStreamException * @throws XMLStreamException
*/ */
public void add(javax.xml.stream.XMLEventReader xMLEventReader) throws javax.xml.stream.XMLStreamException { public void add(XMLEventReader xMLEventReader) throws XMLStreamException {
if(xMLEventReader == null) throw new XMLStreamException("Event reader shouldn't be null"); if (xMLEventReader == null) {
while(xMLEventReader.hasNext()){ throw new XMLStreamException("Event reader shouldn't be null");
}
while (xMLEventReader.hasNext()) {
add(xMLEventReader.nextEvent()); add(xMLEventReader.nextEvent());
} }
} }
@ -76,101 +81,127 @@ public class XMLEventWriterImpl implements XMLEventWriter{
* @param xMLEvent * @param xMLEvent
* @throws XMLStreamException * @throws XMLStreamException
*/ */
public void add(javax.xml.stream.events.XMLEvent xMLEvent) throws javax.xml.stream.XMLStreamException { public void add(XMLEvent xMLEvent) throws XMLStreamException {
int type = xMLEvent.getEventType(); int type = xMLEvent.getEventType();
switch(type){ switch (type) {
case XMLEvent.DTD:{ case XMLEvent.DTD: {
DTD dtd = (DTD)xMLEvent ; DTD dtd = (DTD) xMLEvent;
if (DEBUG)System.out.println("Adding DTD = " + dtd.toString()); if (DEBUG) {
System.out.println("Adding DTD = " + dtd.toString());
}
fStreamWriter.writeDTD(dtd.getDocumentTypeDeclaration()); fStreamWriter.writeDTD(dtd.getDocumentTypeDeclaration());
break; break;
} }
case XMLEvent.START_DOCUMENT :{ case XMLEvent.START_DOCUMENT: {
StartDocument startDocument = (StartDocument)xMLEvent ; StartDocument startDocument = (StartDocument) xMLEvent;
if (DEBUG)System.out.println("Adding StartDocument = " + startDocument.toString()); if (DEBUG) {
System.out.println("Adding StartDocument = " + startDocument.toString());
}
try { try {
fStreamWriter.writeStartDocument(startDocument.getCharacterEncodingScheme(), startDocument.getVersion(), fStreamWriter.writeStartDocument(startDocument.getCharacterEncodingScheme(),
startDocument.isStandalone(), startDocument.standaloneSet()); startDocument.getVersion(),
}catch(XMLStreamException e) { startDocument.isStandalone(), startDocument.standaloneSet());
} catch (XMLStreamException e) {
fStreamWriter.writeStartDocument(startDocument.getVersion()); fStreamWriter.writeStartDocument(startDocument.getVersion());
} }
break; break;
} }
case XMLEvent.START_ELEMENT :{ case XMLEvent.START_ELEMENT: {
StartElement startElement = xMLEvent.asStartElement() ; StartElement startElement = xMLEvent.asStartElement();
if (DEBUG)System.out.println("Adding startelement = " + startElement.toString()); if (DEBUG) {
System.out.println("Adding startelement = " + startElement.toString());
}
QName qname = startElement.getName(); QName qname = startElement.getName();
fStreamWriter.writeStartElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI()); fStreamWriter.writeStartElement(qname.getPrefix(), qname.getLocalPart(),
qname.getNamespaceURI());
//getNamespaces() Returns an Iterator of namespaces declared on this element. This Iterator does not contain /*
//previously declared namespaces unless they appear on the current START_ELEMENT. Therefore getNamespaces() Returns an Iterator of namespaces declared on this element.
//this list may contain redeclared namespaces and duplicate namespace declarations. Use the This Iterator does not contain previously declared namespaces unless they
//getNamespaceContext() method to get the current context of namespace declarations. appear on the current START_ELEMENT. Therefore this list may contain redeclared
namespaces and duplicate namespace declarations. Use the getNamespaceContext()
//so we should be using getNamespaces() to write namespace declarations for this START_ELEMENT method to get the current context of namespace declarations. We should be
Iterator iterator = startElement.getNamespaces(); using getNamespaces() to write namespace declarations for this START_ELEMENT
while(iterator.hasNext()){ */
Namespace namespace = (Namespace)iterator.next(); Iterator<? extends Namespace> iterator = startElement.getNamespaces();
while (iterator.hasNext()) {
Namespace namespace = iterator.next();
fStreamWriter.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI()); fStreamWriter.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
} }
//REVISIT: What about writing attributes ? //REVISIT: What about writing attributes ?
Iterator attributes = startElement.getAttributes(); Iterator<? extends Attribute> attributes = startElement.getAttributes();
while(attributes.hasNext()){ while (attributes.hasNext()) {
Attribute attribute = (Attribute)attributes.next(); Attribute attribute = attributes.next();
QName aqname = attribute.getName(); QName aqname = attribute.getName();
fStreamWriter.writeAttribute(aqname.getPrefix(), aqname.getNamespaceURI(), aqname.getLocalPart(),attribute.getValue()); fStreamWriter.writeAttribute(aqname.getPrefix(), aqname.getNamespaceURI(),
aqname.getLocalPart(), attribute.getValue());
} }
break; break;
} }
case XMLEvent.NAMESPACE:{ case XMLEvent.NAMESPACE: {
Namespace namespace = (Namespace)xMLEvent; Namespace namespace = (Namespace) xMLEvent;
if (DEBUG)System.out.println("Adding namespace = " + namespace.toString()); if (DEBUG) {
System.out.println("Adding namespace = " + namespace.toString());
}
fStreamWriter.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI()); fStreamWriter.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
break ; break;
} }
case XMLEvent.COMMENT: { case XMLEvent.COMMENT: {
Comment comment = (Comment)xMLEvent ; Comment comment = (Comment) xMLEvent;
if (DEBUG)System.out.println("Adding comment = " + comment.toString()); if (DEBUG) {
System.out.println("Adding comment = " + comment.toString());
}
fStreamWriter.writeComment(comment.getText()); fStreamWriter.writeComment(comment.getText());
break; break;
} }
case XMLEvent.PROCESSING_INSTRUCTION:{ case XMLEvent.PROCESSING_INSTRUCTION: {
ProcessingInstruction processingInstruction = (ProcessingInstruction)xMLEvent ; ProcessingInstruction processingInstruction = (ProcessingInstruction) xMLEvent;
if (DEBUG)System.out.println("Adding processing instruction = " + processingInstruction.toString()); if (DEBUG) {
fStreamWriter.writeProcessingInstruction(processingInstruction.getTarget(), processingInstruction.getData()); System.out.println("Adding processing instruction = " + processingInstruction.toString());
}
fStreamWriter.writeProcessingInstruction(processingInstruction.getTarget(),
processingInstruction.getData());
break; break;
} }
case XMLEvent.CHARACTERS:{ case XMLEvent.CHARACTERS: {
Characters characters = xMLEvent.asCharacters(); Characters characters = xMLEvent.asCharacters();
if (DEBUG)System.out.println("Adding characters = " + characters.toString()); if (DEBUG) {
//check if the CHARACTERS are CDATA System.out.println("Adding characters = " + characters.toString());
if(characters.isCData()){
fStreamWriter.writeCData(characters.getData());
} }
else{ //check if the CHARACTERS are CDATA
if (characters.isCData()) {
fStreamWriter.writeCData(characters.getData());
} else {
fStreamWriter.writeCharacters(characters.getData()); fStreamWriter.writeCharacters(characters.getData());
} }
break; break;
} }
case XMLEvent.ENTITY_REFERENCE:{ case XMLEvent.ENTITY_REFERENCE: {
EntityReference entityReference = (EntityReference)xMLEvent ; EntityReference entityReference = (EntityReference) xMLEvent;
if (DEBUG)System.out.println("Adding Entity Reference = "+ entityReference.toString()); if (DEBUG) {
System.out.println("Adding Entity Reference = " + entityReference.toString());
}
fStreamWriter.writeEntityRef(entityReference.getName()); fStreamWriter.writeEntityRef(entityReference.getName());
break; break;
} }
case XMLEvent.ATTRIBUTE:{ case XMLEvent.ATTRIBUTE: {
Attribute attribute = (Attribute)xMLEvent; Attribute attribute = (Attribute) xMLEvent;
if (DEBUG)System.out.println("Adding Attribute = " + attribute.toString()); if (DEBUG) {
System.out.println("Adding Attribute = " + attribute.toString());
}
QName qname = attribute.getName(); QName qname = attribute.getName();
fStreamWriter.writeAttribute(qname.getPrefix(), qname.getNamespaceURI(), qname.getLocalPart(),attribute.getValue()); fStreamWriter.writeAttribute(qname.getPrefix(), qname.getNamespaceURI(),
qname.getLocalPart(), attribute.getValue());
break; break;
} }
case XMLEvent.CDATA:{ case XMLEvent.CDATA: {
//there is no separate CDATA datatype but CDATA event can be reported //there is no separate CDATA datatype but CDATA event can be reported
//by using vendor specific CDATA property. //by using vendor specific CDATA property.
Characters characters = (Characters)xMLEvent; Characters characters = (Characters) xMLEvent;
if (DEBUG)System.out.println("Adding characters = " + characters.toString()); if (DEBUG) {
if(characters.isCData()){ System.out.println("Adding characters = " + characters.toString());
}
if (characters.isCData()) {
fStreamWriter.writeCData(characters.getData()); fStreamWriter.writeCData(characters.getData());
} }
break; break;
@ -179,15 +210,11 @@ public class XMLEventWriterImpl implements XMLEventWriter{
//case XMLEvent.NOTATION_DECLARATION:{ //case XMLEvent.NOTATION_DECLARATION:{
//} //}
case XMLEvent.END_ELEMENT:{ case XMLEvent.END_ELEMENT: {
//we dont need to typecast it.. just call writeEndElement() and fStreamWriter will take care of it.
//EndElement endElement = (EndElement)xMLEvent;
fStreamWriter.writeEndElement(); fStreamWriter.writeEndElement();
break; break;
} }
case XMLEvent.END_DOCUMENT:{ case XMLEvent.END_DOCUMENT: {
//we dont need to typecast just call writeEndDocument() and fStreamWriter will take care rest.
//EndDocument endDocument = (EndDocument)xMLEvent;
fStreamWriter.writeEndDocument(); fStreamWriter.writeEndDocument();
break; break;
} }
@ -200,16 +227,16 @@ public class XMLEventWriterImpl implements XMLEventWriter{
* *
* @throws XMLStreamException * @throws XMLStreamException
*/ */
public void close() throws javax.xml.stream.XMLStreamException { public void close() throws XMLStreamException {
fStreamWriter.close(); fStreamWriter.close();
} }
/** /**
* *
* @throws XMLStreamException will inturn call flush on the stream to which data is being * @throws XMLStreamException will inturn call flush on the stream to which
* written. * data is being written.
*/ */
public void flush() throws javax.xml.stream.XMLStreamException { public void flush() throws XMLStreamException {
fStreamWriter.flush(); fStreamWriter.flush();
} }
@ -217,7 +244,7 @@ public class XMLEventWriterImpl implements XMLEventWriter{
* *
* @return * @return
*/ */
public javax.xml.namespace.NamespaceContext getNamespaceContext() { public NamespaceContext getNamespaceContext() {
return fStreamWriter.getNamespaceContext(); return fStreamWriter.getNamespaceContext();
} }
@ -227,7 +254,7 @@ public class XMLEventWriterImpl implements XMLEventWriter{
* @throws XMLStreamException * @throws XMLStreamException
* @return prefix associated with the URI. * @return prefix associated with the URI.
*/ */
public String getPrefix(String namespaceURI) throws javax.xml.stream.XMLStreamException { public String getPrefix(String namespaceURI) throws XMLStreamException {
return fStreamWriter.getPrefix(namespaceURI); return fStreamWriter.getPrefix(namespaceURI);
} }
@ -236,7 +263,7 @@ public class XMLEventWriterImpl implements XMLEventWriter{
* @param uri Namespace URI * @param uri Namespace URI
* @throws XMLStreamException * @throws XMLStreamException
*/ */
public void setDefaultNamespace(String uri) throws javax.xml.stream.XMLStreamException { public void setDefaultNamespace(String uri) throws XMLStreamException {
fStreamWriter.setDefaultNamespace(uri); fStreamWriter.setDefaultNamespace(uri);
} }
@ -245,7 +272,8 @@ public class XMLEventWriterImpl implements XMLEventWriter{
* @param namespaceContext Namespace Context * @param namespaceContext Namespace Context
* @throws XMLStreamException * @throws XMLStreamException
*/ */
public void setNamespaceContext(javax.xml.namespace.NamespaceContext namespaceContext) throws javax.xml.stream.XMLStreamException { public void setNamespaceContext(NamespaceContext namespaceContext)
throws XMLStreamException {
fStreamWriter.setNamespaceContext(namespaceContext); fStreamWriter.setNamespaceContext(namespaceContext);
} }
@ -255,7 +283,7 @@ public class XMLEventWriterImpl implements XMLEventWriter{
* @param uri Namespace URI * @param uri Namespace URI
* @throws XMLStreamException * @throws XMLStreamException
*/ */
public void setPrefix(String prefix, String uri) throws javax.xml.stream.XMLStreamException { public void setPrefix(String prefix, String uri) throws XMLStreamException {
fStreamWriter.setPrefix(prefix, uri); fStreamWriter.setPrefix(prefix, uri);
} }

@ -35,7 +35,6 @@ import java.nio.charset.CharsetEncoder;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Random; import java.util.Random;
import java.util.Vector; import java.util.Vector;
import java.util.Set; import java.util.Set;
@ -46,7 +45,6 @@ import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import com.sun.org.apache.xerces.internal.impl.Constants; import com.sun.org.apache.xerces.internal.impl.Constants;
@ -71,7 +69,8 @@ import com.sun.xml.internal.stream.util.ReadOnlyIterator;
* @author Santiago.Pericas-Geertsen@sun.com * @author Santiago.Pericas-Geertsen@sun.com
* @author Sunitha.Reddy@sun.com * @author Sunitha.Reddy@sun.com
*/ */
public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamWriterBase { public final class XMLStreamWriterImpl extends AbstractMap<Object, Object>
implements XMLStreamWriterBase {
public static final String START_COMMENT = "<!--"; public static final String START_COMMENT = "<!--";
public static final String END_COMMENT = "-->"; public static final String END_COMMENT = "-->";
@ -115,12 +114,12 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
/** /**
* Collects attributes when the writer is in reparing mode. * Collects attributes when the writer is in reparing mode.
*/ */
private ArrayList fAttributeCache; private ArrayList<Attribute> fAttributeCache;
/** /**
* Collects namespace declarations when the writer is in reparing mode. * Collects namespace declarations when the writer is in reparing mode.
*/ */
private ArrayList fNamespaceDecls; private ArrayList<QName> fNamespaceDecls;
/** /**
* Namespace context encapsulating user specified context * Namespace context encapsulating user specified context
@ -153,7 +152,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
final private String DEFAULT_PREFIX = fSymbolTable.addSymbol(""); final private String DEFAULT_PREFIX = fSymbolTable.addSymbol("");
private final ReadOnlyIterator fReadOnlyIterator = new ReadOnlyIterator(); private final ReadOnlyIterator<String> fReadOnlyIterator = new ReadOnlyIterator<>();
/** /**
* In some cases, this charset encoder is used to determine if a char is * In some cases, this charset encoder is used to determine if a char is
@ -168,7 +167,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* the same uri as the default namespace; It's added to avoid changing the * the same uri as the default namespace; It's added to avoid changing the
* current impl. which has many redundant code for the repair mode * current impl. which has many redundant code for the repair mode
*/ */
HashMap fAttrNamespace = null; HashMap<String, String> fAttrNamespace = null;
/** /**
* Creates a new instance of XMLStreamWriterImpl. Uses platform's default * Creates a new instance of XMLStreamWriterImpl. Uses platform's default
@ -230,9 +229,9 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
*/ */
private void init() { private void init() {
fReuse = false; fReuse = false;
fNamespaceDecls = new ArrayList(); fNamespaceDecls = new ArrayList<>();
fPrefixGen = new Random(); fPrefixGen = new Random();
fAttributeCache = new ArrayList(); fAttributeCache = new ArrayList<>();
fInternalNamespaceContext = new NamespaceSupport(); fInternalNamespaceContext = new NamespaceSupport();
fInternalNamespaceContext.reset(); fInternalNamespaceContext.reset();
fNamespaceContext = new NamespaceContextImpl(); fNamespaceContext = new NamespaceContextImpl();
@ -240,9 +239,9 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
// Set internal state based on property values // Set internal state based on property values
Boolean ob = (Boolean) fPropertyManager.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES); Boolean ob = (Boolean) fPropertyManager.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES);
fIsRepairingNamespace = ob.booleanValue(); fIsRepairingNamespace = ob;
ob = (Boolean) fPropertyManager.getProperty(Constants.ESCAPE_CHARACTERS); ob = (Boolean) fPropertyManager.getProperty(Constants.ESCAPE_CHARACTERS);
setEscapeCharacters(ob.booleanValue()); setEscapeCharacters(ob);
} }
/** /**
@ -279,9 +278,9 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
if (resetProperties) { if (resetProperties) {
Boolean ob = (Boolean) fPropertyManager.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES); Boolean ob = (Boolean) fPropertyManager.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES);
fIsRepairingNamespace = ob.booleanValue(); fIsRepairingNamespace = ob;
ob = (Boolean) fPropertyManager.getProperty(Constants.ESCAPE_CHARACTERS); ob = (Boolean) fPropertyManager.getProperty(Constants.ESCAPE_CHARACTERS);
setEscapeCharacters(ob.booleanValue()); setEscapeCharacters(ob);
} }
} }
@ -369,6 +368,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
/** /**
* Close this XMLStreamWriter by closing underlying writer. * Close this XMLStreamWriter by closing underlying writer.
*/ */
@Override
public void close() throws XMLStreamException { public void close() throws XMLStreamException {
if (fWriter != null) { if (fWriter != null) {
try { try {
@ -392,6 +392,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
/** /**
* Flush this XMLStreamWriter by flushin underlying writer. * Flush this XMLStreamWriter by flushin underlying writer.
*/ */
@Override
public void flush() throws XMLStreamException { public void flush() throws XMLStreamException {
try { try {
fWriter.flush(); fWriter.flush();
@ -405,6 +406,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* *
* @return NamespaceContext * @return NamespaceContext
*/ */
@Override
public NamespaceContext getNamespaceContext() { public NamespaceContext getNamespaceContext() {
return fNamespaceContext; return fNamespaceContext;
} }
@ -416,6 +418,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* @param uri The namespace uri * @param uri The namespace uri
* @throws XMLStreamException if uri specified is "" or null * @throws XMLStreamException if uri specified is "" or null
*/ */
@Override
public String getPrefix(String uri) throws XMLStreamException { public String getPrefix(String uri) throws XMLStreamException {
return fNamespaceContext.getPrefix(uri); return fNamespaceContext.getPrefix(uri);
} }
@ -427,6 +430,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* @throws IllegalArgumentException if the specified property is not supported * @throws IllegalArgumentException if the specified property is not supported
* @return value associated with the specified property. * @return value associated with the specified property.
*/ */
@Override
public Object getProperty(String str) public Object getProperty(String str)
throws IllegalArgumentException { throws IllegalArgumentException {
if (str == null) { if (str == null) {
@ -446,6 +450,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* *
* @param uri Namespace URI * @param uri Namespace URI
*/ */
@Override
public void setDefaultNamespace(String uri) throws XMLStreamException { public void setDefaultNamespace(String uri) throws XMLStreamException {
if (uri != null) { if (uri != null) {
uri = fSymbolTable.addSymbol(uri); uri = fSymbolTable.addSymbol(uri);
@ -479,6 +484,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* @param namespaceContext the namespace context to use for this writer, may not be null * @param namespaceContext the namespace context to use for this writer, may not be null
* @throws XMLStreamException * @throws XMLStreamException
*/ */
@Override
public void setNamespaceContext(NamespaceContext namespaceContext) public void setNamespaceContext(NamespaceContext namespaceContext)
throws XMLStreamException { throws XMLStreamException {
fNamespaceContext.userContext = namespaceContext; fNamespaceContext.userContext = namespaceContext;
@ -493,6 +499,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* @param uri * @param uri
* @throws XMLStreamException * @throws XMLStreamException
*/ */
@Override
public void setPrefix(String prefix, String uri) throws XMLStreamException { public void setPrefix(String prefix, String uri) throws XMLStreamException {
if (prefix == null) { if (prefix == null) {
@ -525,6 +532,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
fInternalNamespaceContext.declarePrefix(prefix, uri); fInternalNamespaceContext.declarePrefix(prefix, uri);
} }
@Override
public void writeAttribute(String localName, String value) public void writeAttribute(String localName, String value)
throws XMLStreamException { throws XMLStreamException {
try { try {
@ -554,6 +562,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
} }
@Override
public void writeAttribute(String namespaceURI, String localName, public void writeAttribute(String namespaceURI, String localName,
String value) throws XMLStreamException { String value) throws XMLStreamException {
try { try {
@ -590,7 +599,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
String value) throws IOException { String value) throws IOException {
fWriter.write(SPACE); fWriter.write(SPACE);
if ((prefix != null) && (prefix != XMLConstants.DEFAULT_NS_PREFIX)) { if ((prefix != null) && (!prefix.equals(XMLConstants.DEFAULT_NS_PREFIX))) {
fWriter.write(prefix); fWriter.write(prefix);
fWriter.write(":"); fWriter.write(":");
} }
@ -603,6 +612,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
fWriter.write("\""); fWriter.write("\"");
} }
@Override
public void writeAttribute(String prefix, String namespaceURI, public void writeAttribute(String prefix, String namespaceURI,
String localName, String value) throws XMLStreamException { String localName, String value) throws XMLStreamException {
try { try {
@ -629,7 +639,8 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
} }
if (!prefix.equals(XMLConstants.XML_NS_PREFIX) || !namespaceURI.equals(XMLConstants.XML_NS_URI)) { if (!prefix.equals(XMLConstants.XML_NS_PREFIX) ||
!namespaceURI.equals(XMLConstants.XML_NS_URI)) {
prefix = fSymbolTable.addSymbol(prefix); prefix = fSymbolTable.addSymbol(prefix);
namespaceURI = fSymbolTable.addSymbol(namespaceURI); namespaceURI = fSymbolTable.addSymbol(namespaceURI);
@ -663,6 +674,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
} }
@Override
public void writeCData(String cdata) throws XMLStreamException { public void writeCData(String cdata) throws XMLStreamException {
try { try {
if (cdata == null) { if (cdata == null) {
@ -681,6 +693,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
} }
@Override
public void writeCharacters(String data) throws XMLStreamException { public void writeCharacters(String data) throws XMLStreamException {
try { try {
if (fStartTagOpened) { if (fStartTagOpened) {
@ -693,6 +706,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
} }
@Override
public void writeCharacters(char[] data, int start, int len) public void writeCharacters(char[] data, int start, int len)
throws XMLStreamException { throws XMLStreamException {
try { try {
@ -706,6 +720,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
} }
@Override
public void writeComment(String comment) throws XMLStreamException { public void writeComment(String comment) throws XMLStreamException {
try { try {
if (fStartTagOpened) { if (fStartTagOpened) {
@ -724,6 +739,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
} }
@Override
public void writeDTD(String dtd) throws XMLStreamException { public void writeDTD(String dtd) throws XMLStreamException {
try { try {
if (fStartTagOpened) { if (fStartTagOpened) {
@ -750,11 +766,12 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* @see <a href="http://www.w3.org/TR/REC-xml-names/#defaulting"> * @see <a href="http://www.w3.org/TR/REC-xml-names/#defaulting">
* Namespaces in XML, 5.2 Namespace Defaulting</a> * Namespaces in XML, 5.2 Namespace Defaulting</a>
*/ */
@Override
public void writeDefaultNamespace(String namespaceURI) public void writeDefaultNamespace(String namespaceURI)
throws XMLStreamException { throws XMLStreamException {
// normalize namespaceURI // normalize namespaceURI
String namespaceURINormalized = null; String namespaceURINormalized;
if (namespaceURI == null) { if (namespaceURI == null) {
namespaceURINormalized = ""; // XMLConstants.NULL_NS_URI namespaceURINormalized = ""; // XMLConstants.NULL_NS_URI
} else { } else {
@ -782,7 +799,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
String tmp = fInternalNamespaceContext.getURI(""); String tmp = fInternalNamespaceContext.getURI("");
if (tmp != null && tmp != namespaceURINormalized) { if (tmp != null && !tmp.equals(namespaceURINormalized)) {
throw new XMLStreamException( throw new XMLStreamException(
"xmlns has been already bound to " +tmp + "xmlns has been already bound to " +tmp +
". Rebinding it to "+ namespaceURINormalized + ". Rebinding it to "+ namespaceURINormalized +
@ -798,6 +815,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
} }
@Override
public void writeEmptyElement(String localName) throws XMLStreamException { public void writeEmptyElement(String localName) throws XMLStreamException {
try { try {
if (fStartTagOpened) { if (fStartTagOpened) {
@ -816,6 +834,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
} }
@Override
public void writeEmptyElement(String namespaceURI, String localName) public void writeEmptyElement(String namespaceURI, String localName)
throws XMLStreamException { throws XMLStreamException {
if (namespaceURI == null) { if (namespaceURI == null) {
@ -828,6 +847,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
writeEmptyElement(prefix, localName, namespaceURI); writeEmptyElement(prefix, localName, namespaceURI);
} }
@Override
public void writeEmptyElement(String prefix, String localName, public void writeEmptyElement(String prefix, String localName,
String namespaceURI) throws XMLStreamException { String namespaceURI) throws XMLStreamException {
try { try {
@ -863,7 +883,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
return; return;
} }
if ((prefix != null) && (prefix != XMLConstants.DEFAULT_NS_PREFIX)) { if ((prefix != null) && (!prefix.equals(XMLConstants.DEFAULT_NS_PREFIX))) {
fWriter.write(prefix); fWriter.write(prefix);
fWriter.write(":"); fWriter.write(":");
} }
@ -874,16 +894,15 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
} }
@Override
public void writeEndDocument() throws XMLStreamException { public void writeEndDocument() throws XMLStreamException {
try { try {
if (fStartTagOpened) { if (fStartTagOpened) {
closeStartTag(); closeStartTag();
} }
ElementState elem = null;
while (!fElementStack.empty()) { while (!fElementStack.empty()) {
elem = (ElementState) fElementStack.pop(); ElementState elem = fElementStack.pop();
fInternalNamespaceContext.popContext(); fInternalNamespaceContext.popContext();
if (elem.isEmpty) { if (elem.isEmpty) {
@ -907,13 +926,14 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
} }
@Override
public void writeEndElement() throws XMLStreamException { public void writeEndElement() throws XMLStreamException {
try { try {
if (fStartTagOpened) { if (fStartTagOpened) {
closeStartTag(); closeStartTag();
} }
ElementState currentElement = (ElementState) fElementStack.pop(); ElementState currentElement = fElementStack.pop();
if (currentElement == null) { if (currentElement == null) {
throw new XMLStreamException("No element was found to write"); throw new XMLStreamException("No element was found to write");
@ -944,6 +964,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
} }
@Override
public void writeEntityRef(String refName) throws XMLStreamException { public void writeEntityRef(String refName) throws XMLStreamException {
try { try {
if (fStartTagOpened) { if (fStartTagOpened) {
@ -973,11 +994,12 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* @see <a href="http://www.w3.org/TR/REC-xml-names/#defaulting"> * @see <a href="http://www.w3.org/TR/REC-xml-names/#defaulting">
* Namespaces in XML, 5.2 Namespace Defaulting</a> * Namespaces in XML, 5.2 Namespace Defaulting</a>
*/ */
@Override
public void writeNamespace(String prefix, String namespaceURI) public void writeNamespace(String prefix, String namespaceURI)
throws XMLStreamException { throws XMLStreamException {
// normalize namespaceURI // normalize namespaceURI
String namespaceURINormalized = null; String namespaceURINormalized;
if (namespaceURI == null) { if (namespaceURI == null) {
namespaceURINormalized = ""; // XMLConstants.NULL_NS_URI namespaceURINormalized = ""; // XMLConstants.NULL_NS_URI
} else { } else {
@ -985,7 +1007,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
try { try {
QName qname = null; QName qname;
if (!fStartTagOpened) { if (!fStartTagOpened) {
throw new IllegalStateException( throw new IllegalStateException(
@ -1013,7 +1035,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
if (fIsRepairingNamespace) { if (fIsRepairingNamespace) {
String tmpURI = fInternalNamespaceContext.getURI(prefix); String tmpURI = fInternalNamespaceContext.getURI(prefix);
if ((tmpURI != null) && (tmpURI == namespaceURINormalized)) { if ((tmpURI != null) && (tmpURI.equals(namespaceURINormalized))) {
return; return;
} }
@ -1030,7 +1052,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
String tmp = fInternalNamespaceContext.getURI(prefix); String tmp = fInternalNamespaceContext.getURI(prefix);
if (tmp != null && tmp != namespaceURINormalized) { if (tmp != null && !tmp.equals(namespaceURINormalized)) {
throw new XMLStreamException("prefix "+prefix+ throw new XMLStreamException("prefix "+prefix+
" has been already bound to " +tmp + " has been already bound to " +tmp +
@ -1051,7 +1073,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
throws IOException { throws IOException {
fWriter.write(" xmlns"); fWriter.write(" xmlns");
if ((prefix != null) && (prefix != XMLConstants.DEFAULT_NS_PREFIX)) { if ((prefix != null) && (!prefix.equals(XMLConstants.DEFAULT_NS_PREFIX))) {
fWriter.write(":"); fWriter.write(":");
fWriter.write(prefix); fWriter.write(prefix);
} }
@ -1064,6 +1086,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
fWriter.write("\""); fWriter.write("\"");
} }
@Override
public void writeProcessingInstruction(String target) public void writeProcessingInstruction(String target)
throws XMLStreamException { throws XMLStreamException {
try { try {
@ -1090,6 +1113,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* @param data * @param data
* @throws XMLStreamException * @throws XMLStreamException
*/ */
@Override
public void writeProcessingInstruction(String target, String data) public void writeProcessingInstruction(String target, String data)
throws XMLStreamException { throws XMLStreamException {
try { try {
@ -1116,6 +1140,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* *
* @throws XMLStreamException in case of an IOException * @throws XMLStreamException in case of an IOException
*/ */
@Override
public void writeStartDocument() throws XMLStreamException { public void writeStartDocument() throws XMLStreamException {
writeStartDocument(null, null, false, false); writeStartDocument(null, null, false, false);
} }
@ -1126,6 +1151,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* @param version the specified version * @param version the specified version
* @throws XMLStreamException in case of an IOException * @throws XMLStreamException in case of an IOException
*/ */
@Override
public void writeStartDocument(String version) throws XMLStreamException { public void writeStartDocument(String version) throws XMLStreamException {
writeStartDocument(null, version, false, false); writeStartDocument(null, version, false, false);
} }
@ -1143,7 +1169,6 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
writeStartDocument(encoding, version, false, false); writeStartDocument(encoding, version, false, false);
} }
@Override
public void writeStartDocument(String encoding, String version, public void writeStartDocument(String encoding, String version,
boolean standalone, boolean standaloneSet) boolean standalone, boolean standaloneSet)
throws XMLStreamException { throws XMLStreamException {
@ -1212,9 +1237,9 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
if (streamEncoding != null && !streamEncoding.equalsIgnoreCase(encoding)) { if (streamEncoding != null && !streamEncoding.equalsIgnoreCase(encoding)) {
// If the equality check failed, check for charset encoding aliases // If the equality check failed, check for charset encoding aliases
boolean foundAlias = false; boolean foundAlias = false;
Set aliases = Charset.forName(encoding).aliases(); Set<String> aliases = Charset.forName(encoding).aliases();
for (Iterator it = aliases.iterator(); !foundAlias && it.hasNext(); ) { for (Iterator<String> it = aliases.iterator(); !foundAlias && it.hasNext(); ) {
if (streamEncoding.equalsIgnoreCase((String) it.next())) { if (streamEncoding.equalsIgnoreCase(it.next())) {
foundAlias = true; foundAlias = true;
} }
} }
@ -1232,6 +1257,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* @param localName * @param localName
* @throws XMLStreamException * @throws XMLStreamException
*/ */
@Override
public void writeStartElement(String localName) throws XMLStreamException { public void writeStartElement(String localName) throws XMLStreamException {
try { try {
if (localName == null) { if (localName == null) {
@ -1261,6 +1287,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* @param localName * @param localName
* @throws XMLStreamException * @throws XMLStreamException
*/ */
@Override
public void writeStartElement(String namespaceURI, String localName) public void writeStartElement(String namespaceURI, String localName)
throws XMLStreamException { throws XMLStreamException {
if (localName == null) { if (localName == null) {
@ -1292,6 +1319,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* @param namespaceURI * @param namespaceURI
* @throws XMLStreamException * @throws XMLStreamException
*/ */
@Override
public void writeStartElement(String prefix, String localName, public void writeStartElement(String prefix, String localName,
String namespaceURI) throws XMLStreamException { String namespaceURI) throws XMLStreamException {
try { try {
@ -1537,10 +1565,10 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
fWriter.write(currentElement.localpart); fWriter.write(currentElement.localpart);
int len = fNamespaceDecls.size(); int len = fNamespaceDecls.size();
QName qname = null; QName qname;
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
qname = (QName) fNamespaceDecls.get(i); qname = fNamespaceDecls.get(i);
if (qname != null) { if (qname != null) {
if (fInternalNamespaceContext.declarePrefix(qname.prefix, if (fInternalNamespaceContext.declarePrefix(qname.prefix,
@ -1552,16 +1580,16 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
fNamespaceDecls.clear(); fNamespaceDecls.clear();
Attribute attr = null; Attribute attr;
for (int j = 0; j < fAttributeCache.size(); j++) { for (int j = 0; j < fAttributeCache.size(); j++) {
attr = (Attribute) fAttributeCache.get(j); attr = fAttributeCache.get(j);
if ((attr.prefix != null) && (attr.uri != null)) { if ((attr.prefix != null) && (attr.uri != null)) {
if (!attr.prefix.equals("") && !attr.uri.equals("") ) { if (!attr.prefix.equals("") && !attr.uri.equals("") ) {
String tmp = fInternalNamespaceContext.getPrefix(attr.uri); String tmp = fInternalNamespaceContext.getPrefix(attr.uri);
if ((tmp == null) || (tmp != attr.prefix)) { if ((tmp == null) || (!tmp.equals(attr.prefix))) {
tmp = getAttrPrefix(attr.uri); tmp = getAttrPrefix(attr.uri);
if (tmp == null) { if (tmp == null) {
if (fInternalNamespaceContext.declarePrefix(attr.prefix, if (fInternalNamespaceContext.declarePrefix(attr.prefix,
@ -1611,29 +1639,29 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* @return * @return
*/ */
private void correctPrefix(QName attr, int type) { private void correctPrefix(QName attr, int type) {
String tmpPrefix = null; String tmpPrefix;
String prefix; String prefix;
String uri; String uri;
prefix = attr.prefix; prefix = attr.prefix;
uri = attr.uri; uri = attr.uri;
boolean isSpecialCaseURI = false; boolean isSpecialCaseURI = false;
if (prefix == null || prefix.equals("")) { if (prefix == null || prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
if (uri == null) { if (uri == null) {
return; return;
} }
if (prefix == XMLConstants.DEFAULT_NS_PREFIX && uri == XMLConstants.DEFAULT_NS_PREFIX) if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix) && uri.equals(XMLConstants.DEFAULT_NS_PREFIX))
return; return;
uri = fSymbolTable.addSymbol(uri); uri = fSymbolTable.addSymbol(uri);
QName decl = null; QName decl;
for (int i = 0; i < fNamespaceDecls.size(); i++) { for (int i = 0; i < fNamespaceDecls.size(); i++) {
decl = (QName) fNamespaceDecls.get(i); decl = fNamespaceDecls.get(i);
if ((decl != null) && (decl.uri == attr.uri)) { if ((decl != null) && (decl.uri.equals(attr.uri))) {
attr.prefix = decl.prefix; attr.prefix = decl.prefix;
return; return;
@ -1642,7 +1670,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
tmpPrefix = fNamespaceContext.getPrefix(uri); tmpPrefix = fNamespaceContext.getPrefix(uri);
if (tmpPrefix == XMLConstants.DEFAULT_NS_PREFIX) { if (XMLConstants.DEFAULT_NS_PREFIX.equals(tmpPrefix)) {
if (type == XMLStreamConstants.START_ELEMENT) { if (type == XMLStreamConstants.START_ELEMENT) {
return; return;
} }
@ -1654,7 +1682,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
if (tmpPrefix == null) { if (tmpPrefix == null) {
StringBuffer genPrefix = new StringBuffer("zdef"); StringBuilder genPrefix = new StringBuilder("zdef");
for (int i = 0; i < 1; i++) { for (int i = 0; i < 1; i++) {
genPrefix.append(fPrefixGen.nextInt()); genPrefix.append(fPrefixGen.nextInt());
@ -1687,13 +1715,13 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
*/ */
private String getAttrPrefix(String uri) { private String getAttrPrefix(String uri) {
if (fAttrNamespace != null) { if (fAttrNamespace != null) {
return (String)fAttrNamespace.get(uri); return fAttrNamespace.get(uri);
} }
return null; return null;
} }
private void addAttrNamespace(String prefix, String uri) { private void addAttrNamespace(String prefix, String uri) {
if (fAttrNamespace == null) { if (fAttrNamespace == null) {
fAttrNamespace = new HashMap(); fAttrNamespace = new HashMap<>();
} }
fAttrNamespace.put(prefix, uri); fAttrNamespace.put(prefix, uri);
} }
@ -1704,7 +1732,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
private boolean isDefaultNamespace(String uri) { private boolean isDefaultNamespace(String uri) {
String defaultNamespace = fInternalNamespaceContext.getURI(DEFAULT_PREFIX); String defaultNamespace = fInternalNamespaceContext.getURI(DEFAULT_PREFIX);
if (uri == defaultNamespace) { if (uri.equals(defaultNamespace)) {
return true; return true;
} }
@ -1732,13 +1760,13 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* Correct's namespaces as per requirements of isReparisingNamespace property. * Correct's namespaces as per requirements of isReparisingNamespace property.
*/ */
protected void repair() { protected void repair() {
Attribute attr = null; Attribute attr;
Attribute attr2 = null; Attribute attr2;
ElementState currentElement = fElementStack.peek(); ElementState currentElement = fElementStack.peek();
removeDuplicateDecls(); removeDuplicateDecls();
for(int i=0 ; i< fAttributeCache.size();i++){ for(int i=0 ; i< fAttributeCache.size();i++){
attr = (Attribute)fAttributeCache.get(i); attr = fAttributeCache.get(i);
if((attr.prefix != null && !attr.prefix.equals("")) || (attr.uri != null && !attr.uri.equals(""))) { if((attr.prefix != null && !attr.prefix.equals("")) || (attr.uri != null && !attr.uri.equals(""))) {
correctPrefix(currentElement,attr); correctPrefix(currentElement,attr);
} }
@ -1754,9 +1782,9 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
for(int i=0 ; i< fAttributeCache.size();i++){ for(int i=0 ; i< fAttributeCache.size();i++){
attr = (Attribute)fAttributeCache.get(i); attr = fAttributeCache.get(i);
for(int j=i+1;j<fAttributeCache.size();j++){ for(int j=i+1;j<fAttributeCache.size();j++){
attr2 = (Attribute)fAttributeCache.get(j); attr2 = fAttributeCache.get(j);
if(!"".equals(attr.prefix)&& !"".equals(attr2.prefix)){ if(!"".equals(attr.prefix)&& !"".equals(attr2.prefix)){
correctPrefix(attr,attr2); correctPrefix(attr,attr2);
} }
@ -1765,10 +1793,10 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
repairNamespaceDecl(currentElement); repairNamespaceDecl(currentElement);
int i = 0; int i;
for (i = 0; i < fAttributeCache.size(); i++) { for (i = 0; i < fAttributeCache.size(); i++) {
attr = (Attribute) fAttributeCache.get(i); attr = fAttributeCache.get(i);
/* If 'attr' is an attribute and it is in no namespace(which means that prefix="", uri=""), attr's /* If 'attr' is an attribute and it is in no namespace(which means that prefix="", uri=""), attr's
namespace should not be redinded. See [http://www.w3.org/TR/REC-xml-names/#defaulting]. namespace should not be redinded. See [http://www.w3.org/TR/REC-xml-names/#defaulting].
*/ */
@ -1780,7 +1808,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
QName qname = null; QName qname = null;
for (i = 0; i < fNamespaceDecls.size(); i++) { for (i = 0; i < fNamespaceDecls.size(); i++) {
qname = (QName) fNamespaceDecls.get(i); qname = fNamespaceDecls.get(i);
if (qname != null) { if (qname != null) {
fInternalNamespaceContext.declarePrefix(qname.prefix, qname.uri); fInternalNamespaceContext.declarePrefix(qname.prefix, qname.uri);
@ -1788,7 +1816,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
for (i = 0; i < fAttributeCache.size(); i++) { for (i = 0; i < fAttributeCache.size(); i++) {
attr = (Attribute) fAttributeCache.get(i); attr = fAttributeCache.get(i);
correctPrefix(attr, XMLStreamConstants.ATTRIBUTE); correctPrefix(attr, XMLStreamConstants.ATTRIBUTE);
} }
} }
@ -1801,9 +1829,8 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
*that is bound to the namespace URIs of those attributes. *that is bound to the namespace URIs of those attributes.
*/ */
void correctPrefix(QName attr1, QName attr2) { void correctPrefix(QName attr1, QName attr2) {
String tmpPrefix = null; String tmpPrefix;
QName decl = null; QName decl;
boolean done = false;
checkForNull(attr1); checkForNull(attr1);
checkForNull(attr2); checkForNull(attr2);
@ -1815,10 +1842,9 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
if (tmpPrefix != null) { if (tmpPrefix != null) {
attr2.prefix = fSymbolTable.addSymbol(tmpPrefix); attr2.prefix = fSymbolTable.addSymbol(tmpPrefix);
} else { } else {
decl = null; for (int n=0; n<fNamespaceDecls.size(); n++) {
for(int n=0;n<fNamespaceDecls.size();n++){ decl = fNamespaceDecls.get(n);
decl = (QName)fNamespaceDecls.get(n); if(decl != null && (decl.uri.equals(attr2.uri))){
if(decl != null && (decl.uri == attr2.uri)){
attr2.prefix = decl.prefix; attr2.prefix = decl.prefix;
return; return;
@ -1826,7 +1852,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
//No namespace mapping found , so declare prefix. //No namespace mapping found , so declare prefix.
StringBuffer genPrefix = new StringBuffer("zdef"); StringBuilder genPrefix = new StringBuilder("zdef");
for (int k = 0; k < 1; k++) { for (int k = 0; k < 1; k++) {
genPrefix.append(fPrefixGen.nextInt()); genPrefix.append(fPrefixGen.nextInt());
@ -1851,11 +1877,11 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
void removeDuplicateDecls(){ void removeDuplicateDecls(){
QName decl1,decl2; QName decl1,decl2;
for(int i =0;i<fNamespaceDecls.size();i++){ for(int i =0; i<fNamespaceDecls.size(); i++) {
decl1 = (QName)fNamespaceDecls.get(i); decl1 = fNamespaceDecls.get(i);
if(decl1!=null) { if(decl1!=null) {
for(int j=i+1;j<fNamespaceDecls.size();j++){ for(int j=i+1;j<fNamespaceDecls.size();j++){
decl2 = (QName)fNamespaceDecls.get(j); decl2 = fNamespaceDecls.get(j);
// QName.equals relies on identity equality, so we can't use it, // QName.equals relies on identity equality, so we can't use it,
// because prefixes aren't interned // because prefixes aren't interned
if(decl2!=null && decl1.prefix.equals(decl2.prefix) && decl1.uri.equals(decl2.uri)) if(decl2!=null && decl1.prefix.equals(decl2.prefix) && decl1.uri.equals(decl2.uri))
@ -1873,12 +1899,12 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* *
*/ */
void repairNamespaceDecl(QName attr) { void repairNamespaceDecl(QName attr) {
QName decl = null; QName decl;
String tmpURI; String tmpURI;
//check for null prefix. //check for null prefix.
for (int j = 0; j < fNamespaceDecls.size(); j++) { for (int j = 0; j < fNamespaceDecls.size(); j++) {
decl = (QName) fNamespaceDecls.get(j); decl = fNamespaceDecls.get(j);
if (decl != null) { if (decl != null) {
if ((attr.prefix != null) && if ((attr.prefix != null) &&
@ -1900,13 +1926,13 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
boolean isDeclared(QName attr) { boolean isDeclared(QName attr) {
QName decl = null; QName decl;
for (int n = 0; n < fNamespaceDecls.size(); n++) { for (int n = 0; n < fNamespaceDecls.size(); n++) {
decl = (QName) fNamespaceDecls.get(n); decl = fNamespaceDecls.get(n);
if ((attr.prefix != null) && if ((attr.prefix != null) &&
((attr.prefix == decl.prefix) && (decl.uri == attr.uri))) { ((attr.prefix.equals(decl.prefix)) && (decl.uri.equals(attr.uri)))) {
return true; return true;
} }
} }
@ -2121,9 +2147,10 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
return null; return null;
} }
public java.util.Iterator getPrefixes(String uri) { //Cleanup note: leaving these warnings to a xerces.internal.util cleanup
public Iterator<String> getPrefixes(String uri) {
Vector prefixes = null; Vector prefixes = null;
Iterator itr = null; Iterator<String> itr = null;
if (uri != null) { if (uri != null) {
uri = fSymbolTable.addSymbol(uri); uri = fSymbolTable.addSymbol(uri);
@ -2140,12 +2167,12 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
if ((prefixes == null) && (itr != null)) { if ((prefixes == null) && (itr != null)) {
return itr; return itr;
} else if ((prefixes != null) && (itr == null)) { } else if ((prefixes != null) && (itr == null)) {
return new ReadOnlyIterator(prefixes.iterator()); return new ReadOnlyIterator<>(prefixes.iterator());
} else if ((prefixes != null) && (itr != null)) { } else if ((prefixes != null) && (itr != null)) {
String ob = null; String ob = null;
while (itr.hasNext()) { while (itr.hasNext()) {
ob = (String) itr.next(); ob = itr.next();
if (ob != null) { if (ob != null) {
ob = fSymbolTable.addSymbol(ob); ob = fSymbolTable.addSymbol(ob);
@ -2156,7 +2183,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
} }
} }
return new ReadOnlyIterator(prefixes.iterator()); return new ReadOnlyIterator<>(prefixes.iterator());
} }
return fReadOnlyIterator; return fReadOnlyIterator;
@ -2165,14 +2192,17 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
// -- Map Interface -------------------------------------------------- // -- Map Interface --------------------------------------------------
@Override
public int size() { public int size() {
return 1; return 1;
} }
@Override
public boolean isEmpty() { public boolean isEmpty() {
return false; return false;
} }
@Override
public boolean containsKey(Object key) { public boolean containsKey(Object key) {
return key.equals(OUTPUTSTREAM_PROPERTY); return key.equals(OUTPUTSTREAM_PROPERTY);
} }
@ -2181,6 +2211,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* Returns the value associated to an implementation-specific * Returns the value associated to an implementation-specific
* property. * property.
*/ */
@Override
public Object get(Object key) { public Object get(Object key) {
if (key.equals(OUTPUTSTREAM_PROPERTY)) { if (key.equals(OUTPUTSTREAM_PROPERTY)) {
return fOutputStream; return fOutputStream;
@ -2188,7 +2219,8 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
return null; return null;
} }
public java.util.Set entrySet() { @Override
public Set<Entry<Object,Object>> entrySet() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@ -2198,6 +2230,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* AbstractMap would cause an unsupported exection to * AbstractMap would cause an unsupported exection to
* be thrown. * be thrown.
*/ */
@Override
public String toString() { public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode()); return getClass().getName() + "@" + Integer.toHexString(hashCode());
} }
@ -2206,6 +2239,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* Overrides the method defined in AbstractMap * Overrides the method defined in AbstractMap
* This is required by the toString() method * This is required by the toString() method
*/ */
@Override
public int hashCode() { public int hashCode() {
return fElementStack.hashCode(); return fElementStack.hashCode();
} }
@ -2213,6 +2247,7 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
* Overrides the method defined in AbstractMap * Overrides the method defined in AbstractMap
* This is required to satisfy the contract for hashCode. * This is required to satisfy the contract for hashCode.
*/ */
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return (this == obj); return (this == obj);
} }

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream; package javax.xml.stream;
import javax.xml.stream.events.XMLEvent; import javax.xml.stream.events.XMLEvent;

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,9 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream; package javax.xml.stream;

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream; package javax.xml.stream;
/** /**

@ -39,53 +39,34 @@ class SecuritySupport {
ClassLoader getContextClassLoader() throws SecurityException{ ClassLoader getContextClassLoader() throws SecurityException{
return (ClassLoader) return AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> {
AccessController.doPrivileged(new PrivilegedAction() { ClassLoader cl = Thread.currentThread().getContextClassLoader();
public Object run() {
ClassLoader cl = null;
//try {
cl = Thread.currentThread().getContextClassLoader();
//} catch (SecurityException ex) { }
if (cl == null) if (cl == null)
cl = ClassLoader.getSystemClassLoader(); cl = ClassLoader.getSystemClassLoader();
return cl; return cl;
}
}); });
} }
String getSystemProperty(final String propName) { String getSystemProperty(final String propName) {
return (String) return AccessController.doPrivileged((PrivilegedAction<String>) () ->
AccessController.doPrivileged(new PrivilegedAction() { System.getProperty(propName));
public Object run() {
return System.getProperty(propName);
}
});
} }
FileInputStream getFileInputStream(final File file) FileInputStream getFileInputStream(final File file)
throws FileNotFoundException throws FileNotFoundException
{ {
try { try {
return (FileInputStream) return AccessController.doPrivileged((PrivilegedExceptionAction<FileInputStream>) ()
AccessController.doPrivileged(new PrivilegedExceptionAction() { -> new FileInputStream(file));
public Object run() throws FileNotFoundException {
return new FileInputStream(file);
}
});
} catch (PrivilegedActionException e) { } catch (PrivilegedActionException e) {
throw (FileNotFoundException)e.getException(); throw (FileNotFoundException)e.getException();
} }
} }
boolean doesFileExist(final File f) { boolean doesFileExist(final File f) {
return ((Boolean) return AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> f.exists());
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new Boolean(f.exists());
}
})).booleanValue();
} }
} }

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream; package javax.xml.stream;
/** /**

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009, 2015, by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream; package javax.xml.stream;
import com.sun.xml.internal.stream.events.XMLEventFactoryImpl; import com.sun.xml.internal.stream.events.XMLEventFactoryImpl;
import java.util.Iterator; import java.util.Iterator;
@ -53,8 +50,7 @@ public abstract class XMLEventFactory {
static final String JAXPFACTORYID = "javax.xml.stream.XMLEventFactory"; static final String JAXPFACTORYID = "javax.xml.stream.XMLEventFactory";
static final String DEFAULIMPL = "com.sun.xml.internal.stream.events.XMLEventFactoryImpl"; static final String DEFAULIMPL = "com.sun.xml.internal.stream.events.XMLEventFactoryImpl";
/**
/**
* Creates a new instance of the {@code XMLEventFactory} builtin * Creates a new instance of the {@code XMLEventFactory} builtin
* system-default implementation. * system-default implementation.
* *
@ -159,6 +155,7 @@ public abstract class XMLEventFactory {
* #newFactory(java.lang.String, java.lang.ClassLoader)} * #newFactory(java.lang.String, java.lang.ClassLoader)}
* method defines no changes in behavior. * method defines no changes in behavior.
*/ */
@Deprecated(since="7")
public static XMLEventFactory newInstance(String factoryId, public static XMLEventFactory newInstance(String factoryId,
ClassLoader classLoader) ClassLoader classLoader)
throws FactoryConfigurationError { throws FactoryConfigurationError {
@ -307,8 +304,8 @@ public abstract class XMLEventFactory {
* @return an instance of the requested StartElement * @return an instance of the requested StartElement
*/ */
public abstract StartElement createStartElement(QName name, public abstract StartElement createStartElement(QName name,
Iterator attributes, Iterator<? extends Attribute> attributes,
Iterator namespaces); Iterator<? extends Namespace> namespaces);
/** /**
* Create a new StartElement. This defaults the NamespaceContext to * Create a new StartElement. This defaults the NamespaceContext to
@ -341,8 +338,8 @@ public abstract class XMLEventFactory {
public abstract StartElement createStartElement(String prefix, public abstract StartElement createStartElement(String prefix,
String namespaceUri, String namespaceUri,
String localName, String localName,
Iterator attributes, Iterator<? extends Attribute> attributes,
Iterator namespaces Iterator<? extends Namespace> namespaces
); );
/** /**
* Create a new StartElement. Namespaces can be added to this StartElement * Create a new StartElement. Namespaces can be added to this StartElement
@ -363,8 +360,8 @@ public abstract class XMLEventFactory {
public abstract StartElement createStartElement(String prefix, public abstract StartElement createStartElement(String prefix,
String namespaceUri, String namespaceUri,
String localName, String localName,
Iterator attributes, Iterator<? extends Attribute> attributes,
Iterator namespaces, Iterator<? extends Namespace> namespaces,
NamespaceContext context NamespaceContext context
); );
@ -376,7 +373,7 @@ public abstract class XMLEventFactory {
* @return an instance of the requested EndElement * @return an instance of the requested EndElement
*/ */
public abstract EndElement createEndElement(QName name, public abstract EndElement createEndElement(QName name,
Iterator namespaces); Iterator<? extends Namespace> namespaces);
/** /**
* Create a new EndElement * Create a new EndElement
@ -400,7 +397,7 @@ public abstract class XMLEventFactory {
public abstract EndElement createEndElement(String prefix, public abstract EndElement createEndElement(String prefix,
String namespaceUri, String namespaceUri,
String localName, String localName,
Iterator namespaces); Iterator<? extends Namespace> namespaces);
/** /**
* Create a Characters event, this method does not check if the content * Create a Characters event, this method does not check if the content

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream; package javax.xml.stream;
import javax.xml.stream.events.XMLEvent; import javax.xml.stream.events.XMLEvent;
@ -44,7 +41,7 @@ import java.util.Iterator;
* @see XMLEventWriter * @see XMLEventWriter
* @since 1.6 * @since 1.6
*/ */
public interface XMLEventReader extends Iterator { public interface XMLEventReader extends Iterator<Object> {
/** /**
* Gets the next XMLEvent. The initial event is * Gets the next XMLEvent. The initial event is
* {@link javax.xml.stream.events.StartDocument StartDocument}. * {@link javax.xml.stream.events.StartDocument StartDocument}.

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream; package javax.xml.stream;
import javax.xml.stream.events.*; import javax.xml.stream.events.*;

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009, 2013, by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream; package javax.xml.stream;
import com.sun.xml.internal.stream.XMLInputFactoryImpl; import com.sun.xml.internal.stream.XMLInputFactoryImpl;
@ -225,6 +222,7 @@ public abstract class XMLInputFactory {
* java.util.ServiceConfigurationError service configuration error} or if * java.util.ServiceConfigurationError service configuration error} or if
* the implementation is not available or cannot be instantiated. * the implementation is not available or cannot be instantiated.
*/ */
@Deprecated(since="7")
public static XMLInputFactory newFactory() public static XMLInputFactory newFactory()
throws FactoryConfigurationError throws FactoryConfigurationError
{ {
@ -246,6 +244,7 @@ public abstract class XMLInputFactory {
* #newFactory(java.lang.String, java.lang.ClassLoader)} method * #newFactory(java.lang.String, java.lang.ClassLoader)} method
* defines no changes in behavior. * defines no changes in behavior.
*/ */
@Deprecated(since="7")
public static XMLInputFactory newInstance(String factoryId, public static XMLInputFactory newInstance(String factoryId,
ClassLoader classLoader) ClassLoader classLoader)
throws FactoryConfigurationError { throws FactoryConfigurationError {

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009, 2013, by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream; package javax.xml.stream;
import com.sun.xml.internal.stream.XMLOutputFactoryImpl; import com.sun.xml.internal.stream.XMLOutputFactoryImpl;
@ -121,7 +118,7 @@ public abstract class XMLOutputFactory {
protected XMLOutputFactory(){} protected XMLOutputFactory(){}
/** /**
* Creates a new instance of the {@code XMLOutputFactory} builtin * Creates a new instance of the {@code XMLOutputFactory} builtin
* system-default implementation. * system-default implementation.
* *
@ -225,6 +222,7 @@ public abstract class XMLOutputFactory {
* Use the new method {@link #newFactory(java.lang.String, * Use the new method {@link #newFactory(java.lang.String,
* java.lang.ClassLoader)} instead. * java.lang.ClassLoader)} instead.
*/ */
@Deprecated(since="7")
public static XMLInputFactory newInstance(String factoryId, public static XMLInputFactory newInstance(String factoryId,
ClassLoader classLoader) ClassLoader classLoader)
throws FactoryConfigurationError { throws FactoryConfigurationError {

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream; package javax.xml.stream;
/** /**

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream; package javax.xml.stream;
/** /**

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream; package javax.xml.stream;
/** /**

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream; package javax.xml.stream;
import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.NamespaceContext;

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream; package javax.xml.stream;
import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.NamespaceContext;

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.events; package javax.xml.stream.events;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.events; package javax.xml.stream.events;
/** /**

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.events; package javax.xml.stream.events;
/** /**

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.events; package javax.xml.stream.events;
import java.util.List; import java.util.List;
@ -39,36 +36,40 @@ import java.util.List;
*/ */
public interface DTD extends XMLEvent { public interface DTD extends XMLEvent {
/** /**
* Returns the entire Document Type Declaration as a string, including * Returns the entire Document Type Declaration as a string, including the
* the internal DTD subset. * internal DTD subset. This may be null if there is not an internal subset.
* This may be null if there is not an internal subset. * If it is not null it must return the entire Document Type Declaration
* If it is not null it must return the entire * which matches the doctypedecl production in the XML 1.0 specification
* Document Type Declaration which matches the doctypedecl *
* production in the XML 1.0 specification * @return the Document Type Declaration
*/ */
String getDocumentTypeDeclaration(); String getDocumentTypeDeclaration();
/** /**
* Returns an implementation defined representation of the DTD. * Returns an implementation defined representation of the DTD. This method
* This method may return null if no representation is available. * may return null if no representation is available.
*/ *
Object getProcessedDTD(); * @return the representation of the DTD
*/
Object getProcessedDTD();
/** /**
* Return a List containing the notations declared in the DTD. * Return a List containing the notations declared in the DTD. This list
* This list must contain NotationDeclaration events. * must contain NotationDeclaration events.
* @see NotationDeclaration *
* @return an unordered list of NotationDeclaration events * @see NotationDeclaration
*/ * @return an unordered list of NotationDeclaration events
List getNotations(); */
List<NotationDeclaration> getNotations();
/** /**
* Return a List containing the general entities, * Return a List containing the general entities, both external and
* both external and internal, declared in the DTD. * internal, declared in the DTD. This list must contain EntityDeclaration
* This list must contain EntityDeclaration events. * events.
* @see EntityDeclaration *
* @return an unordered list of EntityDeclaration events * @see EntityDeclaration
*/ * @return an unordered list of EntityDeclaration events
List getEntities(); */
List<EntityDeclaration> getEntities();
} }

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.events; package javax.xml.stream.events;
/** /**

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.events; package javax.xml.stream.events;
import java.util.Iterator; import java.util.Iterator;
@ -54,6 +51,6 @@ public interface EndElement extends XMLEvent {
* @return an Iterator over Namespace interfaces, or an * @return an Iterator over Namespace interfaces, or an
* empty iterator * empty iterator
*/ */
public Iterator getNamespaces(); public Iterator<Namespace> getNamespaces();
} }

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.events; package javax.xml.stream.events;
/** /**
* An interface for handling Entity Declarations * An interface for handling Entity Declarations

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.events; package javax.xml.stream.events;
/** /**
* An interface for handling Entity events. * An interface for handling Entity events.

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.events; package javax.xml.stream.events;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.events; package javax.xml.stream.events;
/** /**
* An interface for handling Notation Declarations * An interface for handling Notation Declarations

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.events; package javax.xml.stream.events;
/** /**
* An interface that describes the data found in processing instructions * An interface that describes the data found in processing instructions

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.events; package javax.xml.stream.events;
/** /**
* An interface for the start document event * An interface for the start document event

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,16 +23,10 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.events; package javax.xml.stream.events;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.NamespaceContext;
import java.util.Map;
import java.util.Iterator; import java.util.Iterator;
/** /**
@ -62,7 +57,7 @@ public interface StartElement extends XMLEvent {
* @return a readonly Iterator over Attribute interfaces, or an * @return a readonly Iterator over Attribute interfaces, or an
* empty iterator * empty iterator
*/ */
public Iterator getAttributes(); public Iterator<Attribute> getAttributes();
/** /**
* Returns an Iterator of namespaces declared on this element. * Returns an Iterator of namespaces declared on this element.
@ -87,7 +82,7 @@ public interface StartElement extends XMLEvent {
* empty iterator * empty iterator
* *
*/ */
public Iterator getNamespaces(); public Iterator<Namespace> getNamespaces();
/** /**
* Returns the attribute referred to by this name * Returns the attribute referred to by this name

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.events; package javax.xml.stream.events;
import java.io.Writer; import java.io.Writer;

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,17 +23,10 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.util; package javax.xml.stream.util;
import javax.xml.namespace.QName;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLEventReader;
import javax.xml.stream.events.XMLEvent; import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
/** /**

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,13 +23,8 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.util; package javax.xml.stream.util;
import java.io.Reader;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamReader;

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.util; package javax.xml.stream.util;
import javax.xml.stream.events.XMLEvent; import javax.xml.stream.events.XMLEvent;

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -22,10 +23,6 @@
* questions. * questions.
*/ */
/*
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
*/
package javax.xml.stream.util; package javax.xml.stream.util;
import javax.xml.stream.events.XMLEvent; import javax.xml.stream.events.XMLEvent;