Skip to content

Commit

Permalink
command line parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Rodriguez Doncel committed Jul 10, 2015
1 parent 924bd1e commit b85b975
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 33 deletions.
Binary file added web/lib/commons-cli-1.3.1.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions web/nbproject/build-impl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ exists or setup the property manually. For example like this:
<copyfiles files="${file.reference.xercesImpl.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.xml-apis-1.4.01.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.servlet-api.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.commons-cli-1.3.1.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<mkdir dir="${build.web.dir}/META-INF"/>
<manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update"/>
</target>
Expand Down Expand Up @@ -1063,6 +1064,7 @@ exists or setup the property manually. For example like this:
<copyfiles files="${file.reference.xercesImpl.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.xml-apis-1.4.01.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.servlet-api.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.commons-cli-1.3.1.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
</target>
<target depends="init" if="dist.ear.dir" name="-clean-webinf-lib">
<delete dir="${build.web.dir}/WEB-INF/lib"/>
Expand Down
4 changes: 2 additions & 2 deletions web/nbproject/genfiles.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ build.xml.script.CRC32=466dc714
build.xml.stylesheet.CRC32=651128d4@1.68.1.1
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=d06cc901
nbproject/build-impl.xml.script.CRC32=9eadaf0a
nbproject/build-impl.xml.data.CRC32=2ac078c1
nbproject/build-impl.xml.script.CRC32=cc1a9ee5
nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.68.1.1
4 changes: 3 additions & 1 deletion web/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ endorsed.classpath=\
${libs.javaee-endorsed-api-6.0.classpath}
excludes=
file.reference.Chesspresso-lib.jar=lib/Chesspresso-lib.jar
file.reference.commons-cli-1.3.1.jar=lib/commons-cli-1.3.1.jar
file.reference.commons-codec-1.6.jar=lib/commons-codec-1.6.jar
file.reference.commons-compress-1.2.jar=lib/commons-compress-1.2.jar
file.reference.commons-csv-1.0.jar=lib/commons-csv-1.0.jar
Expand Down Expand Up @@ -110,7 +111,8 @@ javac.classpath=\
${file.reference.xercesImpl-2.11.0.jar}:\
${file.reference.xercesImpl.jar}:\
${file.reference.xml-apis-1.4.01.jar}:\
${file.reference.servlet-api.jar}
${file.reference.servlet-api.jar}:\
${file.reference.commons-cli-1.3.1.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.debug=true
Expand Down
4 changes: 4 additions & 0 deletions web/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@
<file>${file.reference.servlet-api.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.commons-cli-1.3.1.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
</web-module-libraries>
<web-module-additional-libraries/>
<source-roots>
Expand Down
96 changes: 74 additions & 22 deletions web/src/java/pgn2rdf/chess/Main.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,102 @@
package pgn2rdf.chess;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.jena.riot.Lang;
import org.apache.log4j.BasicConfigurator;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.Option;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.apache.log4j.varia.NullAppender;
import pgn2rdf.files.GameUploader;
import pgn2rdf.files.RDFStore;

/**
* http://stackoverflow.com/questions/15906842/solr-4-2-1-sslinitializationexception
*
* Important for debugging with Glassfish and Netbeans: http://www.javahispano.org/java-ee/post/2433388
* Important for debugging with Glassfish and Netbeans:
* http://www.javahispano.org/java-ee/post/2433388
*
* @author Victor
*/
public class Main {

public static boolean initialized = false;

public static void main(String[] args) throws IOException {
BasicConfigurator.configure();
System.out.println("Hello world");
String input = new String(Files.readAllBytes(Paths.get("samples/test.pgn")));
String rdf = PGNProcessor.getRDF(input, Lang.TTL);
System.out.println(rdf);
Logger.getRootLogger().removeAllAppenders();
Logger.getRootLogger().addAppender(new NullAppender());

StringBuilder sb = new StringBuilder();
CommandLineParser clparser = null;
CommandLine cl = null;
try {
Options options = new Options();
options.addOption("help", false, "shows this help (Help)");
options.addOption("add", true, "Transforms, expands and uploads a PGN file");
options.addOption("transform", true, "Transforms, a PGN file");
options.addOption("out", true, "Specifies output file");
options.addOption("count", false, "Counts the number of games");
clparser = new BasicParser();
cl = clparser.parse(options, args);
if (cl.hasOption("help")) {
System.out.println("RDFChess command line tool");
new HelpFormatter().printHelp(Main.class.getCanonicalName(), options);
}
if (cl.hasOption("count")) {
int total =RDFStore.countGames();
System.out.println(total);
}
if (cl.hasOption("add")) {
String sfile = cl.getOptionValue("add");
GameUploader.uploadPGN(sfile);
}
if (cl.hasOption("transform")) {
String sfile = cl.getOptionValue("transform");
String sout = cl.getOptionValue("output");
String input = new String(Files.readAllBytes(Paths.get(sfile)));
String rdf = PGNProcessor.getRDF(input, Lang.TTL);
if (sout.isEmpty()) {
System.out.println(rdf);
} else {
FileUtils.writeStringToFile(new File(sout), rdf);
}
}
} catch (Exception e) {
System.err.println("error");
}

}


public static void init() throws Exception {
System.out.println("Initializing RDFChess");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
/*if (initialized == true) {
return;
}
return;
}
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
builder.build());
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(
sslsf).build();
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
builder.build());
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(
sslsf).build();
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getConnectionManager().getSchemeRegistry()
.register(new Scheme("https", 443,
SSLSocketFactory.getSystemSocketFactory()));
initialized = true;
*/
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getConnectionManager().getSchemeRegistry()
.register(new Scheme("https", 443,
SSLSocketFactory.getSystemSocketFactory()));
initialized = true;
*/
}
}
9 changes: 1 addition & 8 deletions web/src/java/pgn2rdf/files/GameUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@
import java.util.Iterator;
import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import static pgn2rdf.chess.ChessECOManager.getChildren;
import static pgn2rdf.chess.ChessECOManager.getLibraryOfCongress;
import static pgn2rdf.chess.ChessECOManager.getMoves;
import static pgn2rdf.chess.ChessECOManager.getName;
import static pgn2rdf.chess.ChessECOManager.getParent;
import static pgn2rdf.chess.ChessECOManager.getSeeAlso;
import pgn2rdf.chess.PGNProcessor;
import static pgn2rdf.files.ChessGameIterator.getMoves;
import static pgn2rdf.files.PGNFolderParser.MD5;
Expand Down Expand Up @@ -99,7 +92,7 @@ private static void uploadECO(String eco) {
/**
* Transforms and uploads a PGN game
*/
private static int uploadPGN(String filename) {
public static int uploadPGN(String filename) {
String ttl = "";
int conta = 0;
try {
Expand Down

0 comments on commit b85b975

Please sign in to comment.