-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Pablo Herrera <[email protected]>
- Loading branch information
1 parent
e61683f
commit 24e8a26
Showing
16 changed files
with
328 additions
and
53 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
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
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
75 changes: 75 additions & 0 deletions
75
util/src/main/java/tc/oc/pgm/util/xml/DocumentWrapper.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,75 @@ | ||
package tc.oc.pgm.util.xml; | ||
|
||
import com.google.common.collect.Sets; | ||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
import org.jdom2.Attribute; | ||
import org.jdom2.Content; | ||
import org.jdom2.DocType; | ||
import org.jdom2.Document; | ||
import org.jdom2.Element; | ||
import org.jdom2.Namespace; | ||
|
||
public class DocumentWrapper extends Document { | ||
|
||
private static final Set<String> IGNORED = Sets.newHashSet("variant", "tutorial"); | ||
|
||
private boolean visitingAllowed = true; | ||
|
||
public DocumentWrapper() { | ||
super(); | ||
} | ||
|
||
public DocumentWrapper(Element rootElement, DocType docType, String baseURI) { | ||
super(rootElement, docType, baseURI); | ||
} | ||
|
||
public DocumentWrapper(Element rootElement, DocType docType) { | ||
super(rootElement, docType); | ||
} | ||
|
||
public DocumentWrapper(Element rootElement) { | ||
super(rootElement); | ||
} | ||
|
||
public void setVisitingAllowed(boolean visitingAllowed) { | ||
this.visitingAllowed = visitingAllowed; | ||
} | ||
|
||
public void runWithoutVisitation(DocumentWorker worker) throws InvalidXMLException { | ||
this.visitingAllowed = false; | ||
worker.run(); | ||
this.visitingAllowed = true; | ||
} | ||
|
||
public boolean isVisitingAllowed() { | ||
return visitingAllowed; | ||
} | ||
|
||
public void checkUnvisited(Consumer<Node> unvisited) { | ||
checkVisited(getRootElement(), unvisited); | ||
} | ||
|
||
private void checkVisited(Element el, Consumer<Node> unvisited) { | ||
for (Attribute attribute : el.getAttributes()) { | ||
if (attribute.getNamespace() == Namespace.NO_NAMESPACE | ||
&& !((VisitableAttribute) attribute).wasVisited()) | ||
unvisited.accept(Node.fromNullable(attribute)); | ||
} | ||
|
||
for (int i = 0; i < el.getContentSize(); i++) { | ||
Content c = el.getContent(i); | ||
if (!(c instanceof InheritingElement)) continue; | ||
InheritingElement child = (InheritingElement) c; | ||
|
||
if (child.getNamespace() == Namespace.NO_NAMESPACE && !IGNORED.contains(child.getName())) { | ||
if (!child.wasVisited()) unvisited.accept(Node.fromNullable(child)); | ||
else checkVisited(child, unvisited); | ||
} | ||
} | ||
} | ||
|
||
public interface DocumentWorker { | ||
void run() throws InvalidXMLException; | ||
} | ||
} |
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.