From 2e3486e39a1e8244c9d78538e7619eaeefec87e2 Mon Sep 17 00:00:00 2001
From: nikolaibeliaev <fr13.dev@gmail.com>
Date: Fri, 15 Mar 2019 11:08:14 +0700
Subject: [PATCH] initial commit

---
 .gitignore                  |  7 +++
 example.xml                 | 65 ++++++++++++++++++++++++++++
 src/dev/fr13/XsdSchema.java | 85 +++++++++++++++++++++++++++++++++++++
 примерсхемыкакматрешка.xsd  | 24 +++++++++++
 4 files changed, 181 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 example.xml
 create mode 100644 src/dev/fr13/XsdSchema.java
 create mode 100644 примерсхемыкакматрешка.xsd

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..fad1678
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+*.jar
+.DS_Store
\ No newline at end of file
diff --git a/example.xml b/example.xml
new file mode 100644
index 0000000..b5387d0
--- /dev/null
+++ b/example.xml
@@ -0,0 +1,65 @@
+<?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 />
+	<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>
+		<quantity>10</quantity>
+		<itemTotalAmountWithoutTax>35000000</itemTotalAmountWithoutTax>
+		<taxPercentage>10</taxPercentage>
+		<taxAmount>3500000</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>
diff --git a/src/dev/fr13/XsdSchema.java b/src/dev/fr13/XsdSchema.java
new file mode 100644
index 0000000..1cf562f
--- /dev/null
+++ b/src/dev/fr13/XsdSchema.java
@@ -0,0 +1,85 @@
+package dev.fr13;
+
+import org.apache.xmlbeans.impl.inst2xsd.Inst2XsdOptions;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class XsdSchema {
+
+    private File sourceFile;
+    private boolean printHelp = false;
+
+    public static void main(String[] args) throws FileNotFoundException {
+	// write your code here
+        XsdSchema xsdSchema = new XsdSchema(args);
+        if (xsdSchema.getPrintHelp()) {
+
+        } else {
+            xsdSchema.checkSourceFile();
+        }
+
+        Inst2XsdOptions inst2XsdOptions = new Inst2XsdOptions();
+        //XmlObject.Factory.parse("src\\dev\\fr13\example.xml")
+    }
+
+    XsdSchema(String[] args) {
+
+        int argsCount = args.length;
+        String pathToFile = "";
+
+        if (argsCount == 0) {
+            return;
+        }
+
+        for (int i=0; i < args.length; i++) {
+
+            switch (args[i]) {
+                case "-i":
+                    pathToFile = args.length > 1 ? args[i + 1]:"";
+                    break;
+                case "--input":
+                    pathToFile = args.length > 1 ? args[i + 1]:"";
+                    break;
+                case "-h":
+                    setPrintHelp(true);
+                    break;
+                case "--help":
+                    setPrintHelp(true);
+                    break;
+            }
+
+            if (printHelp) {
+                pathToFile = "";
+                break;
+            }
+        }
+
+        if (pathToFile.isEmpty()) {
+            return;
+        }
+
+        sourceFile = new File(pathToFile);
+
+    }
+
+    private boolean getPrintHelp() {
+        return printHelp;
+    }
+
+    private void setPrintHelp(boolean printHelp) {
+        this.printHelp = printHelp;
+    }
+
+    private void checkSourceFile() throws FileNotFoundException {
+
+        Path path = Paths.get(sourceFile.toURI());
+        if (Files.notExists(path)) {
+            throw new FileNotFoundException("no such file " + sourceFile.getPath());
+        }
+
+    }
+}
diff --git a/примерсхемыкакматрешка.xsd b/примерсхемыкакматрешка.xsd
new file mode 100644
index 0000000..02e1e33
--- /dev/null
+++ b/примерсхемыкакматрешка.xsd
@@ -0,0 +1,24 @@
+<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>
\ No newline at end of file