Class MutableXMLStreamReader
java.lang.Object
javax.xml.stream.util.StreamReaderDelegate
org.codehaus.stax2.util.StreamReader2Delegate
org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader
- All Implemented Interfaces:
AutoCloseable,XMLStreamConstants,XMLStreamReader,org.codehaus.stax2.typed.TypedXMLStreamReader,org.codehaus.stax2.validation.Validatable,org.codehaus.stax2.XMLStreamReader2
public class MutableXMLStreamReader
extends org.codehaus.stax2.util.StreamReader2Delegate
implements AutoCloseable
A mutable
XMLStreamReader2, allowing simple string manipulation (replacement) of the underlying document-
Field Summary
Fields inherited from class org.codehaus.stax2.util.StreamReader2Delegate
_delegate2Fields inherited from interface javax.xml.stream.XMLStreamConstants
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENTFields inherited from interface org.codehaus.stax2.XMLStreamReader2
FEATURE_DTD_OVERRIDE -
Constructor Summary
ConstructorsConstructorDescriptionMutableXMLStreamReader(InputStream inputStream, Path fileName) Constructs a new object using the contents of the given input stream as the initial contents of the document.MutableXMLStreamReader(Path path) Constructs a new object using the contents of the given file as the initial contents of the document. -
Method Summary
Modifier and TypeMethodDescriptionvoidRemoves the mark under the givenmarkNrgetBetween(Object mark1, Object mark2) Returns the substring of the document between the end of the first mark and the start of the second marked elementintReturns current (adjusted bydeltaending char offsetintReturns current (adjusted bydeltastarting char offsetReturns the name of the file associated with the documentReturns the current state of the document, in string formatbooleanIf the mark with the givenmarkNrhas been recordedbooleanWhether the document has been modifiedvoidRecords the currentLocationInfoand delta under the givenmarkNrintnext()voidReplaces the current element with the replacement textvoidreplaceBetween(Object mark1, Object mark2, String replacement) Replaces the document between two marks with the given replacement.voidreplaceMark(Object mark, String replacement) Replaces the document between the starting and ending character offset of the given markvoidrewind()Recreates the underlying delegateXMLStreamReader2based on the current state of the documentMethods inherited from class org.codehaus.stax2.util.StreamReader2Delegate
closeCompletely, getAttributeAs, getAttributeAsArray, getAttributeAsBinary, getAttributeAsBinary, getAttributeAsBoolean, getAttributeAsDecimal, getAttributeAsDouble, getAttributeAsDoubleArray, getAttributeAsFloat, getAttributeAsFloatArray, getAttributeAsInt, getAttributeAsIntArray, getAttributeAsInteger, getAttributeAsLong, getAttributeAsLongArray, getAttributeAsQName, getAttributeIndex, getAttributeInfo, getDepth, getDTDInfo, getElementAs, getElementAsBinary, getElementAsBinary, getElementAsBoolean, getElementAsDecimal, getElementAsDouble, getElementAsFloat, getElementAsInt, getElementAsInteger, getElementAsLong, getElementAsQName, getFeature, getLocationInfo, getNonTransientNamespaceContext, getPrefixedName, getText, isEmptyElement, isPropertySupported, readElementAsArray, readElementAsBinary, readElementAsBinary, readElementAsDoubleArray, readElementAsFloatArray, readElementAsIntArray, readElementAsLongArray, setFeature, setParent, setProperty, setValidationProblemHandler, skipElement, stopValidatingAgainst, stopValidatingAgainst, validateAgainstMethods inherited from class javax.xml.stream.util.StreamReaderDelegate
close, getAttributeCount, getAttributeLocalName, getAttributeName, getAttributeNamespace, getAttributePrefix, getAttributeType, getAttributeValue, getAttributeValue, getCharacterEncodingScheme, getElementText, getEncoding, getEventType, getLocalName, getLocation, getName, getNamespaceContext, getNamespaceCount, getNamespacePrefix, getNamespaceURI, getNamespaceURI, getNamespaceURI, getParent, getPIData, getPITarget, getPrefix, getProperty, getText, getTextCharacters, getTextCharacters, getTextLength, getTextStart, getVersion, hasName, hasNext, hasText, isAttributeSpecified, isCharacters, isEndElement, isStandalone, isStartElement, isWhiteSpace, nextTag, require, standaloneSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.AutoCloseable
closeMethods inherited from interface javax.xml.stream.XMLStreamReader
close, getAttributeCount, getAttributeLocalName, getAttributeName, getAttributeNamespace, getAttributePrefix, getAttributeType, getAttributeValue, getAttributeValue, getCharacterEncodingScheme, getElementText, getEncoding, getEventType, getLocalName, getLocation, getName, getNamespaceContext, getNamespaceCount, getNamespacePrefix, getNamespaceURI, getNamespaceURI, getNamespaceURI, getPIData, getPITarget, getPrefix, getProperty, getText, getTextCharacters, getTextCharacters, getTextLength, getTextStart, getVersion, hasName, hasNext, hasText, isAttributeSpecified, isCharacters, isEndElement, isStandalone, isStartElement, isWhiteSpace, nextTag, require, standaloneSet
-
Constructor Details
-
MutableXMLStreamReader
public MutableXMLStreamReader(Path path) throws IOException, XMLStreamException, TransformerException Constructs a new object using the contents of the given file as the initial contents of the document.- Parameters:
path- file containing the initial document contents- Throws:
IOException- thrown in case of an I/O problemsXMLStreamException- thrown if the file cannot be parsedTransformerException
-
MutableXMLStreamReader
public MutableXMLStreamReader(InputStream inputStream, Path fileName) throws IOException, XMLStreamException, TransformerException Constructs a new object using the contents of the given input stream as the initial contents of the document.- Parameters:
inputStream- stream containing the initial document contentsfileName- name of the file- Throws:
IOException- thrown in case of an I/O problemsXMLStreamException- thrown if the file cannot be parsedTransformerException
-
-
Method Details
-
getFileName
Returns the name of the file associated with the document- Returns:
- name of the file associated with the document
-
getSource
Returns the current state of the document, in string format- Returns:
- current state of the document, in string format
-
isModified
public boolean isModified()Whether the document has been modified- Returns:
trueif the document has been modified
-
getCurrentStartingCharOffset
public int getCurrentStartingCharOffset()Returns current (adjusted bydeltastarting char offset- Returns:
- current (adjusted by
deltastarting char offset
-
getCurrentEndingCharOffset
public int getCurrentEndingCharOffset()Returns current (adjusted bydeltaending char offset- Returns:
- current (adjusted by
deltaending char offset
-
replace
Replaces the current element with the replacement text- Parameters:
replacement- string replacing the current element
-
getBetween
Returns the substring of the document between the end of the first mark and the start of the second marked element- Parameters:
mark1- starting mark of the substringmark2- ending mark of the substring- Returns:
- substring of the document between two marks
-
replaceBetween
Replaces the document between two marks with the given replacement.- Parameters:
mark1- starting mark of the string to be replacedmark2- ending mark of the string to be replacedreplacement- replacement string
-
replaceMark
Replaces the document between the starting and ending character offset of the given mark- Parameters:
mark- mark to be replaced between its starting and ending character offsetreplacement- replacement string
-
rewind
Recreates the underlying delegateXMLStreamReader2based on the current state of the document- Throws:
XMLStreamException- thrown if the document cannot be parsed
-
next
- Specified by:
nextin interfaceXMLStreamReader- Overrides:
nextin classStreamReaderDelegate- Throws:
XMLStreamException
-
hasMark
If the mark with the givenmarkNrhas been recorded- Parameters:
markNr- number of the mark to check- Returns:
trueif the given mark exists
-
mark
Records the currentLocationInfoand delta under the givenmarkNr- Parameters:
markNr- number of the mark to record to
-
clearMark
Removes the mark under the givenmarkNr- Parameters:
markNr- number of the mark to remove
-