Skip to content

Commit

Permalink
Update for #10, boilerplatepath parameter added
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelligent2013 committed Feb 13, 2021
1 parent 84c6209 commit 2d84f75
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
25 changes: 22 additions & 3 deletions src/main/java/com/metanorma/stepmod2mn.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
*/
public class stepmod2mn {

static final String CMD = "java -jar stepmod2mn.jar <resource_xml_file> [options -o or -v]";
static final String CMD = "java -jar stepmod2mn.jar <resource_xml_file> [options -o, -v, -b <path>]";
static final String CMD_SVGscope = "java -jar stepmod2mn.jar <start folder to process xml maps files> --svg";
static final String CMD_SVG = "java -jar stepmod2mn.jar --xml <Express Imagemap XML file path> --image <Image file name> [--svg <resulted SVG map file or folder>] [-v]";

Expand Down Expand Up @@ -121,7 +121,13 @@ public class stepmod2mn {
.desc("output file name")
.hasArg()
.required(false)
.build());
.build());
addOption(Option.builder("b")
.longOpt("boilerplatepath")
.desc("path to boilerplate text storage folder")
.hasArg()
.required(false)
.build());
addOption(Option.builder("v")
.longOpt("version")
.desc("display application version")
Expand All @@ -140,6 +146,8 @@ public class stepmod2mn {

String resourcePath = "";

String boilerplatePath = "";

/**
* Main method.
*
Expand Down Expand Up @@ -245,6 +253,11 @@ public static void main(String[] args) throws ParseException {
outFileName = cmd.getOptionValue("output");
}

String boilerplatePath = "";
if (cmd.hasOption("boilerplatepath")) {
boilerplatePath = cmd.getOptionValue("boilerplatepath") + File.separator;
}

// if remote file (http or https)
if (argXMLin.toLowerCase().startsWith("http") || argXMLin.toLowerCase().startsWith("www.")) {

Expand Down Expand Up @@ -300,6 +313,7 @@ public static void main(String[] args) throws ParseException {
try {
stepmod2mn app = new stepmod2mn();
app.setResourcePath(resourcePath);
app.setBoilerplatePath(boilerplatePath);
app.convertstepmod2mn(argXMLin, fileOut);
System.out.println("End!");

Expand Down Expand Up @@ -360,6 +374,7 @@ private void convertstepmod2mn(String xmlFilePath, File fileOut) throws IOExcept
transformer.setParameter("docfile", bibdataFileName);
transformer.setParameter("pathSeparator", File.separator);
transformer.setParameter("path", resourcePath);
transformer.setParameter("boilerplate_path", boilerplatePath);

transformer.setParameter("debug", DEBUG);

Expand Down Expand Up @@ -425,7 +440,11 @@ private static void printVersion(boolean print) {
public void setResourcePath(String resourcePath) {
this.resourcePath = resourcePath;
}


public void setBoilerplatePath(String boilerplatePath) {
this.boilerplatePath = boilerplatePath;
}

private String processLinearizedXML(String xmlFilePath){
try {
InputStream xmlInputStream = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,8 @@
<xsl:with-param name="identifier" select="'SC4_xxxx'"/>
<!-- Example: Put boilerplate for type select, see https://github.com/metanorma/iso-tc184-sc4-directives/blob/master/supplementary-directives.adoc -->
<xsl:with-param name="text"></xsl:with-param>
<xsl:with-param name="file">https://raw.githubusercontent.com/metanorma/stepmod2mn/master/src/main/resources/empty.adoc</xsl:with-param>
<!-- Example /src/main/resources/empty.adoc -->
<xsl:with-param name="file"></xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:if>
Expand Down
28 changes: 19 additions & 9 deletions src/main/resources/stepmod2mn.adoc.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
<xsl:strip-space elements="*"/>

<xsl:param name="path"/>

<xsl:param name="boilerplate_path"/>

<!-- placeholders, global variables -->
<xsl:variable name="FILE_EXT" select="'.xml'"/>
Expand Down Expand Up @@ -656,15 +658,23 @@
<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:choose>
<xsl:when test="normalize-space($text) != '' or normalize-space($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(concat($boilerplate_path, $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:when>
<xsl:otherwise>
<xsl:text>Error: boilerplate text is empty.</xsl:text>
<xsl:text>&#xa;&#xa;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="b" mode="text">
Expand Down

0 comments on commit 2d84f75

Please sign in to comment.