1
0
mirror of https://github.com/fr13Dev/generatingXSD synced 2024-12-22 11:03:13 +00:00

prepared to mvn

This commit is contained in:
nikolaibeliaev 2019-03-20 10:47:35 +07:00
parent c576c92f7e
commit 6ae76859f9
3 changed files with 90 additions and 169 deletions

View File

@ -1,65 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>
<commonInvoiceInput>
<generalInvoiceInfo>
<invoiceType>01GTKT</invoiceType>
<templateCode>01GTKT0/001</templateCode>
<currencyCode>VND</currencyCode>
<adjustmentType>1</adjustmentType>
<paymentStatus>true</paymentStatus>
<paymentType>TM</paymentType>
<paymentTypeName>TM</paymentTypeName>
<cusGetInvoiceRight>true</cusGetInvoiceRight>
<buyerIdNo>123456789</buyerIdNo>
<buyerIdType>1</buyerIdType>
</generalInvoiceInfo>
<buyerInfo>
<buyerName>Lương Thị Huyền</buyerName>
<buyerLegalName></buyerLegalName>
<buyerTaxCode>3901212654</buyerTaxCode>
<buyerAddressLine>HN VN</buyerAddressLine>
<buyerPhoneNumber>09880830406</buyerPhoneNumber>
<buyerEmail></buyerEmail>
<buyerIdNo>123456789</buyerIdNo>
<buyerIdType>1</buyerIdType>
</buyerInfo>
<sellerInfo>
<sellerLegalName>Supplier perfom test 1</sellerLegalName>
<sellerTaxCode>0100109106-501</sellerTaxCode>
<sellerAddressLine>test</sellerAddressLine>
<sellerPhoneNumber>0123456789</sellerPhoneNumber>
<sellerEmail>PerformanceTest1@viettel.com.vn</sellerEmail>
<sellerBankName>vtbank</sellerBankName>
<sellerBankAccount>23423424</sellerBankAccount>
</sellerInfo>
<payments>
<paymentMethodName>TM</paymentMethodName>
</payments>
<deliveryInfo />
<invoice>
<general>
<currency>USD</currency>
<isPaid>true</isPaid>
</general>
<seller>
<legalName>Trade LLC</legalName>
<taxCode>558731212</taxCode>
<addressLine>CA</addressLine>
<phoneNumber>784875863</phoneNumber>
<bankName>World bank</bankName>
<bankAccount>111177</bankAccount>
</seller>
<buyer>
<name>Tom Smith</name>
<taxCode>87312131</taxCode>
<addressLine>CA</addressLine>
<phoneNumber>95453121312</phoneNumber>
</buyer>
<itemInfo>
<lineNumber>1</lineNumber>
<itemCode>ENGLISH_COURSE</itemCode>
<itemName>Khóa học tiếng anh</itemName>
<unitName>khóa học</unitName>
<unitPrice>3500000</unitPrice>
<code>0001</code>
<name>ENGLISH_COURSE</name>
<unit>ea</unit>
<price>1000</price>
<quantity>10</quantity>
<itemTotalAmountWithoutTax>35000000</itemTotalAmountWithoutTax>
<taxPercentage>10</taxPercentage>
<taxAmount>3500000</taxAmount>
<totalAmountWithoutTax>9000</totalAmountWithoutTax>
<vatRate>10</vatRate>
<taxAmount>1000</taxAmount>
<discount>0</discount>
<itemDiscount>0</itemDiscount>
</itemInfo>
<summarizeInfo>
<sumOfTotalLineAmountWithoutTax>35000000</sumOfTotalLineAmountWithoutTax>
<totalAmountWithoutTax>35000000</totalAmountWithoutTax>
<totalTaxAmount>3500000</totalTaxAmount>
<totalAmountWithTax>38500000</totalAmountWithTax>
<totalAmountWithTaxInWords>Ba mươi tám triệu năm trăm nghìn đồng chẵn</totalAmountWithTaxInWords>
<discountAmount>0</discountAmount>
<taxPercentage>10</taxPercentage>
</summarizeInfo>
<taxBreakdowns>
<taxPercentage>10</taxPercentage>
<taxableAmount>35000000</taxableAmount>
<taxAmount>3500000</taxAmount>
</taxBreakdowns>
</commonInvoiceInput>
<total>
<amountWithoutTax>9000</amountWithoutTax>
<taxAmount>1000</taxAmount>
<amountWithTax>10000</amountWithTax>
<amountWithTaxInWords>Ten thousands</amountWithTaxInWords>
</total>
</invoice>

View File

@ -16,48 +16,56 @@ import java.nio.file.Paths;
public class XsdSchema {
private File sourceFile;
private boolean printHelp = false;
private final String nameSpace = "";
private final Inst2XsdOptions schema = new Inst2XsdOptions();
private final File SOURCE_FILE;
private final File OUTPUT_FILE;
private final String NAME_SPACE;
private final int SCHEMA_DESIGN;
public static void main(String[] args) throws IOException, XmlException {
// write your code here
// delete setters and getters
XsdSchema xsdSchema = new XsdSchema(args);
/*if (xsdSchema.getPrintHelp()) {
System.out.println("HELP");
return;
} else {
xsdSchema.checkSourceFile();
}
xsdSchema.checkSourceFile();
//System.out.println(xsdSchema.getSourceFile().getPath());
XmlObject xmlObject = XmlObject.Factory.parse(xsdSchema.SOURCE_FILE);
SchemaDocument schema = xsdSchema.getSchema(xmlObject);
if (schema != null)
schema.save(xsdSchema.OUTPUT_FILE);
XmlObject [] xmlObjects = new XmlObject[1];
xmlObjects[0] = XmlObject.Factory.parse(xsdSchema.getSourceFile());
SchemaDocument schema = xsdSchema.getSchema(xmlObjects);
System.out.println(schema);*/
}
private SchemaDocument getSchema(XmlObject [] xmlObjects) {
private SchemaDocument getSchema(XmlObject xmlObject) {
Inst2XsdOptions inst2XsdOptions = new Inst2XsdOptions();
inst2XsdOptions.setDesign(Inst2XsdOptions.DESIGN_VENETIAN_BLIND);
inst2XsdOptions.setDesign(SCHEMA_DESIGN);
XmlObject [] xmlObjects = new XmlObject[1];
xmlObjects[0] = xmlObject;
SchemaDocument [] schemaDocuments = Inst2Xsd.inst2xsd(xmlObjects, inst2XsdOptions);
if (schemaDocuments != null && schemaDocuments.length > 0) {
schemaDocuments[0].getSchema().setTargetNamespace(NAME_SPACE);
return schemaDocuments[0];
}
return null;
}
XsdSchema(String[] args) {
private XsdSchema(String[] args) {
Options options = new Options();
Option option = new Option("i", "input", true, "input file path");
option.setRequired(true);
options.addOption(option);
Option inputOption = new Option("i", "input", true, "input xml file path");
inputOption.setRequired(true);
options.addOption(inputOption);
Option outputOption = new Option("o", "output", true, "output xsd file path");
options.addOption(outputOption);
Option nameSpaceOption = new Option("n", "name-space", true, "target name space");
options.addOption(nameSpaceOption);
Option schemaOption = new Option("s", "schema-design", true,
"schema design: 1-Russian Doll, 2-Salami slice, 3-Venetian blind");
options.addOption(schemaOption);
CommandLineParser commandLineParser = new DefaultParser();
HelpFormatter helpFormatter = new HelpFormatter();
@ -67,86 +75,49 @@ public class XsdSchema {
cmd = commandLineParser.parse(options, args);
} catch (ParseException e) {
System.out.println(e.getMessage());
helpFormatter.printHelp("bla bla", options);
helpFormatter.printHelp("This tool creates xsd file from xml.", options);
System.exit(1);
}
String input = cmd.getOptionValue("input");
System.out.println(input);
SOURCE_FILE = new File(cmd.getOptionValue("input"));
/*int argsCount = args.length;
String pathToFile = "";
if (argsCount == 0) {
return;
String outputFile = cmd.getOptionValue("output");
if (outputFile == null) {
this.OUTPUT_FILE = new File(SOURCE_FILE.getParent() + File.separatorChar + "schema.xsd");
} else {
this.OUTPUT_FILE = new File(outputFile);
}
for (int i=0; i < args.length; i++) {
String ns = cmd.getOptionValue("name-space");
NAME_SPACE = ns != null ? ns : "http://v8.default.com";
switch (args[i]) {
case "-i":
pathToFile = args.length > 1 ? args[i + 1]:"";
String schema = cmd.getOptionValue("schema-design");
if (schema == null) {
this.SCHEMA_DESIGN = 3;
}
else {
switch (schema) {
case "1":
this.SCHEMA_DESIGN = Inst2XsdOptions.DESIGN_RUSSIAN_DOLL;
break;
case "--input":
pathToFile = args.length > 1 ? args[i + 1]:"";
case "2":
this.SCHEMA_DESIGN = Inst2XsdOptions.DESIGN_SALAMI_SLICE;
break;
case "-h":
setPrintHelp(true);
case "3":
this.SCHEMA_DESIGN = Inst2XsdOptions.DESIGN_VENETIAN_BLIND;
break;
case "--help":
setPrintHelp(true);
break;
case "-nm":
//name space
break;
case "--namespace":
// name space
break;
case "-s":
//schema
break;
case "--schema":
// schema
break;
}
if (printHelp) {
break;
default:
throw new IllegalArgumentException("Unknown value for design type.");
}
}
if (pathToFile.isEmpty()) {
return;
}
sourceFile = new File(pathToFile);*/
}
private boolean getPrintHelp() {
return printHelp;
}
public File getSourceFile() {
return sourceFile;
}
private void setPrintHelp(boolean printHelp) {
this.printHelp = printHelp;
}
private void checkSourceFile() throws FileNotFoundException {
Path path = Paths.get(sourceFile.toURI());
Path path = Paths.get(SOURCE_FILE.toURI());
if (Files.notExists(path)) {
throw new FileNotFoundException("no such file " + sourceFile.getPath());
throw new FileNotFoundException("no such file " + SOURCE_FILE.getPath());
}
}
enum SchemaDesign {
RUSSIAN_DOLL,
SALAMI_SLICE,
VENETIAN_BLIND
}
}

View File

@ -1,24 +0,0 @@
<xs:schema xmlns:tns="http://test" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://test" attributeFormDefault="unqualified" elementFormDefault="qualified">
<xs:element name="Customer">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerId" type="xs:int"/>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
<xs:element name="Address">
<xs:complexType>
<xs:sequence>
<xs:element name="City" type="xs:string"/>
<xs:element name="Zip" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Info">
<xs:sequence>
<xs:element ref="tns:Customer"/>
</xs:sequence>
</xs:complexType>
</xs:schema>