Skip to content

Commit

Permalink
1.3.0-rc.007 (2023-07-12)
Browse files Browse the repository at this point in the history
+ [New freemarker configuration model, compatibility
mode](https://github.com/fugerit-org/fj-bom/issues/38)
  • Loading branch information
fugerit79 committed Jul 12, 2023
1 parent cd068d7 commit 0567c12
Show file tree
Hide file tree
Showing 34 changed files with 973 additions and 133 deletions.
2 changes: 1 addition & 1 deletion docgen/parameters.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title" : "Venus (Fugerit Document Generation Framework)",
"name": "Venus",
"version" : "1.3.0-rc.006",
"version" : "1.3.0-rc.007",
"date" : "12/07/2023",
"organization" : {
"name" : "Fugerit Org",
Expand Down
4 changes: 2 additions & 2 deletions docgen/release-notes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1.3.0-rc.006 (2023-07-12)
1.3.0-rc.007 (2023-07-12)
------------------
+ [New freemarker configuration model, compatibility mode](https://github.com/fugerit-org/fj-bom/issues/38) [TODO : xsd]
+ [New freemarker configuration model, compatibility mode](https://github.com/fugerit-org/fj-bom/issues/38)

1.3.0-rc.004 (2023-07-11)
------------------
Expand Down
2 changes: 1 addition & 1 deletion fj-doc-base-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>1.3.0-rc.006</version>
<version>1.3.0-rc.007</version>
</parent>

<name>fj-doc-base-json</name>
Expand Down
2 changes: 1 addition & 1 deletion fj-doc-base-yaml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>1.3.0-rc.006</version>
<version>1.3.0-rc.007</version>
</parent>

<name>fj-doc-base-yaml</name>
Expand Down
2 changes: 1 addition & 1 deletion fj-doc-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>1.3.0-rc.006</version>
<version>1.3.0-rc.007</version>
</parent>

<name>fj-doc-base</name>
Expand Down
498 changes: 498 additions & 0 deletions fj-doc-base/src/main/docs/fdp_xsd_config_ref.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion fj-doc-bom-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>1.3.0-rc.006</version>
<version>1.3.0-rc.007</version>
</parent>

<name>fj-doc-bom-core</name>
Expand Down
2 changes: 1 addition & 1 deletion fj-doc-bom-fop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>1.3.0-rc.006</version>
<version>1.3.0-rc.007</version>
</parent>

<name>fj-doc-bom-fop</name>
Expand Down
2 changes: 1 addition & 1 deletion fj-doc-freemarker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>1.3.0-rc.006</version>
<version>1.3.0-rc.007</version>
</parent>

<name>fj-doc-freemarker</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class FreeMarkerFunctionStep extends DocProcessorBasic {
*/
private static final long serialVersionUID = -23134236839366841L;


@Override
public int process(DocProcessContext context, DocProcessData data) throws Exception {
int res = super.process(context, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public class FreemarkerDocProcessConfigFacade {

public static final String ATT_CHAIN_STEP = "chainStep";

public static final String STEP_TYPE_CONFIG = "config";

public static final String STEP_TYPE_FUNCTION = "function";

public static final String STEP_TYPE_MAP = "map";

public static FreemarkerDocProcessConfig newSimpleConfig( String id, String templatePath ) throws ConfigException {
FreemarkerDocProcessConfig config = new FreemarkerDocProcessConfig();
config.setDefaultChain(
Expand Down Expand Up @@ -77,12 +83,6 @@ public static FreemarkerDocProcessConfig loadConfig( Reader xmlReader ) throws C
Element currentTag = (Element) docChainLisgt.item( k );
DocChainModel model = new DocChainModel();
XmlBeanHelper.setFromElement( model, currentTag );
// attributes mapping
if ( DocChainModel.MAP_ATTS_ENUM.equalsIgnoreCase( model.getMapAtts() ) ) {
Element mapAttsEnumTag = (Element)currentTag.getElementsByTagName( "mapAttsEnum" ).item( 0 );
model.setMapAttsEnum( DOMUtils.attributesToProperties( mapAttsEnumTag ) );
log.debug( "chain att enum {} -> {}", model.getId(), model.getMapAttsEnum() );
}
if ( StringUtils.isNotEmpty( model.getParent() ) ) {
DocChainModel parent = config.getDocChainList().get( model.getParent() );
if ( parent == null ) {
Expand All @@ -100,6 +100,24 @@ public static FreemarkerDocProcessConfig loadConfig( Reader xmlReader ) throws C
chainStepModel.setStepType( atts.getProperty( "stepType" ) );
atts.remove( "stepType" );
chainStepModel.setAttributes(atts);
if ( STEP_TYPE_CONFIG.equalsIgnoreCase( chainStepModel.getStepType() ) ) {
NodeList configList = currentChainStepTag.getElementsByTagName( STEP_TYPE_CONFIG );
if ( configList.getLength() != 1 ) {
throw new ConfigException( "Expcted only one config tag : "+configList.getLength() );
} else {
Element configTag = (Element)configList.item( 0 );
atts.putAll( DOMUtils.attributesToProperties( configTag ) );
}
} else if ( STEP_TYPE_FUNCTION.equalsIgnoreCase( chainStepModel.getStepType() )
|| STEP_TYPE_MAP.equalsIgnoreCase( chainStepModel.getStepType() ) ) {
NodeList subList = currentChainStepTag.getElementsByTagName( chainStepModel.getStepType() );
for ( int j=0; j<subList.getLength(); j++ ) {
Element currentFunctionTag = (Element)subList.item(j);
String key = currentFunctionTag.getAttribute( "name" );
String value = currentFunctionTag.getAttribute( "value" );
atts.setProperty(key, value);
}
}
model.getChainStepList().add(chainStepModel);
}
config.getDocChainList().add(model);
Expand Down Expand Up @@ -132,8 +150,8 @@ public static FreemarkerDocProcessConfig loadConfig( Reader xmlReader ) throws C

private static final Properties BUILT_IN_STEPS = new Properties();
static {
BUILT_IN_STEPS.setProperty( "config" , FreeMarkerConfigStep.class.getName() );
BUILT_IN_STEPS.setProperty( "function" , FreeMarkerFunctionStep.class.getName() );
BUILT_IN_STEPS.setProperty( STEP_TYPE_CONFIG , FreeMarkerConfigStep.class.getName() );
BUILT_IN_STEPS.setProperty( STEP_TYPE_FUNCTION , FreeMarkerFunctionStep.class.getName() );
BUILT_IN_STEPS.setProperty( "complex" , FreeMarkerComplexProcessStep.class.getName() );
BUILT_IN_STEPS.setProperty( "map" , FreeMarkerMapStep.class.getName() );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package org.fugerit.java.doc.freemarker.process;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.Reader;
import java.io.StringReader;
import java.util.Properties;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.sax.SAXSource;

import org.fugerit.java.core.io.StreamIO;
import org.fugerit.java.core.lang.helpers.ClassHelper;
import org.fugerit.java.core.lang.helpers.StringUtils;
import org.fugerit.java.core.xml.XMLException;
import org.fugerit.java.core.xml.config.XMLSchemaCatalogConfig;
import org.fugerit.java.core.xml.sax.SAXParseResult;
import org.fugerit.java.core.xml.sax.eh.ResultErrorHandler;
import org.fugerit.java.doc.base.model.DocBase;
import org.fugerit.java.doc.base.parser.DocParserContext;
import org.fugerit.java.doc.base.xml.DocContentHandler;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class FreemarkerDocProcessConfigValidator {

private FreemarkerDocProcessConfigValidator() {}

private static XMLSchemaCatalogConfig init() {
XMLSchemaCatalogConfig catalog = null;
try ( InputStream is = ClassHelper.loadFromDefaultClassLoader( "config_fm_xsd/schema-validator-config-freemarker.xml" ) ) {
catalog = XMLSchemaCatalogConfig.loadConfigSchema( is );
} catch (Exception e) {
throw new RuntimeException( e );
}
return catalog;
}

private static final XMLSchemaCatalogConfig SCHEMA_CATALOG = init();

public static SAXParseResult validateVersion( Reader xmlData ) throws XMLException {
SAXParseResult result = new SAXParseResult();
try {
String buffer = StreamIO.readString( xmlData );
String xsdVersion = getXsdVersion( new StringReader( buffer ) );
log.info( "xsdVersion -> '{}'", xsdVersion );
String validateVersion = "current";
if ( StringUtils.isNotEmpty( xsdVersion ) ) {
validateVersion = "version-"+xsdVersion;
}
log.info( "validateVersion -> '{}'", validateVersion );
SCHEMA_CATALOG.validateCacheSchema( new ResultErrorHandler( result ) , new SAXSource( new InputSource( new StringReader( buffer ) ) ), validateVersion );
} catch (Exception e) {
throw new XMLException( e );
}
return result;
}

private static String getXsdVersion( Reader xmlReader ) throws XMLException {
String version = null;
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware( true );
final Properties infos = new Properties();
SAXParser parser = spf.newSAXParser();
DefaultHandler versionHandler = new DefaultHandler() {
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if ( DocBase.TAG_NAME.equalsIgnoreCase( qName ) || DocBase.TAG_NAME.equalsIgnoreCase( qName ) ) {
Properties props = DocContentHandler.attsToProperties(attributes);
String xsdVersion = DocParserContext.findXsdVersion(props);
infos.setProperty( "xsdVersion" , xsdVersion );
}
}
};
parser.parse( new InputSource( xmlReader ) , versionHandler );
version = infos.getProperty( "xsdVersion" );
} catch (Exception e) {
throw new XMLException( e );
}
return version;
}

public static SAXParseResult validate( Reader xmlData ) throws XMLException {
SAXParseResult result = new SAXParseResult();
try {
SCHEMA_CATALOG.validateCacheSchema( new ResultErrorHandler( result ) , new SAXSource( new InputSource( xmlData ) ), "current" );
} catch (Exception e) {
throw new XMLException( e );
}
return result;
}

public static void logResult( SAXParseResult result ) throws XMLException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try ( PrintStream ps = new PrintStream( baos ) ) {
result.printErrorReport( ps );
log.info( "Validation issues : \n{}", new String( baos.toByteArray() ) );
}
}

public static boolean logValidation( Reader xmlData ) throws XMLException {
SAXParseResult result = new SAXParseResult();
try {
SCHEMA_CATALOG.validateCacheSchema( new ResultErrorHandler( result ) , new SAXSource( new InputSource( xmlData ) ), "current" );
} catch (Exception e) {
throw new XMLException( e );
}
if ( result.isTotalSuccess() ) {
log.info( "Validation completed without errors or warning" );
} else {
logResult( result );
}
return result.isPartialSuccess();
}

}
Loading

0 comments on commit 0567c12

Please sign in to comment.