-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Listen to character events, and emit characters.
- Loading branch information
1 parent
9028193
commit 13bd7a2
Showing
12 changed files
with
767 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/com/github/olivergondza/saxeed/internal/CharChunk.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.github.olivergondza.saxeed.internal; | ||
|
||
import javax.xml.stream.XMLStreamException; | ||
import javax.xml.stream.XMLStreamWriter; | ||
|
||
public class CharChunk { | ||
private char[] origData; | ||
private int origStart; | ||
private int origLength; | ||
|
||
/** | ||
* Updated content. | ||
*/ | ||
private String replacement; | ||
|
||
public CharChunk() { | ||
} | ||
|
||
public void update(char[] charsData, int charsStart, int charsLength) { | ||
origData = charsData; | ||
origStart = charsStart; | ||
origLength = charsLength; | ||
replacement = null; | ||
} | ||
|
||
public void update(String text) { | ||
replacement = text; | ||
origData = null; | ||
origStart = -1; | ||
origLength = -1; | ||
} | ||
|
||
public void clear() { | ||
update(null); | ||
} | ||
|
||
public boolean isEmpty() { | ||
return origData == null && replacement == null; | ||
} | ||
|
||
public String get() { | ||
if (replacement != null) { | ||
return replacement; | ||
} | ||
|
||
// cleared | ||
if (origData == null) { | ||
return null; | ||
} | ||
|
||
// Construct the String iff some visitor really need a String instance. | ||
// This is to prevent data copying/allocation that might not be needed. | ||
replacement = new String(origData, origStart, origLength); | ||
return replacement; | ||
} | ||
|
||
/*package*/ void write(XMLStreamWriter writer) throws XMLStreamException { | ||
// origData are erased when content is updated | ||
if (origData != null) { | ||
writer.writeCharacters(origData, origStart, origLength); | ||
} else { | ||
writer.writeCharacters(replacement); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/github/olivergondza/saxeed/internal/Element.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.github.olivergondza.saxeed.internal; | ||
|
||
import javax.xml.stream.XMLStreamException; | ||
import javax.xml.stream.XMLStreamWriter; | ||
|
||
/** | ||
* Element introduced by visitor to be added to the output document. | ||
*/ | ||
public interface Element { | ||
/** | ||
* Element that can write itself to XMLStreamWriter. | ||
*/ | ||
interface SelfWriting extends Element { | ||
void write(XMLStreamWriter writer) throws XMLStreamException; | ||
} | ||
|
||
final class TextString implements SelfWriting { | ||
private final String text; | ||
|
||
public TextString(String text) { | ||
this.text = text; | ||
} | ||
|
||
@Override | ||
public void write(XMLStreamWriter writer) throws XMLStreamException { | ||
writer.writeCharacters(text); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.