Skip to content
Snippets Groups Projects
Commit 539acade authored by Goik Martin's avatar Goik Martin
Browse files

Xmlparse revamped

parent da0ef31d
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<oxygenxml.version>25.1.0.0</oxygenxml.version>
<maven.compiler.release>17</maven.compiler.release>
</properties>
<distributionManagement>
......@@ -48,14 +48,11 @@
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<version>3.11.0</version>
</plugin>
</plugins>
......
File moved
......@@ -2,9 +2,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hdm.util</groupId>
<groupId>de.hdm_stuttgart.mi.utils</groupId>
<artifactId>xmlparse</artifactId>
<version>0.9</version>
<version>1.0</version>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
......@@ -12,64 +12,80 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
</properties>
<distributionManagement>
<repository>
<id>mi-nexus</id>
<url>https://maven.mi.hdm-stuttgart.de/nexus/repository/mi-maven</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>gnu.getopt</groupId>
<artifactId>java-getopt</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
<version>2.12.2</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}-nodeps</finalName>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
<version>3.5.3</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<optimize>true</optimize>
</configuration>
<version>3.11.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.2.1</version>
<version>3.5.0</version>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>de.hdm_stuttgart.mi.utils.xmlparse.Parser</Main-Class>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
<configuration>
<finalName>${project.artifactId}-${project.version}</finalName>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
</plugins>
......
package hdm.utils.xmlparse;
package de.hdm_stuttgart.mi.utils.xmlparse;
import gnu.getopt.LongOpt;
......@@ -7,15 +7,16 @@ import java.util.Map;
import java.util.Vector;
/**
* Practical extension to gnu's copt package
* Practical extension to gnu's opt package
*
*/
public class LongoptExplanation extends LongOpt {
/**
* @param isRequired
* @param name
* @param flag
* @param val
* @param isRequired true if parameter is being required, false otherwise.
* @param name Parameter's name
* @param flag Getopt flags
* @param val Parameter's value
* @throws IllegalArgumentException
*/
public static void add
......@@ -23,16 +24,15 @@ public class LongoptExplanation extends LongOpt {
String name,
StringBuffer flag,
int val) throws IllegalArgumentException{
addOption(name, new LongoptExplanation(isRequired, name, flag, val));
}
/**
* @param isRequired
* @param name
* @param argumentRequiredFlag
* @param flag
* @param val
* @param explain
* @param isRequired true if parameter is being required, false otherwise.
* @param name Parameter's name
* @param argumentRequiredFlag T
* @param flag Getopt flags
* @param val Parameter's value
* @param explain Explanation to CLI end user.
* @throws IllegalArgumentException
*/
public static void add
......@@ -54,17 +54,20 @@ public class LongoptExplanation extends LongOpt {
}
}
/**
* @return defined option set
* <p>Option values.</p>
* @return Set of option values being defined.
*/
public static LongoptExplanation [] getOptions(){
return optionOverName.values().toArray(new LongoptExplanation[0]);
}
/**
* <p>Short option list</p>
* @return short options
*/
public static String getShortOptString(){
StringBuffer shortOptString = new StringBuffer();
LongoptExplanation [] options = getOptions();
final StringBuffer shortOptString = new StringBuffer();
final LongoptExplanation [] options = getOptions();
for (int i = 0; i < options.length; i++){
shortOptString.append((char)options[i].getVal());
......@@ -78,6 +81,7 @@ public class LongoptExplanation extends LongOpt {
return shortOptString.toString();
}
/**
* <p>End user CLI usage description.</p>
* @return Usage description
*/
public static String getUsage(){
......@@ -140,6 +144,6 @@ public class LongoptExplanation extends LongOpt {
}
private boolean isRequiredArgument;
private String argumentExplanation;
private static Map <String, LongoptExplanation> optionOverName = new Hashtable<String, LongoptExplanation> ();
static Vector<LongoptExplanation> optionsInOrder = new Vector<LongoptExplanation> ();
static private Map <String, LongoptExplanation> optionOverName = new Hashtable<String, LongoptExplanation> ();
static private Vector<LongoptExplanation> optionsInOrder = new Vector<LongoptExplanation> ();
}
package hdm.utils.xmlparse;
package de.hdm_stuttgart.mi.utils.xmlparse;
import gnu.getopt.Getopt;
......@@ -32,7 +32,7 @@ public class Parser {
while ((c = g.getopt()) != -1){
switch(c){
case 0:
final int longOptionCode = (new Integer(sb.toString())).intValue();
final int longOptionCode = Integer.parseInt(sb.toString());
processOptionCode(longOptionCode, g);
case 1://
if (null == xmlFileName){//Not yet initialized?
......@@ -85,35 +85,27 @@ public class Parser {
}
}
private static void processOptionCode(int optionCode, Getopt getopt){
switch(optionCode){
case OPTION_HELP:
printUsage();
System.exit(0);
break;
case OPTION_VALIDATION:
doValidation = true;
break;
case OPTION_SCHEMAVALIDATION:
doValidation = true;
doSchemaValidation=true;
break;
case OPTION_DEBUG:
doDebugging = true;
break;
case OPTION_VERSION:
System.out.print("Version " + version + "\n");
System.exit(0);
break;
default:
System.err.println
("processOptionCode:No such long option code:" +
optionCode + ":" + (char)optionCode);
System.exit(1);
switch (optionCode) {
case OPTION_HELP -> {
printUsage();
System.exit(0);
}
case OPTION_VALIDATION -> doValidation = true;
case OPTION_SCHEMAVALIDATION -> {
doValidation = true;
doSchemaValidation = true;
}
case OPTION_DEBUG -> doDebugging = true;
case OPTION_VERSION -> {
System.out.print("Version " + version + "\n");
System.exit(0);
}
default -> {
System.err.println
("processOptionCode:No such long option code:" +
optionCode + ":" + (char) optionCode);
System.exit(1);
}
}
}
private static void printUsage(){
......
package hdm.utils.xmlparse;
package de.hdm_stuttgart.mi.utils.xmlparse;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
......
package hdm.util.xmlparse;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment