Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Getting ready for 1.1
  • Loading branch information
menzowindhouwer committed Oct 6, 2017
2 parents e87515c + 917a15c commit 42c0d85
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 62 deletions.
48 changes: 27 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>nl.mpi.tla</groupId>
<artifactId>SchemAnon</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>9.6.0-5</version>
<version>9.7.0-14</version>
<type>jar</type>
</dependency>
<dependency>
Expand Down Expand Up @@ -62,8 +62,10 @@
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly SchemAnon</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<id>make-assembly SchemAnon</id>
<!-- this is used for inheritance merges -->
<phase>package</phase>
<!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
Expand All @@ -79,25 +81,29 @@
<finalName>SchemAnon</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</execution>
</executions>
</plugin>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>CLARIN-Snapshot</id>
<url>https://nexus.clarin.eu/content/repositories/clarin-snapshot</url>
</snapshotRepository>
<repository>
<id>CLARIN</id>
<url>https://nexus.clarin.eu/content/repositories/Clarin</url>
</repository>
</distributionManagement>
<!--<repositories>
<distributionManagement>
<snapshotRepository>
<id>CLARIN-Snapshot</id>
<url>https://nexus.clarin.eu/content/repositories/clarin-snapshot</url>
</snapshotRepository>
<repository>
<id>local</id>
<url>file://${project.basedir}/lib</url>
<id>CLARIN</id>
<url>https://nexus.clarin.eu/content/repositories/Clarin</url>
</repository>
</repositories>-->
</project>
</distributionManagement>
<repositories>
<repository>
<id>CLARIN</id>
<name>CLARIN Repository</name>
<url>https://nexus.clarin.eu/content/repositories/Clarin</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
73 changes: 49 additions & 24 deletions src/main/java/nl/mpi/tla/schemanon/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 The Language Archive - Max Planck Institute for Psycholinguistics
* Copyright (C) 2014 - 2017 The Language Archive - Max Planck Institute for Psycholinguistics, Meertens Institute
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -24,67 +24,77 @@
import java.net.URL;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.transform.stream.StreamSource;
import nl.mpi.tla.schemanon.Message;
import org.apache.commons.io.FileUtils;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import net.sf.saxon.s9api.SaxonApiException;
import org.apache.commons.io.comparator.SizeFileComparator;


/**
* @author Menzo Windhouwer
*/
public class Main {

public static int validate(SchemAnon tron, File input) {
public static int validate(SchemAnon tron, File input, boolean svrl, boolean quiet) {
int code = 0;
try {
if (tron.validate(input)) {
System.out.println("SchemAnon["+input+"]: VALID");
} else {
System.out.println("SchemAnon["+input+"]: INVALID!");
if (!tron.validate(input))
code = 1;
if (!quiet) {
for (Message msg : tron.getMessages()) {
System.out.println("SchemAnon["+input+"]: "+(code==0?"VALID":"INVALID!"));
System.out.println("" + (msg.isError() ? "ERROR" : "WARNING") + (msg.getLocation() != null ? " at " + msg.getLocation() : ""));
System.out.println(" " + msg.getText());
}
System.out.println();
}
for (Message msg : tron.getMessages()) {
System.out.println("" + (msg.isError() ? "ERROR" : "WARNING") + (msg.getLocation() != null ? " at " + msg.getLocation() : ""));
System.out.println(" " + msg.getText());
if (svrl) {
File output = new File(input.getPath()+".svrl");
SaxonUtils.save(tron.getReport().asSource(),output);
}
System.out.println();
} catch (SchemAnonException | IOException ex) {
} catch (SaxonApiException | SchemAnonException | IOException ex) {
System.err.println("FATAL: validating file["+input+"]: "+ex);
ex.printStackTrace(System.err);
System.exit(4);
}
return code;
}

private static void showHelp() {
System.err.println("INF: SchemAnon <options> -- <XSD> <INPUT>? <EXT>*");
System.err.println("INF: <XSD> URL to the XSD Schema");
System.err.println("INF: SchemAnon <options> -- <URL> <INPUT>? <EXT>*");
System.err.println("INF: <URL> URL to the XSD Schema and/or Schematron rules");
System.err.println("INF: <INPUT> input directory or file (default: STDIN)");
System.err.println("INF: <EXT> file extension to filter on in the input directory (optional)");
System.err.println("INF: <EXT> file extension to filter on in the input directory (default: xml)");
System.err.println("INF: SchemAnon options:");
System.err.println("INF: -p=<PHASE> Schematron phase to use (optional)");
System.err.println("INF: -s Save the Schematron SVRL report (default: don't save)");
System.err.println("INF: -i Print progress info (default: on progress info)");
System.err.println("INF: -q Be quiet (default: print validation info)");
}

public static void main(String[] args) {
boolean quiet = false;
boolean svrl = false;
boolean iter = false;
String phase = null;
// check command line
OptionParser parser = new OptionParser( "p:?*" );
OptionParser parser = new OptionParser( "p:sqi?*" );
OptionSet options = parser.parse(args);
if (options.has("p"))
phase = (String)options.valueOf("p");
svrl = options.has("s");
quiet = options.has("q");
iter = options.has("i");
if (options.has("?")) {
showHelp();
System.exit(0);
}

List arg = options.nonOptionArguments();
if (arg.size()<1) {
System.err.println("FTL: no XSD Schema specified!");
System.err.println("FTL: no XSD Schema or Schematron rules specified!");
showHelp();
System.exit(1);
}
Expand All @@ -107,12 +117,27 @@ public static void main(String[] args) {
ArrayList<String> extensions = new ArrayList<String>();
for (int e=2;e<arg.size();e++)
extensions.add((String)arg.get(e));
if (extensions.isEmpty())
extensions.add("xml");
inputs = FileUtils.listFiles(location,extensions.toArray(new String[]{}),true);
File[] files = {};
files = inputs.toArray(files);
Arrays.sort(files, SizeFileComparator.SIZE_COMPARATOR);
inputs = new ArrayList(Arrays.asList(files));
} else {
inputs.add(location);
}
for (File input:inputs)
code = validate(tron,input)>0?1:code;
int i = 0;
for (File input:inputs) {
if (iter) {
System.err.print("INF: ["+(++i)+"/"+inputs.size()+"]"+input+" ("+input.length()+" bytes)");
if (!quiet)
System.err.println();
}
code = validate(tron,input,svrl,quiet)>0?1:code;
if (iter && quiet)
System.err.println(">> "+(code>0?"INVALID":"VALID"));
}
} else {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Expand All @@ -121,7 +146,7 @@ public static void main(String[] args) {
line = line.trim();
if (!line.startsWith("#")) {
File input = new File(line);
code = validate(tron,input)>0?1:code;
code = validate(tron,input,svrl,quiet)>0?1:code;
}
}
} catch(IOException ex) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/nl/mpi/tla/schemanon/Message.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 menzowindhouwer
* Copyright (C) 2014 - 2017 The Language Archive - Max Planck Institute for Psycholinguistics, Meertens Institute
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/nl/mpi/tla/schemanon/SaxonUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 The Language Archive - Max Planck Institute for Psycholinguistics
* Copyright (C) 2014 - 2017 The Language Archive - Max Planck Institute for Psycholinguistics, Meertens Institute
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -30,6 +30,7 @@
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

Expand Down Expand Up @@ -218,4 +219,20 @@ static public XPathSelector evaluateXPath(XdmItem ctxt, String xp) throws SaxonA
static public XdmNode wrapNode(Node node) {
return getDocumentBuilder().wrap(node);
}

/**
* Save a XML Source to a file.
*/
static public void save(Source source,File result) throws SaxonApiException {
try {
XsltTransformer transformer = buildTransformer(SaxonUtils.class.getResource("/identity.xsl")).load();
transformer.setSource(source);
transformer.setDestination(getProcessor().newSerializer(result));
transformer.transform();
transformer.close();
} catch (Exception ex) {
throw new SaxonApiException(ex);
}
}

}
Loading

0 comments on commit 42c0d85

Please sign in to comment.