Split xml tag writer from content writer interface object hierachy.

This commit is contained in:
Willem Cazander 2014-03-14 19:03:56 +01:00
parent 80ade0b3f4
commit 82d966b849
17 changed files with 294 additions and 212 deletions

View file

@ -131,14 +131,14 @@ public class EldDocWriterElementClass extends AbstractApiDocWriter {
writer.printTagCharacters(Tag.dt,"All Element Parents:");
writer.printTagStart(Tag.dd);
if (parents.isEmpty()) {
writer.characters("No parent.");
writer.printCharacters("No parent.");
}
for (int i=0;i<parents.size();i++) {
TreeNode n = parents.get(i);
String uri = toElementUri(pathPrefix, n.module, n.namespace, n.elementClass);
writer.printHref(uri, n.namespace.getId()+":"+n.elementClass.getId());
if (i<parents.size()-1) {
writer.characters(",&nbsp;");
writer.printCharacters(",&nbsp;");
}
}
writer.printTagEnd(Tag.dd);
@ -149,14 +149,14 @@ public class EldDocWriterElementClass extends AbstractApiDocWriter {
writer.printTagCharacters(Tag.dt,"All Element Childeren:");
writer.printTagStart(Tag.dd);
if (childs.isEmpty()) {
writer.characters("No childeren.");
writer.printCharacters("No childeren.");
}
for (int i=0;i<childs.size();i++) {
TreeNode n = childs.get(i);
String uri = toElementUri(pathPrefix, n.module, n.namespace, n.elementClass);
writer.printHref(uri, n.namespace.getId()+":"+n.elementClass.getId());
if (i<childs.size()-1) {
writer.characters(",&nbsp;");
writer.printCharacters(",&nbsp;");
}
}
writer.printTagEnd(Tag.dd);

View file

@ -61,8 +61,8 @@ public class EldDocXTreePageWriter extends DefaultPageWriterTree implements ApiD
writer.printTagStart(Tag.ul);
writer.printTagStart(Tag.li,"",null,"circle");
writer.characters(node.namespace.getId());
writer.characters(":");
writer.printCharacters(node.namespace.getId());
writer.printCharacters(":");
writer.printHref(href, node.elementClass.getId(), node.elementClass.getId(), "strong");
writer.printTagEnd(Tag.li);

View file

@ -149,7 +149,7 @@ public abstract class AbstractApiDocWriter {
writer.docTableRowLastStart(n, null);
String c = printValue(doc,writer,value);
if (c!=null) {
writer.characters(c);
writer.printCharacters(c);
}
writer.docTableRowLastEnd();
}

View file

@ -45,12 +45,12 @@ public class ApiDocContentWriter extends ContentWriterHtml {
}
public void docCommentGenerated() throws SAXException {
comment("Generated by "+ApiDocContentWriter.class.getSimpleName()+" on "+new Date());
printComment("Generated by "+ApiDocContentWriter.class.getSimpleName()+" on "+new Date());
}
public void docHtmlStart(String title,List<String> keywords,String pathPrefix) throws SAXException {
printDocType(DocType.HTML_4_TRANSITIONAL);
comment("NewPage");
printComment("NewPage");
printHtmlStart("en");
// ====== Write head
@ -80,7 +80,7 @@ public class ApiDocContentWriter extends ContentWriterHtml {
public void docHtmlEnd(String copyright,String statsJS) throws SAXException {
printTagStart(Tag.p,ApiDocContentCss.legalCopy);
printTagStart(Tag.small);
characters(copyright);
printCharacters(copyright);
printTagEnd(Tag.small);
printTagEnd(Tag.p);
if (statsJS!=null) {
@ -97,7 +97,7 @@ public class ApiDocContentWriter extends ContentWriterHtml {
String[] lines = about.split("\n");
for (int i=0;i<lines.length;i++) {
String line = lines[i];
characters(line);
printCharacters(line);
if (i<lines.length-1) {
printTagStartEnd(Tag.br);
}
@ -114,7 +114,7 @@ public class ApiDocContentWriter extends ContentWriterHtml {
printTagCharacters(Tag.div, summary,ApiDocContentCss.block.name());
printTagEnd(Tag.div);
printTagStart(Tag.p);
characters("See:&nbsp;");
printCharacters("See:&nbsp;");
printHref("#package_description", "Description");
printTagEnd(Tag.p);
printTagEnd(Tag.div);
@ -124,15 +124,15 @@ public class ApiDocContentWriter extends ContentWriterHtml {
printHrefNamed("package_description");
printTagCharacters(Tag.h2, title);
printTagCharacters(Tag.div, summary,ApiDocContentCss.block.name());
characters(description);
printCharacters(description);
}
public void docPageClassStart(String title,String subTitle,Tag titleTag) throws SAXException {
comment("======== START OF CLASS DATA ========");
printComment("======== START OF CLASS DATA ========");
printTagStart(Tag.div,ApiDocContentCss.header);
if (subTitle!=null) {
printTagStart(Tag.div,ApiDocContentCss.subTitle);
characters(subTitle);
printCharacters(subTitle);
printTagEnd(Tag.div);
}
printTagCharacters(titleTag, title, "title");
@ -140,7 +140,7 @@ public class ApiDocContentWriter extends ContentWriterHtml {
}
public void docPageClassEnd() throws SAXException {
comment("======== END OF CLASS DATA ========");
printComment("======== END OF CLASS DATA ========");
}
public void docPageContentStart() throws SAXException {
@ -153,7 +153,7 @@ public class ApiDocContentWriter extends ContentWriterHtml {
public void docPageBlockStart(String title,String namedLink,String comment) throws SAXException {
if (comment!=null) {
comment(comment);
printComment(comment);
}
docPageBlockStart();
printHrefNamed(namedLink);
@ -186,11 +186,11 @@ public class ApiDocContentWriter extends ContentWriterHtml {
if (tableDescription!=null) {
atts.addAttribute ("", "summary", "", "", tableDescription);
}
startElement("", "table", "", atts);
printTagStart(Tag.table,atts);
printTagStart(Tag.caption);
printTagStart(Tag.span);characters(tableTitle);printTagEnd(Tag.span);
printTagStart(Tag.span,ApiDocContentCss.tabEnd);characters("&nbsp;");printTagEnd(Tag.span);
printTagStart(Tag.span);printCharacters(tableTitle);printTagEnd(Tag.span);
printTagStart(Tag.span,ApiDocContentCss.tabEnd);printCharacters("&nbsp;");printTagEnd(Tag.span);
printTagEnd(Tag.caption);
}
@ -208,9 +208,9 @@ public class ApiDocContentWriter extends ContentWriterHtml {
atts.addAttribute ("", "class", "", "", ApiDocContentCss.colFirst.name());
}
atts.addAttribute ("", "scope", "", "", "col");
startElement("", "th", "", atts);
characters(titleFirst);
endElement("", "th", "");
printTagStart(Tag.th,atts);
printCharacters(titleFirst);
printTagEnd(Tag.th);
if (titleLast==null) {
printTagEnd(Tag.tr);
return;
@ -218,8 +218,8 @@ public class ApiDocContentWriter extends ContentWriterHtml {
atts = new AttributesImpl();
atts.addAttribute ("", "class", "", "", ApiDocContentCss.colLast.name());
atts.addAttribute ("", "scope", "", "", "col");
startElement("", "th", "", atts);
characters(titleLast);
printTagStart(Tag.th,atts);
printCharacters(titleLast);
printTagEnd(Tag.th);
printTagEnd(Tag.tr);
}
@ -261,7 +261,7 @@ public class ApiDocContentWriter extends ContentWriterHtml {
printTagStart(Tag.code);
}
if (dataFirstHref==null) {
characters(dataFirst);
printCharacters(dataFirst);
} else {
printHref(dataFirstHref, dataFirst, dataFirst);
}
@ -282,12 +282,12 @@ public class ApiDocContentWriter extends ContentWriterHtml {
printTagStart(Tag.td,ApiDocContentCss.colLast);
if (dataLastCode) {
printTagStart(Tag.code);characters(dataLast);printTagEnd(Tag.code);
printTagStart(Tag.code);printCharacters(dataLast);printTagEnd(Tag.code);
} else {
printTagStart(Tag.div,ApiDocContentCss.block);characters(dataLast);printTagEnd(Tag.div);
printTagStart(Tag.div,ApiDocContentCss.block);printCharacters(dataLast);printTagEnd(Tag.div);
}
if (dataBlock!=null) {
printTagStart(Tag.div,ApiDocContentCss.block);characters(dataBlock);printTagEnd(Tag.div);
printTagStart(Tag.div,ApiDocContentCss.block);printCharacters(dataBlock);printTagEnd(Tag.div);
}
printTagEnd(Tag.td);

View file

@ -54,6 +54,7 @@ import org.x4o.xml.eld.doc.api.dom.ApiDocNodeWriter;
import org.x4o.xml.eld.doc.api.dom.ApiDocPage;
import org.x4o.xml.eld.doc.api.dom.ApiDocPageWriter;
import org.x4o.xml.io.XMLConstants;
import org.x4o.xml.io.sax.ext.ContentWriterXml;
import org.x4o.xml.lang.X4OLanguageClassLoader;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -179,7 +180,7 @@ public class ApiDocWriter extends AbstractApiDocWriter {
writer.docPageClassEnd();
docNavBar(writer,false,concept,node);
writer.docHtmlEnd(doc.getDocCopyright(),doc.getDocStatsJS());
writer.closeWriterSafe();
writer.getContentWriterWrapped().closeWriterSafe();
// Writer other files
writeAllFrameNavNode(node);
@ -209,7 +210,7 @@ public class ApiDocWriter extends AbstractApiDocWriter {
}
private void defaultWriteNodeDescription(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
event.getWriter().characters(event.getEventObject().getDescription());
event.getWriter().printCharacters(event.getEventObject().getDescription());
}
private void writeNodeDescription(ApiDocWriteEvent<ApiDocNode> event,boolean isPageMode) throws SAXException {
@ -418,7 +419,7 @@ public class ApiDocWriter extends AbstractApiDocWriter {
String nodeTitle = node.getId();
if (nodes.hasNext()==false) {
writer.printTagStart(Tag.li);
writer.characters(nodeTitle);
writer.printCharacters(nodeTitle);
writer.printTagEnd(Tag.li);
} else {
writer.printTagStart(Tag.li);
@ -455,8 +456,8 @@ public class ApiDocWriter extends AbstractApiDocWriter {
try {
Writer out = new OutputStreamWriter(new FileOutputStream(outputFile), encoding);
ApiDocContentWriter result = new ApiDocContentWriter(out,encoding);
result.getPropertyConfig().setProperty(ApiDocContentWriter.OUTPUT_CHAR_NEWLINE, XMLConstants.CHAR_NEWLINE+"");
result.getPropertyConfig().setProperty(ApiDocContentWriter.OUTPUT_CHAR_TAB, " ");
result.getPropertyConfig().setProperty(ContentWriterXml.OUTPUT_CHAR_NEWLINE, XMLConstants.CHAR_NEWLINE+"");
result.getPropertyConfig().setProperty(ContentWriterXml.OUTPUT_CHAR_TAB, " ");
return result;
} catch (UnsupportedEncodingException e) {
throw new SAXException(e);
@ -631,13 +632,14 @@ public class ApiDocWriter extends AbstractApiDocWriter {
"\tif (targetPage != \"\" && targetPage != \"undefined\")\n"+
"\t\t { top."+ApiDocContentCss.frameContent.name()+".location = top.targetPage; }\n"+
"}\n";
public void writeIndex() throws SAXException {
File outputFile = createOutputPathFile(basePath,"index.html");
ApiDocContentWriter writer = createContentWriter(outputFile);
try {
writer.printDocType(DocType.HTML_4_FRAMESET);
writer.comment("NewPage");
writer.printComment("NewPage");
writer.printHtmlStart("en");
writeHeader(writer,"",doc.getName());
writer.printScriptInline(FRAME_JS);
@ -682,16 +684,16 @@ public class ApiDocWriter extends AbstractApiDocWriter {
writer.printScriptNoDiv();
writer.printTagCharacters(Tag.h2, "Frame Alert");
writer.printTagStart(Tag.p);
writer.characters("This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to ");
writer.printCharacters("This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to ");
writer.printHref(rootLink, "Non-frame version");
writer.characters(".");
writer.printCharacters(".");
writer.printTagEnd(Tag.p);
writer.printTagEnd(Tag.noframes);
writer.printTagEnd(Tag.frameset);
writer.printHtmlEnd();
} finally {
writer.closeWriterSafe();
writer.getContentWriterWrapped().closeWriterSafe();
}
}
@ -717,7 +719,7 @@ public class ApiDocWriter extends AbstractApiDocWriter {
String conceptParentPlural = conceptParent.getName()+"s";
writer.printDocType(DocType.HTML_4_TRANSITIONAL);
writer.comment("NewPage");
writer.printComment("NewPage");
writer.printHtmlStart("en");
writeHeader(writer,"","All "+conceptPlural+" of "+doc.getName());
writer.printTagStart(Tag.body);
@ -748,7 +750,7 @@ public class ApiDocWriter extends AbstractApiDocWriter {
writer.printTagEnd(Tag.body);
writer.printHtmlEnd();
} finally {
writer.closeWriterSafe();
writer.getContentWriterWrapped().closeWriterSafe();
}
}
@ -790,7 +792,7 @@ public class ApiDocWriter extends AbstractApiDocWriter {
//String conceptParentPlural = conceptParent.getName()+"s";
writer.printDocType(DocType.HTML_4_TRANSITIONAL);
writer.comment("NewPage");
writer.printComment("NewPage");
writer.printHtmlStart("en");
writeHeader(writer,pathPrefix,"All "+conceptPlural+" of "+doc.getName());
writer.printTagStart(Tag.body);
@ -859,7 +861,7 @@ public class ApiDocWriter extends AbstractApiDocWriter {
writer.printTagEnd(Tag.body);
writer.printHtmlEnd();
} finally {
writer.closeWriterSafe();
writer.getContentWriterWrapped().closeWriterSafe();
}
}
@ -887,7 +889,7 @@ public class ApiDocWriter extends AbstractApiDocWriter {
docNavBar(writer,false,null,null);
writer.docHtmlEnd(doc.getDocCopyright(),doc.getDocStatsJS());
} finally {
writer.closeWriterSafe();
writer.getContentWriterWrapped().closeWriterSafe();
}
}
@ -957,7 +959,7 @@ public class ApiDocWriter extends AbstractApiDocWriter {
}
File outputPath = new File(buf.toString());
if (outputPath.exists()==false) {
//System.out.println("Creating path: "+outputPath);
//System.out.println("Creating path: "+outputPath); // TODO add logger
outputPath.mkdirs();
}
buf.append(File.separatorChar);
@ -981,22 +983,22 @@ public class ApiDocWriter extends AbstractApiDocWriter {
barCssDiv = "bottomNav";
barId = "navbar_bottom";
}
writer.comment("========= START OF "+barComment+" NAVBAR =======");
writer.printComment("========= START OF "+barComment+" NAVBAR =======");
writer.printTagStart(Tag.div,barCssDiv);
writer.printHrefNamed(barId); // Print named link navigation
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "href", "", "", "#skip-"+barId);
atts.addAttribute ("", "title", "", "", "Skip navigation links");
writer.startElement("", "a", "", atts);
writer.comment(" ");
writer.endElement("", "a", "");
writer.printTagStart(Tag.a, atts);
writer.printComment(" ");
writer.printTagEnd(Tag.a);
writer.printHrefNamed(barId+"_firstrow");
atts = new AttributesImpl();// Print nav bar
atts.addAttribute ("", "class", "", "", "navList");
atts.addAttribute ("", "title", "", "", "Navigation");
writer.startElement("", "ul", "", atts);
writer.printTagStart(Tag.ul, atts);
for (ApiDocNavLink navLink:conf.getNavLinks()) {
String selectedCss = null;
@ -1015,7 +1017,7 @@ public class ApiDocWriter extends AbstractApiDocWriter {
docNavBarListItemHref(writer,pathPrefix+href,navTitle,navLink.getText(),selectedCss,null,null);
}
}
writer.endElement("", "ul", "");
writer.printTagEnd(Tag.ul);
writer.docNavBarAbout(doc.getDocAbout());
@ -1086,7 +1088,7 @@ public class ApiDocWriter extends AbstractApiDocWriter {
writer.printTagStart(Tag.div); // don't print empty div
}
writer.printTagStart(Tag.ul,ApiDocContentCss.subNavList);
writer.printTagStart(Tag.li);writer.characters(groupName+":&nbsp;");writer.printTagEnd(Tag.li);
writer.printTagStart(Tag.li);writer.printCharacters(groupName+":&nbsp;");writer.printTagEnd(Tag.li);
for (int l=0;l<links.size();l++) {
ApiDocNavLink link = links.get(l);
writer.printTagStart(Tag.li);
@ -1097,9 +1099,9 @@ public class ApiDocWriter extends AbstractApiDocWriter {
if (link.getHref()!=null) {
docNavBarListItemHref(writer,link.getHref(), link.getTitle(), link.getText(), null, null, tab);
} else {
writer.characters(link.getText());
writer.printCharacters(link.getText());
if (tab!=null) {
writer.characters(tab);
writer.printCharacters(tab);
}
}
writer.printTagEnd(Tag.li);
@ -1113,13 +1115,13 @@ public class ApiDocWriter extends AbstractApiDocWriter {
}
writer.printHrefNamed("skip-"+barId);
writer.printTagEnd(Tag.div);
writer.comment("========= END OF "+barComment+" NAVBAR =======");
writer.printComment("========= END OF "+barComment+" NAVBAR =======");
}
private void docNavBarListItemHref(ApiDocContentWriter writer,String href,String title,String text,String cssClass,String spanCss,String linkSpace) throws SAXException {
writer.printTagStart(Tag.li,cssClass);
writer.printHref(href,title,text,spanCss);
writer.characters(linkSpace);
writer.printCharacters(linkSpace);
writer.printTagEnd(Tag.li);
}
}

View file

@ -50,7 +50,7 @@ public class DefaultPageWriterHelp implements ApiDocPageWriter {
writer.printTagStart(Tag.div,"header");
writer.printTagCharacters(Tag.h1, "How This API Document Is Organized", "title");
writer.printTagStart(Tag.div,"subTitle");
writer.characters("This ApiDoc document has pages corresponding to the items in the navigation bar, described as follows.");
writer.printCharacters("This ApiDoc document has pages corresponding to the items in the navigation bar, described as follows.");
writer.printTagEnd(Tag.div);
writer.printTagEnd(Tag.div);
@ -59,14 +59,14 @@ public class DefaultPageWriterHelp implements ApiDocPageWriter {
for (ApiDocConcept concept:doc.getConcepts()) {
writer.printTagCharacters(Tag.h2, concept.getName());
writer.printTagStart(Tag.p);
writer.characters(concept.getDescriptionHelp());
writer.printCharacters(concept.getDescriptionHelp());
writer.printTagEnd(Tag.p);
writer.docPageBlockNext();
}
for (ApiDocPage docPage:doc.getDocPages()) {
writer.printTagCharacters(Tag.h2, docPage.getName());
writer.printTagStart(Tag.p);
writer.characters(docPage.getDescription());
writer.printCharacters(docPage.getDescription());
writer.printTagEnd(Tag.p);
writer.docPageBlockNext();
}

View file

@ -47,12 +47,12 @@ public class DefaultPageWriterIndexAll implements ApiDocPageWriter {
writer.docPageContentStart();
for (char i='A';i<='Z';i++) {
writer.printHref("#_"+i+"_", ""+i);
writer.characters("&nbsp;");
writer.printCharacters("&nbsp;");
}
for (char i='A';i<='Z';i++) {
writer.printHrefNamed("_"+i+"_");
writer.printTagCharacters(Tag.h2, ""+i);
writer.characters("TODO");
writer.printCharacters("TODO");
}
writer.docPageContentEnd();
}

View file

@ -80,8 +80,8 @@ public class DefaultPageWriterTree implements ApiDocPageWriter {
writer.printTagStart(Tag.ul);
writer.printTagStart(Tag.li,"",null,"circle");
if (node.getParent()!=null) {
writer.characters(node.getParent().getId());
writer.characters(":");
writer.printCharacters(node.getParent().getId());
writer.printCharacters(":");
}
writer.printHref(href, node.getName(), node.getName(), "strong");
writer.printTagEnd(Tag.li);