[Git][java-team/libeuclid-java][master] 4 commits: New upstream version 2.18
Andrius Merkys (@merkys)
gitlab at salsa.debian.org
Tue Jun 9 07:17:20 BST 2026
Andrius Merkys pushed to branch master at Debian Java Maintainers / libeuclid-java
Commits:
f3f42be3 by Andrius Merkys at 2026-06-08T09:40:26-04:00
New upstream version 2.18
- - - - -
14a9baf5 by Andrius Merkys at 2026-06-08T09:40:28-04:00
Update upstream source from tag 'upstream/2.18'
Update to upstream version '2.18'
with Debian dir 484c10e0a4f556b82e4875055be0e17cc75f5c7f
- - - - -
12515464 by Andrius Merkys at 2026-06-08T09:41:41-04:00
Bump copyright years.
- - - - -
223e753e by Andrius Merkys at 2026-06-08T09:41:59-04:00
Update changelog for 2.18-1 release
- - - - -
24 changed files:
- CITATION.cff
- README.md
- debian/changelog
- debian/copyright
- pom.xml
- − src/main/java/org/xmlcml/args/ArgIterator.java-old
- − src/main/java/org/xmlcml/args/ArgumentOption.java-old
- − src/main/java/org/xmlcml/args/DefaultArgProcessor.java-old
- − src/main/java/org/xmlcml/args/StringPair.java-old
- − src/main/java/org/xmlcml/args/VariableProcessor.java-old
- − src/main/java/org/xmlcml/args/sandpit/SandpitArgProcessor.java-old
- − src/main/java/org/xmlcml/files/EuclidSource.java-old
- − src/main/java/org/xmlcml/files/QuickscrapeNorma.java-old
- − src/main/java/org/xmlcml/files/QuickscrapeNormaList.java-old
- − src/main/java/org/xmlcml/files/ResultElement.java-old
- − src/main/java/org/xmlcml/files/ResultsElement.java-old
- − src/main/java/org/xmlcml/files/ResultsElementList.java-old
- − src/test/java/org/xmlcml/args/DefaultArgProcessorTest.java-old
- − src/test/java/org/xmlcml/args/sandpit/SandpitArgProcessorDoubleTest.java-old
- − src/test/java/org/xmlcml/args/sandpit/SandpitArgProcessorIntegerTest.java-old
- src/main/java/org/xmlcml/euclid/test/DoubleTestBase.java → src/test/java/org/xmlcml/euclid/test/DoubleTestBase.java
- src/main/java/org/xmlcml/euclid/test/EuclidTestBase.java → src/test/java/org/xmlcml/euclid/test/EuclidTestBase.java
- src/main/java/org/xmlcml/euclid/test/StringTestBase.java → src/test/java/org/xmlcml/euclid/test/StringTestBase.java
- − src/test/java/org/xmlcml/files/QuickscrapeNormaTest.java-old
Changes:
=====================================
CITATION.cff
=====================================
@@ -1,8 +1,8 @@
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
title: Euclid
-version: 2.15
-date-released: 2026-04-11
+version: 2.18
+date-released: 2026-06-06
url: "https://github.com/BlueObelisk/euclid"
preferred-citation:
type: article
=====================================
README.md
=====================================
@@ -17,7 +17,7 @@ It's used a lot in CML tools (JUMBO, JUMBO-converters) and also AMI (for extract
Instructions to increase the version:
```shell
-mvn versions:set -DnewVersion=2.16-SNAPSHOT
+mvn versions:set -DnewVersion=2.19-SNAPSHOT
```
Deploy to Sonatype with the following commands, for snapshots and releases respectively:
=====================================
debian/changelog
=====================================
@@ -1,3 +1,10 @@
+libeuclid-java (2.18-1) unstable; urgency=medium
+
+ * New upstream version 2.18
+ * Bump copyright years.
+
+ -- Andrius Merkys <merkys at debian.org> Mon, 08 Jun 2026 09:41:55 -0400
+
libeuclid-java (2.15-1) unstable; urgency=medium
* New upstream version 2.15
=====================================
debian/copyright
=====================================
@@ -4,7 +4,7 @@ Upstream-Contact: https://github.com/BlueObelisk/euclid/issues
Source: https://github.com/BlueObelisk/euclid
Files: *
-Copyright: 1994-2025, Peter Murray-Rust
+Copyright: 1994-2026, Peter Murray-Rust
License: Apache-2.0
Files: src/main/java/blogspot/*
@@ -38,7 +38,7 @@ Copyright: 2024, Egon Willighagen <egonw at users.sf.net>
License: Apache-2.0
Files: debian/*
-Copyright: 2019-2025, Andrius Merkys <merkys at debian.org>
+Copyright: 2019-2026, Andrius Merkys <merkys at debian.org>
License: Apache-2.0
License: Apache-2.0
=====================================
pom.xml
=====================================
@@ -3,7 +3,7 @@
<groupId>org.blueobelisk</groupId>
<artifactId>euclid</artifactId>
- <version>2.15</version>
+ <version>2.18</version>
<packaging>jar</packaging>
<properties>
@@ -250,9 +250,7 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
- <!--
<scope>test</scope>
- -->
</dependency>
<!--
@@ -266,24 +264,24 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
- <version>2.21.0</version>
+ <version>2.22.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>
- <version>2.25.4</version>
+ <version>2.26.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
- <version>2.25.4</version>
+ <version>2.26.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
- <version>2.25.4</version>
+ <version>2.26.0</version>
</dependency>
<dependency>
@@ -300,13 +298,13 @@
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
- <version>2.14.1</version>
+ <version>2.14.2</version>
</dependency>
<dependency>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
- <version>1.4.0</version>
+ <version>1.4.4</version>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
=====================================
src/main/java/org/xmlcml/args/ArgIterator.java-old deleted
=====================================
@@ -1,207 +0,0 @@
-package org.xmlcml.args;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.ListIterator;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.xmlcml.euclid.IntArray;
-import org.xmlcml.euclid.IntRange;
-import org.xmlcml.euclid.RealArray;
-import org.xmlcml.euclid.RealRange;
-
-/** wraps ListIterator as this causes reflection problems.
- *
- * Tokens of form -[digit]... are treated as numbers
- * Tokens of form -[letter]... are treated as flags
- *
- * @author pm286
- *
- */
- at Deprecated
-public class ArgIterator {
-
-
- private static final Logger LOG = Logger.getLogger(ArgIterator.class);
- static {
- LOG.setLevel(Level.DEBUG);
- }
-
- private final static char MINUS = '-';
-
- private ListIterator<String> listIterator;
- private RealArray doubleArray;
-
- public ArgIterator(ListIterator<String> listIterator) {
- this.listIterator = listIterator;
- }
-
- public ArgIterator(String[] args) {
- listIterator = args == null ? null : Arrays.asList(args).listIterator();
- }
-
- public boolean hasNext() {
- return listIterator == null ? false : listIterator.hasNext();
- }
-
- public String previous() {
- return listIterator == null ? null : listIterator.previous();
- }
-
- public String next() {
- return listIterator == null ? null : listIterator.next();
- }
-
- /** read tokens until next - sign.
- *
- * minus must be folloed by a letter, not a number
- * leave iterator ready to read next minus
- *
- * @param argIterator
- * @return
- */
- public List<String> createTokenListUpToNextNonDigitMinus(ArgumentOption argumentOption) {
- List<String> list = this.createTokenListUpToNextNonDigitMinus();
- checkListSemantics(argumentOption, list);
- return list;
- }
-
- private void checkListSemantics(ArgumentOption argumentOption, List<String> list) {
- String msg = null;
- msg = argumentOption.checkArgumentCount(list);
- if (msg != null) throw new IllegalArgumentException(argumentOption.getVerbose()+"; "+msg);
- msg = argumentOption.checkArgumentValues(list);
- if (msg != null) throw new IllegalArgumentException(argumentOption.getVerbose()+"; "+msg);
- }
-
-
- /** read tokens until next - sign.
- *
- * leave iterator ready to read next minus
- *
- * @param argIterator
- * @return
- */
- public List<String> createTokenListUpToNextNonDigitMinus() {
- List<String> list = new ArrayList<String>();
- while (this.hasNext()) {
- String next = this.next();
- Character next1 = next.length() <= 1 ? null : next.charAt(1);
- // flag is -letter... or --
- if (next.charAt(0) == MINUS && (Character.isLetter(next1) || next1 == MINUS)) {
- this.previous();
- break;
- }
- list.add(next);
- }
- return list;
- }
-
- // STRING
- public List<String> getStrings(ArgumentOption option) {
- return createTokenListUpToNextNonDigitMinus(option);
- }
-
- public String getString(ArgumentOption option) {
- List<String> tokens = createTokenListUpToNextNonDigitMinus(option);
- if (tokens.size() != 1) {
- throw new RuntimeException("Expected only 1 argument; found: "+tokens.size());
- }
- return tokens.get(0);
- }
-
- // BOOLEAN
- public Boolean getBoolean(ArgumentOption option) {
- Boolean bool = null;
- String s = getString(option);
- try {
- bool = new Boolean(s);
- } catch (Exception e) {
- throw new RuntimeException("Cannot create a Boolean from: "+s);
- }
- return bool;
- }
-
- // DOUBLE
- public Double getDouble(ArgumentOption option) {
- Double dubble = null;
- String s = getString(option);
- try {
- dubble = new Double(s);
- } catch (Exception e) {
- throw new RuntimeException("Cannot create a Double from: "+s);
- }
- return dubble;
- }
-
- // REAL RANGE
-
- public RealRange getRealRange(ArgumentOption option) {
- List<String> tokens = this.createTokenListUpToNextNonDigitMinus(option);
- List<RealRange> intRangeList = RealRange.createRealRangeList(tokens);
- if (intRangeList.size() != 1) {
- throw new RuntimeException("requires exactly one RealRange token: "+tokens);
- }
- return intRangeList.get(0);
- }
-
- public List<RealRange> getRealRangeList(ArgumentOption option) {
- List<String> tokens = this.createTokenListUpToNextNonDigitMinus(option);
- return RealRange.createRealRangeList(tokens);
- }
-
- // REAL ARRAY
- public RealArray getDoubleArray(ArgumentOption option) {
- List<String> tokens = this.createTokenListUpToNextNonDigitMinus(option);
- RealArray realArray = null;
- try {
- realArray = new RealArray(tokens.toArray(new String[0]));
- } catch (Exception e) {
- throw new RuntimeException("bad real array"+tokens, e);
- }
- return realArray;
- }
-
- // INTEGER
- public Integer getInteger(ArgumentOption option) {
- Integer intg = null;
- String s = getString(option);
- try {
- intg = new Integer(s);
- } catch (Exception e) {
- throw new RuntimeException("Cannot create an Integer from: "+s, e);
- }
- return intg;
- }
-
- // INT RANGE
- public IntRange getIntRange(ArgumentOption option) {
- List<String> tokens = this.createTokenListUpToNextNonDigitMinus(option);
- List<IntRange> intRangeList = IntRange.createIntRangeList(tokens);
- if (intRangeList.size() != 1) {
- throw new RuntimeException("requires exactly one IntRange token: "+tokens);
- }
- return intRangeList.get(0);
- }
-
- public List<IntRange> getIntRangeList(ArgumentOption option) {
- List<String> tokens = this.createTokenListUpToNextNonDigitMinus(option);
- return IntRange.createIntRangeList(tokens);
- }
-
- // INT ARRAY
- public IntArray getIntArray(ArgumentOption option) {
- List<String> tokens = this.createTokenListUpToNextNonDigitMinus(option);
- IntArray intArray = null;
- try {
- intArray = new IntArray(tokens.toArray(new String[0]));
- } catch (Exception e) {
- throw new RuntimeException("bad integer array"+tokens, e);
- }
- return intArray;
- }
-
-
-}
\ No newline at end of file
=====================================
src/main/java/org/xmlcml/args/ArgumentOption.java-old deleted
=====================================
@@ -1,866 +0,0 @@
-package org.xmlcml.args;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import nu.xom.Attribute;
-import nu.xom.Element;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.xmlcml.euclid.IntRange;
-import org.xmlcml.euclid.RealRange;
-import org.xmlcml.xml.XMLUtil;
-
-/** simple option for controlling arguments.
- *
- * @author pm286
- *
- */
- at Deprecated
-
-public class ArgumentOption {
- private static final String BRIEF = "brief";
- private static final String LONG = "long";
- public static final String NAME = "name";
- private static final String HELP = "help";
- public static final String VALUE = "value";
- private static final String ARGS = "args";
- private static final String CLASS_TYPE = "class";
- private static final String DEFAULT = "default";
- private static final String COUNT_RANGE = "countRange";
- private static final String VALUE_RANGE = "valueRange";
- private static final String FINAL_METHOD = "finalMethod";
- private static final String INIT_METHOD = "initMethod";
- private static final String OUTPUT_METHOD = "outputMethod";
- private static final String PARSE_METHOD = "parseMethod";
- private static final String RUN_METHOD = "runMethod";
- // these may be obsolete
- private static final String FORBIDDEN = "forbidden";
- private static final String REQUIRED = "required";
-
- private static final String PATTERN = "pattern";
-
- private static final Pattern INT_RANGE = Pattern.compile("\\{(\\*|\\-?\\d+),(\\-?\\d*|\\*)\\}");
- private static final Pattern DOUBLE_RANGE = Pattern.compile("\\{(\\-?\\+?\\d+\\.?\\d*|\\*),(\\-?\\+?\\d+\\.?\\d*|\\*)\\}");
-
- public static String CLASSNAME = "className";
-
- private static final Logger LOG = Logger.getLogger(ArgumentOption.class);
- static {
- LOG.setLevel(Level.DEBUG);
- }
-
- private static Set<String> MANDATORY_ATTRIBUTES;
- static {
- MANDATORY_ATTRIBUTES = new HashSet<String>();
- MANDATORY_ATTRIBUTES.add(NAME);
- MANDATORY_ATTRIBUTES.add(LONG);
- MANDATORY_ATTRIBUTES.add(ARGS);
-// MANDATORY_ATTRIBUTES.add(PARSE_METHOD); // not required for some args
- }
- private static Set<String> MANDATORY_CHILDREN;
- static {
- MANDATORY_CHILDREN = new HashSet<String>();
- MANDATORY_CHILDREN.add(HELP);
- }
- private static Map<String, String> OPTIONAL_ATTRIBUTES;
- static {
- OPTIONAL_ATTRIBUTES = new HashMap<String, String>();
- OPTIONAL_ATTRIBUTES.put(CLASS_TYPE, "java.lang.String"); // class defaults to String
- OPTIONAL_ATTRIBUTES.put(DEFAULT, ""); // default defaults to ""
- }
-
- private String name;
- private String brief;
- private String verbose;
- private String help;
- private Class<?> classType;
- private Object defalt;
- private IntRange countRange;
- private String countRangeString;
- private IntRange intValueRange = null;
- private RealRange realValueRange = null;
- private String valueRangeString;
- private String patternString = null;
- private Pattern pattern = null;
- private String forbiddenString = null;
- private List<String> forbiddenArguments = null;
- private String requiredString = null;
- private List<String> requiredArguments = null;
-
- private List<String> defaultStrings;
- private List<Integer> defaultIntegers;
- private List<Double> defaultDoubles;
-
- private List<String> stringValues;
- private List<Double> doubleValues;
- private List<Integer> integerValues;
-
- private Double defaultDouble;
- private String defaultString;
- private Integer defaultInteger;
- private Boolean defaultBoolean;
-
- private String stringValue;
- private Integer integerValue;
- private Double doubleValue;
- private Boolean booleanValue;
- private String args;
- private List<StringPair> stringPairValues;
-
- private String parseMethodName;
- private String runMethodName;
- private String outputMethodName;
- private String finalMethodName;
- private String initMethodName;
-
- private Class<? extends DefaultArgProcessor> argProcessorClass;
- private List<Element> valueNodes;
- private List<Element> helpNodes;
- private Element element;
-
- public ArgumentOption(Class<? extends DefaultArgProcessor> argProcessorClass) {
- setDefaults();
- this.argProcessorClass = argProcessorClass;
- }
-
- private void setDefaults() {
- brief = "";
- intValueRange = new IntRange(-Integer.MAX_VALUE, Integer.MAX_VALUE);
- realValueRange = new RealRange(-Double.MAX_VALUE, Double.MAX_VALUE);
- }
-
- /** factory method option for ArgumentOptions
- *
- * @param argProcessor
- * @param element
- * @return
- */
- public static ArgumentOption createOption(Class<? extends DefaultArgProcessor> argProcessor, Element element) {
-
- ArgumentOption argumentOption = new ArgumentOption(argProcessor);
- argumentOption.setElement(element);
- Set<String> mandatorySet = new HashSet<String>(MANDATORY_ATTRIBUTES);
- Map<String, String> optionalAttributes = new HashMap<String, String>(OPTIONAL_ATTRIBUTES);
- // get class first because so much else depends
- String classType = element.getAttributeValue(CLASS_TYPE);
-
- argumentOption.setClassType(classType);
- lookForKnownAttributes(element, argumentOption, mandatorySet, optionalAttributes);
- if (mandatorySet.size() > 0) {
- throw new RuntimeException("The following attributes for "+argumentOption.name+" are mandatory: "+mandatorySet);
- }
- argumentOption.getDefaults(optionalAttributes);
- argumentOption.getOrCreateHelpNodes();
- argumentOption.getOrCreateValues();
- return argumentOption;
- }
-
- private void setElement(Element element) {
- this.element = element;
- }
-
- private void getDefaults(Map<String, String> optionalAttributes) {
- for (String name : optionalAttributes.keySet()) {
- String value = optionalAttributes.get(name);
- if (value != null) {
- this.setValue(name, value);
- }
- }
- }
-
- public List<Element> getOrCreateHelpNodes() {
- if (helpNodes == null) {
- helpNodes = XMLUtil.getQueryElements(element, "./*[local-name()='"+HELP+"']");
- if (helpNodes.size() != 1) {
- throw new RuntimeException("No help given for "+this.name);
- } else {
- this.setHelp(helpNodes.get(0).getValue());
- }
- }
- return helpNodes;
- }
-
- public List<Element> getOrCreateValues() {
- if (valueNodes == null) {
- valueNodes = XMLUtil.getQueryElements(element, "./*[local-name()='"+VALUE+"']");
- }
- LOG.trace("VALUES: "+valueNodes);
- return valueNodes;
- }
-
- private static void lookForKnownAttributes(Element element,
- ArgumentOption argumentOption, Set<String> mandatorySet,
- Map<String, String> optionalAttributes) {
- for (int i = 0; i < element.getAttributeCount(); i++) {
- Attribute attribute = element.getAttribute(i);
- String name = attribute.getLocalName();
- String value = attribute.getValue();
- argumentOption.setValue(name, value);
- mandatorySet.remove(name);
- optionalAttributes.put(name, null);
- }
- }
-
- private void setValue(String namex, String value) {
- if (BRIEF.equals(namex)) {
- this.setBrief(value);
- } else if (LONG.equals(namex)) {
- this.setLong(value);
- } else if (NAME.equals(namex)) {
- this.setName(value);
- } else if (HELP.equals(namex)) {
- this.setHelp(value);
- } else if (ARGS.equals(namex)) {
- this.setArgs(value);
- } else if (CLASS_TYPE.equals(namex)) {
- this.setClassType(value);
- } else if (DEFAULT.equals(namex)) {
- this.setDefault(value);
- } else if (COUNT_RANGE.equals(namex)) {
- this.setCountRange(value);
- } else if (FORBIDDEN.equals(namex)) {
- this.setForbiddenString(value);
- } else if (REQUIRED.equals(namex)) {
- this.setRequiredString(value);
- } else if (FINAL_METHOD.equals(namex)) {
- this.setFinalMethod(value);
- } else if (INIT_METHOD.equals(namex)) {
- this.setInitMethod(value);
- } else if (OUTPUT_METHOD.equals(namex)) {
- this.setOutputMethod(value);
- } else if (PARSE_METHOD.equals(namex)) {
- this.setParseMethod(value);
- } else if (PATTERN.equals(namex)) {
- this.setPatternString(value);
- } else if (RUN_METHOD.equals(namex)) {
- this.setRunMethod(value);
- } else if (VALUE_RANGE.equals(namex)) {
- this.setValueRange(value);
- } else {
- throw new RuntimeException("Unknown attribute on <arg name='"+name+"'>: "+namex+"='"+value+"'");
- }
- }
-
-
-
- private void setCountRange(String value) {
- countRangeString = value;
- setCountRange(createIntRange(countRangeString));
- }
-
- private void setCountRange(IntRange intRange) {
- this.countRange = intRange;
- }
-
- private void setValueRange(String value) {
- valueRangeString = value;
- if (Integer.class.equals(classType)) {
- setValueRange(createIntRange(valueRangeString));
- } else if (Double.class.equals(classType)) {
- setValueRange(createDoubleRange(valueRangeString));
- } else {
- throw new RuntimeException("Must give class if using valueRanges: "+classType);
- }
- }
-
- private void setValueRange(RealRange realRange) {
- this.realValueRange = realRange;
- }
-
- private void setValueRange(IntRange intRange) {
- this.intValueRange = intRange;
- }
-
- private RealRange createDoubleRange(String valueRangeString) {
- RealRange realRange = null;
- Matcher matcher = DOUBLE_RANGE.matcher(valueRangeString);
- if (matcher.matches()) {
- String min = matcher.group(1);
- double minReal = (min.equals("*")) ? -1 * Double.MAX_VALUE : new Double(min);
- String max = matcher.group(2);
- double maxReal = (max.equals("*")) ? Double.MAX_VALUE : new Double(max);
- if (minReal > maxReal) {
- throw new RuntimeException("Minimum ("+minReal+")must be less-than/equals: "+maxReal+" in :"+valueRangeString);
- }
- realRange = new RealRange(minReal, maxReal);
- } else {
- throw new RuntimeException("count range must be of form {min,max}; was "+valueRangeString);
- }
- return realRange;
- }
-
- private IntRange createIntRange(String ss) {
- IntRange intRange = null;
- Matcher matcher = INT_RANGE.matcher(ss);
- if (matcher.matches()) {
- String min = matcher.group(1);
- int minInt = (min.equals("*")) ? -1*Integer.MAX_VALUE : new Integer(min);
- String max = matcher.group(2);
- int maxInt = (max.equals("*")) ? Integer.MAX_VALUE : new Integer(max);
- if (minInt > maxInt) {
- throw new RuntimeException("Minimum ("+min+") must be less-than/equals max ("+max+") in "+ss);
- }
- intRange = new IntRange(minInt, maxInt);
- } else {
- throw new RuntimeException("count range must be of form {min,max}; was "+ss);
- }
- return intRange;
- }
-
- private void setClassType(String className) {
- if (className != null) {
- try {
- classType = Class.forName(className);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("Cannot create class for: "+className);
- }
- } else {
- classType = java.lang.String.class;
- }
- }
-
- public String getBrief() {
- return brief;
- }
-
- public void setBrief(String brief) {
- this.brief = brief;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getVerbose() {
- return verbose;
- }
-
- public void setLong(String verbose) {
- this.verbose = verbose;
- }
-
- public String getArgs() {
- return args;
- }
-
- public void setArgs(String args) {
- this.args = args;
- }
-
-
-
- public String getHelp() {
- StringBuilder sb = new StringBuilder();
- sb.append("\n"+brief);
- sb.append(" or "+verbose+" ");
- if (args.trim().length() > 0) {
- sb.append(" "+args);
- }
- sb.append("\n");
- sb.append(help);
- return sb.toString();
- }
-
- public void setHelp(String help) {
- this.help = help;
- }
-
- public Class<?> getClassType() {
- return classType;
- }
-
- public void setClassType(Class<?> classType) {
- this.classType = classType;
- }
-
- public Object getDefault() {
- return defalt;
- }
-
- public void setDefault(Object defalt) {
- this.defalt = defalt;
- }
-
- public String getParseMethodName() {
- return parseMethodName;
- }
-
- public void setParseMethod(String parseMethodName) {
- if (parseMethodName != null) {
- try {
- Method method = argProcessorClass.getMethod(parseMethodName, ArgumentOption.class, ArgIterator.class);
- this.parseMethodName = parseMethodName;
- } catch (NoSuchMethodException e) {
- throw new RuntimeException("Non-existent method "+argProcessorClass+"; "+parseMethodName+" (edit ArgProcessor)", e);
- }
- }
- }
-
- public String getRunMethodName() {
- return runMethodName;
- }
-
- public void setRunMethod(String runMethodName) {
- if (runMethodName != null) {
- try {
- Method method = argProcessorClass.getMethod(runMethodName, ArgumentOption.class);
- LOG.trace("RUN METHOD "+method);
- this.runMethodName = runMethodName;
- } catch (NoSuchMethodException e) {
- throw new RuntimeException("Non-existent method "+argProcessorClass+"; "+runMethodName+" (edit ArgProcessor)", e);
- }
- }
- }
-
- public String getOutputMethodName() {
- return outputMethodName;
- }
-
- public void setOutputMethod(String outputMethodName) {
- if (outputMethodName != null) {
- try {
- Method method = argProcessorClass.getMethod(outputMethodName, ArgumentOption.class);
- LOG.trace("OUTPUT METHOD "+method);
- this.outputMethodName = outputMethodName;
- } catch (NoSuchMethodException e) {
- throw new RuntimeException("Non-existent outputMethod "+argProcessorClass+"; "+outputMethodName+" (edit ArgProcessor)", e);
- }
- }
- }
-
- public void setInitMethod(String initMethodName) {
- if (initMethodName != null) {
- try {
- LOG.trace("INIT METHODNAME "+initMethodName);
- Method method = argProcessorClass.getMethod(initMethodName, ArgumentOption.class);
- LOG.trace("INIT METHOD "+method);
- this.initMethodName = initMethodName;
- } catch (NoSuchMethodException e) {
- throw new RuntimeException("Non-existent initMethod "+argProcessorClass+"; "+initMethodName+" (edit ArgProcessor)", e);
- }
- }
- }
-
- public String getInitMethodName() {
- return initMethodName;
- }
-
- public void setFinalMethod(String finalMethodName) {
- if (finalMethodName != null) {
- try {
- Method method = argProcessorClass.getMethod(finalMethodName, ArgumentOption.class);
- LOG.trace("FINAL METHOD "+method);
- this.finalMethodName = finalMethodName;
- } catch (NoSuchMethodException e) {
- throw new RuntimeException("Non-existent finalMethod "+argProcessorClass+"; "+finalMethodName+" (edit ArgProcessor)", e);
- }
- }
- }
-
- public String getFinalMethodName() {
- return finalMethodName;
- }
-
-
- public String getPatternString() {
- return patternString;
- }
-
- public void setPatternString(String patternString) {
- if (patternString == null) {
- LOG.error("null pattern");
- } else {
- Pattern pattern = Pattern.compile(patternString);
- }
- }
-
- private String getForbiddenString() {
- return forbiddenString;
- }
-
- public String getRequiredString() {
- return requiredString;
- }
-
- public void setRequiredString(String required) {
- this.requiredString = required;
- }
-
- public void setForbiddenString(String forbidden) {
- this.forbiddenString = forbidden;
- }
-
-
- public ArgumentOption processArgs(List<String> inputs) {
- ensureDefaults();
- stringValue = defaultString;
- stringValues = defaultStrings;
- doubleValue = defaultDouble;
- doubleValues = defaultDoubles;
- doubleValue = defaultDouble;
- doubleValues = defaultDoubles;
- if (!countRange.includes(inputs.size())) {
- throw new RuntimeException("Bad number of arguments: "+inputs.size()+" incompatible with "+countRangeString);
- }
- if (classType == null) {
- classType = String.class;
- }
- if (classType.equals(String.class)) {
- stringValues = inputs;
- stringValue = (inputs.size() == 0) ? defaultString : inputs.get(0);
- } else if (classType.equals(Double.class)) {
- doubleValues = new ArrayList<Double>();
- for (String input : inputs) {
- doubleValues.add(new Double(input));
- }
- doubleValue = (doubleValues.size() == 0) ? defaultDouble : doubleValues.get(0);
- for (Number number : doubleValues) {
- if (!realValueRange.includes((double)number)) {
- throw new RuntimeException("bad numeric value: "+number+" should conform to "+valueRangeString);
- }
- }
- } else if (classType.equals(Boolean.class)) {
- booleanValue = inputs.size() == 1 ? new Boolean(inputs.get(0)) : defaultBoolean;
- } else if (classType.equals(Integer.class)) {
- integerValues = new ArrayList<Integer>();
- for (String input : inputs) {
- integerValues.add(new Integer(input));
- }
- integerValue = (integerValues.size() == 0) ? defaultInteger : integerValues.get(0);
- for (Number number : integerValues) {
- if (!realValueRange.includes((double)number)) {
- throw new RuntimeException("bad numeric value: "+number+" should conform to "+valueRangeString);
- }
- }
- } else if (classType.equals(StringPair.class)) {
- checkStringPairs(inputs);
- } else {
- LOG.error("currently cannot support type: "+classType);
- }
- return this;
- }
-
- private void checkStringPairs(List<String> inputs) {
- stringPairValues = new ArrayList<StringPair>();
- for (String input : inputs) {
- String[] fields = input.trim().split(",");
- if (fields.length != 2) {
- throw new RuntimeException("Cannot parse "+input+" as comma-separated pair (foo,bar)");
- }
- stringPairValues.add(new StringPair(fields[0], fields[1]));
- }
- // NYI
-// stringPairValueValue = (stringPairValues.size() == 0) ? defaultStringPairValue : stringPairValues.get(0);
- }
-
- public ArgumentOption ensureDefaults() {
- if (classType == null) {
- // no defaults
- } else if (defalt == null) {
- // no defaults
- } else if (classType.equals(String.class)) {
- defaultStrings = new ArrayList<String>();
- defaultStrings.add((String)defalt);
- if (countRange.isEqualTo(new IntRange(1,1))) {
- defaultString = (String)defalt;
- }
- } else if (classType.equals(Integer.class)) {
- Integer defaultInteger = null;
- try {
- defaultInteger = new Integer(String.valueOf(defalt));
- } catch (Exception e) {
- throw new RuntimeException("default should be of type Integer");
- }
- // FIXME no defaults
- } else if (classType.equals(Double.class) && defalt instanceof Double) {
- Double defaultDouble = null;
- try {
- defaultDouble = new Double(String.valueOf(defalt));
- } catch (Exception e) {
- throw new RuntimeException("default should be of type Double");
- }
- // FIXME no defaults
- } else if (classType.equals(Boolean.class) && defalt instanceof String) {
- defaultBoolean = false;
- try {
- defaultBoolean = new Boolean(String.valueOf(defalt));
- } catch (Exception e) {
- throw new RuntimeException("default should be of type Boolean");
- }
- } else {
- LOG.error("Incompatible type and default: "+classType+"; "+defalt.getClass());
- }
- return this;
- }
-
- public String getDefaultString() {
- return defaultString;
- }
-
- public Integer getDefaultInteger() {
- return defaultInteger;
- }
-
- public Double getDefaultDouble() {
- return defaultDouble;
- }
-
- public Boolean getDefaultBoolean() {
- return defaultBoolean;
- }
-
- public List<String> getDefaultStrings() {
- return defaultStrings;
- }
-
- public List<Integer> getDefaultIntegers() {
- return defaultIntegers;
- }
-
- public List<Double> getDefaultDoubles() {
- return defaultDoubles;
- }
-
- public boolean matches(String arg) {
- return (brief.equals(arg) || verbose.equals(arg));
- }
-
- public List<Double> getDoubleValues() {
- return doubleValues;
- }
-
- public List<Integer> getIntegerValues() {
- return integerValues;
- }
-
- public List<String> getStringValues() {
- return stringValues;
- }
-
- public String getStringValue() {
- return stringValue;
- }
-
- public Integer getIntegerValue() {
- return integerValue;
- }
-
- public Double getDoubleValue() {
- return doubleValue;
- }
-
- public Boolean getBooleanValue() {
- return booleanValue;
- }
-
- public List<StringPair> getStringPairValues() {
- return stringPairValues;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append(brief+" or "+verbose+"; "+countRange+"; "+parseMethodName+"; ");
- if (classType == null) {
- sb.append("NULL CLASS: "+defaultString+" / "+defaultStrings+"; "+stringValue+"; "+stringValues);
- } else if (classType.equals(String.class)) {
- sb.append("STRING: "+defaultString+" / "+defaultStrings+"; "+stringValue+"; "+stringValues);
- } else if (classType.equals(Integer.class)) {
- sb.append("INTEGER: "+defaultInteger+" / "+defaultIntegers+"; "+integerValue+"; "+integerValues);
- } else if (classType.equals(Double.class)) {
- sb.append("DOUBLE: "+defaultDouble+" / "+defaultDoubles+"; "+doubleValue+"; "+doubleValues);
- } else if (classType.equals(Boolean.class)) {
- sb.append("BOOLEAN: "+defaultBoolean+"; "+booleanValue);
- } else if (classType.equals(StringPair.class)) {
- sb.append("STRINGPAIRS: ; "+stringPairValues);
- } else if (classType.equals(Object.class)) {
- sb.append("OBJECT ; "+stringValue);
- }
- return sb.toString();
- }
-
- /** checks argument count;
- *
- * @param list
- * @return null indicates correct; non-null is explanatory message.
- */
- public String checkArgumentCount(List<String> list) {
- String message = null;
- if (countRange != null) {
- if (!countRange.includes(list.size())) {
- message = "argument count ("+list.size()+") is not compatible with "+countRangeString;
- }
- }
- return message;
- }
-
- /** checks argument values;
- *
- * @param list
- * @return null indicates correct; non-null is explanatory message.
- */
- public String checkArgumentValues(List<String> list) {
- String message = null;
- for (String s : list) {
- if (s == null) {
- message = "Cannot have null values in "+verbose;
- break;
- }
- message = checkBooleanValue(s);
- if (message != null) break;
- message = checkNumericValue(s);
- if (message != null) break;
- message = checkPatternValue(s);
- if (message != null) break;
- }
- return message;
- }
-
- private String checkBooleanValue(String s) {
- String message = null;
- if (classType != null && classType.isAssignableFrom(Boolean.class)) {
- try {
- new Boolean(s);
- } catch (Exception e) {
- message = "Argument for "+verbose +" ("+s+") should be true or false";
- }
- }
- return message;
- }
-
- private String checkPatternValue(String s) {
- String message = null;
- if (classType != null && classType.isAssignableFrom(String.class)) {
- if (pattern != null) {
- Matcher matcher = pattern.matcher(s);
- message = "Argument for "+verbose +" ("+s+") does not match "+pattern;
- }
- }
- return message;
- }
-
- private String checkNumericValue(String s) {
- String message = null;
- if (classType == null) {
- throw new RuntimeException("null classType");
- } else if (Double.class.isAssignableFrom(classType)) {
- message = checkDouble(s, message);
- } else if (Integer.class.isAssignableFrom(classType)) {
- message = checkInteger(s, message);
- }
-
- return message;
- }
-
- private String checkDouble(String s, String message) {
- Double d = null;
- try {
- d = new Double(s);
- } catch (NumberFormatException nfe) {
- message = "Not a number: "+nfe+"; in "+verbose;
- }
- if (realValueRange == null) {
- LOG.error("No value range");
- }
- if (d == null || !realValueRange.includes(d)) {
- message = "value: "+s+" incompatible with: "+realValueRange;
- }
- return message;
- }
-
- private String checkInteger(String s, String message) {
- Integer ii = null;
- try {
- ii = new Integer(s);
- } catch (NumberFormatException nfe) {
- message = "Not a number: "+nfe+"; in "+verbose;
- }
- if (intValueRange == null) {
- LOG.error("No value range");
-
- }
- if (ii == null || !intValueRange.includes(ii)) {
- message = "value: "+s+" incompatible with: "+intValueRange;
- }
- return message;
- }
-
- public void processDependencies(List<ArgumentOption> argumentOptionList) {
- processForbidden(argumentOptionList);
- processRequired(argumentOptionList);
- }
-
- private void processRequired(List<ArgumentOption> argumentOptionList) {
- this.getRequiredArguments();
- if (requiredArguments != null) {
- for (String requiredArgument : requiredArguments) {
- LOG.trace(this.getVerbose()+" REQUIRED "+requiredArgument);
- if (!argumentOccursInOptions(requiredArgument, argumentOptionList)) {
- throw new RuntimeException("Cannot find required option: "+requiredArgument);
- }
- }
- }
- }
-
- private static boolean argumentOccursInOptions(String requiredArgument, List<ArgumentOption> argumentOptionList) {
- for (ArgumentOption argumentOption : argumentOptionList) {
- String optionVerbose = argumentOption.getVerbose();
- if (requiredArgument.equals(optionVerbose)) {
- return true;
- }
- }
- return false;
- }
-
- private void processForbidden(List<ArgumentOption> argumentOptionList) {
- for (ArgumentOption argumentOption : argumentOptionList) {
- if (isForbidden(argumentOption)) {
- throw new RuntimeException("Must not have both "+this.verbose+" and "+argumentOption.getVerbose());
- }
- }
- }
-
- private boolean isForbidden(ArgumentOption argumentOption) {
- String argument = argumentOption.getVerbose();
- if (argument != null) {
- List<String> forbiddenArguments = this.getForbiddenArguments();
- for (String forbiddenArgument : forbiddenArguments) {
- if (argument.equals(forbiddenArgument)) {
- return true;
- }
- }
- }
- return false;
- }
-
- private List<String> getForbiddenArguments() {
- forbiddenArguments = getWhitespaceSeparatedArguments(this.getForbiddenString());
- return forbiddenArguments;
- }
-
- private List<String> getRequiredArguments() {
- requiredArguments = getWhitespaceSeparatedArguments(this.getRequiredString());
- return requiredArguments;
- }
-
- private static List<String> getWhitespaceSeparatedArguments(String strings) {
- return (strings == null) ? new ArrayList<String>() :
- new ArrayList<String>(Arrays.asList(strings.split("\\s+")));
- }
-
-
-}
=====================================
src/main/java/org/xmlcml/args/DefaultArgProcessor.java-old deleted
=====================================
@@ -1,655 +0,0 @@
-package org.xmlcml.args;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.InputStream;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import nu.xom.Builder;
-import nu.xom.Element;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.exception.ExceptionUtils;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.xmlcml.files.QuickscrapeNorma;
-import org.xmlcml.files.QuickscrapeNormaList;
-import org.xmlcml.xml.XMLUtil;
-
- at Deprecated
-
-public class DefaultArgProcessor {
-
-
- private static final Logger LOG = Logger.getLogger(DefaultArgProcessor.class);
- static {
- LOG.setLevel(Level.DEBUG);
- }
-
- public static final String MINUS = "-";
- public static final String[] DEFAULT_EXTENSIONS = {"html", "xml", "pdf"};
- public final static String H = "-h";
- public final static String HELP = "--help";
- private static Pattern INTEGER_RANGE = Pattern.compile("(.*)\\{(\\d+),(\\d+)\\}(.*)");
-
- private static String RESOURCE_NAME_TOP = "/org/xmlcml/args";
- private static String ARGS_RESOURCE = RESOURCE_NAME_TOP+"/"+"args.xml";
-
- private static final Pattern INTEGER_RANGE_PATTERN = Pattern.compile("(\\d+):(\\d+)");
- protected static final String ARGS_XML = "args.xml";
- public static Pattern GENERAL_PATTERN = Pattern.compile("\\{([^\\}]*)\\}");
-
- /** creates a list of tokens that are found in an allowed list.
- *
- * @param allowed
- * @param tokens
- * @return list of allowed tokens
- */
- protected static List<String> getChosenList(List<String> allowed, List<String> tokens) {
- List<String> chosenTokens = new ArrayList<String>();
- for (String method : tokens) {
- if (allowed.contains(method)) {
- chosenTokens.add(method);
- } else {
- LOG.error("Unknown token: "+method);
- }
- }
- return chosenTokens;
- }
-
- protected String output;
- protected List<String> extensionList = null;
- private boolean recursive = false;
- protected List<String> inputList;
- public List<ArgumentOption> argumentOptionList;
- public List<ArgumentOption> chosenArgumentOptionList;
- protected QuickscrapeNormaList quickscrapeNormaList;
- protected QuickscrapeNorma currentQuickscrapeNorma;
- protected String summaryFileName;
- protected Map<String, String> variableByNameMap;
- private VariableProcessor variableProcessor;
-
-
-
- protected List<ArgumentOption> getArgumentOptionList() {
- return argumentOptionList;
- }
-
- public DefaultArgProcessor() {
- readArgumentOptions(ARGS_RESOURCE);
- }
-
- public DefaultArgProcessor(String resourceName) {
- this();
- readArgumentOptions(resourceName);
- }
-
- public void readArgumentOptions(String resourceName) {
- ensureArgumentOptionList();
- try {
- InputStream is = this.getClass().getResourceAsStream(resourceName);
- if (is == null) {
- throw new RuntimeException("Cannot read/find input resource stream: "+resourceName);
- }
- Element argElement = new Builder().build(is).getRootElement();
- List<Element> elementList = XMLUtil.getQueryElements(argElement, "/*/*[local-name()='arg']");
- for (Element element : elementList) {
- ArgumentOption argOption = ArgumentOption.createOption(this.getClass(), element);
- LOG.trace("created ArgumentOption: "+argOption);
- argumentOptionList.add(argOption);
- }
- } catch (Exception e) {
- throw new RuntimeException("Cannot read/process args file "+resourceName, e);
- }
- }
-
- private void ensureArgumentOptionList() {
- if (this.argumentOptionList == null) {
- this.argumentOptionList = new ArrayList<ArgumentOption>();
- }
- }
-
- public void expandWildcardsExhaustively() {
- while (expandWildcardsOnce());
- }
-
- public boolean expandWildcardsOnce() {
- boolean change = false;
- ensureInputList();
- List<String> newInputList = new ArrayList<String>();
- for (String input : inputList) {
- List<String> expanded = expandWildcardsOnce(input);
- newInputList.addAll(expanded);
- change |= (expanded.size() > 1 || !expanded.get(0).equals(input));
- }
- inputList = newInputList;
- return change;
- }
-
-
- /** expand expressions/wildcards in input.
- *
- * @param input
- * @return
- */
- private List<String> expandWildcardsOnce(String input) {
- Matcher matcher = GENERAL_PATTERN.matcher(input);
- List<String> inputs = new ArrayList<String>();
- if (matcher.find()) {
- String content = matcher.group(1);
- String pre = input.substring(0, matcher.start());
- String post = input.substring(matcher.end());
- inputs = expandIntegerMatch(content, pre, post);
- if (inputs.size() == 0) {
- inputs = expandStrings(content, pre, post);
- }
- if (inputs.size() == 0) {
- LOG.error("Cannot expand "+content);
- }
- } else {
- inputs.add(input);
- }
- return inputs;
- }
-
- private List<String> expandIntegerMatch(String content, String pre, String post) {
- List<String> stringList = new ArrayList<String>();
- Matcher matcher = INTEGER_RANGE_PATTERN.matcher(content);
- if (matcher.find()) {
- int start = Integer.parseInt(matcher.group(1));
- int end = Integer.parseInt(matcher.group(2));
- for (int i = start; i <= end; i++) {
- String s = pre + i + post;
- stringList.add(s);
- }
- }
- return stringList;
- }
-
- private List<String> expandStrings(String content, String pre, String post) {
- List<String> newStringList = new ArrayList<String>();
- List<String> vars = Arrays.asList(content.split("\\|"));
- for (String var : vars) {
- newStringList.add(pre + var + post);
- }
-
- return newStringList;
- }
-
- // ============ METHODS ===============
-
- public void parseExtensions(ArgumentOption option, ArgIterator argIterator) {
- List<String> extensions = argIterator.createTokenListUpToNextNonDigitMinus(option);
- setExtensions(extensions);
- }
-
-
- public void parseQuickscrapeNorma(ArgumentOption option, ArgIterator argIterator) {
- List<String> qDirectoryNames = argIterator.createTokenListUpToNextNonDigitMinus(option);
- createQuickscrapeNormaList(qDirectoryNames);
- }
-
- public void printHelp(ArgumentOption option, ArgIterator argIterator) {
- printHelp();
- }
-
- public void parseInput(ArgumentOption option, ArgIterator argIterator) {
- List<String> inputs = argIterator.createTokenListUpToNextNonDigitMinus(option);
- inputList = expandAllWildcards(inputs);
- }
-
-
- public void parseOutput(ArgumentOption option, ArgIterator argIterator) {
- output = argIterator.getString(option);
- }
-
- public void parseRecursive(ArgumentOption option, ArgIterator argIterator) {
- recursive = argIterator.getBoolean(option);
- }
-
- public void parseSummaryFile(ArgumentOption option, ArgIterator argIterator) {
- summaryFileName = argIterator.getString(option);
- }
-
- public void outputMethod(ArgumentOption option) {
- LOG.error("outputMethod NYI");
- }
-
- // =====================================
-
- private void createQuickscrapeNormaList(List<String> qDirectoryNames) {
- FileFilter directoryFilter = new FileFilter() {
- public boolean accept(File file) {
- return file.isDirectory();
- }
- };
-
- quickscrapeNormaList = new QuickscrapeNormaList();
- for (String qDirectoryName : qDirectoryNames) {
- File qDirectory = new File(qDirectoryName);
- if (!qDirectory.exists()) {
- LOG.error("File does not exist: "+qDirectory.getAbsolutePath());
- continue;
- }
- if (!qDirectory.isDirectory()) {
- LOG.error("Not a directory: "+qDirectory.getAbsolutePath());
- continue;
- }
- QuickscrapeNorma quickscrapeNorma = new QuickscrapeNorma(qDirectoryName);
- if (quickscrapeNorma.containsNoReservedFilenames()) {
- List<File> childFiles = new ArrayList<File>(Arrays.asList(qDirectory.listFiles(directoryFilter)));
- List<String> childFilenames = new ArrayList<String>();
- for (File childFile : childFiles) {
- if (childFile.isDirectory()) {
- childFilenames.add(childFile.toString());
- }
- }
- LOG.trace(childFilenames);
- // recurse (no mixed directory structures)
- createQuickscrapeNormaList(childFilenames);
- } else {
- quickscrapeNormaList.add(quickscrapeNorma);
- }
- }
- }
-
-
- private List<String> expandAllWildcards(List<String> inputs) {
- inputList = new ArrayList<String>();
- for (String input : inputs) {
- inputList.addAll(expandWildcards(input));
- }
- return inputList;
- }
-
- /** expand expressions/wildcards in input.
- *
- * @param input
- * @return
- */
- private List<String> expandWildcards(String input) {
- Matcher matcher = INTEGER_RANGE.matcher(input);
- List<String> inputs = new ArrayList<String>();
- if (matcher.matches()) {
- int start = Integer.parseInt(matcher.group(2));
- int end = Integer.parseInt(matcher.group(3));
- if (start <= end) {
- for (int i = start; i <= end; i++) {
- String input0 = matcher.group(1)+i+matcher.group(4);
- inputs.add(input0);
- }
- }
- } else {
- inputs.add(input);
- }
- LOG.trace("inputs: "+inputs);
- return inputs;
- }
-
- // =====================================
- public void setExtensions(List<String> extensions) {
- this.extensionList = extensions;
- }
-
-
- public List<String> getInputList() {
- ensureInputList();
- return inputList;
- }
-
- public String getString() {
- ensureInputList();
- return (inputList.size() != 1) ? null : inputList.get(0);
- }
- private void ensureInputList() {
- if (inputList == null) {
- inputList = new ArrayList<String>();
- }
- }
-
- public String getOutput() {
- return output;
- }
-
- public boolean isRecursive() {
- return recursive;
- }
-
- public String getSummaryFileName() {
- return summaryFileName;
- }
-
- public QuickscrapeNormaList getQuickscrapeNormaList() {
- ensureQuickscrapeNormaList();
- return quickscrapeNormaList;
- }
-
- protected void ensureQuickscrapeNormaList() {
- if (quickscrapeNormaList == null) {
- quickscrapeNormaList = new QuickscrapeNormaList();
- }
- }
-
-
- // --------------------------------
-
- public void parseArgs(String[] commandLineArgs) {
- if (commandLineArgs == null || commandLineArgs.length == 0) {
- printHelp();
- } else {
- String[] totalArgs = addDefaultsAndParsedArgs(commandLineArgs);
- ArgIterator argIterator = new ArgIterator(totalArgs);
- LOG.trace("args with defaults is: "+new ArrayList<String>(Arrays.asList(totalArgs)));
- while (argIterator.hasNext()) {
- String arg = argIterator.next();
- LOG.trace("arg> "+arg);
- try {
- addArgumentOptionsAndRunParseMethods(argIterator, arg);
- } catch (Exception e) {
- throw new RuntimeException("cannot process argument: "+arg+" ("+ExceptionUtils.getRootCauseMessage(e)+")", e);
- }
- }
- finalizeArgs();
- }
- }
-
- public void parseArgs(String args) {
- parseArgs(args.split("\\s+"));
- }
-
- private void finalizeArgs() {
- processArgumentDependencies();
- finalizeInputList();
- }
-
- private void processArgumentDependencies() {
- for (ArgumentOption argumentOption : chosenArgumentOptionList) {
- argumentOption.processDependencies(chosenArgumentOptionList);
- }
- }
-
- private void finalizeInputList() {
- List<String> inputList0 = new ArrayList<String>();
- ensureInputList();
- for (String input : inputList) {
- File file = new File(input);
- if (file.isDirectory()) {
- LOG.debug("DIR: "+file.getAbsolutePath()+"; "+file.isDirectory());
- addDirectoryFiles(inputList0, file);
- } else {
- inputList0.add(input);
- }
- }
- inputList = inputList0;
- }
-
- private void addDirectoryFiles(List<String> inputList0, File file) {
- String[] extensions = getExtensions().toArray(new String[0]);
- List<File> files = new ArrayList<File>(
- FileUtils.listFiles(file, extensions, recursive));
- for (File file0 : files) {
- inputList0.add(file0.toString());
- }
- }
-
- private String[] addDefaultsAndParsedArgs(String[] commandLineArgs) {
- String[] defaultArgs = createDefaultArgumentStrings();
- List<String> totalArgList = new ArrayList<String>(Arrays.asList(createDefaultArgumentStrings()));
- List<String> commandArgList = Arrays.asList(commandLineArgs);
- totalArgList.addAll(commandArgList);
- String[] totalArgs = totalArgList.toArray(new String[0]);
- return totalArgs;
- }
-
- private String[] createDefaultArgumentStrings() {
- StringBuilder sb = new StringBuilder();
- for (ArgumentOption option : argumentOptionList) {
- String defalt = String.valueOf(option.getDefault());
- if (defalt != null && defalt.toString().trim().length() > 0) {
- String command = getBriefOrVerboseCommand(option);
- sb.append(command+" "+option.getDefault()+" ");
- }
- }
- String s = sb.toString().trim();
- return s.length() == 0 ? new String[0] : s.split("\\s+");
- }
-
- private String getBriefOrVerboseCommand(ArgumentOption option) {
- String command = option.getBrief();
- if (command == null || command.trim().length() == 0) {
- command = option.getVerbose();
- }
- return command;
- }
-
- public List<String> getExtensions() {
- ensureExtensionList();
- return extensionList;
- }
-
- private void ensureExtensionList() {
- if (extensionList == null) {
- extensionList = new ArrayList<String>();
- }
- }
-
- public void runRunMethodsOnChosenArgOptions() {
- for (ArgumentOption option : chosenArgumentOptionList) {
- String runMethodName = option.getRunMethodName();
- LOG.trace("Method: "+runMethodName);
- if (runMethodName != null) {
- LOG.trace("Method " + runMethodName);
- try {
- runRunMethod(option);
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException("cannot process argument: "+option.getVerbose()+" ("+ExceptionUtils.getRootCauseMessage(e)+")", e);
- }
- }
- }
- }
-
- public void runOutputMethodsOnChosenArgOptions() {
- for (ArgumentOption option : chosenArgumentOptionList) {
- String outputMethodName = option.getOutputMethodName();
- LOG.trace("OUTPUT "+outputMethodName);
- if (outputMethodName != null) {
- try {
- runOutputMethod(option);
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException("cannot process argument: "+option.getVerbose()+" ("+ExceptionUtils.getRootCauseMessage(e)+")");
- }
- }
- }
- }
-
- public void runFinalMethodsOnChosenArgOptions() {
- ensureChosenArgumentList();
- for (ArgumentOption option : chosenArgumentOptionList) {
- String finalMethodName = option.getFinalMethodName();
- if (finalMethodName != null) {
- try {
- runFinalMethod(option);
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException("cannot process argument: "+option.getVerbose()+" ("+ExceptionUtils.getRootCauseMessage(e)+")");
- }
- }
- }
- }
-
- protected void addArgumentOptionsAndRunParseMethods(ArgIterator argIterator, String arg) throws Exception {
- ensureChosenArgumentList();
- boolean processed = false;
- if (!arg.startsWith(MINUS)) {
- LOG.error("Parsing failed at: ("+arg+"), expected \"-\" trying to recover");
- } else {
- for (ArgumentOption option : argumentOptionList) {
- if (option.matches(arg)) {
- LOG.trace("OPTION>> "+option);
- String initMethodName = option.getInitMethodName();
- if (initMethodName != null) {
- runInitMethod(option, initMethodName);
- }
- String parseMethodName = option.getParseMethodName();
- if (parseMethodName != null) {
- runParseMethod(argIterator, option, parseMethodName);
- }
- processed = true;
- chosenArgumentOptionList.add(option);
- break;
- }
- }
- if (!processed) {
- LOG.error("Unknown arg: ("+arg+"), trying to recover");
- }
- }
- }
-
- private void runInitMethod(ArgumentOption option, String initMethodName) {
- runMethod(null, option, initMethodName);
- }
-
- private void runParseMethod(ArgIterator argIterator, ArgumentOption option, String parseMethodName) {
- runMethod(argIterator, option, parseMethodName);
- }
-
- private void runMethod(ArgIterator argIterator, ArgumentOption option, String methodName) {
- Method method;
- try {
- if (argIterator == null) {
- method = this.getClass().getMethod(methodName, option.getClass());
- } else {
- method = this.getClass().getMethod(methodName, option.getClass(), argIterator.getClass());
- }
- } catch (NoSuchMethodException e) {
- debugMethods();
- throw new RuntimeException("Cannot find: "+methodName+" in "+this.getClass()+"; from argument "+option.getClass()+";", e);
- }
- method.setAccessible(true);
- try {
- if (argIterator == null) {
- method.invoke(this, option);
- } else {
- method.invoke(this, option, argIterator);
- }
- } catch (Exception e) {
- LOG.trace("failed to run "+methodName+" in "+this.getClass()+"; from argument "+option.getClass()+";"+e.getCause());
-// e.printStackTrace();
- throw new RuntimeException("Cannot run: "+methodName+" in "+this.getClass()+"; from argument "+option.getClass()+";", e);
- }
- }
-
- private void debugMethods() {
- LOG.debug("methods for "+this.getClass());
- for (Method meth : this.getClass().getDeclaredMethods()) {
- LOG.debug(meth);
- }
- }
-
- protected void runRunMethod(ArgumentOption option) throws Exception {
- String runMethodName = option.getRunMethodName();
- if (runMethodName != null) {
- LOG.trace("running "+runMethodName);
- Method runMethod = null;
- try {
- runMethod = this.getClass().getMethod(runMethodName, option.getClass());
- } catch (NoSuchMethodException nsme) {
- throw new RuntimeException(runMethodName+"; "+this.getClass()+"; "+option.getClass()+"; \nContact Norma developers: ", nsme);
- }
- runMethod.setAccessible(true);
- runMethod.invoke(this, option);
- }
- }
-
- protected void runOutputMethod(ArgumentOption option) throws Exception {
- String outputMethodName = option.getOutputMethodName();
- if (outputMethodName != null) {
- Method outputMethod = null;
- try {
- outputMethod = this.getClass().getMethod(outputMethodName, option.getClass());
- } catch (NoSuchMethodException nsme) {
- throw new RuntimeException(outputMethodName+"; "+this.getClass()+"; "+option.getClass()+"; \nContact Norma developers: ", nsme);
- }
- outputMethod.setAccessible(true);
- outputMethod.invoke(this, option);
- }
- }
-
- protected void runFinalMethod(ArgumentOption option) throws Exception {
- String finalMethodName = option.getFinalMethodName();
- if (finalMethodName != null) {
- Method finalMethod = null;
- try {
- finalMethod = this.getClass().getMethod(finalMethodName, option.getClass());
- } catch (NoSuchMethodException nsme) {
- throw new RuntimeException(finalMethodName+"; "+this.getClass()+"; "+option.getClass()+"; \nContact Norma developers: ", nsme);
- }
- finalMethod.setAccessible(true);
- finalMethod.invoke(this, option);
- }
- }
-
- private void ensureChosenArgumentList() {
- if (chosenArgumentOptionList == null) {
- chosenArgumentOptionList = new ArrayList<ArgumentOption>();
- }
- }
-
- protected void printHelp() {
- for (ArgumentOption option : argumentOptionList) {
- System.err.println(option.getHelp());
- }
- }
-
- public List<ArgumentOption> getChosenArgumentList() {
- ensureChosenArgumentList();
- return chosenArgumentOptionList;
- }
-
- public String createDebugString() {
- StringBuilder sb = new StringBuilder();
- getChosenArgumentList();
- for (ArgumentOption argumentOption : chosenArgumentOptionList) {
- sb.append(argumentOption.toString()+"\n");
- }
- return sb.toString();
- }
-
- public void runAndOutput() {
- ensureQuickscrapeNormaList();
- if (quickscrapeNormaList.size() == 0) {
- LOG.warn("Could not find list of CMdirs; possible error");
- }
- for (int i = 0; i < quickscrapeNormaList.size(); i++) {
- currentQuickscrapeNorma = quickscrapeNormaList.get(i);
- runRunMethodsOnChosenArgOptions();
- runOutputMethodsOnChosenArgOptions();
- }
- runFinalMethodsOnChosenArgOptions();
- }
-
- protected void addVariableAndExpandReferences(String name, String value) {
- ensureVariableProcessor();
- try {
- variableProcessor.addVariableAndExpandReferences(name, value);
- } catch (Exception e) {
- LOG.error("add variable {"+name+", "+value+"} failed");
- }
- }
-
- public VariableProcessor ensureVariableProcessor() {
- if (variableProcessor == null) {
- variableProcessor = new VariableProcessor();
- }
- return variableProcessor;
- }
-
-}
=====================================
src/main/java/org/xmlcml/args/StringPair.java-old deleted
=====================================
@@ -1,19 +0,0 @@
-package org.xmlcml.args;
-
-/** a pair of strings.
- *
- * @author pm286
- *
- */
- at Deprecated
-
-public class StringPair {
-
- public String left;
- public String right;
-
- public StringPair(String left, String right) {
- this.left = left;
- this.right = right;
- }
-}
=====================================
src/main/java/org/xmlcml/args/VariableProcessor.java-old deleted
=====================================
@@ -1,72 +0,0 @@
-package org.xmlcml.args;
-
-import java.util.HashMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-
-/** holds symbolic variabls for processing input.
- *
- * @author pm286
- *
- */
- at Deprecated
-
-public class VariableProcessor {
-
-
- private static final Logger LOG = Logger.getLogger(VariableProcessor.class);
- static {
- LOG.setLevel(Level.DEBUG);
- }
-
- // ${ ... }
- private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\$\\{[^\\}]*\\}");
- private HashMap<String, String> variableByNameMap;
-
- public VariableProcessor() {
- this.variableByNameMap = new HashMap<String, String>();
- }
-
- public String getVariable(String name) {
- return variableByNameMap.get(name);
- }
-
- public boolean addVariableAndExpandReferences(String name, String value) {
- boolean added = true;
- if (variableByNameMap.containsKey(name)) {
- LOG.error("Duplicate variable name: "+name);
- added = false;
- } else {
- try {
- value = substituteVariables(value);
- } catch (Exception e) {
- added = false;
- }
- }
- return added;
- }
-
- public String substituteVariables(String value) {
- StringBuilder sb = new StringBuilder();
- Matcher matcher = VARIABLE_PATTERN.matcher(value);
- int start = 0;
- int end = 0;
- while (matcher.find()) {
- start = matcher.start();
- sb.append(value.substring(end, start));
- end = matcher.end();
- String variableRef = value.substring(start + 2, end - 1);
- String variableValue = variableByNameMap.get(variableRef);
- if (variableValue == null) {
- throw new RuntimeException("Cannot resolve variable ${"+variableRef+"} in "+value);
- }
- sb.append(variableValue);
- }
- sb.append(value.substring(end));
- return sb.toString();
- }
-
-}
=====================================
src/main/java/org/xmlcml/args/sandpit/SandpitArgProcessor.java-old deleted
=====================================
@@ -1,89 +0,0 @@
-package org.xmlcml.args.sandpit;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.xmlcml.args.ArgIterator;
-import org.xmlcml.args.ArgumentOption;
-import org.xmlcml.args.DefaultArgProcessor;
-import org.xmlcml.euclid.IntArray;
-import org.xmlcml.euclid.RealArray;
-
-/**
- * Processes commandline arguments.
- * for Norma
- *
- * @author pm286
- */
-public class SandpitArgProcessor extends DefaultArgProcessor{
-
- public static final Logger LOG = Logger.getLogger(SandpitArgProcessor.class);
- static {
- LOG.setLevel(Level.DEBUG);
- }
-
- private static String RESOURCE_NAME_TOP = "/org/xmlcml/args/sandpit";
- private static String ARGS_RESOURCE = RESOURCE_NAME_TOP+"/"+"args.xml";
-
- private Double dubble;
- private RealArray doubleArray;
- private Integer intg;
- private IntArray intArray;
-
- public SandpitArgProcessor() {
- super(ARGS_RESOURCE);
- }
-
- public SandpitArgProcessor(String[] args) {
- this();
- parseArgs(args);
- }
-
- // ============= METHODS =============
-
- public void parseDouble(ArgumentOption option, ArgIterator argIterator) {
- dubble = argIterator.getDouble(option);
- }
-
-
- public void parseDoubleArray(ArgumentOption option, ArgIterator argIterator) {
- doubleArray = argIterator.getDoubleArray(option);
- }
-
- public void parseInteger(ArgumentOption option, ArgIterator argIterator) {
- intg = argIterator.getInteger(option);
- }
-
-
- public void parseIntegerArray(ArgumentOption option, ArgIterator argIterator) {
- intArray = argIterator.getIntArray(option);
- }
-
-
- // ===========run===============
-
- public Double getDouble() {
- return dubble;
- }
-
- public RealArray getDoubleArray() {
- return doubleArray;
- }
-
- public Integer getInteger() {
- return intg;
- }
-
- public IntArray getIntArray() {
- return intArray;
- }
-
- public void runTest(ArgumentOption option) {
- LOG.debug("RUN_TEST "+"is a dummy");
- }
-
-
- // ==========================
-
-
-
-}
=====================================
src/main/java/org/xmlcml/files/EuclidSource.java-old deleted
=====================================
@@ -1,76 +0,0 @@
-package org.xmlcml.files;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.net.URL;
-
-import org.apache.commons.io.FilenameUtils;
-import org.xmlcml.euclid.Euclid;
-
-/** general static utilities.
- *
- * @author pm286
- *
- */
- at Deprecated
-
-public class EuclidSource {
-
-
- public static final String DOI = "doi:";
- public static final String HTTP = "http://";
- public static final String HTTPS = "https://";
- public static final String HTM = "htm";
- public static final String HTML = "html";
- public static final String PDF = "pdf";
- public static final String SVG = "svg";
- public static final String XML = "xml";
-
- public static final String LINE_NUMBER = "lineNumber";
- public static final String LINE_VALUE = "lineValue";
- public static final String XPATH = "xpath";
-
- public static boolean endsWithSeparator(String filename) {
- return filename != null && FilenameUtils.indexOfLastSeparator(filename) == filename.length()-1;
- }
-
- /** crude tool to guess whether is URL from name.
- *
- * @param name
- * @return
- */
- public static boolean isURL(String name) {
- return name.startsWith(HTTP) || name.startsWith(HTTPS);
- }
-
- /** heuristic ducktype to get input stream;
- *
- * First assumes name is resource on classpath.
- * if fails; tries it as http:// or https:// URL
- * if fails; tries as filename
- *
- * @param name (of resource, URL, or filename)
- * @return Opened stream, or null if not found
- */
- public static InputStream getInputStream(String name) {
- InputStream is = Euclid.class.getResourceAsStream(name);
- if (is == null) {
- try {
- is = new URL(name).openStream();
- } catch (Exception e) {
- // not a URL
- }
- }
- if (is == null) {
- try {
- is = new FileInputStream(name);
- } catch (FileNotFoundException e) {
- // no file
- }
- }
- return is;
- }
-
-
-}
=====================================
src/main/java/org/xmlcml/files/QuickscrapeNorma.java-old deleted
=====================================
@@ -1,595 +0,0 @@
-package org.xmlcml.files;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import nu.xom.Document;
-import nu.xom.Element;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.FilenameUtils;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.xmlcml.args.ArgumentOption;
-import org.xmlcml.xml.XMLUtil;
-
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimap;
-
-
-/** collection of files within the ContentMine system.
- *
- * The structure of scholarly articles often requires many constituent articles. For example an article may have a PDF, an HTML abstract, several GIFs for images, some tables in HTML, some DOCX files, CIFs for crystallography, etc.. These all need keeping together...
-
-Note that the Catalog (from CottageLabs) primarily holds metadata. [It's possible to hold some of the HTML content, but it soon starts to degrade performance]. We therefore have metadata in the Catalog and contentFiles on disk. These files and Open and can, in principle, be used independently of the Catalog.
-
-I am designing a "QuickscrapeNorma" which passes the bundle down the pipeline. This should be independent of what language [Python , JS, Java...] is used to create or read them. We believe that a normal filing system is satisfactory (at least at present while we develop the technology).
-
-A typical pass for one DOI (e.g. journal.pone.0115884 ) through the pipeline (mandatory files are marked *, optional ?) might look like:
-
-DOI --> Quickscrape -->
-
-create directory contentmine/some/where/journal.pone.0115884/. It may contain
-
-results.json * // a listing of scraped files
-
-fulltext.xml ? // publishers XML
-fulltext.pdf ? // publishers PDF
-fulltext.html ? // raw HTML
-fulltext.pdf.txt ? // raw text from pdf
-provisional.pdf ? // provisional PDF (often disappears)
-
-foo12345.docx ? // data files numbered by publisher/author
-bar54321.docx ?
-ah1234.cif ? // crystallographic data
-pqr987.cml ? // chemistry file
-mmm.csv ? // table
-pic5656.png ? // images
-pic5657.gif ? // image
-suppdata.pdf ? // supplemental data
-
-and more
-
-only results.json is mandatory. However there will normally be at least one fulltext.* file and probably at least one *.html file (as the landing page must be in HTML). Since quickscrape can extract data without fulltext it might also be deployed against a site with data files.
-
-There may be some redundancy - *.xml may be trasformable into *.html and *.pdf into *.html. The PDF may also contain the same images as some exposed *.png.
-
-==================
-
-This container (directory) is then massed to Norma. Norma will normalize as much information as possible, and we can expect this to continue to develop. This includes:
-* conversion to Unicode (XML, HTML, and most "text" files)
-* normalization of characters (e.g. Angstrom -> Aring, smart quotes => "", superscript "o" to degrees, etc.)
-* creating well-formed HTML (often very hard)
-* converting PDF to SVG (very empirical and heuristic)
-* converting SVG to running text.
-* building primitives (circles, squares, from the raw graphics)
-* building graphics objects (arrows, textboxes, flowcharts) from the primitives
-* building text from SVG
-
-etc...
-
-This often creates a lot of temporary files, which may be usefully cached for a period. We may create a subdirectory ./svg with intermediate pages, or extracted SVGs. These will be recorded in results.json, which will act as metadata for the files and subdirectories.
-
-Norma will create ./svg/*.svg from PDF (using PDFBox and PDF2SVG), then fulltext.pdf.xhtml (heuristically created XHTML). Norma will also create wellformed fulltext.html.xhtml from raw fulltext.html or from fulltext.xml.xhtml from fulltext.xml.
-
-In the future Norma will also convert MS-formats such as DOCX and PPT using Apach POI.
-
-Norma will then structure any flat structures into structured XHTML using grouping rules such as in XSLT2.
-
-At this stage we shall have structured XHTML files ("scholarly HTML") with linked images and tables and supplemental data. We'll update results.json
-
-========================
-
-AMI can further index or transform the ScholarlyHTML and associated files. An AMI plugin (e.g. AMI-species) will produce species.results.xml - a file with the named species in textual context. Similar outputs come from sequence, or other tagging (geotagging).
-
-The main community development will come from regexes. For example we have
-regex.crystal.results.xml, regex.farm.results.xml, regex.clinical_trials.results.xml, etc.
-
-The results file include the regexes used and other metadata (more needed!). Again we can update results.json. We may also wish to delete temporary files such as the *.svg in PDF2SVG....
-
- *
- * @author pm286
- *
- */
- at Deprecated
-
-public class QuickscrapeNorma {
-
-
-
- private static final Logger LOG = Logger.getLogger(QuickscrapeNorma.class);
- static {
- LOG.setLevel(Level.DEBUG);
- }
-
- private static final String DOCX = "docx";
- private static final String EPUB = "epub";
- private static final String HTML = "html";
- private static final String PDF = "pdf";
- private static final String XML = "xml";
-
- public static final String ABSTRACT_HTML = "abstract.html";
- public static final String FULLTEXT_DOCX = "fulltext.docx";
- public static final String FULLTEXT_HTML = "fulltext.html";
- public static final String FULLTEXT_PDF = "fulltext.pdf";
- public static final String FULLTEXT_PDF_TXT = "fulltext.pdf.txt";
- public static final String FULLTEXT_XML = "fulltext.xml";
- public static final String RESULTS_JSON = "results.json";
- public static final String RESULTS_XML = "results.xml";
- public static final String RESULTS_HTML = "results.html";
- public static final String SCHOLARLY_HTML = "scholarly.html";
-
- public final static List<String> RESERVED_FILE_NAMES;
- static {
- RESERVED_FILE_NAMES = Arrays.asList(new String[] {
- ABSTRACT_HTML,
- FULLTEXT_DOCX,
- FULLTEXT_HTML,
- FULLTEXT_PDF,
- FULLTEXT_PDF_TXT,
- FULLTEXT_XML,
- RESULTS_JSON,
- RESULTS_XML,
- SCHOLARLY_HTML
- });
- }
- public static final String RESULTS_DIR = "results/";
- public static final String PDF_DIR = "pdf/";
-
- public final static List<String> RESERVED_DIR_NAMES;
- static {
- RESERVED_DIR_NAMES = Arrays.asList(new String[] {
- RESULTS_DIR,
- PDF_DIR,
- });
- }
-
- public final static Map<String, String> RESERVED_FILES_BY_EXTENSION = new HashMap<String, String>();
- private static final String RESULTS_DIRECTORY_NAME = "results";
- static {
- RESERVED_FILES_BY_EXTENSION.put(DOCX, FULLTEXT_DOCX);
-// RESERVED_FILES_BY_EXTENSION.put(EPUB, FULLTEXT_EPUB);
- RESERVED_FILES_BY_EXTENSION.put(HTML, FULLTEXT_HTML);
- RESERVED_FILES_BY_EXTENSION.put(PDF, FULLTEXT_PDF);
- RESERVED_FILES_BY_EXTENSION.put(XML, FULLTEXT_XML);
- }
-
- public static boolean isReservedFilename(String name) {
- return RESERVED_FILE_NAMES.contains(name);
- }
-
- public static boolean isReservedDirectory(String name) {
- return RESERVED_DIR_NAMES.contains(name);
- }
-
- private File directory;
- private List<File> reservedFileList;
- private List<File> nonReservedFileList;
- private List<File> reservedDirList;
- private List<File> nonReservedDirList;
-
- public QuickscrapeNorma() {
-
- }
-
- /** creates QN object but does not alter filestore.
- *
- * @param directory
- */
- public QuickscrapeNorma(File directory) {
- this.directory = directory;
- }
-
- /** ensures filestore matches a QuickscrapeNorma structure.
- *
- * @param directory
- * @param delete
- */
- public QuickscrapeNorma(File directory, boolean delete) {
- this(directory);
- this.createDirectory(directory, delete);
- }
-
- public QuickscrapeNorma(String filename) {
- this(new File(filename), false);
- }
-
- public void ensureReservedFilenames() {
- if (reservedFileList == null) {
- reservedFileList = new ArrayList<File>();
- nonReservedFileList = new ArrayList<File>();
- reservedDirList = new ArrayList<File>();
- nonReservedDirList = new ArrayList<File>();
- List<File> files = new ArrayList<File>(FileUtils.listFiles(directory, null, false));
- for (File file : files) {
- if (file.isDirectory()) {
- if (isReservedDirectory(FilenameUtils.getName(file.getAbsolutePath()))) {
- reservedDirList.add(file);
- } else {
- nonReservedDirList.add(file);
- }
- } else {
- if (isReservedFilename(FilenameUtils.getName(file.getAbsolutePath()))) {
- reservedFileList.add(file);
- } else {
- nonReservedFileList.add(file);
- }
- }
- }
- }
- }
-
- public List<File> getReservedDirectoryList() {
- ensureReservedFilenames();
- return reservedDirList;
- }
-
- public List<File> getReservedFileList() {
- ensureReservedFilenames();
- return reservedFileList;
- }
-
- public List<File> getNonReservedDirectoryList() {
- ensureReservedFilenames();
- return nonReservedDirList;
- }
-
- public List<File> getNonReservedFileList() {
- ensureReservedFilenames();
- return nonReservedFileList;
- }
-
- public static boolean containsNoReservedFilenames(File dir) {
- if (dir != null && dir.isDirectory()) {
- List<File> files = new ArrayList<File>(FileUtils.listFiles(dir, null, false));
-// int nonReserved = 0;
- for (File file : files) {
- if (!file.isHidden()) {
- String name = FilenameUtils.getName(file.getAbsolutePath());
- if (isReservedFilename(name)) {
- return false;
- }
-// nonReserved++;
- }
- }
- return true;
- }
- return false;
- }
-
- public boolean containsNoReservedFilenames() {
- return QuickscrapeNorma.containsNoReservedFilenames(directory);
- }
-
- public void createDirectory(File dir, boolean delete) {
- this.directory = dir;
- if (dir == null) {
- throw new RuntimeException("Null directory");
- }
- if (delete) {
- try {
- FileUtils.forceDelete(dir);
- } catch (IOException e) {
- throw new RuntimeException("Cannot delete directory: "+dir, e);
- }
- }
- try {
- FileUtils.forceMkdir(dir);
- } catch (IOException e) {
- throw new RuntimeException("Cannot make directory: "+dir+" already exists");
- } // maybe
- }
-
- public void readDirectory(File dir) {
- this.directory = dir;
- Multimap<String, File> map = HashMultimap.create();
-
- requireDirectoryExists(dir);
-// fileList = new ArrayList<File>(FileUtils.listFiles(dir, null, false));
- checkRequiredQuickscrapeFiles();
-// indexByFileExtensions();
- }
-
- private void checkRequiredQuickscrapeFiles() {
- requireExistingNonEmptyFile(new File(directory, RESULTS_JSON));
- }
-
- public static boolean isExistingFile(File file) {
- boolean ok = (file != null);
- ok &= file.exists();
- ok &= !file.isDirectory();
- return ok;
- }
-
- public static boolean isExistingDirectory(File file) {
- boolean ok = (file != null);
- ok &= file.exists();
- ok &= file.isDirectory();
- return ok;
- }
-
- private void requireDirectoryExists(File dir) {
- if (dir == null) {
- throw new RuntimeException("Null directory");
- }
- if (!dir.exists()) {
- throw new RuntimeException("Directory: "+dir+" does not exist");
- }
- if (!dir.isDirectory()) {
- throw new RuntimeException("File: "+dir+" is not a directory");
- }
- }
-
- private void requireExistingNonEmptyFile(File file) {
- if (file == null) {
- throw new RuntimeException("Null file");
- }
- if (!file.exists()) {
- throw new RuntimeException("File: "+file+" does not exist");
- }
- if (file.isDirectory()) {
- throw new RuntimeException("File: "+file+" must not be a directory");
- }
- if (FileUtils.sizeOf(file) == 0) {
- throw new RuntimeException("File: "+file+" must not be empty");
- }
- }
-
- public boolean hasFulltextXML() {
- return isExistingFile(getExistingFulltextXML());
- }
-
- public File getExistingFulltextXML() {
- return getExistingReservedFile(FULLTEXT_XML);
- }
-
- public boolean hasFulltextHTML() {
- return isExistingFile(new File(directory, FULLTEXT_HTML));
- }
-
- public File getExisitingFulltextHTML() {
- return getExistingReservedFile(FULLTEXT_HTML);
- }
-
- public boolean hasResultsJSON() {
- return isExistingFile(new File(directory, RESULTS_JSON));
- }
-
- public File getExistingResultsJSON() {
- return getExistingReservedFile(RESULTS_JSON);
- }
-
- public boolean hasResultsXML() {
- return isExistingFile(new File(directory, RESULTS_XML));
- }
-
- public File getExistingResultsXML() {
- return getExistingReservedFile(RESULTS_XML);
- }
-
- public boolean hasScholarlyHTML() {
- return isExistingFile(new File(directory, SCHOLARLY_HTML));
- }
-
- public File getExistingScholarlyHTML() {
- return getExistingReservedFile(SCHOLARLY_HTML);
- }
-
- public boolean hasFulltextPDF() {
- return isExistingFile(new File(directory, FULLTEXT_PDF));
- }
-
- public File getExisitingFulltextPDF() {
- return getExistingReservedFile(FULLTEXT_PDF);
- }
-
- public File getReservedFile(String reservedName) {
-
- File file = !isReservedFilename(reservedName) ? null : new File(directory, reservedName);
- return file;
- }
-
- public File getExistingReservedFile(String reservedName) {
- File file = new File(directory, reservedName);
- return isExistingFile(file) ? file : null;
- }
-
- public boolean hasFulltextDOCX() {
- return isExistingFile(new File(directory, FULLTEXT_DOCX));
- }
-
- public File getFulltextDOCX() {
- return new File(directory, FULLTEXT_DOCX);
- }
-
- public File getExistingResultsDir() {
- return new File(directory, RESULTS_DIR);
- }
-
- @Override
- public String toString() {
- ensureReservedFilenames();
- StringBuilder sb = new StringBuilder();
- sb.append("dir: "+directory+"\n");
- for (File file : getReservedFileList()) {
- sb.append(file.toString()+"\n");
- }
- return sb.toString();
- }
-
- public void writeFile(String content, String filename) {
- if (filename == null) {
- LOG.error("Null output file");
- return;
- }
- File file = new File(directory, filename);
- if (file.exists()) {
- LOG.error("file already exists (overwritten) "+file);
- }
- if (content != null) {
- try {
- FileUtils.write(file, content);
- } catch (IOException e) {
- throw new RuntimeException("Cannot write file: ", e);
- }
- } else {
- LOG.trace("Null content");
- }
- }
-
- public File getDirectory() {
- return directory;
- }
-
- public List<File> listFiles(boolean recursive) {
- List<File> files = new ArrayList<File>(FileUtils.listFiles(directory, null, recursive));
- return files;
- }
-
- public void writeResults(String resultsFileName, String results) throws Exception {
- File resultsFile = new File(directory, resultsFileName);
- FileUtils.writeStringToFile(resultsFile, results);
- }
-
- public void writeResults(File resultsFile, Element resultsXML) {
-// File resultsFile = new File(directory, resultsFileName);
- try {
- XMLUtil.debug(resultsXML, new FileOutputStream(resultsFile), 1);
- } catch (IOException e) {
- throw new RuntimeException("cannot write XML ", e);
- }
- }
-
- public void writeResults(String resultsFileName, Element resultsXML) {
- writeResults(new File(directory, resultsFileName), resultsXML);
- }
-
- public static String getQNReservedFilenameForExtension(String name) {
- String filename = null;
- String extension = FilenameUtils.getExtension(name);
- if (extension.equals("")) {
- // no type
- } else if (PDF.equals(extension)) {
- filename = FULLTEXT_PDF;
- } else if (XML.equals(extension)) {
- filename = FULLTEXT_XML;
- } else if (HTML.equals(extension)) {
- filename = FULLTEXT_HTML;
- }
- return filename;
- }
-
- public Element getMetadataElement() {
- Element metadata = new Element("qsNorma");
- metadata.appendChild(this.toString());
- return metadata;
- }
-
- public static boolean isNonEmptyNonReservedInputList(List<String> inputList) {
- return inputList != null &&
- (inputList.size() != 1 ||
- !QuickscrapeNorma.isReservedFilename(inputList.get(0)));
- }
-
- public void copyTo(File destDir, boolean overwrite) throws IOException {
- if (destDir == null) {
- throw new RuntimeException("Null destination file in copyTo()");
- } else {
- boolean canWrite = true;
- if (destDir.exists()) {
- if (overwrite) {
- try {
- FileUtils.forceDelete(destDir);
- } catch (IOException e) {
- LOG.error("cannot delete: "+destDir);
- canWrite = false;
- }
- } else {
- LOG.error("Cannot overwrite :"+destDir);
- canWrite = false;
- }
- }
- if (canWrite) {
- FileUtils.copyDirectory(this.directory, destDir);
- if (!destDir.exists() || !destDir.isDirectory()) {
- throw new RuntimeException("failed to create directory: "+destDir);
- }
- }
- }
- }
-
- /** creates a subdirectory of results/ and writes each result file to its own directory.
- *
- * Example:
- * qsnorma1_2_3/
- * results/
- * words/
- * frequencies/
- * results.xml
- * lengths/
- * results.xml
- *
- * here the option is defined in an element in args.xml with name="words"
- *
- * @param option
- * @param resultsElementList
- * @param resultsDirectoryName
- */
- public List<File> createResultsDirectoriesAndOutputResultsElement(
- ArgumentOption option, List<ResultsElement> resultsElementList, String resultsDirectoryName) {
- File optionDirectory = new File(getResultsDirectory(), option.getName());
- List<File> outputDirectoryList = new ArrayList<File>();
- for (ResultsElement resultsElement : resultsElementList) {
- File outputDirectory = createResultsDirectoryAndOutputResultsElement(optionDirectory, resultsElement);
- outputDirectoryList.add(outputDirectory);
- }
- return outputDirectoryList;
-
- }
-
- private File createResultsDirectoryAndOutputResultsElement(File optionDirectory, ResultsElement resultsElement) {
- File resultsSubDirectory = null;
- String title = resultsElement.getTitle();
- if (title == null) {
- LOG.error("null title");
- } else {
- resultsSubDirectory = new File(optionDirectory, title);
- resultsSubDirectory.mkdirs();
- File resultsFile = new File(resultsSubDirectory, QuickscrapeNorma.RESULTS_XML);
- writeResults(resultsFile, resultsElement);
- LOG.debug("Wrote "+resultsFile.getAbsolutePath());
- }
- return resultsSubDirectory;
- }
-
- private File getResultsDirectory() {
- File resultsDirectory = new File(getDirectory(), RESULTS_DIRECTORY_NAME);
- return resultsDirectory;
- }
-
- public ResultsElement getResultsElement(String pluginName, String methodName) {
- File resultsDir = getExistingResultsDir();
- ResultsElement resultsElement = null;
- if (QuickscrapeNorma.isExistingDirectory(resultsDir)) {
- File pluginDir = new File(resultsDir, pluginName);
- if (QuickscrapeNorma.isExistingDirectory(pluginDir)) {
- File methodDir = new File(pluginDir, methodName);
- if (QuickscrapeNorma.isExistingDirectory(methodDir)) {
- File resultsXML = new File(methodDir, QuickscrapeNorma.RESULTS_XML);
- if (QuickscrapeNorma.isExistingFile(resultsXML)) {
- Document resultsDoc = XMLUtil.parseQuietlyToDocument(resultsXML);
- resultsElement = ResultsElement.createResults(resultsDoc.getRootElement());
- }
- }
- }
- }
- return resultsElement;
- }
-
-}
=====================================
src/main/java/org/xmlcml/files/QuickscrapeNormaList.java-old deleted
=====================================
@@ -1,59 +0,0 @@
-package org.xmlcml.files;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-
-/** list of QuickscrapeNorma objects.
- *
- * @author pm286
- *
- */
- at Deprecated
-
-public class QuickscrapeNormaList implements Iterable<QuickscrapeNorma> {
-
-
- private static final Logger LOG = Logger
- .getLogger(QuickscrapeNormaList.class);
- static {
- LOG.setLevel(Level.DEBUG);
- }
-
- private List<QuickscrapeNorma> qnList;
-
- public QuickscrapeNormaList() {
- ensureQNList();
- }
-
- private void ensureQNList() {
- if (qnList == null) {
- qnList = new ArrayList<QuickscrapeNorma>();
- }
- }
-
- public int size() {
- ensureQNList();
- return qnList.size();
- }
-
- @Override
- public Iterator<QuickscrapeNorma> iterator() {
- ensureQNList();
- return qnList.iterator();
- }
-
- public QuickscrapeNorma get(int i) {
- ensureQNList();
- return qnList.get(i);
- }
-
- public void add(QuickscrapeNorma qn) {
- ensureQNList();
- qnList.add(qn);
- }
-
-}
=====================================
src/main/java/org/xmlcml/files/ResultElement.java-old deleted
=====================================
@@ -1,103 +0,0 @@
-package org.xmlcml.files;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-
-import nu.xom.Attribute;
-import nu.xom.Element;
-import nu.xom.Node;
-import nu.xom.ParentNode;
-
-/** a container for a "result" from an action on a QSNorma.
- *
- * Normally output to the "results" directory
- *
- * @author pm286
- *
- */
- at Deprecated
-
-public class ResultElement extends Element {
-
-
- private static final Logger LOG = Logger.getLogger(ResultElement.class);
- static {
- LOG.setLevel(Level.DEBUG);
- }
-
- public static final String TAG = "result";
- public static final String TITLE = "title";
- public static final String PRE = "pre";
- private static final String EXACT = "exact";
- public static final String MATCH = "match";
- public static final String POST = "post";
- private static final String NAME = "name";
- private static final String XPATH = "xpath";
-
- public ResultElement() {
- super(TAG);
- }
-
- public ResultElement(String title) {
- this();
- this.setTitle(title);
- }
-
- private void setTitle(String title) {
- if (title == null) {
- throw new RuntimeException("title cannot be null");
- }
- this.addAttribute(new Attribute(TITLE, title));
- }
-
- public String getExact() {
- return this.getAttributeValue(EXACT);
- }
-
- public void setExact(String value) {
- setValue(EXACT, value);
- }
-
- public String getMatch() {
- return this.getAttributeValue(MATCH);
- }
-
- public void setMatch(String value) {
- setValue(MATCH, value);
- }
-
- public String getName() {
- return this.getAttributeValue(NAME);
- }
-
- public void setName(String value) {
- setValue(NAME, value);
- }
-
- public String getPre() {
- return this.getAttributeValue(PRE);
- }
-
- public void setPre(String value) {
- setValue(PRE, value);
- }
-
- public String getPost() {
- return this.getAttributeValue(POST);
- }
-
- public void setPost(String value) {
- setValue(POST, value);
- }
-
- public void setValue(String name, String value) {
- Attribute attribute = new Attribute(name, value);
- this.addAttribute(attribute);
- }
-
- public void setXPath(String xpath) {
- this.addAttribute(new Attribute(XPATH, xpath));
- }
-
-
-}
=====================================
src/main/java/org/xmlcml/files/ResultsElement.java-old deleted
=====================================
@@ -1,172 +0,0 @@
-package org.xmlcml.files;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import nu.xom.Attribute;
-import nu.xom.Element;
-import nu.xom.Node;
-import nu.xom.Text;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.xmlcml.xml.XMLUtil;
-
-/** a container for ResultElement's.
- *
- * @author pm286
- *
- */
- at Deprecated
-
-public class ResultsElement extends Element implements Iterable<ResultElement> {
-
-
- private static final Logger LOG = Logger.getLogger(ResultsElement.class);
- static {
- LOG.setLevel(Level.DEBUG);
- }
-
- public static final String TAG = "results";
- public static final String TITLE = "title";
-
- protected List<ResultElement> resultElementList;
- public List<String> nameList;
-
- public ResultsElement() {
- super(TAG);
- }
-
- public ResultsElement(ResultsElement element) {
- this();
- copyAttributesAndAddChildren(element);
- }
-
- public ResultsElement(String title) {
- this();
- this.setTitle(title);
- }
-
- public void setTitle(String title) {
- this.addAttribute(new Attribute(TITLE, title));
- }
-
- public String getTitle() {
- return this.getAttributeValue(TITLE);
- }
-
- /** create ResultsElement from reading Element.
- *
- * @param element
- * @return
- */
- public static ResultsElement createResults(Element element) {
- return (ResultsElement) createResults0(element);
- }
-
- private static Element createResults0(Element element) {
- Element newElement = null;
- String tag = element.getLocalName();
- if (ResultsElement.TAG.equals(tag)) {
- newElement = new ResultsElement();
- } else if (ResultElement.TAG.equals(tag)) {
- newElement = new ResultElement();
- } else {
- LOG.error("Unknown element: "+tag);
- }
- XMLUtil.copyAttributes(element, newElement);
- for (int i = 0; i < element.getChildCount(); i++) {
- Node child = element.getChild(i);
- if (child instanceof Text) {
- child = child.copy();
- } else {
- child = ResultsElement.createResults0((Element)child);
- }
- if (newElement != null && child != null) {
- newElement.appendChild(child);
- }
- }
- LOG.trace("XML :"+newElement.toXML());
- return newElement;
- }
-
- /** transfers with detachment ResultElement's in one ResultsElement to another.
- *
- * @param subResultsElement source of ResultElement's
- */
- public void transferResultElements(ResultsElement subResultsElement) {
- List<ResultElement> subResults = subResultsElement.getOrCreateResultElementList();
- for (ResultElement subResult : subResults) {
- subResult.detach();
- this.appendChild(subResult);
- }
- }
-
- protected List<ResultElement> getOrCreateResultElementList() {
- resultElementList = new ArrayList<ResultElement>();
- List<Element> resultChildren = XMLUtil.getQueryElements(this, "./*[local-name()='"+ResultElement.TAG+"']");
- for (Element resultElement : resultChildren) {
- resultElementList.add((ResultElement) resultElement);
- }
- return resultElementList;
- }
-
- @Override
- public Iterator<ResultElement> iterator() {
- getOrCreateResultElementList();
- return resultElementList.iterator();
- }
-
- public int size() {
- getOrCreateResultElementList();
- return resultElementList == null ? 0 : resultElementList.size();
- }
-
- protected void copyAttributesAndAddChildren(ResultsElement resultsElement) {
- if (resultsElement == null) {
- throw new RuntimeException("Null ResultsElement");
- }
- XMLUtil.copyAttributesFromTo(resultsElement, this);
- for (ResultElement resultElement : resultsElement) {
- this.appendChild(resultElement);
- }
- }
-
- public void setAllResultElementNames(String name) {
- for (ResultElement resultElement : this) {
- resultElement.setName(name);
- }
- }
-
- public void setXPath(String xpath) {
- for (ResultElement resultElement : this) {
- resultElement.setXPath(xpath);
- }
- }
-
- public void addMatchAttributes(List<String> matchList) {
- if (this.size() != matchList.size()) {
- throw new RuntimeException("name list wrong length ("+matchList.size()+") rather than ("+this.size()+")");
- }
- int i = 0;
- for (ResultElement resultElement : this) {
- resultElement.setMatch(matchList.get(i));
- // cosmetic - keeps attributes in natural order
- resultElement.setPost(resultElement.getPost());
- i++;
- }
- }
-
- public List<String> getExactList() {
- if (nameList == null) {
- nameList = new ArrayList<String>();
- for (ResultElement resultElement : this) {
- String name = resultElement.getExact();
- nameList.add(name);
- }
- }
- return nameList;
- }
-
-}
=====================================
src/main/java/org/xmlcml/files/ResultsElementList.java-old deleted
=====================================
@@ -1,46 +0,0 @@
-package org.xmlcml.files;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-
-/** wrapper for collection of ResultsElement.
- *
- * @author pm286
- *
- */
- at Deprecated
-
-public class ResultsElementList implements Iterable<ResultsElement> {
-
- private static final Logger LOG = Logger.getLogger(ResultsElementList.class);
- static {
- LOG.setLevel(Level.DEBUG);
- }
-
- protected List<ResultsElement> resultsElementList;
-
- public ResultsElementList() {
-
- }
-
- public void add(ResultsElement resultsElement) {
- ensureResultsElementList();
- resultsElementList.add(resultsElement);
- }
-
- protected void ensureResultsElementList() {
- if (resultsElementList == null) {
- resultsElementList = new ArrayList<ResultsElement>();
- }
- }
-
- @Override
- public Iterator<ResultsElement> iterator() {
- ensureResultsElementList();
- return resultsElementList.iterator();
- }
-}
=====================================
src/test/java/org/xmlcml/args/DefaultArgProcessorTest.java-old deleted
=====================================
@@ -1,77 +0,0 @@
-package org.xmlcml.args;
-
-import junit.framework.Assert;
-
-import org.apache.log4j.Logger;
-import org.junit.Test;
-import org.xmlcml.args.DefaultArgProcessor;
-
-public class DefaultArgProcessorTest {
-
-
- private static final Logger LOG = Logger.getLogger(DefaultArgProcessorTest.class);
- static {LOG.setLevel(org.apache.log4j.Level.DEBUG);}
-
- @Test
- public void testArgs() {
- String[] args = {
- "-i", "foo", "bar",
- "-o", "plugh",
- };
- DefaultArgProcessor argProcessor = new DefaultArgProcessor();
- argProcessor.parseArgs(args);
- Assert.assertEquals("input", 2, argProcessor.getInputList().size());
- Assert.assertEquals("input", "foo", argProcessor.getInputList().get(0));
- Assert.assertEquals("input", "bar", argProcessor.getInputList().get(1));
- Assert.assertEquals("output", "plugh", argProcessor.getOutput());
- }
-
- @Test
- public void testSingleWildcards() {
- String[] args = {
- "-i", "foo{1:3}bof", "bar{a|b|zzz}plugh",
- };
- DefaultArgProcessor argProcessor = new DefaultArgProcessor();
- argProcessor.parseArgs(args);
- Assert.assertEquals("input", 2, argProcessor.getInputList().size());
- Assert.assertEquals("input", "foo{1:3}bof", argProcessor.getInputList().get(0));
- Assert.assertEquals("input", "bar{a|b|zzz}plugh", argProcessor.getInputList().get(1));
- argProcessor.expandWildcardsExhaustively();
- Assert.assertEquals("input", 6, argProcessor.getInputList().size());
- Assert.assertEquals("input", "foo1bof", argProcessor.getInputList().get(0));
- Assert.assertEquals("input", "foo2bof", argProcessor.getInputList().get(1));
- Assert.assertEquals("input", "foo3bof", argProcessor.getInputList().get(2));
- Assert.assertEquals("input", "baraplugh", argProcessor.getInputList().get(3));
- Assert.assertEquals("input", "barbplugh", argProcessor.getInputList().get(4));
- Assert.assertEquals("input", "barzzzplugh", argProcessor.getInputList().get(5));
- }
-
-
- @Test
- public void testMultipleWildcards() {
- String[] args = {
- "-i", "foo{1:3}bof{3:6}plugh",
- };
- DefaultArgProcessor argProcessor = new DefaultArgProcessor();
- argProcessor.parseArgs(args);
- Assert.assertEquals("input", 1, argProcessor.getInputList().size());
- Assert.assertEquals("input", "foo{1:3}bof{3:6}plugh", argProcessor.getInputList().get(0));
- argProcessor.expandWildcardsExhaustively();
- Assert.assertEquals("input", 12, argProcessor.getInputList().size());
- Assert.assertEquals("input", "foo1bof3plugh", argProcessor.getInputList().get(0));
- }
-
- @Test
- public void testArgCounts() {
- String[] args = {"-o", "foo"};
- new DefaultArgProcessor().parseArgs(args);
- try {
- args = new String[]{"-o", "foo", "bar"};
- new DefaultArgProcessor().parseArgs(args);
- } catch (Exception e) {
- Assert.assertEquals("too many arguments",
- "cannot process argument: -o (IllegalArgumentException: --output; argument count (2) is not compatible with {1,1})",
- e.getMessage());
- }
- }
-}
=====================================
src/test/java/org/xmlcml/args/sandpit/SandpitArgProcessorDoubleTest.java-old deleted
=====================================
@@ -1,98 +0,0 @@
-package org.xmlcml.args.sandpit;
-
-import junit.framework.Assert;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.junit.Test;
-import org.xmlcml.euclid.RealArray;
-
-public class SandpitArgProcessorDoubleTest {
-
-
- private static final Logger LOG = Logger
- .getLogger(SandpitArgProcessorDoubleTest.class);
- static {
- LOG.setLevel(Level.DEBUG);
- }
-
- @Test
- public void testDouble() {
- String args[] = {"--double", "4.5"};
- SandpitArgProcessor sandpitArgProcessor = new SandpitArgProcessor(args);
- Assert.assertEquals("double", 4.5, sandpitArgProcessor.getDouble(), 0.0001);
- }
-
- @Test
- public void testDoubleOutOfRange() {
- String args[] = new String[]{"--double", "2.0"}; // will be out of range
- try {
- new SandpitArgProcessor(args);
- Assert.fail("Should throw RuntimeException; Illegal value");
- } catch (RuntimeException e) {
- Assert.assertEquals("illegal value",
- "cannot process argument: --double (IllegalArgumentException: --double; value: 2.0 incompatible with: (3.1,7.2))",
- e.getMessage());
- }
- args = new String[]{"--double", "12.0"}; // will be out of range
- try {
- new SandpitArgProcessor(args);
- Assert.fail("Should throw RuntimeException; Illegal value");
- } catch (RuntimeException e) {
- Assert.assertEquals("illegal value",
- "cannot process argument: --double (IllegalArgumentException: --double; value: 12.0 incompatible with: (3.1,7.2))",
- e.getMessage());
- }
- }
-
- @Test
- public void testBadDouble() {
- String args[] = new String[]{"--double", "foo"}; // will be out of range
- try {
- new SandpitArgProcessor(args);
- Assert.fail("Should throw RuntimeException; Illegal value");
- } catch (RuntimeException e) {
- Assert.assertEquals("illegal value",
- "cannot process argument: --double (IllegalArgumentException: --double; value: foo incompatible with: (3.1,7.2))", e.getMessage());
- }
- }
-
- @Test
- public void testTooManyDoubles() {
- String[] args = new String[]{"--double", "4.0", "7.0"}; // will be out of range
- try {
- new SandpitArgProcessor(args);
- Assert.fail("Should throw RuntimeException; Too many values");
- } catch (RuntimeException e) {
- Assert.assertEquals("too many doubles",
- "cannot process argument: --double (IllegalArgumentException: --double; "
- + "argument count (2) is not compatible with {1,1})", e.getMessage());
- }
- }
-
- @Test
- public void testDoubleArray() {
- String[] args = new String[]{"--doublearray", "4.0", "7.0", "5.0"};
- try {
- SandpitArgProcessor sandpitArgProcessor = new SandpitArgProcessor(args);
- RealArray doubleArray = sandpitArgProcessor.getDoubleArray();
- Assert.assertTrue("array values", new RealArray(new double[]{4.0, 7.0, 5.0}).equals(doubleArray, 0.001));
- } catch (RuntimeException e) {
- Assert.fail("should not throw "+e);
- }
- }
-
- @Test
- public void testBadDoubleArray() {
- String[] args = new String[]{"--doublearray", "4.0", "7.0", "foo", "-4.0"};
- try {
- SandpitArgProcessor sandpitArgProcessor = new SandpitArgProcessor(args);
- Assert.fail("should throw bad element exception");
- } catch (RuntimeException e) {
- Assert.assertEquals("bad element",
- "cannot process argument: --doublearray (IllegalArgumentException: --doublearray; value: foo incompatible with: (3.1,7.2))",
- e.getMessage());
- }
- }
-
-}
=====================================
src/test/java/org/xmlcml/args/sandpit/SandpitArgProcessorIntegerTest.java-old deleted
=====================================
@@ -1,111 +0,0 @@
-package org.xmlcml.args.sandpit;
-
-import junit.framework.Assert;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.junit.Test;
-import org.xmlcml.euclid.IntArray;
-
-public class SandpitArgProcessorIntegerTest {
-
-
- private static final Logger LOG = Logger
- .getLogger(SandpitArgProcessorIntegerTest.class);
- static {
- LOG.setLevel(Level.DEBUG);
- }
-
- @Test
- public void testInteger() {
- String args[] = {"--integer", "4"};
- SandpitArgProcessor sandpitArgProcessor = new SandpitArgProcessor(args);
- Assert.assertEquals("int", 4, (int)sandpitArgProcessor.getInteger());
- }
-
- @Test
- public void testIntegerOutOfRange() {
- String args[] = new String[]{"--integer", "2"}; // will be out of range
- try {
- new SandpitArgProcessor(args);
- Assert.fail("Should throw RuntimeException; Illegal value");
- } catch (RuntimeException e) {
- Assert.assertEquals("illegal value",
- "cannot process argument: --integer (IllegalArgumentException: --integer; value: 2 incompatible with: (3,7))",
- e.getMessage());
- }
- args = new String[]{"--integer", "12"}; // will be out of range
- try {
- new SandpitArgProcessor(args);
- Assert.fail("Should throw RuntimeException; Illegal value");
- } catch (RuntimeException e) {
- Assert.assertEquals("illegal value",
- "cannot process argument: --integer (IllegalArgumentException: --integer; value: 12 incompatible with: (3,7))",
- e.getMessage());
- }
- }
-
- @Test
- public void testBadInteger() {
- String args[] = new String[]{"--integer", "foo"}; // will be out of range
- try {
- new SandpitArgProcessor(args);
- Assert.fail("Should throw RuntimeException; Illegal value");
- } catch (RuntimeException e) {
- Assert.assertEquals("illegal value",
- "cannot process argument: --integer (IllegalArgumentException: --integer; value: foo incompatible with: (3,7))", e.getMessage());
- }
- }
-
- @Test
- public void testTooManyIntegers() {
- String[] args = new String[]{"--integer", "4", "7"}; // will be out of range
- try {
- new SandpitArgProcessor(args);
- Assert.fail("Should throw RuntimeException; Too many values");
- } catch (RuntimeException e) {
- Assert.assertEquals("too many ints",
- "cannot process argument: --integer (IllegalArgumentException: --integer; "
- + "argument count (2) is not compatible with {1,1})", e.getMessage());
- }
- }
-
- @Test
- public void testIntegerArray() {
- String[] args = new String[]{"--integerarray", "4", "7", "5"};
- try {
- SandpitArgProcessor sandpitArgProcessor = new SandpitArgProcessor(args);
- IntArray intArray = sandpitArgProcessor.getIntArray();
- Assert.assertTrue("array values", new IntArray(new int[]{4, 7, 5}).equals(intArray));
- } catch (RuntimeException e) {
- Assert.fail("should not throw "+e);
- }
- }
-
- @Test
- public void testBadIntegerArray() {
- String[] args = new String[]{"--integerarray", "4", "7", "foo", "-4"};
- try {
- new SandpitArgProcessor(args);
- Assert.fail("should throw bad element exception");
- } catch (RuntimeException e) {
- Assert.assertEquals("bad element",
- "cannot process argument: --integerarray (IllegalArgumentException: --integerarray; value: foo incompatible with: (3,7))",
- e.getMessage());
- }
- }
-
- @Test
- public void testIntegerArrayValueOUtOfRange() {
- String[] args = new String[]{"--integerarray", "4", "7", "-3", "6"};
- try {
- new SandpitArgProcessor(args);
- Assert.fail("should throw bad element exception");
- } catch (RuntimeException e) {
- Assert.assertEquals("bad element",
- "cannot process argument: --integerarray (IllegalArgumentException: --integerarray; value: -3 incompatible with: (3,7))",
- e.getMessage());
- }
- }
-
-}
=====================================
src/main/java/org/xmlcml/euclid/test/DoubleTestBase.java → src/test/java/org/xmlcml/euclid/test/DoubleTestBase.java
=====================================
=====================================
src/main/java/org/xmlcml/euclid/test/EuclidTestBase.java → src/test/java/org/xmlcml/euclid/test/EuclidTestBase.java
=====================================
=====================================
src/main/java/org/xmlcml/euclid/test/StringTestBase.java → src/test/java/org/xmlcml/euclid/test/StringTestBase.java
=====================================
=====================================
src/test/java/org/xmlcml/files/QuickscrapeNormaTest.java-old deleted
=====================================
@@ -1,49 +0,0 @@
-package org.xmlcml.files;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-import junit.framework.Assert;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.junit.Test;
-import org.xmlcml.Fixtures;
-import org.xmlcml.args.DefaultArgProcessor;
-
-public class QuickscrapeNormaTest {
-
-
- private static final Logger LOG = Logger.getLogger(QuickscrapeNormaTest.class);
- static {
- LOG.setLevel(Level.DEBUG);
- }
-
- public final static File QUICKSCRAPE_NORMA_DIR = new File("src/test/resources/org/xmlcml/files/");
- public final static File PLOS0115884_DIR = new File(QUICKSCRAPE_NORMA_DIR, "journal.pone.0115884");
-
- @Test
- public void testReadQuickscrapeNorma() {
- QuickscrapeNorma quickscrapeNorma = new QuickscrapeNorma();
- quickscrapeNorma.readDirectory(PLOS0115884_DIR);
- Assert.assertEquals("fileCount", 4, quickscrapeNorma.getReservedFileList().size());
- Assert.assertTrue("XML", quickscrapeNorma.hasFulltextXML());
- }
-
- @Test
- public void testQuickscrapeNorma() throws IOException {
- File container0115884 = new File("target/plosone/0115884/");
- // copy so we don't write back into test area
- FileUtils.copyDirectory(Fixtures.TEST_PLOSONE_0115884_DIR, container0115884);
- String[] args = {
- "-q", container0115884.toString(),
- };
- DefaultArgProcessor argProcessor = new DefaultArgProcessor();
- argProcessor.parseArgs(args);
- QuickscrapeNormaList quickscrapeNormaList = argProcessor.getQuickscrapeNormaList();
- Assert.assertEquals(1, quickscrapeNormaList.size());
- LOG.trace(quickscrapeNormaList.get(0).toString());
- }
-}
View it on GitLab: https://salsa.debian.org/java-team/libeuclid-java/-/compare/9e0614f8d44c0c3df559cf0382a9706e60d5b7bc...223e753e0fc77205004b91ca53326412dac1c677
--
View it on GitLab: https://salsa.debian.org/java-team/libeuclid-java/-/compare/9e0614f8d44c0c3df559cf0382a9706e60d5b7bc...223e753e0fc77205004b91ca53326412dac1c677
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20260609/e01949f9/attachment.htm>
More information about the pkg-java-commits
mailing list