X4O: Removed iterator for tree walker and bettered tag folding code
This commit is contained in:
parent
045f6d07f6
commit
9638d876b5
6 changed files with 27 additions and 16 deletions
|
|
@ -73,6 +73,13 @@ public abstract class AbstractX4OPhase implements X4OPhase {
|
|||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
}
|
||||
|
||||
/**
|
||||
* If the session has an debug writer than ouput an phase message for debugging to the writer.
|
||||
*
|
||||
* @param languageSession The language session to run phase for.
|
||||
* @param message The message to write the the debug output.
|
||||
* @throws X4OPhaseException when debug writer has error.
|
||||
*/
|
||||
public void debugPhaseMessage(X4OLanguageSession languageSession, String message) throws X4OPhaseException {
|
||||
if (!languageSession.hasX4ODebugWriter()) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import org.x4o.xml.lang.X4OLanguageSession;
|
|||
import org.x4o.xml.lang.X4OLanguageSessionLocal;
|
||||
|
||||
/**
|
||||
* X4OPhaseManager stores the X4OPhaseHandler and puts them in the right order. And will execute the phases when runPhases is called.
|
||||
* DefaultX4OPhaseManager stores the X4O phases and runs them in the right order.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 6, 2008
|
||||
|
|
@ -263,14 +263,11 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
}
|
||||
|
||||
class X4OPhaseComparator implements Comparator<X4OPhase> {
|
||||
/**
|
||||
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public int compare(X4OPhase e1, X4OPhase e2) {
|
||||
|
||||
@Override
|
||||
public int compare(X4OPhase e1, X4OPhase e2) {
|
||||
String pid = e1.getId();
|
||||
String[] dpids = e2.getPhaseDependencies();
|
||||
|
||||
for (int i = 0; i < dpids.length; i++) {
|
||||
String dpid = dpids[i];
|
||||
if (pid.equals(dpid)) {
|
||||
|
|
@ -305,7 +302,10 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
if (element.getElementClass() != null && element.getElementClass().getSkipPhases().contains(phase.getId()) == false) {
|
||||
phase.runElementPhase(element);
|
||||
}
|
||||
for (Element e : element.getChilderen()) {
|
||||
List<Element> elementChilderen = element.getChilderen();
|
||||
int elementChilderenSize = elementChilderen.size();
|
||||
for (int i = 0; i < elementChilderenSize; i++) {
|
||||
Element e = elementChilderen.get(i);
|
||||
executePhaseTree(e, phase);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ package org.x4o.xml.lang.phase;
|
|||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
|
||||
/**
|
||||
* An X4OPhaseListener can be placed on an X4OPhaseHandler and is called before and after the phase has runned.
|
||||
* An X4OPhaseListener is fired before and after the phase has been executed.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Dec 31, 2008
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ import org.xml.sax.helpers.AttributesImpl;
|
|||
*/
|
||||
public class SAX3WriterEnum<TAG extends Enum<?>, TAG_WRITER extends ContentWriter> implements SAX3WriterEnumHammer<TAG>, Closeable {
|
||||
|
||||
private final Attributes EMPTY_ATTRIBUTES = new AttributesImpl();
|
||||
static private final Attributes EMPTY_ATTRIBUTES = new AttributesImpl();
|
||||
private final TAG_WRITER contentWriter;
|
||||
private final String tagNamespaceUri;
|
||||
private final String tagNamespacePrefix;
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ import org.xml.sax.helpers.AttributesImpl;
|
|||
*/
|
||||
public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag, SAX3WriterXml> {
|
||||
|
||||
static public final List<String> HTML_VOID_TAGS = Collections.unmodifiableList(Tag.valuesVoidElement());
|
||||
static private final List<String> HTML_VOID_TAGS = Collections.unmodifiableList(Tag.valuesVoidElementAsString());
|
||||
|
||||
public SAX3WriterHtml(Writer out, String encoding) {
|
||||
super(new SAX3WriterXml(out, encoding), "", SAX3XMLConstants.NULL_NS_URI);
|
||||
|
|
@ -397,8 +397,12 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag, SAX3Write
|
|||
return voidElement;
|
||||
}
|
||||
|
||||
static public List<String> valuesVoidElement() {
|
||||
return Arrays.stream(values()).filter(v -> v.voidElement()).map(v -> v.name()).toList();
|
||||
static public List<Tag> valuesVoidElement() {
|
||||
return Arrays.stream(values()).filter(v -> v.voidElement()).toList();
|
||||
}
|
||||
|
||||
static public List<String> valuesVoidElementAsString() {
|
||||
return valuesVoidElement().stream().map(v -> v.name()).toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -477,11 +477,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
|||
}
|
||||
|
||||
private boolean allowEndElementFolding(String tag) {
|
||||
if (getPropertyConfig().getProperty(OUTPUT_FOLD_EMPTY_TAGS) == null) {
|
||||
return true;
|
||||
}
|
||||
if (foldEmptyTags == null) {
|
||||
foldEmptyTags = new HashSet<>();
|
||||
if (getPropertyConfig().getProperty(OUTPUT_FOLD_EMPTY_TAGS) != null) {
|
||||
foldEmptyTags.addAll(getPropertyConfig().getPropertyList(OUTPUT_FOLD_EMPTY_TAGS));
|
||||
}
|
||||
foldEmptyTags = new HashSet<>(getPropertyConfig().getPropertyList(OUTPUT_FOLD_EMPTY_TAGS));
|
||||
}
|
||||
if (foldEmptyTags.isEmpty()) {
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue