From e503113fd108c0b8ce70885f4d8712fd5c19df40 Mon Sep 17 00:00:00 2001 From: Alexander Dyuzhev Date: Fri, 13 Oct 2023 21:24:49 +0300 Subject: [PATCH] exclude documents list added, #78 --- README.adoc | 15 +++++++++++ src/main/java/org/metanorma/stepmod2mn.java | 28 +++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index 1361798..198dea6 100644 --- a/README.adoc +++ b/README.adoc @@ -76,6 +76,21 @@ java -Xss5m -jar target/stepmod2mn-1.19.jar data/ --output documents/ ---- +=== Convert all resource.xml and module.xml in the specified folder and sub-folders into the Metanorma AsciiDoc format, except specified documents: + +[source,sh] +---- +java -Xss5m -jar target/stepmod2mn-1.19.jar [--exclude ] +---- + +e.g. + +[source,sh] +---- +java -Xss5m -jar target/stepmod2mn-1.19.jar data/ --exclude "machining_features" +---- + + === Convert the documents specified in the publication index xml file in the tags 'resource_docs' and 'modules' into the Metanorma AsciiDoc format: [source,sh] diff --git a/src/main/java/org/metanorma/stepmod2mn.java b/src/main/java/org/metanorma/stepmod2mn.java index 4bb9e43..7996d88 100644 --- a/src/main/java/org/metanorma/stepmod2mn.java +++ b/src/main/java/org/metanorma/stepmod2mn.java @@ -35,7 +35,7 @@ */ public class stepmod2mn { - static final String CMD = "java -Xss5m -jar stepmod2mn.jar [options -o, -v, -b -t ]"; + static final String CMD = "java -Xss5m -jar stepmod2mn.jar [options -o, -v, -b -t -e ]"; static final String CMD_SVGscope = "java -jar stepmod2mn.jar --svg"; static final String CMD_SVG = "java -jar stepmod2mn.jar --xml --image [--svg ] [-v]"; @@ -133,6 +133,12 @@ public class stepmod2mn { .hasArg() .required(false) .build()); + addOption(Option.builder("e") + .longOpt("exclude") + .desc("exclude specified documents (list in the quotes, spaces separated)") + .hasArg() + .required(false) + .build()); addOption(Option.builder("v") .longOpt("version") .desc("display application version") @@ -155,6 +161,7 @@ public class stepmod2mn { String outputPathSchemas = ""; + List excludeList = new ArrayList<>(); /** * Main method. * @@ -274,6 +281,11 @@ public static void main(String[] args) throws ParseException { boilerplatePath = cmd.getOptionValue("boilerplatepath") + File.separator; } + List excludeList = new ArrayList<>(); + if (cmd.hasOption("exclude")) { + excludeList = Arrays.asList(cmd.getOptionValue("exclude").split(" ")); + } + String inputFolder = ""; List> inputOutputFiles = new ArrayList<>(); @@ -417,6 +429,7 @@ public static void main(String[] args) throws ParseException { app.setResourcePath(resourcePath); app.setRepositoryIndexPath(repositoryIndexPath); app.setOutputPathSchemas(outputPathSchemas); + app.setExcludeList(excludeList); boolean res = app.convertstepmod2mn(filenameIn, fileOut); if (!res) { badInputOutputFiles.add(entry); @@ -463,7 +476,6 @@ public static void main(String[] args) throws ParseException { //private void convertstepmod2mn(File fXMLin, File fileOut) throws IOException, TransformerException, SAXParseException { private boolean convertstepmod2mn(String xmlFilePath, File fileOut) throws IOException, TransformerException, SAXParseException { - System.out.println("Transforming..."); try { Source srcXSL = null; @@ -480,6 +492,14 @@ private boolean convertstepmod2mn(String xmlFilePath, File fileOut) throws IOExc return false; } + String documentName = XMLUtils.getTextByXPath(linearizedXML, "*/@name"); + if (excludeList.contains(documentName)) { + System.out.println(" '" + documentName + "' excluded from the processing."); + return false; + } + + System.out.println("Transforming..."); + // load linearized xml Source src = new StreamSource(new StringReader(linearizedXML)); ClassLoader cl = this.getClass().getClassLoader(); @@ -592,6 +612,10 @@ public void setBoilerplatePath(String boilerplatePath) { this.boilerplatePath = boilerplatePath; } + public void setExcludeList(List excludeList) { + this.excludeList = excludeList; + } + public void setRepositoryIndexPath(String repositoryIndexPath) { this.repositoryIndexPath = repositoryIndexPath; }