Skip to content

Commit

Permalink
include-only option added, #83
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelligent2013 committed Oct 22, 2023
1 parent a94a32d commit 5935484
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 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> -e <documents list>]";
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> -inc <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 @@ -139,6 +139,12 @@ public class stepmod2mn {
.hasArg()
.required(false)
.build());
addOption(Option.builder("inc")
.longOpt("include-only")
.desc("process specified documents only (list in the quotes, spaces separated)")
.hasArg()
.required(false)
.build());
addOption(Option.builder("v")
.longOpt("version")
.desc("display application version")
Expand All @@ -162,6 +168,7 @@ public class stepmod2mn {
String outputPathSchemas = "";

List<String> excludeList = new ArrayList<>();
List<String> includeOnlyList = new ArrayList<>();
/**
* Main method.
*
Expand Down Expand Up @@ -286,6 +293,11 @@ public static void main(String[] args) throws ParseException {
excludeList = Arrays.asList(cmd.getOptionValue("exclude").split(" "));
}

List<String> includeOnlyList = new ArrayList<>();
if (cmd.hasOption("include-only")) {
includeOnlyList = Arrays.asList(cmd.getOptionValue("include-only").split(" "));
}

String inputFolder = "";

List<Map.Entry<String,String>> inputOutputFiles = new ArrayList<>();
Expand Down Expand Up @@ -416,9 +428,6 @@ public static void main(String[] args) throws ParseException {
File fileIn = new File(filenameIn);
File fileOut = new File(filenameOut);
stepmod2mn app = new stepmod2mn();
System.out.println(String.format(INPUT_LOG, XML_INPUT, filenameIn));
System.out.println(String.format(OUTPUT_LOG, Constants.FORMAT.toUpperCase(), filenameOut));
System.out.println();
app.setBoilerplatePath(boilerplatePath);
if (Util.isUrl(filenameIn)) {
resourcePath = Util.getParentUrl(filenameIn);
Expand All @@ -430,6 +439,7 @@ public static void main(String[] args) throws ParseException {
app.setRepositoryIndexPath(repositoryIndexPath);
app.setOutputPathSchemas(outputPathSchemas);
app.setExcludeList(excludeList);
app.setIncludeOnlyList(includeOnlyList);
boolean res = app.convertstepmod2mn(filenameIn, fileOut);
if (!res) {
badInputOutputFiles.add(entry);
Expand Down Expand Up @@ -488,8 +498,11 @@ 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 {
try {

System.out.println(String.format(INPUT_LOG, XML_INPUT, xmlFilePath));

Source srcXSL = null;

String bibdataFileName = fileOut.getName();

// get linearized XML with default attributes substitution from DTD
Expand All @@ -505,10 +518,18 @@ private boolean convertstepmod2mn(String xmlFilePath, File fileOut) throws IOExc

String documentName = XMLUtils.getTextByXPath(linearizedXML, "*/@name");
if (excludeList.contains(documentName)) {
System.out.println(" '" + documentName + "' excluded from the processing.");
System.out.println("The document '" + documentName + "' excluded from the processing.");
return false;
}

if (!includeOnlyList.isEmpty() && !includeOnlyList.contains(documentName)) {
System.out.println("The document '" + documentName + "' skipped from the processing.");
return false;
}

System.out.println(String.format(OUTPUT_LOG, Constants.FORMAT.toUpperCase(), fileOut.toString()));
System.out.println();

System.out.println("Transforming...");

// load linearized xml
Expand Down Expand Up @@ -627,6 +648,10 @@ public void setExcludeList(List<String> excludeList) {
this.excludeList = excludeList;
}

public void setIncludeOnlyList(List<String> includeOnlyList) {
this.includeOnlyList = includeOnlyList;
}

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

0 comments on commit 5935484

Please sign in to comment.