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

View File

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