-
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.
feat(bookmarks): Permit references to tags from previous invocations
- Loading branch information
1 parent
59e9c64
commit 2720eb2
Showing
8 changed files
with
345 additions
and
26 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/main/java/com/github/olivergondza/saxeed/Bookmark.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,19 @@ | ||
package com.github.olivergondza.saxeed; | ||
|
||
/** | ||
* A reference to a tag acquired in a previous Saxeed run, to be queried in the next run. | ||
* | ||
* The reference is valid only between to consecutive runs. Provided the document was modified between the executions, | ||
* Saxeed provides no guarantee it will match anything, fail predictable, or match the intended tag. | ||
* | ||
* To bookmark an element, call {@link Tag#bookmark()}. The object returned is valid outside the Saxeed transformation. | ||
* In the next processing, use {@link Tag#isBookmarked(Bookmark)} or {@link Tag#isBookmarked(java.util.List)} to | ||
* identify the element, | ||
*/ | ||
public interface Bookmark { | ||
|
||
/** | ||
* Determine if the tag was removed from the output. | ||
*/ | ||
boolean isOmitted(); | ||
} |
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
11 changes: 0 additions & 11 deletions
11
src/main/java/com/github/olivergondza/saxeed/Transformation.java
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
src/main/java/com/github/olivergondza/saxeed/internal/BookmarkImpl.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,74 @@ | ||
package com.github.olivergondza.saxeed.internal; | ||
|
||
import com.github.olivergondza.saxeed.Bookmark; | ||
import com.github.olivergondza.saxeed.TagName; | ||
|
||
import java.util.Objects; | ||
|
||
public class BookmarkImpl implements Bookmark { | ||
private String value; | ||
private boolean omitted = false; | ||
|
||
static BookmarkImpl from(BookmarkImpl parent, TagName name, int count) { | ||
return new BookmarkImpl(pathFrom(parent, name, count)); | ||
} | ||
|
||
static String pathFrom(BookmarkImpl parent, TagName name, int count) { | ||
StringBuilder sb = new StringBuilder(); | ||
if (parent != null) { | ||
assert parent.value != null: "Parent tag " + parent + " must not be written by the time its children " + name + " are still being created."; | ||
sb.append(parent.value); | ||
} | ||
|
||
sb.append('/').append(name.getLocal()); | ||
String nsUri = name.getNsUri(); | ||
if (!nsUri.isEmpty()) { | ||
sb.append('<').append(nsUri).append('>'); | ||
} | ||
sb.append('[').append(count).append(']'); | ||
return sb.toString(); | ||
} | ||
|
||
private BookmarkImpl(String bookmark) { | ||
this.value = bookmark; | ||
} | ||
|
||
/*package*/ void update(String value) { | ||
this.value = value; | ||
} | ||
|
||
/*package*/ void omit() { | ||
omitted = true; | ||
} | ||
|
||
@Override | ||
public boolean isOmitted() { | ||
return omitted; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
BookmarkImpl bookmark = (BookmarkImpl) o; | ||
|
||
// If either is omitted, they are not equal. This is to prevent that omitted bookmark would match real tag based | ||
// on value clash. | ||
if (omitted || bookmark.omitted) { | ||
return false; | ||
} | ||
|
||
return Objects.equals(value, bookmark.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(value, omitted); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
} |
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.