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
  • Constructor Details

  • Method Details

    • getFileName

      public Path getFileName()
      Returns the name of the file associated with the document
      Returns:
      name of the file associated with the document
    • getSource

      public String 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:
      true if the document has been modified
    • getCurrentStartingCharOffset

      public int getCurrentStartingCharOffset()
      Returns current (adjusted by delta starting char offset
      Returns:
      current (adjusted by delta starting char offset
    • getCurrentEndingCharOffset

      public int getCurrentEndingCharOffset()
      Returns current (adjusted by delta ending char offset
      Returns:
      current (adjusted by delta ending char offset
    • replace

      public void replace(String replacement)
      Replaces the current element with the replacement text
      Parameters:
      replacement - string replacing the current element
    • getBetween

      public String getBetween(Object mark1, Object mark2)
      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 substring
      mark2 - ending mark of the substring
      Returns:
      substring of the document between two marks
    • replaceBetween

      public void replaceBetween(Object mark1, Object mark2, String replacement)
      Replaces the document between two marks with the given replacement.
      Parameters:
      mark1 - starting mark of the string to be replaced
      mark2 - ending mark of the string to be replaced
      replacement - replacement string
    • replaceMark

      public void replaceMark(Object mark, String replacement)
      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 offset
      replacement - replacement string
    • rewind

      public void rewind() throws XMLStreamException
      Recreates the underlying delegate XMLStreamReader2 based on the current state of the document
      Throws:
      XMLStreamException - thrown if the document cannot be parsed
    • next

      public int next() throws XMLStreamException
      Specified by:
      next in interface XMLStreamReader
      Overrides:
      next in class StreamReaderDelegate
      Throws:
      XMLStreamException
    • hasMark

      public boolean hasMark(Object markNr)
      If the mark with the given markNr has been recorded
      Parameters:
      markNr - number of the mark to check
      Returns:
      true if the given mark exists
    • mark

      public void mark(Object markNr)
      Records the current LocationInfo and delta under the given markNr
      Parameters:
      markNr - number of the mark to record to
    • clearMark

      public void clearMark(Object markNr)
      Removes the mark under the given markNr
      Parameters:
      markNr - number of the mark to remove