
de.citec.scie.web.utils.ArgumentParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webservice Show documentation
Show all versions of webservice Show documentation
Module providing the webservice interface based on the Jetty
embedded webserver and the FreeMarker template engine. Defines a simple
format for providing textual annotations and produced output in HTML or
JSON. This module has no dependencies to the other SCIE modules (except
for the PDF text extractor) or the UIMA framework and thus can be used
in any context, where text is annotated by an algorithm and should be
presented to an end user.
The newest version!
/*
* SCIE -- Spinal Cord Injury Information Extraction
* Copyright (C) 2013, 2014
* Raphael Dickfelder, Jan Göpfert, Benjamin Paaßen, Andreas Stöckel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package de.citec.scie.web.utils;
import java.io.File;
/**
* Utility class used in the webservice implementations webservice-ner and
* webservice-scie for parsing the database file, the port and the host from the
* command line.
*
* @author Andreas Stöckel -- [email protected]
*/
public class ArgumentParser {
/**
* Contains the default port the server should listen on.
*/
private static final int DEFAULT_PORT = 8080;
/**
* Contains the default host the server should bind to ([::] equals 0.0.0.0
* in IPv6).
*/
private static final String DEFAULT_HOST = "[::]";
/**
* Points at the database file.
*/
private final File db;
/**
* Port at which the server should listen.
*/
private final int port;
/**
* Host to which the server should bind.
*/
private final String host;
/**
* Constructor of the ArgumentParser class.
*
* @param args contains the command line arguments.
*/
public ArgumentParser(String[] args) {
if (args.length < 1 || args.length > 3) {
printUsage();
}
// Read the DB file
db = new File(args[0]);
if (!db.exists() || !db.isFile()) {
System.err.println("Database file \"" + args[0]
+ "\" not found or not a valid file!");
printUsage();
}
// Read the port
if (args.length >= 2) {
port = Integer.valueOf(args[1]);
} else {
port = DEFAULT_PORT;
}
// Read the host
if (args.length >= 3) {
host = args[2];
} else {
host = DEFAULT_HOST;
}
}
/**
* Prints the usage of the program on the command line and exist.
*/
private static void printUsage() {
System.err.println("Usage: Server [] "
+ "[]");
System.exit(1);
}
/**
* Returns the database file that should be used. The file is ensured to
* exist at the time of the creation of the ArgumentParser.
*
* @return the database file.
*/
public File getDB() {
return db;
}
/**
* Returns the host on which the server should be listening.
*
* @return the host on which the server should be listening.
*/
public int getPort() {
return port;
}
/**
* Returns the host the server should bind to.
*
* @return the host the server should bind to.
*/
public String getHost() {
return host;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy