Skip to content

Commit

Permalink
Merge pull request #81 from metanorma/issue/78
Browse files Browse the repository at this point in the history
exclude documents list added, #78
  • Loading branch information
Intelligent2013 authored Oct 13, 2023
2 parents d7fbbb0 + e503113 commit 47bb416
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
15 changes: 15 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Input-folder> [--exclude <documents list>]
----

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]
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/org/metanorma/stepmod2mn.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class stepmod2mn {

static final String CMD = "java -Xss5m -jar stepmod2mn.jar <resource or module or publication index xml file> [options -o, -v, -b <path> -t <type>]";
static final String CMD = "java -Xss5m -jar stepmod2mn.jar <resource or module or publication index xml file> [options -o, -v, -b <path> -t <type> -e <documents list>]";
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 @@ -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")
Expand All @@ -155,6 +161,7 @@ public class stepmod2mn {

String outputPathSchemas = "";

List<String> excludeList = new ArrayList<>();
/**
* Main method.
*
Expand Down Expand Up @@ -274,6 +281,11 @@ public static void main(String[] args) throws ParseException {
boilerplatePath = cmd.getOptionValue("boilerplatepath") + File.separator;
}

List<String> excludeList = new ArrayList<>();
if (cmd.hasOption("exclude")) {
excludeList = Arrays.asList(cmd.getOptionValue("exclude").split(" "));
}

String inputFolder = "";

List<Map.Entry<String,String>> inputOutputFiles = new ArrayList<>();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -592,6 +612,10 @@ public void setBoilerplatePath(String boilerplatePath) {
this.boilerplatePath = boilerplatePath;
}

public void setExcludeList(List<String> excludeList) {
this.excludeList = excludeList;
}

public void setRepositoryIndexPath(String repositoryIndexPath) {
this.repositoryIndexPath = repositoryIndexPath;
}
Expand Down

0 comments on commit 47bb416

Please sign in to comment.