Skip to content

Commit

Permalink
Update for #10, boilerplate to type select and enumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelligent2013 committed Feb 12, 2021
1 parent df09dd3 commit 32ca591
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 59 deletions.
28 changes: 28 additions & 0 deletions src/main/java/com/metanorma/Util.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.metanorma;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -11,6 +12,7 @@
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.jar.Attributes;
Expand Down Expand Up @@ -128,4 +130,30 @@ public static long getFileSize(File file) {
long length = file.length();
return length;
}

public static String getFileContent(String filepath) {
String fileContent = "";
try {
if (filepath.toLowerCase().startsWith("http") || filepath.toLowerCase().startsWith("www.")) {
URL url = new URL(filepath);
ByteArrayOutputStream output = new ByteArrayOutputStream();
try (InputStream inputStream = url.openStream()) {
int n = 0;
byte [] buffer = new byte[1024];
while (-1 != (n = inputStream.read(buffer))) {
output.write(buffer, 0, n);
}
}
byte[] bytes = output.toByteArray();
fileContent = new String(bytes);
} else {
Path filePath = Paths.get(filepath);
byte[] bytes = Files.readAllBytes(filePath);
fileContent = new String(bytes);
}
} catch (Exception ex) {
return "Can't read a file " + filepath + ":" + ex.toString();
}
return fileContent;
}
}
6 changes: 4 additions & 2 deletions src/main/resources/stepmod.base_xsl/common.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -1389,8 +1389,10 @@ or name()='screen' or name()='ul' or name()='example' or name()='note' or name()
<xsl:param name="linebreakchar" select="'#'"/>
<xsl:param name="warning_gif" select="'../../../../images/warning.gif'"/>

<xsl:variable name="message_" select="normalize-space($message)"/>

<xsl:message>
<xsl:value-of select="translate($message,$linebreakchar,'&#010;')"/>
<xsl:value-of select="translate($message_,$linebreakchar,'&#010;')"/>
</xsl:message>

<xsl:if test="contains($INLINE_ERRORS,'yes')">
Expand All @@ -1414,7 +1416,7 @@ width="20" height="20"/> -->
</font> -->
<xsl:text>_</xsl:text>
<xsl:call-template name="output_line_breaks">
<xsl:with-param name="str" select="$message"/>
<xsl:with-param name="str" select="$message_"/>
<xsl:with-param name="break_char" select="'#'"/>
<xsl:with-param name="replace_break_char" select="'true'"/>
</xsl:call-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ $Id: express_description.xsl,v 1.8 2015/08/03 09:40:44 mikeward Exp $
<xsl:when test="$description_parts_by_space[3] = 'is'">yes</xsl:when>
<xsl:when test="substring($description_parts_by_space[2], string-length($description_parts_by_space[2])) = ','"> <!-- Example An *application_context*, as defined in ISO 10303-1, is a -->
<xsl:variable name="description_parts_by_comma" select="str:split($description,',')"/>
<xsl:if test="starts-with(normalize-space($description_parts_by_comma[3]), 'is')">yes</xsl:if>
<xsl:if test="starts-with(normalize-space($description_parts_by_comma[3]), 'is ')">yes</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:variable>
Expand Down
11 changes: 1 addition & 10 deletions src/main/resources/stepmod.base_xsl/res_doc/resource.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -1924,16 +1924,7 @@ the types, entity specializations, and functions that are specific to this part
<xsl:apply-templates select="$express_xml/express/schema/type">
<xsl:with-param name="main_clause" select="($schema_no+3)" />
</xsl:apply-templates>

<!-- https://github.com/metanorma/stepmod2mn/issues/10 -->
<xsl:if test="not($express_xml/express/schema/type/select) and not($express_xml/express/schema/type/enumeration)">
<xsl:call-template name="insertBoilerplate">
<xsl:with-param name="folder" select="'General'"/>
<xsl:with-param name="identifier" select="'SC4_xxxx'"/>
<xsl:with-param name="text">Example: Put boilerplate from https://github.com/metanorma/iso-tc184-sc4-directives/blob/master/supplementary-directives.adoc</xsl:with-param>
</xsl:call-template>
</xsl:if>


<!-- display the EXPRESS for the entities in the schema.
The template is in sect4_express.xsl -->
<xsl:apply-templates select="$express_xml/express/schema/entity">
Expand Down
136 changes: 91 additions & 45 deletions src/main/resources/stepmod.base_xsl/res_doc/sect_4_express.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -808,51 +808,77 @@
</xsl:call-template>


<xsl:apply-templates select="./select" mode="description"/>

<!-- output description from external file -->
<xsl:call-template name="output_external_description">
<xsl:with-param name="schema" select="../@name"/>
<xsl:with-param name="entity" select="./@name"/>
<xsl:with-param name="type" select="./@name"/>

</xsl:call-template>
<!-- output description from express -->

<!-- <p> -->
<xsl:call-template name="insertParagraph">
<xsl:with-param name="text">
<xsl:choose>
<xsl:when test="string-length(./description)>0">
<xsl:apply-templates select="./description"/>
</xsl:when>
<xsl:otherwise>

<!--
disable error checking for selects as boiler plate
should output text -->
<xsl:if test="not(./select)">
<xsl:variable name="external_description">
<xsl:call-template name="check_external_description">
<xsl:with-param name="schema" select="../@name"/>
<xsl:with-param name="entity" select="@name"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="$external_description='false'">
<xsl:call-template name="error_message">
<xsl:with-param
name="message"
select="concat('Error e3: No description provided for ',$aname)"/>
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
<!-- </p> -->
<!-- output any issue against type -->

<!-- boilerplate text for type select -->
<xsl:variable name="type_select_boilerplate">
<xsl:apply-templates select="./select" mode="description"/>
</xsl:variable>

<xsl:copy-of select="$type_select_boilerplate"/>

<!-- output description from external file -->
<xsl:call-template name="output_external_description">
<xsl:with-param name="schema" select="../@name"/>
<xsl:with-param name="entity" select="./@name"/>
<xsl:with-param name="type" select="./@name"/>

</xsl:call-template>
<!-- output description from express -->

<!-- <p> -->
<xsl:call-template name="insertParagraph">
<xsl:with-param name="text">
<xsl:choose>
<xsl:when test="string-length(./description)>0">
<xsl:apply-templates select="./description"/>
</xsl:when>
<xsl:otherwise>

<!--
disable error checking for selects as boiler plate
should output text -->
<xsl:if test="not(./select)">
<xsl:variable name="external_description">
<xsl:call-template name="check_external_description">
<xsl:with-param name="schema" select="../@name"/>
<xsl:with-param name="entity" select="@name"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="$external_description='false'">
<xsl:call-template name="error_message">
<xsl:with-param
name="message"
select="concat('Error e3: No description provided for ',$aname)"/>
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
<!-- </p> -->


<!-- https://github.com/metanorma/stepmod2mn/issues/10 -->
<!-- If no text is provided in descriptions.xml for SELECT and ENUMERATION types, the XSLT pastes boilerplate descriptions in the document. -->
<xsl:if test="./select and normalize-space($type_select_boilerplate) = ''">
<xsl:variable name="external_description">
<xsl:call-template name="check_external_description">
<xsl:with-param name="schema" select="../@name"/>
<xsl:with-param name="entity" select="@name"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="$external_description='false'">
<xsl:call-template name="insertBoilerplate">
<xsl:with-param name="folder" select="'General'"/>
<xsl:with-param name="identifier" select="'SC4_xxxx'"/>
<xsl:with-param name="text">Example: Put boilerplate for type select, see https://github.com/metanorma/iso-tc184-sc4-directives/blob/master/supplementary-directives.adoc</xsl:with-param>
<xsl:with-param name="file">https://raw.githubusercontent.com/metanorma/stepmod2mn/master/README.adoc</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:if>


<!-- output any issue against type -->
<xsl:call-template name="output_express_issue">
<xsl:with-param name="resdoc_name" select="$resdoc_name"/>
<xsl:with-param name="schema" select="../@name"/>
Expand Down Expand Up @@ -886,7 +912,25 @@
</code>
<!-- end blockquote -->
<!-- </p> -->

<xsl:apply-templates select="enumeration" mode="describe_enums"/>
<xsl:if test="./enumeration">
<xsl:variable name="external_description">
<xsl:call-template name="check_external_description">
<xsl:with-param name="schema" select="../@name"/>
<xsl:with-param name="entity" select="@name"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="$external_description='false'">
<xsl:call-template name="insertBoilerplate">
<xsl:with-param name="folder" select="'General'"/>
<xsl:with-param name="identifier" select="'SC4_xxxx'"/>
<xsl:with-param name="text">Example: Put boilerplate for type enumeration, see https://github.com/metanorma/iso-tc184-sc4-directives/blob/master/supplementary-directives.adoc
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:if>

<xsl:call-template name="output_where_formal"/>
<xsl:call-template name="output_where_informal"/>

Expand Down Expand Up @@ -3866,6 +3910,8 @@

</xsl:choose>
</xsl:if>


</xsl:template>


Expand Down
20 changes: 19 additions & 1 deletion src/main/resources/stepmod2mn.adoc.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:java="http://xml.apache.org/xalan/java"
xmlns:metanorma-class="xalan://com.metanorma.RegExEscaping"
exclude-result-prefixes="mml tbx xlink xalan java metanorma-class"
xmlns:metanorma-class-util="xalan://com.metanorma.Util"
exclude-result-prefixes="mml tbx xlink xalan java metanorma-class metanorma-class-util"
version="1.0">


Expand Down Expand Up @@ -649,6 +650,23 @@
<xsl:text>&gt;&gt;</xsl:text>
</xsl:template>


<xsl:template name="insertBoilerplate">
<xsl:param name="folder"/>
<xsl:param name="identifier"/>
<xsl:param name="text"/>
<xsl:param name="file"/>
<xsl:text>[</xsl:text><xsl:value-of select="$folder"/><xsl:text>:</xsl:text><xsl:value-of select="$identifier"/><xsl:text>]</xsl:text>
<xsl:text>&#xa;</xsl:text>
<xsl:copy-of select="$text"/>
<xsl:if test="normalize-space($file) != ''">
<xsl:copy-of select="java:com.metanorma.Util.getFileContent($file)"/>
</xsl:if>
<xsl:text>&#xa;</xsl:text>
<xsl:text>[end_</xsl:text><xsl:value-of select="$folder"/><xsl:text>]</xsl:text>
<xsl:text>&#xa;&#xa;</xsl:text>
</xsl:template>

<xsl:template match="b" mode="text">
<xsl:text>*</xsl:text><xsl:apply-templates mode="text"/><xsl:text>*</xsl:text>
</xsl:template>
Expand Down

0 comments on commit 32ca591

Please sign in to comment.