2025-05-07 21:46:32 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2004-2014, Willem Cazander
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
|
|
|
|
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
|
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
|
|
|
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|
|
|
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
package org.x4o.maisdoc;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import org.x4o.maisdoc.flake.MaisDocGenerator;
|
|
|
|
|
import org.x4o.maisdoc.flake.DefaultPageWriterHelp;
|
|
|
|
|
import org.x4o.maisdoc.flake.DefaultPageWriterIndexAll;
|
|
|
|
|
import org.x4o.maisdoc.flake.DefaultPageWriterTree;
|
|
|
|
|
import org.x4o.maisdoc.model.MaisDoc;
|
|
|
|
|
import org.x4o.maisdoc.model.MaisDocConcept;
|
|
|
|
|
import org.x4o.maisdoc.model.MaisDocNode;
|
|
|
|
|
import org.x4o.maisdoc.model.MaisDocRemoteClass;
|
|
|
|
|
import org.x4o.sax3.SAX3WriterXml;
|
|
|
|
|
import org.x4o.sax3.io.SAX3PropertyConfig;
|
|
|
|
|
import org.x4o.sax3.io.SAX3PropertyConfig.PropertyConfigItem;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ApiDocWriter writes the api documentation.
|
|
|
|
|
*
|
|
|
|
|
* @author Willem Cazander
|
|
|
|
|
* @version 1.0 Aug 26, 2010
|
|
|
|
|
*/
|
|
|
|
|
@Deprecated // marked until make working to write multiple project or mix api docs in one big tree
|
|
|
|
|
public class MaisDocWriter {
|
2025-11-07 21:48:59 +01:00
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
// NOTE: this class is unused, and is waiting for ApiDocProject code and replaces most code in EldDocWriter to here.
|
|
|
|
|
|
2025-11-07 21:48:59 +01:00
|
|
|
private final static String PROPERTY_CONTEXT_PREFIX = SAX3PropertyConfig.X4O_PROPERTIES_PREFIX + "api-doc/";
|
2025-05-07 21:46:32 +02:00
|
|
|
public final static SAX3PropertyConfig DEFAULT_PROPERTY_CONFIG;
|
2025-11-07 21:48:59 +01:00
|
|
|
|
|
|
|
|
//@formatter:off
|
2025-05-07 21:46:32 +02:00
|
|
|
public final static String OUTPUT_PATH = PROPERTY_CONTEXT_PREFIX+"output/path";
|
|
|
|
|
public final static String DOC_NAME = PROPERTY_CONTEXT_PREFIX+"doc/name";
|
|
|
|
|
public final static String DOC_DESCRIPTION = PROPERTY_CONTEXT_PREFIX+"doc/description";
|
|
|
|
|
public final static String DOC_ABOUT = PROPERTY_CONTEXT_PREFIX+"doc/about";
|
|
|
|
|
public final static String DOC_COPYRIGHT = PROPERTY_CONTEXT_PREFIX+"doc/copyright";
|
|
|
|
|
public final static String DOC_PAGE_SUB_TITLE = PROPERTY_CONTEXT_PREFIX+"doc/page-sub-title";
|
|
|
|
|
public final static String DOC_NO_FRAME_ALL_NAME = PROPERTY_CONTEXT_PREFIX+"doc/no-frame-all-name";
|
|
|
|
|
public final static String META_KEYWORDS = PROPERTY_CONTEXT_PREFIX+"meta/keywords";
|
|
|
|
|
public final static String META_STYLESHEET = PROPERTY_CONTEXT_PREFIX+"meta/stylesheet";
|
|
|
|
|
public final static String META_STYLESHEET_THEMA = PROPERTY_CONTEXT_PREFIX+"meta/stylesheet-thema";
|
|
|
|
|
public final static String JAVADOC_LINK = PROPERTY_CONTEXT_PREFIX+"javadoc/link";
|
|
|
|
|
public final static String JAVADOC_LINK_OFFLINE = PROPERTY_CONTEXT_PREFIX+"javadoc/link-offline";
|
|
|
|
|
public final static String PAGE_PRINT_TREE = PROPERTY_CONTEXT_PREFIX+"page/print-tree";
|
|
|
|
|
public final static String PAGE_PRINT_XTREE = PROPERTY_CONTEXT_PREFIX+"page/print-xtree";
|
|
|
|
|
public final static String PAGE_PRINT_INDEX_ALL = PROPERTY_CONTEXT_PREFIX+"page/print-index-all";
|
|
|
|
|
public final static String PAGE_PRINT_HELP = PROPERTY_CONTEXT_PREFIX+"page/print-help";
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
DEFAULT_PROPERTY_CONFIG = new SAX3PropertyConfig(true,SAX3WriterXml.DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX,
|
|
|
|
|
new PropertyConfigItem(true,OUTPUT_PATH,File.class),
|
|
|
|
|
new PropertyConfigItem(DOC_NAME,String.class,"X4O API DOC"),
|
|
|
|
|
new PropertyConfigItem(DOC_DESCRIPTION,String.class,"X4O API Documentation."),
|
|
|
|
|
new PropertyConfigItem(false,DOC_ABOUT,String.class),
|
|
|
|
|
new PropertyConfigItem(false,DOC_COPYRIGHT,String.class),
|
|
|
|
|
new PropertyConfigItem(false,DOC_PAGE_SUB_TITLE,String.class),
|
|
|
|
|
new PropertyConfigItem(DOC_NO_FRAME_ALL_NAME,String.class,"All Elements"),
|
|
|
|
|
new PropertyConfigItem(false,META_KEYWORDS,List.class),
|
|
|
|
|
new PropertyConfigItem(false,META_STYLESHEET,File.class),
|
|
|
|
|
new PropertyConfigItem(false,META_STYLESHEET_THEMA,String.class),
|
|
|
|
|
new PropertyConfigItem(false,JAVADOC_LINK,List.class),
|
|
|
|
|
new PropertyConfigItem(false,JAVADOC_LINK_OFFLINE,Map.class),
|
|
|
|
|
new PropertyConfigItem(PAGE_PRINT_TREE,Boolean.class,true),
|
|
|
|
|
new PropertyConfigItem(PAGE_PRINT_XTREE,Boolean.class,true),
|
|
|
|
|
new PropertyConfigItem(PAGE_PRINT_INDEX_ALL,Boolean.class,true),
|
|
|
|
|
new PropertyConfigItem(PAGE_PRINT_HELP,Boolean.class,true)
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-11-07 21:48:59 +01:00
|
|
|
//@formatter:on
|
|
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
/** The config of this writer. */
|
|
|
|
|
private final SAX3PropertyConfig propertyConfig;
|
2025-11-07 21:48:59 +01:00
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
public MaisDocWriter(SAX3PropertyConfig parentConfig) {
|
2025-11-07 21:48:59 +01:00
|
|
|
this.propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX);
|
2025-05-07 21:46:32 +02:00
|
|
|
this.propertyConfig.copyParentProperties(parentConfig);
|
|
|
|
|
}
|
2025-11-07 21:48:59 +01:00
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
/**
|
|
|
|
|
* Writes the language documentation to the base path.
|
2025-11-07 21:48:59 +01:00
|
|
|
*
|
|
|
|
|
* @throws IOException Is thrown when error is done.
|
2025-05-07 21:46:32 +02:00
|
|
|
*/
|
|
|
|
|
public void writeDocumentation() throws IOException {
|
|
|
|
|
File basePath = propertyConfig.getPropertyFile(OUTPUT_PATH);
|
|
|
|
|
MaisDocGenerator writer = new MaisDocGenerator();
|
|
|
|
|
MaisDoc doc = buildLanguageDoc();
|
|
|
|
|
writer.write(doc, basePath);
|
|
|
|
|
}
|
2025-11-07 21:48:59 +01:00
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
/**
|
|
|
|
|
* Creates a fully configured ApiDoc object.
|
2025-11-07 21:48:59 +01:00
|
|
|
*
|
|
|
|
|
* @return The ApiDoc configured to write eld documentation.
|
2025-05-07 21:46:32 +02:00
|
|
|
*/
|
|
|
|
|
private MaisDoc buildLanguageDoc() {
|
2025-11-07 21:48:59 +01:00
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
// Generic config
|
|
|
|
|
MaisDoc doc = new MaisDoc();
|
2025-11-07 21:48:59 +01:00
|
|
|
doc.setName(propertyConfig.getPropertyString(DOC_NAME));
|
|
|
|
|
doc.setDescription(propertyConfig.getPropertyString(DOC_DESCRIPTION));
|
|
|
|
|
doc.setDocAbout(propertyConfig.getPropertyString(DOC_ABOUT, () -> createDefaultAbout(doc.getName())));
|
|
|
|
|
doc.setDocCopyright(propertyConfig.getPropertyString(DOC_COPYRIGHT, () -> createForeverCopyright()));
|
|
|
|
|
doc.setDocPageSubTitle(propertyConfig.getPropertyString(DOC_PAGE_SUB_TITLE, () -> createDefaultPageSubTitle(doc.getName())));
|
|
|
|
|
doc.setMetaStyleSheetThema(propertyConfig.getPropertyString(META_STYLESHEET_THEMA));
|
|
|
|
|
doc.setMetaStyleSheet(propertyConfig.getPropertyFile(META_STYLESHEET));
|
|
|
|
|
doc.addMetaKeywordAll(propertyConfig.getPropertyList(META_KEYWORDS, () -> createDefaultKeywords()));
|
|
|
|
|
doc.setNoFrameAllName(propertyConfig.getPropertyString(DOC_NO_FRAME_ALL_NAME));
|
2025-05-07 21:46:32 +02:00
|
|
|
doc.setFrameNavPrintParent(true);
|
|
|
|
|
doc.setFrameNavPrintParentId(true);
|
2025-11-07 21:48:59 +01:00
|
|
|
doc.setGroupTypeName("summary", "Summary", 1);
|
|
|
|
|
doc.setGroupTypeName("overview", "Overview", 2);
|
|
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
// Javadoc linking config
|
|
|
|
|
List<String> javadocLinkList = propertyConfig.getPropertyList(JAVADOC_LINK);
|
2025-11-07 21:48:59 +01:00
|
|
|
Map<String, String> javadocLinkOfflineMap = propertyConfig.getPropertyMap(JAVADOC_LINK_OFFLINE);
|
|
|
|
|
if (javadocLinkList != null) {
|
|
|
|
|
for (String javadocUrl : javadocLinkList) {
|
2025-05-07 21:46:32 +02:00
|
|
|
doc.addRemoteClass(new MaisDocRemoteClass(javadocUrl));
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-07 21:48:59 +01:00
|
|
|
if (javadocLinkOfflineMap != null) {
|
|
|
|
|
for (Map.Entry<String, String> offlineLink : javadocLinkOfflineMap.entrySet()) {
|
|
|
|
|
doc.addRemoteClass(new MaisDocRemoteClass(offlineLink.getKey(), offlineLink.getValue()));
|
2025-05-07 21:46:32 +02:00
|
|
|
}
|
|
|
|
|
}
|
2025-11-07 21:48:59 +01:00
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
// Tree and navagation config
|
|
|
|
|
// doc.setFrameNavConceptClass(ElementClass.class);
|
|
|
|
|
//
|
|
|
|
|
// doc.addTreeNodePageModeClass(X4OLanguageSession.class);
|
|
|
|
|
// doc.addTreeNodePageModeClass(X4OLanguageModule.class);
|
|
|
|
|
// doc.addTreeNodePageModeClass(ElementInterface.class);
|
|
|
|
|
// doc.addTreeNodePageModeClass(ElementNamespace.class);
|
|
|
|
|
//
|
|
|
|
|
// doc.addAnnotatedClasses(EldDocWriterLanguage.class);
|
|
|
|
|
// doc.addAnnotatedClasses(EldDocWriterLanguageModule.class);
|
|
|
|
|
// doc.addAnnotatedClasses(EldDocWriterElementClass.class);
|
|
|
|
|
// doc.addAnnotatedClasses(EldDocWriterElementNamespace.class);
|
|
|
|
|
// doc.addAnnotatedClasses(EldDocWriterElementInterface.class);
|
|
|
|
|
//
|
|
|
|
|
// ApiDocConcept adcRoot = doc.addConcept(new ApiDocConcept(null,C_CONTEXT,X4OLanguage.class));
|
|
|
|
|
//
|
|
|
|
|
// ApiDocConcept adcMod = doc.addConcept(new ApiDocConcept(adcRoot,C_MODULE,X4OLanguageModule.class));
|
|
|
|
|
// ApiDocConcept adcIface = doc.addConcept(new ApiDocConcept(adcMod,C_INTERFACE,ElementInterface.class));
|
|
|
|
|
// ApiDocConcept adcNs = doc.addConcept(new ApiDocConcept(adcMod,C_NAMESPACE,ElementNamespace.class));
|
|
|
|
|
// ApiDocConcept adcEc = doc.addConcept(new ApiDocConcept(adcNs,C_ELEMENT,ElementClass.class));
|
2025-11-07 21:48:59 +01:00
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
// mm maybe redo something here
|
|
|
|
|
// adcMod.addChildConcepts(new ApiDocConcept(adcMod,CC_ATTRIBUTE_H,ElementNamespaceAttribute.class));
|
|
|
|
|
// adcMod.addChildConcepts(new ApiDocConcept(adcMod,CC_CONFIGURATOR_G,ElementConfiguratorGlobal.class));
|
|
|
|
|
// adcMod.addChildConcepts(new ApiDocConcept(adcMod,CC_BINDING,ElementBindingHandler.class));
|
|
|
|
|
// adcIface.addChildConcepts(new ApiDocConcept(adcMod,CC_ATTRIBUTE,ElementClassAttribute.class));
|
|
|
|
|
// adcIface.addChildConcepts(new ApiDocConcept(adcMod,CC_CONFIGURATOR,ElementConfigurator.class));
|
|
|
|
|
// adcEc.addChildConcepts(new ApiDocConcept(adcEc,CC_CONFIGURATOR,ElementConfigurator.class));
|
|
|
|
|
// adcEc.addChildConcepts(new ApiDocConcept(adcEc,CC_ATTRIBUTE,ElementClassAttribute.class));
|
2025-11-07 21:48:59 +01:00
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
// Non-tree pages config
|
|
|
|
|
// if (propertyConfig.getPropertyBoolean(PAGE_PRINT_XTREE)) { doc.addDocPage(EldDocXTreePageWriter.createDocPage()); }
|
|
|
|
|
// if (propertyConfig.getPropertyBoolean(PAGE_PRINT_TREE)) { doc.addDocPage(DefaultPageWriterTree.createDocPage()); }
|
|
|
|
|
// if (propertyConfig.getPropertyBoolean(PAGE_PRINT_INDEX_ALL)) { doc.addDocPage(DefaultPageWriterIndexAll.createDocPage()); }
|
|
|
|
|
// if (propertyConfig.getPropertyBoolean(PAGE_PRINT_HELP)) { doc.addDocPage(DefaultPageWriterHelp.createDocPage()); }
|
2025-11-07 21:48:59 +01:00
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
// Doc tree config
|
|
|
|
|
// ApiDocNode rootNode = new ApiDocNode(language,"language",getLanguageNameUpperCase()+" Language","The X4O "+getLanguageNameUpperCase()+" Language");
|
|
|
|
|
// doc.setRootNode(rootNode);
|
|
|
|
|
// for (X4OLanguageModule mod:language.getLanguageModules()) { ApiDocNode modNode = rootNode.addNode(createNodeLanguageModule(mod));
|
|
|
|
|
// for (ElementBindingHandler bind:mod.getElementBindingHandlers()) { modNode.addNode(createNodeElementBindingHandler(bind)); }
|
|
|
|
|
// for (ElementConfiguratorGlobal conf:mod.getElementConfiguratorGlobals()) { modNode.addNode(createNodeElementConfiguratorGlobal(conf)); }
|
|
|
|
|
// for (ElementInterface iface:mod.getElementInterfaces()) { ApiDocNode ifaceNode = modNode.addNode(createNodeElementInterface(iface));
|
|
|
|
|
// for (ElementClassAttribute eca:iface.getElementClassAttributes()) { ifaceNode.addNode(createNodeElementClassAttribute(eca)); }
|
|
|
|
|
// for (ElementConfigurator conf:iface.getElementConfigurators()) { ifaceNode.addNode(createNodeElementConfigurator(conf)); } }
|
|
|
|
|
// for (ElementNamespace ns:mod.getElementNamespaces()) { ApiDocNode nsNode = modNode.addNode(createNodeElementNamespace(ns));
|
|
|
|
|
// for (ElementNamespaceAttribute attr:ns.getElementNamespaceAttributes()) { nsNode.addNode(createNodeElementNamespaceAttribute(attr)); }
|
|
|
|
|
// for (ElementClass ec:ns.getElementClasses()) { ApiDocNode ecNode = nsNode.addNode(createNodeElementClass(ec));
|
|
|
|
|
// for (ElementClassAttribute eca:ec.getElementClassAttributes()) { ecNode.addNode(createNodeElementClassAttribute(eca)); }
|
|
|
|
|
// for (ElementConfigurator conf:ec.getElementConfigurators()) { ecNode.addNode(createNodeElementConfigurator(conf)); } } }
|
|
|
|
|
// }
|
|
|
|
|
return doc;
|
|
|
|
|
}
|
2025-11-07 21:48:59 +01:00
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
private String createDefaultPageSubTitle(String name) {
|
|
|
|
|
StringBuilder buf = new StringBuilder(100);
|
|
|
|
|
buf.append(name);
|
|
|
|
|
buf.append(" ");// note use real space as 'html/header/title' will not always escape entities. TODO: add to html writer
|
|
|
|
|
buf.append("API");
|
|
|
|
|
return buf.toString();
|
|
|
|
|
}
|
2025-11-07 21:48:59 +01:00
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
private String createDefaultAbout(String name) {
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
StringBuilder buf = new StringBuilder(100);
|
|
|
|
|
buf.append(name);
|
|
|
|
|
buf.append("™ ");
|
|
|
|
|
buf.append(calendar.get(Calendar.YEAR));
|
|
|
|
|
return buf.toString();
|
|
|
|
|
}
|
2025-11-07 21:48:59 +01:00
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
private String createForeverCopyright() {
|
|
|
|
|
StringBuilder buf = new StringBuilder(100);
|
|
|
|
|
buf.append("Copyright © ");
|
|
|
|
|
buf.append("Δ∞");
|
|
|
|
|
buf.append(" ");
|
|
|
|
|
buf.append("仙上主天");
|
|
|
|
|
buf.append(" ");
|
|
|
|
|
buf.append("All Rights Reserved.");
|
|
|
|
|
return buf.toString();
|
|
|
|
|
}
|
2025-11-07 21:48:59 +01:00
|
|
|
|
2025-05-07 21:46:32 +02:00
|
|
|
private List<String> createDefaultKeywords() {
|
|
|
|
|
List<String> keywords = new ArrayList<String>(10);
|
|
|
|
|
keywords.add("language");
|
|
|
|
|
keywords.add("documentation");
|
|
|
|
|
return keywords;
|
|
|
|
|
}
|
|
|
|
|
}
|