org.codehaus.mojo.versions.rewriting
Class ModifiedPomXMLEventReader

java.lang.Object
  extended by org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader
All Implemented Interfaces:
Iterator, javax.xml.stream.XMLEventReader

public class ModifiedPomXMLEventReader
extends Object
implements javax.xml.stream.XMLEventReader

Represents the modified pom file. Note: implementations of the StAX API (JSR-173) are not good round-trip rewriting while keeping all unchanged bytes in the file as is. For example, the StAX API specifies that CR characters will be stripped. Current implementations do not keep " and ' characters consistent.

Author:
Stephen Connolly

Constructor Summary
ModifiedPomXMLEventReader(StringBuffer pom, javax.xml.stream.XMLInputFactory factory)
          Constructor ModifiedPomXMLEventReader creates a new ModifiedPomXMLEventReader instance.
 
Method Summary
 StringBuffer asStringBuffer()
          Returns a copy of the backing string buffer.
 void clearMark(int index)
          Clears the mark.
 void close()
          
 String getBetween(int index1, int index2)
           
 String getElementText()
          
 String getMarkVerbatim(int index)
          the verbatim text of the current element when mark(int) was called.
 String getPeekVerbatim()
          Returns the verbatim text of the element returned by peek().
 Object getProperty(String name)
          
 String getVerbatim()
          Getter for property 'verbatim'.
 boolean hasMark(int index)
          Returns true if the specified mark is defined.
 boolean hasNext()
          
 boolean isModified()
          Getter for property 'modified'.
 void mark(int index)
          Sets a mark to the current event.
 Object next()
          
 javax.xml.stream.events.XMLEvent nextEvent()
          
 javax.xml.stream.events.XMLEvent nextTag()
          
 org.apache.maven.model.Model parse()
           
 javax.xml.stream.events.XMLEvent peek()
          
 void remove()
          
 void replace(String replacement)
          Replaces the current element with the replacement text.
 void replaceBetween(int index1, int index2, String replacement)
          Replaces all content between marks index1 and index2 with the replacement text.
 void replaceMark(int index, String replacement)
          Replaces the specified marked element with the replacement text.
 void rewind()
          Rewind to the start so we can run through again.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModifiedPomXMLEventReader

public ModifiedPomXMLEventReader(StringBuffer pom,
                                 javax.xml.stream.XMLInputFactory factory)
                          throws javax.xml.stream.XMLStreamException
Constructor ModifiedPomXMLEventReader creates a new ModifiedPomXMLEventReader instance.

Parameters:
pom - of type StringBuffer
factory - of type XMLInputFactory
Throws:
javax.xml.stream.XMLStreamException - when
Method Detail

rewind

public void rewind()
            throws javax.xml.stream.XMLStreamException
Rewind to the start so we can run through again.

Throws:
javax.xml.stream.XMLStreamException - when things go wrong.

isModified

public boolean isModified()
Getter for property 'modified'.

Returns:
Value for property 'modified'.

next

public Object next()

Specified by:
next in interface Iterator

remove

public void remove()

Specified by:
remove in interface Iterator

nextEvent

public javax.xml.stream.events.XMLEvent nextEvent()
                                           throws javax.xml.stream.XMLStreamException

Specified by:
nextEvent in interface javax.xml.stream.XMLEventReader
Throws:
javax.xml.stream.XMLStreamException

peek

public javax.xml.stream.events.XMLEvent peek()
                                      throws javax.xml.stream.XMLStreamException

Specified by:
peek in interface javax.xml.stream.XMLEventReader
Throws:
javax.xml.stream.XMLStreamException

getElementText

public String getElementText()
                      throws javax.xml.stream.XMLStreamException

Specified by:
getElementText in interface javax.xml.stream.XMLEventReader
Throws:
javax.xml.stream.XMLStreamException

nextTag

public javax.xml.stream.events.XMLEvent nextTag()
                                         throws javax.xml.stream.XMLStreamException

Specified by:
nextTag in interface javax.xml.stream.XMLEventReader
Throws:
javax.xml.stream.XMLStreamException

getProperty

public Object getProperty(String name)

Specified by:
getProperty in interface javax.xml.stream.XMLEventReader

close

public void close()
           throws javax.xml.stream.XMLStreamException

Specified by:
close in interface javax.xml.stream.XMLEventReader
Throws:
javax.xml.stream.XMLStreamException

asStringBuffer

public StringBuffer asStringBuffer()
Returns a copy of the backing string buffer.

Returns:
a copy of the backing string buffer.

clearMark

public void clearMark(int index)
Clears the mark.

Parameters:
index - the mark to clear.

getMarkVerbatim

public String getMarkVerbatim(int index)
the verbatim text of the current element when mark(int) was called.

Parameters:
index - The mark index.
Returns:
the current element when mark(int) was called.

getPeekVerbatim

public String getPeekVerbatim()
Returns the verbatim text of the element returned by peek().

Returns:
the verbatim text of the element returned by peek().

hasNext

public boolean hasNext()

Specified by:
hasNext in interface Iterator
Specified by:
hasNext in interface javax.xml.stream.XMLEventReader

getVerbatim

public String getVerbatim()
Getter for property 'verbatim'.

Returns:
Value for property 'verbatim'.

mark

public void mark(int index)
Sets a mark to the current event.

Parameters:
index - the mark to set.

replace

public void replace(String replacement)
Replaces the current element with the replacement text.

Parameters:
replacement - The replacement.

hasMark

public boolean hasMark(int index)
Returns true if the specified mark is defined.

Parameters:
index - The mark.
Returns:
true if the specified mark is defined.

getBetween

public String getBetween(int index1,
                         int index2)

replaceBetween

public void replaceBetween(int index1,
                           int index2,
                           String replacement)
Replaces all content between marks index1 and index2 with the replacement text.

Parameters:
index1 - The event mark to replace after.
index2 - The event mark to replace before.
replacement - The replacement.

replaceMark

public void replaceMark(int index,
                        String replacement)
Replaces the specified marked element with the replacement text.

Parameters:
index - The mark.
replacement - The replacement.

parse

public org.apache.maven.model.Model parse()
                                   throws IOException,
                                          org.codehaus.plexus.util.xml.pull.XmlPullParserException
Throws:
IOException
org.codehaus.plexus.util.xml.pull.XmlPullParserException


Copyright © 2008-2011 Codehaus. All Rights Reserved.