
org.openfuxml.addon.wiki.emitter.GlosstermEmitter Maven / Gradle / Ivy
package org.openfuxml.addon.wiki.emitter;
import java.util.HashMap;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.openfuxml.transform.xhtml.EmitterFactory;
import org.openfuxml.transform.xhtml.emitter.SimpleEmitter;
import org.xml.sax.Attributes;
public class GlosstermEmitter extends SimpleEmitter {
private String acronymTitle;
private StringBuilder acronym = new StringBuilder();
public GlosstermEmitter(EmitterFactory ef)
{
super(ef,"glossterm");
}
@Override
protected void localContent(XMLStreamWriter writer, char[] ch, int start, int length) throws XMLStreamException {
if (length > 0) {
acronym.append(ch, start, length);
}
super.localContent(writer, ch, start, length);
}
@Override
public boolean localEnd(XMLStreamWriter writer, String htmlElementName) throws XMLStreamException {
HashMap acronyms = new HashMap();
if (acronym.length() > 0) {
String acronym = this.acronym.toString().trim();
if (acronym.length() > 0) {
String previousTitle = acronyms.put(acronym, acronymTitle);
if (previousTitle != null) {
if (acronymTitle == null || previousTitle.length() > acronymTitle.length()) {
acronyms.put(acronym, previousTitle);
}
}
}
}
return super.localEnd(writer, htmlElementName);
}
@Override
public boolean localStart(XMLStreamWriter writer, String htmlElementName, Attributes atts) throws XMLStreamException {
if (htmlElementName.equals("acronym")) {
acronymTitle = atts.getValue("title");
}
return super.localStart(writer, htmlElementName, atts);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy