From 2c1e36adcd75712f8332ca8e1b1f9323fea9a78f Mon Sep 17 00:00:00 2001 From: Dharani Thangarasu Date: Mon, 4 Oct 2021 11:22:24 +0530 Subject: [PATCH] Modified xml Reading approach --- docio/employeereport/Employee.java | 295 ++++++++++++ docio/employeereport/EmployeeReport.java | 156 +------ docio/employeereport/Employees.java | 208 +-------- docio/mailmergeevent/MailMergeEvent.java | 200 ++------ docio/mailmergeevent/ProductDetail.java | 50 +- docio/mailmergeevent/ProductList.java | 24 + docio/mailmergeevent/Product_PriceList.java | 24 +- docio/mailmergeevent/Products.java | 57 +++ docio/nestedmailmerge/CustomerDetails.java | 70 ++- .../CustomerDetailsImplicit.java | 81 ---- docio/nestedmailmerge/EmployeeDetails.java | 70 +++ .../EmployeeDetailsImplicit.java | 93 ---- docio/nestedmailmerge/Employees.java | 53 +++ docio/nestedmailmerge/NestedMailMerge.java | 437 +----------------- docio/nestedmailmerge/OrderDetails.java | 37 ++ docio/salesinvoice/SalesInvoice.java | 425 ++--------------- docio/salesinvoice/TestOrder.java | 138 +++++- docio/salesinvoice/TestOrderDetail.java | 53 ++- docio/salesinvoice/TestOrderDetails.java | 24 + docio/salesinvoice/TestOrderTotal.java | 32 +- docio/salesinvoice/TestOrderTotals.java | 25 + docio/salesinvoice/TestOrders.java | 25 + docio/tablestyles/Suppliers.java | 99 +++- docio/tablestyles/SuppliersList.java | 24 + docio/tablestyles/TableStyles.java | 147 +----- docio/updatefields/StockDetails.java | 48 +- docio/updatefields/StockMarket.java | 24 + docio/updatefields/UpdateFields.java | 114 +---- 28 files changed, 1256 insertions(+), 1777 deletions(-) create mode 100644 docio/employeereport/Employee.java create mode 100644 docio/mailmergeevent/ProductList.java create mode 100644 docio/mailmergeevent/Products.java delete mode 100644 docio/nestedmailmerge/CustomerDetailsImplicit.java delete mode 100644 docio/nestedmailmerge/EmployeeDetailsImplicit.java create mode 100644 docio/nestedmailmerge/Employees.java create mode 100644 docio/salesinvoice/TestOrderDetails.java create mode 100644 docio/salesinvoice/TestOrderTotals.java create mode 100644 docio/salesinvoice/TestOrders.java create mode 100644 docio/tablestyles/SuppliersList.java create mode 100644 docio/updatefields/StockMarket.java diff --git a/docio/employeereport/Employee.java b/docio/employeereport/Employee.java new file mode 100644 index 0000000..3e43be9 --- /dev/null +++ b/docio/employeereport/Employee.java @@ -0,0 +1,295 @@ +package employeereport; + +import javax.xml.bind.annotation.XmlElement; + +public class Employee { + private String m_employeeID; + private String m_lastName; + private String m_firstName; + private String m_title; + private String m_titleOfCourtesy; + private String m_birthDate; + private String m_hireDate; + private String m_address; + private String m_city; + private String m_region; + private String m_postalCode; + private String m_country; + private String m_homePhone; + private String m_extension; + private String m_photo; + private String m_notes; + private String m_reportsTo; + + /** + * Gets the employee id. + */ + @XmlElement(name = "EmployeeID") + public String getEmployeeID() throws Exception { + return m_employeeID; + } + + /** + * Sets the employee id. + */ + public String setEmployeeID(String value) throws Exception { + m_employeeID = value; + return value; + } + + /** + * Gets the last name of the employee. + */ + @XmlElement(name = "LastName") + public String getLastName() throws Exception { + return m_lastName; + } + + /** + * Sets the last name of the employee. + */ + public String setLastName(String value) throws Exception { + m_lastName = value; + return value; + } + + /** + * Gets the first name of the employee. + */ + @XmlElement(name = "FirstName") + public String getFirstName() throws Exception { + return m_firstName; + } + + /** + * Sets the first name of the employee. + */ + public String setFirstName(String value) throws Exception { + m_firstName = value; + return value; + } + + /** + * Gets the title of the employee. + */ + @XmlElement(name = "Title") + public String getTitle() throws Exception { + return m_title; + } + + /** + * Sets the title of the employee. + */ + public String setTitle(String value) throws Exception { + m_title = value; + return value; + } + + /** + * Gets the title of courtesy of the employee. + */ + @XmlElement(name = "TitleOfCourtesy") + public String getTitleOfCourtesy() throws Exception { + return m_titleOfCourtesy; + } + + /** + * Sets the title of courtesy of the employee. + */ + public String setTitleOfCourtesy(String value) throws Exception { + m_titleOfCourtesy = value; + return value; + } + + /** + * Gets the birth date of the employee. + */ + @XmlElement(name = "BirthDate") + public String getBirthDate() throws Exception { + return m_birthDate; + } + + /** + * Sets the birth date of the employee. + */ + public String setBirthDate(String value) throws Exception { + m_birthDate = value; + return value; + } + + /** + * Gets the hire date of the employee. + */ + @XmlElement(name = "HireDate") + public String getHireDate() throws Exception { + return m_hireDate; + } + + /** + * Sets the hire date of the employee. + */ + public String setHireDate(String value) throws Exception { + m_hireDate = value; + return value; + } + + /** + * Gets the address of the employee. + */ + @XmlElement(name = "Address") + public String getAddress() throws Exception { + return m_address; + } + + /** + * Sets the address of the employee. + */ + public String setAddress(String value) throws Exception { + m_address = value; + return value; + } + + /** + * Gets the city of the employee. + */ + @XmlElement(name = "City") + public String getCity() throws Exception { + return m_city; + } + + /** + * Sets the city of the employee. + */ + public String setCity(String value) throws Exception { + m_city = value; + return value; + } + + /** + * Gets the region of the employee. + */ + @XmlElement(name = "Region") + public String getRegion() throws Exception { + return m_region; + } + + /** + * Sets the hire date of the employee. + */ + public String setRegion(String value) throws Exception { + m_region = value; + return value; + } + + /** + * Gets the postal code of the employee. + */ + @XmlElement(name = "PostalCode") + public String getPostalCode() throws Exception { + return m_postalCode; + } + + /** + * Sets the postal code of the employee. + */ + public String setPostalCode(String value) throws Exception { + m_postalCode = value; + return value; + } + + /** + * Gets the country of the employee. + */ + @XmlElement(name = "Country") + public String getCountry() throws Exception { + return m_country; + } + + /** + * Sets the country of the employee. + */ + public String setCountry(String value) throws Exception { + m_country = value; + return value; + } + + /** + * Gets the contact number of the employee. + */ + @XmlElement(name = "HomePhone") + public String getHomePhone() throws Exception { + return m_homePhone; + } + + /** + * Sets the contact number of the employee. + */ + public String setHomePhone(String value) throws Exception { + m_homePhone = value; + return value; + } + + /** + * Gets the extension of the employee. + */ + @XmlElement(name = "Extension") + public String getExtension() throws Exception { + return m_extension; + } + + /** + * Sets the extension of the employee. + */ + public String setExtension(String value) throws Exception { + m_extension = value; + return value; + } + + /** + * Gets the photo of the employee. + */ + @XmlElement(name = "Photo") + public String getPhoto() throws Exception { + return m_photo; + } + + /** + * Sets the photo of the employee. + */ + public String setPhoto(String value) throws Exception { + m_photo = value; + return value; + } + + /** + * Gets the notes. + */ + @XmlElement(name = "Notes") + public String getNotes() throws Exception { + return m_notes; + } + + /** + * Sets the notes. + */ + public String setNotes(String value) throws Exception { + m_notes = value; + return value; + } + + /** + * Gets the reporter of the employee. + */ + @XmlElement(name = "ReportsTo") + public String getReportsTo() throws Exception { + return m_reportsTo; + } + + /** + * Sets the reporter of the employee. + */ + public String setReportsTo(String value) throws Exception { + m_reportsTo = value; + return value; + } +} diff --git a/docio/employeereport/EmployeeReport.java b/docio/employeereport/EmployeeReport.java index b0d86f7..917429c 100644 --- a/docio/employeereport/EmployeeReport.java +++ b/docio/employeereport/EmployeeReport.java @@ -1,11 +1,11 @@ package employeereport; +import java.util.List; import java.io.*; +import javax.xml.bind.*; import com.syncfusion.docio.*; -import com.syncfusion.javahelper.system.*; +import com.syncfusion.javahelper.system.ConvertSupport; import com.syncfusion.javahelper.system.collections.generic.ListSupport; -import com.syncfusion.javahelper.system.io.*; -import com.syncfusion.javahelper.system.xml.*; public class EmployeeReport { public static void main(String[] args) throws Exception { @@ -67,146 +67,22 @@ private static void mergeField_EmployeeImage(Object sender, MergeImageFieldEvent * */ private static MailMergeDataTable getMailMergeDataTableEmployee() throws Exception { - ListSupport employees = new ListSupport(Employees.class); - FileStreamSupport fs = new FileStreamSupport(getDataDir("EmployeesList.xml"), FileMode.Open, - FileAccess.Read); - XmlReaderSupport reader = XmlReaderSupport.create(fs); - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "Employees")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - while (!(reader.getLocalName() == "Employees")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "Employee": - - employees.add(getEmployees(reader)); - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName() == "Employees") - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - MailMergeDataTable dataTable = new MailMergeDataTable("Employees", employees); - reader.close(); - fs.close(); + // Loads the XML file. + File file = new File(getDataDir("EmployeesList.xml")); + // Create a new instance for the JAXBContext. + JAXBContext jaxbContext = JAXBContext.newInstance(Employees.class); + // Reads the XML file. + Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + Employees employees = (Employees) jaxbUnmarshaller.unmarshal(file); + // Gets the list of employee details. + List employee = employees.getEmployees(); + ListSupport employeeList = new ListSupport(Employee.class); + employeeList.addRange(employee); + // Creates an instance of MailMergeDataTable by specifying mail merge group name and IEnumerable collection. + MailMergeDataTable dataTable = new MailMergeDataTable("Employees", employeeList); return dataTable; } - /** - * - * Gets the employees. - * - * @param reader The reader. - */ - private static Employees getEmployees(XmlReaderSupport reader) throws Exception { - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "Employee")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - Employees employee = new Employees(); - while (!(reader.getLocalName() == "Employee")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "EmployeeID": - - employee.setEmployeeID(reader.readContentAsString()); - break; - case "LastName": - - employee.setLastName(reader.readContentAsString()); - break; - case "FirstName": - - employee.setFirstName(reader.readContentAsString()); - break; - case "Title": - - employee.setTitle(reader.readContentAsString()); - break; - case "TitleOfCourtesy": - - employee.setTitleOfCourtesy(reader.readContentAsString()); - break; - case "BirthDate": - - employee.setBirthDate(reader.readContentAsString()); - break; - case "HireDate": - - employee.setHireDate(reader.readContentAsString()); - break; - case "Address": - - employee.setAddress(reader.readContentAsString()); - break; - case "City": - - employee.setCity(reader.readContentAsString()); - break; - case "Region": - - employee.setRegion(reader.readContentAsString()); - break; - case "PostalCode": - - employee.setPostalCode(reader.readContentAsString()); - break; - case "Country": - - employee.setCountry(reader.readContentAsString()); - break; - case "HomePhone": - - employee.setHomePhone(reader.readContentAsString()); - break; - case "Extension": - - employee.setExtension(reader.readContentAsString()); - break; - case "Photo": - - employee.setPhoto(reader.readContentAsString()); - break; - case "Notes": - - employee.setNotes(reader.readContentAsString()); - break; - case "ReportsTo": - - employee.setReportsTo(reader.readContentAsString()); - break; - default: - - reader.skip(); - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName() == "Employee") - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - return employee; - } /** * Get the file path * diff --git a/docio/employeereport/Employees.java b/docio/employeereport/Employees.java index 70fbf7a..3023152 100644 --- a/docio/employeereport/Employees.java +++ b/docio/employeereport/Employees.java @@ -1,200 +1,24 @@ package employeereport; -public class Employees { - private String m_employeeID; - private String m_lastName; - private String m_firstName; - private String m_title; - private String m_titleOfCourtesy; - private String m_birthDate; - private String m_hireDate; - private String m_address; - private String m_city; - private String m_region; - private String m_postalCode; - private String m_country; - private String m_homePhone; - private String m_extension; - private String m_photo; - private String m_notes; - private String m_reportsTo; - - public String getEmployeeID() throws Exception { - return m_employeeID; - } - - public String setEmployeeID(String value) throws Exception { - m_employeeID = value; - return value; - } - - public String getLastName() throws Exception { - return m_lastName; - } - - public String setLastName(String value) throws Exception { - m_lastName = value; - return value; - } - - public String getFirstName() throws Exception { - return m_firstName; - } - - public String setFirstName(String value) throws Exception { - m_firstName = value; - return value; - } - - public String getTitle() throws Exception { - return m_title; - } - - public String setTitle(String value) throws Exception { - m_title = value; - return value; - } - - public String getTitleOfCourtesy() throws Exception { - return m_titleOfCourtesy; - } - - public String setTitleOfCourtesy(String value) throws Exception { - m_titleOfCourtesy = value; - return value; - } - - public String getBirthDate() throws Exception { - return m_birthDate; - } - - public String setBirthDate(String value) throws Exception { - m_birthDate = value; - return value; - } - - public String getHireDate() throws Exception { - return m_hireDate; - } - - public String setHireDate(String value) throws Exception { - m_hireDate = value; - return value; - } - - public String getAddress() throws Exception { - return m_address; - } - - public String setAddress(String value) throws Exception { - m_address = value; - return value; - } - - public String getCity() throws Exception { - return m_city; - } +import java.util.List; +import javax.xml.bind.annotation.*; - public String setCity(String value) throws Exception { - m_city = value; - return value; - } - - public String getRegion() throws Exception { - return m_region; - } - - public String setRegion(String value) throws Exception { - m_region = value; - return value; - } - - public String getPostalCode() throws Exception { - return m_postalCode; - } - - public String setPostalCode(String value) throws Exception { - m_postalCode = value; - return value; - } - - public String getCountry() throws Exception { - return m_country; - } - - public String setCountry(String value) throws Exception { - m_country = value; - return value; - } - - public String getHomePhone() throws Exception { - return m_homePhone; - } - - public String setHomePhone(String value) throws Exception { - m_homePhone = value; - return value; - } - - public String getExtension() throws Exception { - return m_extension; - } - - public String setExtension(String value) throws Exception { - m_extension = value; - return value; - } - - public String getPhoto() throws Exception { - return m_photo; - } - - public String setPhoto(String value) throws Exception { - m_photo = value; - return value; - } - - public String getNotes() throws Exception { - return m_notes; - } - - public String setNotes(String value) throws Exception { - m_notes = value; - return value; - } - - public String getReportsTo() throws Exception { - return m_reportsTo; - } - - public String setReportsTo(String value) throws Exception { - m_reportsTo = value; - return value; - } +@XmlRootElement(name = "Employees") +public class Employees { + private List Employee; - public Employees(String employeeID, String lastName, String firstName, String title, String titleOfCourtesy, - String birthDate, String hireDate, String address, String city, String region, String postalCode, - String country, String homePhone, String extension, String photo, String notes, String reportsTo) - throws Exception { - m_employeeID = employeeID; - m_lastName = lastName; - m_firstName = firstName; - m_title = title; - m_titleOfCourtesy = titleOfCourtesy; - m_birthDate = birthDate; - m_hireDate = hireDate; - m_address = address; - m_city = city; - m_region = region; - m_postalCode = postalCode; - m_country = country; - m_homePhone = homePhone; - m_extension = extension; - m_photo = photo; - m_notes = notes; - m_reportsTo = reportsTo; + /** + * Gets the list of the employee. + */ + @XmlElement(name = "Employee") + public List getEmployees() { + return Employee; } - public Employees() throws Exception { + /** + * Sets the list of the employee. + */ + public void setEmployees(List employee) { + this.Employee = employee; } } diff --git a/docio/mailmergeevent/MailMergeEvent.java b/docio/mailmergeevent/MailMergeEvent.java index 1e63d9a..14a9a74 100644 --- a/docio/mailmergeevent/MailMergeEvent.java +++ b/docio/mailmergeevent/MailMergeEvent.java @@ -1,14 +1,13 @@ package mailmergeevent; import java.io.*; -import mailmergeevent.ProductDetail; -import mailmergeevent.Product_PriceList; +import java.util.List; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; import com.syncfusion.docio.*; -import com.syncfusion.javahelper.system.*; import com.syncfusion.javahelper.system.collections.generic.ListSupport; import com.syncfusion.javahelper.system.drawing.ColorSupport; import com.syncfusion.javahelper.system.io.*; -import com.syncfusion.javahelper.system.xml.*; public class MailMergeEvent { public static void main(String[] args) throws Exception { @@ -68,7 +67,6 @@ public void remove(MergeImageFieldEventHandler delegate) throws Exception { // Execute Mail Merge with groups. mailMerge.executeGroup(mailMergeDataTablePriceList); mailMerge.executeGroup(mailMergeDataTableProductData); - FormatType type = FormatType.Docx; // Save and close the document. document.save("Mail Merge Event.docx", FormatType.Docx); document.close(); @@ -113,87 +111,20 @@ private static void mergeField_ProductImage(Object sender, MergeImageFieldEventA * */ private static MailMergeDataTable getMailMergeDataTablePriceList() throws Exception { - // Gets the product_pricelist as “IEnumerable” collection. - ListSupport product_PriceList = new ListSupport(Product_PriceList.class); - FileStreamSupport fs = new FileStreamSupport(getDataDir("ProductPriceList.xml"), FileMode.Open, - FileAccess.Read); - XmlReaderSupport reader = XmlReaderSupport.create(fs); - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "Products")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - while (!(reader.getLocalName() == "Products")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "Product_PriceList": - - product_PriceList.add(getProduct_PriceList(reader)); - break; - } - } else - - { - reader.read(); - if (((reader.getLocalName() == "Products")) - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - // Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection. - MailMergeDataTable dataTable1 = new MailMergeDataTable("Product_PriceList", product_PriceList); - reader.close(); - fs.close(); - return dataTable1; - } - - /** - * - * Gets the product price list. - * - * @param reader The reader. - */ - private static Product_PriceList getProduct_PriceList(XmlReaderSupport reader) throws Exception { - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "Product_PriceList")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - Product_PriceList product_PriceList = new Product_PriceList(); - while (!(reader.getLocalName() == "Product_PriceList")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "ProductName": - - product_PriceList.setProductName(reader.readContentAsString()); - break; - case "Price": - - product_PriceList.setPrice(reader.readContentAsString()); - break; - default: - - reader.skip(); - break; - } - } else - - { - reader.read(); - if (((reader.getLocalName() == "Product_PriceList")) - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - return product_PriceList; + // Loads the XML file. + File file = new File(getDataDir("ProductPriceList.xml")); + // Create a new instance for the JAXBContext. + JAXBContext jaxbContext = JAXBContext.newInstance(ProductDetail.class); + // Reads the XML file. + Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + ProductDetail products = (ProductDetail) jaxbUnmarshaller.unmarshal(file); + // Gets the list of product price details. + List list = products.getPriceList(); + ListSupport priceList = new ListSupport(Product_PriceList.class); + priceList.addRange(list); + // Creates an instance of MailMergeDataTable by specifying mail merge group name and IEnumerable collection. + MailMergeDataTable dataTable = new MailMergeDataTable("Product_PriceList", priceList); + return dataTable; } /** @@ -202,91 +133,22 @@ private static Product_PriceList getProduct_PriceList(XmlReaderSupport reader) t * */ private static MailMergeDataTable getMailMergeDataTableProductData() throws Exception { - // Gets the product detail as “IEnumerable” collection. - ListSupport productDetail = new ListSupport(ProductDetail.class); - FileStreamSupport fs = new FileStreamSupport(getDataDir("Product.xml"), FileMode.Open, FileAccess.Read); - XmlReaderSupport reader = XmlReaderSupport.create(fs); - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "ProductList")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - while (!(reader.getLocalName() == "ProductList")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "Products": - - productDetail.add(getProductDetail(reader)); - break; - } - } else - - { - reader.read(); - if (((reader.getLocalName() == "ProductList")) - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - // Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection. - MailMergeDataTable dataTable2 = new MailMergeDataTable("ProductDetail", productDetail); - reader.close(); - fs.close(); - return dataTable2; + // Loads the XML file. + File file = new File(getDataDir("Product.xml")); + // Create a new instance for the JAXBContext. + JAXBContext jaxbContext = JAXBContext.newInstance(ProductList.class); + // Reads the XML file. + Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + ProductList products = (ProductList) jaxbUnmarshaller.unmarshal(file); + // Gets the list of product details. + List list = products.getProducts(); + ListSupport productList = new ListSupport(Products.class); + productList.addRange(list); + // Creates an instance of MailMergeDataTable by specifying mail merge group name and IEnumerable collection. + MailMergeDataTable dataTable = new MailMergeDataTable("ProductDetail", productList); + return dataTable; } - /** - * - * Gets the product details. - * - * @param reader The reader. - */ - private static ProductDetail getProductDetail(XmlReaderSupport reader) throws Exception { - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "Products")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - ProductDetail productDetail = new ProductDetail(); - while (!(reader.getLocalName() == "Products")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "SNO": - - productDetail.setSNO(reader.readContentAsString()); - break; - case "ProductName": - - productDetail.setProductName(reader.readContentAsString()); - break; - case "ProductImage": - - productDetail.setProductImage(reader.readContentAsString()); - break; - default: - - reader.skip(); - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName() == "Products") - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - return productDetail; - } /** * Get the file path * diff --git a/docio/mailmergeevent/ProductDetail.java b/docio/mailmergeevent/ProductDetail.java index 7853aed..b96a20d 100644 --- a/docio/mailmergeevent/ProductDetail.java +++ b/docio/mailmergeevent/ProductDetail.java @@ -1,43 +1,25 @@ package mailmergeevent; -public class ProductDetail { - private String m_sNO; - private String m_productName; - private String m_productImage; - - public String getSNO() throws Exception { - return m_sNO; - } - - public String setSNO(String value) throws Exception { - m_sNO = value; - return value; - } - - public String getProductName() throws Exception { - return m_productName; - } - - public String setProductName(String value) throws Exception { - m_productName = value; - return value; - } +import java.util.List; +import javax.xml.bind.annotation.*; - public String getProductImage() throws Exception { - return m_productImage; - } +@XmlRootElement(name = "Products") +public class ProductDetail { + private List PriceList; - public String setProductImage(String value) throws Exception { - m_productImage = value; - return value; + /** + * Gets the list of product price. + */ + @XmlElement(name = "Product_PriceList") + public List getPriceList() { + return PriceList; } - public ProductDetail(String sNO, String productName, String productImage) throws Exception { - m_sNO = sNO; - m_productName = productName; - m_productImage = productImage; + /** + * Sets the list of product price. + */ + public void setPriceList(List priceList) { + this.PriceList = priceList; } - public ProductDetail() throws Exception { - } } diff --git a/docio/mailmergeevent/ProductList.java b/docio/mailmergeevent/ProductList.java new file mode 100644 index 0000000..9b3849d --- /dev/null +++ b/docio/mailmergeevent/ProductList.java @@ -0,0 +1,24 @@ +package mailmergeevent; + +import java.util.List; +import javax.xml.bind.annotation.*; + +@XmlRootElement(name = "ProductList") +public class ProductList { + private List Products; + + /** + * Gets the list of product. + */ + @XmlElement(name = "Products") + public List getProducts() { + return Products; + } + + /** + * Sets the list of product. + */ + public void setProducts(List products) { + this.Products = products; + } +} diff --git a/docio/mailmergeevent/Product_PriceList.java b/docio/mailmergeevent/Product_PriceList.java index 2716987..ca538b0 100644 --- a/docio/mailmergeevent/Product_PriceList.java +++ b/docio/mailmergeevent/Product_PriceList.java @@ -1,32 +1,40 @@ package mailmergeevent; +import javax.xml.bind.annotation.XmlElement; + public class Product_PriceList { private String m_productName; private String m_price; + /** + * Gets the name of the product. + */ + @XmlElement(name = "ProductName") public String getProductName() throws Exception { return m_productName; } + /** + * Sets the name of the product. + */ public String setProductName(String value) throws Exception { m_productName = value; return value; } + /** + * Gets the price of the product. + */ + @XmlElement(name = "Price") public String getPrice() throws Exception { return m_price; } + /** + * Sets the price of the product. + */ public String setPrice(String value) throws Exception { m_price = value; return value; } - - public Product_PriceList(String productName, String price) throws Exception { - m_productName = productName; - m_price = price; - } - - public Product_PriceList() throws Exception { - } } diff --git a/docio/mailmergeevent/Products.java b/docio/mailmergeevent/Products.java new file mode 100644 index 0000000..9e91f7c --- /dev/null +++ b/docio/mailmergeevent/Products.java @@ -0,0 +1,57 @@ +package mailmergeevent; + +import javax.xml.bind.annotation.XmlElement; + +public class Products { + private String m_sNO; + private String m_productName; + private String m_productImage; + + /** + * Gets the serial number of the product. + */ + @XmlElement(name = "SNO") + public String getSNO() throws Exception { + return m_sNO; + } + + /** + * Sets the serial number of the product. + */ + public String setSNO(String value) throws Exception { + m_sNO = value; + return value; + } + + /** + * Gets the name of the product. + */ + @XmlElement(name = "ProductName") + public String getProductName() throws Exception { + return m_productName; + } + + /** + * Sets the name of the product. + */ + public String setProductName(String value) throws Exception { + m_productName = value; + return value; + } + + /** + * Gets the image of the product. + */ + @XmlElement(name = "ProductImage") + public String getProductImage() throws Exception { + return m_productImage; + } + + /** + * Sets the image of the product. + */ + public String setProductImage(String value) throws Exception { + m_productImage = value; + return value; + } +} diff --git a/docio/nestedmailmerge/CustomerDetails.java b/docio/nestedmailmerge/CustomerDetails.java index afd5e22..b0ac01d 100644 --- a/docio/nestedmailmerge/CustomerDetails.java +++ b/docio/nestedmailmerge/CustomerDetails.java @@ -1,63 +1,129 @@ package nestedmailmerge; +import java.util.List; + +import javax.xml.bind.annotation.*; + +@XmlRootElement(name = "Customers") public class CustomerDetails { private String m_employeeID; private String m_customerID; private String m_companyName; + private String m_contactName; private String m_city; private String m_country; + private List m_orders; + /** + * Gets the Id of the employee. + */ + @XmlElement(name = "EmployeeID") public String getEmployeeID() throws Exception { return m_employeeID; } + /** + * Sets the Id of the employee. + */ public String setEmployeeID(String value) throws Exception { m_employeeID = value; return value; } + /** + * Gets the Id of the customer. + */ + @XmlElement(name = "CustomerID") public String getCustomerID() throws Exception { return m_customerID; } + /** + * Sets the Id of the customer. + */ public String setCustomerID(String value) throws Exception { m_customerID = value; return value; } + /** + * Gets the name of the company. + */ + @XmlElement(name = "CompanyName") public String getCompanyName() throws Exception { return m_companyName; } + /** + * Sets the name of the company. + */ public String setCompanyName(String value) throws Exception { m_companyName = value; return value; } + /** + * Gets the contact name of the customer. + */ + @XmlElement(name = "ContactName") public String getContactName() throws Exception { - return m_companyName; + return m_contactName; } + /** + * Sets the contact name of the customer. + */ public String setContactName(String value) throws Exception { - m_companyName = value; + m_contactName = value; return value; } + /** + * Gets the city of the customer. + */ + @XmlElement(name = "City") public String getCity() throws Exception { return m_city; } + /** + * Sets the city of the customer. + */ public String setCity(String value) throws Exception { m_city = value; return value; } + /** + * Gets the country of the customer. + */ + @XmlElement(name = "Country") public String getCountry() throws Exception { return m_country; } + /** + * Sets the country of the customer. + */ public String setCountry(String value) throws Exception { m_country = value; return value; } + + /** + * Gets the order details of the customer. + */ + @XmlElement(name = "Orders") + public List getOrders() throws Exception { + return m_orders; + } + + /** + * Sets the order details of the customer. + */ + public void setOrders(List orders) throws Exception { + m_orders = orders; + this.m_orders = orders; + } + } diff --git a/docio/nestedmailmerge/CustomerDetailsImplicit.java b/docio/nestedmailmerge/CustomerDetailsImplicit.java deleted file mode 100644 index 99ca75c..0000000 --- a/docio/nestedmailmerge/CustomerDetailsImplicit.java +++ /dev/null @@ -1,81 +0,0 @@ -package nestedmailmerge; - -import com.syncfusion.javahelper.system.collections.generic.ListSupport; - -public class CustomerDetailsImplicit { - private String m_employeeID; - private String m_customerID; - private String m_companyName; - private String m_city; - private String m_country; - private ListSupport m_orders; - - public ListSupport getOrders() throws Exception { - if (m_orders == null) - m_orders = new ListSupport(OrderDetails.class); - return m_orders; - } - - public ListSupport setOrders(ListSupport value) throws Exception { - m_orders = value; - return value; - } - - public String getEmployeeID() throws Exception { - return m_employeeID; - } - - public String setEmployeeID(String value) throws Exception { - m_employeeID = value; - return value; - } - - public String getCustomerID() throws Exception { - return m_customerID; - } - - public String setCustomerID(String value) throws Exception { - m_customerID = value; - return value; - } - - public String getCompanyName() throws Exception { - return m_companyName; - } - - public String setCompanyName(String value) throws Exception { - m_companyName = value; - return value; - } - - public String getContactName() throws Exception { - return m_companyName; - } - - public String setContactName(String value) throws Exception { - m_companyName = value; - return value; - } - - public String getCity() throws Exception { - return m_city; - } - - public String setCity(String value) throws Exception { - m_city = value; - return value; - } - - public String getCountry() throws Exception { - return m_country; - } - - public String setCountry(String value) throws Exception { - m_country = value; - return value; - } - - public CustomerDetailsImplicit() throws Exception { - m_orders = new ListSupport(OrderDetails.class); - } -} diff --git a/docio/nestedmailmerge/EmployeeDetails.java b/docio/nestedmailmerge/EmployeeDetails.java index 713625c..584be13 100644 --- a/docio/nestedmailmerge/EmployeeDetails.java +++ b/docio/nestedmailmerge/EmployeeDetails.java @@ -1,5 +1,9 @@ package nestedmailmerge; +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; + public class EmployeeDetails { private String m_employeeID; private String m_lastName; @@ -8,67 +12,133 @@ public class EmployeeDetails { private String m_city; private String m_country; private String m_extension; + private List m_customerDetails; + /** + * Gets the Id of the employee. + */ + @XmlElement(name = "EmployeeID") public String getEmployeeID() throws Exception { return m_employeeID; } + /** + * Sets the Id of the employee. + */ public String setEmployeeID(String value) throws Exception { m_employeeID = value; return value; } + /** + * Gets the last name of the employee. + */ + @XmlElement(name = "LastName") public String getLastName() throws Exception { return m_lastName; } + /** + * Sets the last name of the employee. + */ public String setLastName(String value) throws Exception { m_lastName = value; return value; } + /** + * Gets the first name of the employee. + */ + @XmlElement(name = "FirstName") public String getFirstName() throws Exception { return m_firstName; } + /** + * Sets the first name of the employee. + */ public String setFirstName(String value) throws Exception { m_firstName = value; return value; } + /** + * Gets the address of the employee. + */ + @XmlElement(name = "Address") public String getAddress() throws Exception { return m_address; } + /** + * Sets the address of the employee. + */ public String setAddress(String value) throws Exception { m_address = value; return value; } + /** + * Gets the city of the employee. + */ + @XmlElement(name = "City") public String getCity() throws Exception { return m_city; } + /** + * Sets the city of the employee. + */ public String setCity(String value) throws Exception { m_city = value; return value; } + /** + * Gets the country of the employee. + */ + @XmlElement(name = "Country") public String getCountry() throws Exception { return m_country; } + /** + * Sets the country of the employee. + */ public String setCountry(String value) throws Exception { m_country = value; return value; } + /** + * Gets the extension of the employee. + */ + @XmlElement(name = "Extension") public String getExtension() throws Exception { return m_extension; } + /** + * Sets the extension of the employee. + */ public String setExtension(String value) throws Exception { m_extension = value; return value; + + } + + /** + * Gets the customer details. + */ + @XmlElement(name = "Customers") + public List getCustomerDetails() { + return m_customerDetails; + } + + /** + * Sets the customer details. + */ + public void setCustomerDetails(List customerDetails) { + m_customerDetails = customerDetails; } } diff --git a/docio/nestedmailmerge/EmployeeDetailsImplicit.java b/docio/nestedmailmerge/EmployeeDetailsImplicit.java deleted file mode 100644 index aa2a654..0000000 --- a/docio/nestedmailmerge/EmployeeDetailsImplicit.java +++ /dev/null @@ -1,93 +0,0 @@ -package nestedmailmerge; - -import com.syncfusion.javahelper.system.collections.generic.ListSupport; - -public class EmployeeDetailsImplicit { - private String m_employeeID; - private String m_lastName; - private String m_firstName; - private String m_address; - private String m_city; - private String m_country; - private String m_extension; - private ListSupport m_customers; - - public String getEmployeeID() throws Exception { - return m_employeeID; - } - - public String setEmployeeID(String value) throws Exception { - m_employeeID = value; - return value; - } - - public String getLastName() throws Exception { - return m_lastName; - } - - public String setLastName(String value) throws Exception { - m_lastName = value; - return value; - } - - public String getFirstName() throws Exception { - return m_firstName; - } - - public String setFirstName(String value) throws Exception { - m_firstName = value; - return value; - } - - public String getAddress() throws Exception { - return m_address; - } - - public String setAddress(String value) throws Exception { - m_address = value; - return value; - } - - public String getCity() throws Exception { - return m_city; - } - - public String setCity(String value) throws Exception { - m_city = value; - return value; - } - - public String getCountry() throws Exception { - return m_country; - } - - public String setCountry(String value) throws Exception { - m_country = value; - return value; - } - - public String getExtension() throws Exception { - return m_extension; - } - - public String setExtension(String value) throws Exception { - m_extension = value; - return value; - } - - public ListSupport getCustomers() throws Exception { - if (m_customers == null) - m_customers = new ListSupport(CustomerDetailsImplicit.class); - return m_customers; - } - - public ListSupport setCustomers(ListSupport value) - throws Exception { - m_customers = value; - return value; - } - - public EmployeeDetailsImplicit() throws Exception { - m_customers = new ListSupport(CustomerDetailsImplicit.class); - } -} diff --git a/docio/nestedmailmerge/Employees.java b/docio/nestedmailmerge/Employees.java new file mode 100644 index 0000000..637fb2b --- /dev/null +++ b/docio/nestedmailmerge/Employees.java @@ -0,0 +1,53 @@ +package nestedmailmerge; + +import java.util.List; + +import javax.xml.bind.annotation.*; + +import com.syncfusion.javahelper.system.collections.generic.ListSupport; + +@XmlRootElement(name = "EmployeesList") +public class Employees { + + private List Employee; + + /** + * Gets the list of employee details. + */ + @XmlElement(name = "Employees") + public List getEmployees() throws Exception { + return Employee; + } + + /** + * Sets the list of employee details. + */ + public void setEmployees(List employee) { + this.Employee = employee; + } + + /** + * Gets the list of customer details. + */ + public ListSupport getCustomers() throws Exception { + ListSupport customersList = new ListSupport(CustomerDetails.class); + for (EmployeeDetails employee : Employee) { + customersList.addRange(employee.getCustomerDetails()); + } + return customersList; + } + + /** + * Gets the list of order details. + */ + public ListSupport getOrders() throws Exception { + ListSupport customersList = new ListSupport(OrderDetails.class); + for (EmployeeDetails employee : Employee) { + for (CustomerDetails customer : employee.getCustomerDetails()) { + customersList.addRange(customer.getOrders()); + } + } + return customersList; + } + +} diff --git a/docio/nestedmailmerge/NestedMailMerge.java b/docio/nestedmailmerge/NestedMailMerge.java index b55bc93..d910630 100644 --- a/docio/nestedmailmerge/NestedMailMerge.java +++ b/docio/nestedmailmerge/NestedMailMerge.java @@ -1,6 +1,10 @@ package nestedmailmerge; import java.io.File; +import java.util.List; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; import com.syncfusion.docio.*; import com.syncfusion.javahelper.system.*; @@ -46,432 +50,31 @@ public static void main(String[] args) throws Exception { * @exception XmlException Unexpected xml tag + reader.LocalName */ private static MailMergeDataSet getMailMergeDataSet() throws Exception { + // Loads the XML file. + File file = new File(getDataDir("Employees.xml")); + // Create a new instance for the JAXBContext. + JAXBContext jaxbContext = JAXBContext.newInstance(Employees.class); + // Reads the XML file. + Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + Employees employees = (Employees) jaxbUnmarshaller.unmarshal(file); // Gets the employee details as “IEnumerable” collection. - ListSupport employees = new ListSupport(EmployeeDetails.class); - // Gets the customer details as “IEnumerable” collection. - ListSupport customers = new ListSupport(CustomerDetails.class); - // Gets the order details as “IEnumerable” collection. - ListSupport orders = new ListSupport(OrderDetails.class); - FileStreamSupport stream = new FileStreamSupport(getDataDir("Employees.xml"), FileMode.OpenOrCreate); - XmlReaderSupport reader = XmlReaderSupport.create(stream); - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "EmployeesList")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - while (!(reader.getLocalName() == "EmployeesList")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "Employees": - - employees.add(getEmployee(reader, customers, orders)); - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName() == "EmployeesList") - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - reader.close(); - stream.close(); + ListSupport employeeList = new ListSupport(EmployeeDetails.class); + // Gets the list of employee details. + List list = employees.getEmployees(); + employeeList.addRange(list); + // Gets the customer details as IEnumerable collection. + ListSupport customers = employees.getCustomers(); + // Gets the order details as IEnumerable collection. + ListSupport orders = employees.getOrders(); // Creates an instance of the MailMergeDataSet. MailMergeDataSet dataSet = new MailMergeDataSet(); - dataSet.add(new MailMergeDataTable("Employees", employees)); + dataSet.add(new MailMergeDataTable("Employees", employeeList)); dataSet.add(new MailMergeDataTable("Customers", customers)); dataSet.add(new MailMergeDataTable("Orders", orders)); return dataSet; } - /** - * - * Gets the employee. - * - * @param reader The reader. - * @param customers The customers. - * @param orders The orders. - * @return - * @exception System.Exception reader - * @exception XmlException Unexpected xml tag + reader.LocalName - */ - private static EmployeeDetails getEmployee(XmlReaderSupport reader, ListSupport customers, - ListSupport orders) throws Exception { - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "Employees")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - EmployeeDetails employee = new EmployeeDetails(); - while (!(reader.getLocalName() == "Employees")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "EmployeeID": - - employee.setEmployeeID(reader.readContentAsString()); - break; - case "LastName": - - employee.setLastName(reader.readContentAsString()); - break; - case "FirstName": - - employee.setFirstName(reader.readContentAsString()); - break; - case "Address": - - employee.setAddress(reader.readContentAsString()); - break; - case "City": - - employee.setCity(reader.readContentAsString()); - break; - case "Country": - - employee.setCountry(reader.readContentAsString()); - break; - case "Extension": - - employee.setExtension(reader.readContentAsString()); - break; - case "Customers": - - customers.add(getCustomer(reader, orders)); - break; - default: - - reader.skip(); - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName() == "Employees") - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - return employee; - } - - /** - * - * Gets the customer. - * - * @param reader The reader. - * @param orders The orders. - * @return - * @exception System.Exception reader - * @exception XmlException Unexpected xml tag + reader.LocalName - */ - private static CustomerDetails getCustomer(XmlReaderSupport reader, ListSupport orders) - throws Exception { - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "Customers")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - CustomerDetails customer = new CustomerDetails(); - while (!(reader.getLocalName() == "Customers")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "EmployeeID": - - customer.setEmployeeID(reader.readContentAsString()); - break; - case "CustomerID": - - customer.setCustomerID(reader.readContentAsString()); - break; - case "CompanyName": - - customer.setCompanyName(reader.readContentAsString()); - break; - case "ContactName": - - customer.setContactName(reader.readContentAsString()); - break; - case "City": - - customer.setCity(reader.readContentAsString()); - break; - case "Country": - - customer.setCountry(reader.readContentAsString()); - break; - case "Orders": - - orders.add(getOrders(reader)); - break; - } - reader.read(); - } else - - { - reader.read(); - if ((reader.getLocalName() == "Customers") - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - return customer; - } - - /** - * - * Gets the mail merge data table. - * - * @return - * @exception System.Exception reader - * @exception XmlException Unexpected xml tag + reader.LocalName - */ - private MailMergeDataTable getMailMergeDataTable(String basePath) throws Exception { - // Gets the employee details implicit as “IEnumerable” collection. - ListSupport employees = new ListSupport( - EmployeeDetailsImplicit.class); - FileStreamSupport stream = new FileStreamSupport(basePath + "/DocIO/Employees.xml", FileMode.OpenOrCreate); - XmlReaderSupport reader = XmlReaderSupport.create(stream); - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "EmployeesList")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - while (!(reader.getLocalName() == "EmployeesList")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "Employees": - - employees.add(getEmployee(reader)); - break; - } - } else - { - reader.read(); - if ((reader.getLocalName() == "EmployeesList") - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - reader.close(); - stream.close(); - // Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection. - MailMergeDataTable dataTable = new MailMergeDataTable("Employees", employees); - return dataTable; - } - - /** - * - * Gets the employee. - * - * @param reader The reader. - * @return - * @exception System.Exception reader - * @exception XmlException Unexpected xml tag + reader.LocalName - */ - private EmployeeDetailsImplicit getEmployee(XmlReaderSupport reader) throws Exception { - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "Employees")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - EmployeeDetailsImplicit employee = new EmployeeDetailsImplicit(); - while (!(reader.getLocalName() == "Employees")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "EmployeeID": - - employee.setEmployeeID(reader.readContentAsString()); - break; - case "LastName": - - employee.setLastName(reader.readContentAsString()); - break; - case "FirstName": - - employee.setFirstName(reader.readContentAsString()); - break; - case "Address": - - employee.setAddress(reader.readContentAsString()); - break; - case "City": - - employee.setCity(reader.readContentAsString()); - break; - case "Country": - - employee.setCountry(reader.readContentAsString()); - break; - case "Extension": - - employee.setExtension(reader.readContentAsString()); - break; - case "Customers": - - employee.getCustomers().add(getCustomer(reader)); - break; - default: - - reader.skip(); - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName() == "Employees") - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - return employee; - } - - /** - * - * Gets the customer. - * - * @param reader The reader. - * @return - * @exception System.Exception reader - * @exception XmlException Unexpected xml tag + reader.LocalName - */ - private CustomerDetailsImplicit getCustomer(XmlReaderSupport reader) throws Exception { - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "Customers")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - CustomerDetailsImplicit customer = new CustomerDetailsImplicit(); - while (!(reader.getLocalName() == "Customers")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "EmployeeID": - - customer.setEmployeeID(reader.readContentAsString()); - break; - case "CustomerID": - - customer.setCustomerID(reader.readContentAsString()); - break; - case "CompanyName": - - customer.setCompanyName(reader.readContentAsString()); - break; - case "ContactName": - - customer.setContactName(reader.readContentAsString()); - break; - case "City": - - customer.setCity(reader.readContentAsString()); - break; - case "Country": - - customer.setCountry(reader.readContentAsString()); - break; - case "Orders": - - customer.getOrders().add(getOrders(reader)); - break; - } - reader.read(); - } else - - { - reader.read(); - if ((reader.getLocalName() == "Customers") - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - return customer; - } - - /** - * - * Gets the orders. - * - * @param reader The reader. - * @return - * @exception System.Exception reader - * @exception XmlException Unexpected xml tag + reader.LocalName - */ - private static OrderDetails getOrders(XmlReaderSupport reader) throws Exception { - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "Orders")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - OrderDetails order = new OrderDetails(); - while (!(reader.getLocalName() == "Orders")) { - if (reader.getNodeType().getEnumValue() != XmlNodeType.EndElement.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "OrderID": - - order.setOrderID(reader.readContentAsString()); - break; - case "CustomerID": - - order.setCustomerID(reader.readContentAsString()); - break; - case "OrderDate": - - order.setOrderDate(reader.readContentAsString()); - break; - case "RequiredDate": - - order.setRequiredDate(reader.readContentAsString()); - break; - case "ShippedDate": - - order.setShippedDate(reader.readContentAsString()); - break; - } - reader.read(); - } else - - { - reader.read(); - if ((reader.getLocalName() == "Orders") - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - return order; - } /** * Get the file path * diff --git a/docio/nestedmailmerge/OrderDetails.java b/docio/nestedmailmerge/OrderDetails.java index 3f39c0d..6a90da3 100644 --- a/docio/nestedmailmerge/OrderDetails.java +++ b/docio/nestedmailmerge/OrderDetails.java @@ -1,5 +1,7 @@ package nestedmailmerge; +import javax.xml.bind.annotation.XmlElement; + public class OrderDetails { private String m_orderID; private String m_customerID; @@ -7,46 +9,81 @@ public class OrderDetails { private String m_requiredDate; private String m_shippedDate; + /** + * Gets the Id of the order. + */ + @XmlElement(name = "OrderID") public String getOrderID() throws Exception { return m_orderID; } + /** + * Sets the Id of the order. + */ public String setOrderID(String value) throws Exception { m_orderID = value; return value; } + /** + * Gets the Id of the customer. + */ + @XmlElement(name = "CustomerID") public String getCustomerID() throws Exception { return m_customerID; } + /** + * Sets the Id of the customer. + */ public String setCustomerID(String value) throws Exception { m_customerID = value; return value; } + /** + * Gets the date of order. + */ + @XmlElement(name = "OrderDate") public String getOrderDate() throws Exception { return m_orderDate; } + /** + * Sets the date of order. + */ public String setOrderDate(String value) throws Exception { m_orderDate = value; return value; } + /** + * Gets the required date of order. + */ + @XmlElement(name = "RequiredDate") public String getRequiredDate() throws Exception { return m_requiredDate; } + /** + * Sets the required date of order. + */ public String setRequiredDate(String value) throws Exception { m_requiredDate = value; return value; } + /** + * Gets the shipped date of order. + */ + @XmlElement(name = "ShippedDate") public String getShippedDate() throws Exception { return m_shippedDate; } + /** + * Sets the shipped date of order. + */ public String setShippedDate(String value) throws Exception { m_shippedDate = value; return value; diff --git a/docio/salesinvoice/SalesInvoice.java b/docio/salesinvoice/SalesInvoice.java index 1cac2e3..c77b9da 100644 --- a/docio/salesinvoice/SalesInvoice.java +++ b/docio/salesinvoice/SalesInvoice.java @@ -2,12 +2,13 @@ import java.io.File; import java.util.*; + +import javax.xml.bind.*; + import com.syncfusion.docio.*; import com.syncfusion.javahelper.system.*; import com.syncfusion.javahelper.system.collections.generic.ListSupport; import com.syncfusion.javahelper.system.drawing.*; -import com.syncfusion.javahelper.system.io.*; -import com.syncfusion.javahelper.system.xml.*; public class SalesInvoice { public static void main(String[] args) throws Exception { @@ -71,44 +72,23 @@ private static void mailMerge_MergeField(Object sender, MergeFieldEventArgs args * */ private static MailMergeDataTable getTestOrder(int TestOrderId) throws Exception { - // Gets the test order as “IEnumerable” collection. - ListSupport orders = new ListSupport(TestOrder.class); - FileStreamSupport fs = new FileStreamSupport(getDataDir("TestOrder.xml"), FileMode.Open, FileAccess.Read); - XmlReaderSupport reader = XmlReaderSupport.create(fs); - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName().equals("TestOrders"))) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - while (!(reader.getLocalName().equals("TestOrders"))) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "TestOrder": - // Gets the test order. - TestOrder testOrder = getTestOrder(reader); - if (testOrder.getOrderID().equals(Int32Support.toString(TestOrderId))) { - orders.add(testOrder); - break; - } - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName().equals("TestOrders")) - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; + // Loads the XML file. + File file = new File(getDataDir("TestOrder.xml")); + // Create a new instance for the JAXBContext. + JAXBContext jaxbContext = JAXBContext.newInstance(TestOrders.class); + // Reads the XML file. + Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + TestOrders testOrders = (TestOrders) jaxbUnmarshaller.unmarshal(file); + // Gets the list of test order details. + List list = testOrders.getTestOrder(); + ListSupport testOrderList = new ListSupport(TestOrder.class); + for (TestOrder testOrder : list) { + if (testOrder.getOrderID().equals(Int32Support.toString(TestOrderId))) { + testOrderList.add(testOrder); } } - // Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection. - MailMergeDataTable dataTable = new MailMergeDataTable("Orders", orders); - reader.close(); - fs.close(); + // Creates an instance of MailMergeDataTable by specifying mail merge group name and IEnumerable collection. + MailMergeDataTable dataTable = new MailMergeDataTable("Orders", testOrderList); return dataTable; } @@ -119,45 +99,23 @@ private static MailMergeDataTable getTestOrder(int TestOrderId) throws Exception * */ private static MailMergeDataTable getTestOrderDetails(int TestOrderId) throws Exception { - // Gets the test order details as “IEnumerable” collection. - ListSupport orders = new ListSupport(TestOrderDetail.class); - FileStreamSupport fs = new FileStreamSupport(getDataDir("TestOrderDetails.xml"), FileMode.Open, - FileAccess.Read); - XmlReaderSupport reader = XmlReaderSupport.create(fs); - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName().equals("TestOrderDetails"))) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - while (!(reader.getLocalName().equals("TestOrderDetails"))) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "TestOrderDetail": - // Gets the test order details. - TestOrderDetail testOrder = getTestOrderDetail(reader); - if ((testOrder.getOrderID().equals(Int32Support.toString(TestOrderId)))) { - orders.add(testOrder); - break; - } - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName().equals("TestOrderDetails")) - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; + // Loads the XML file. + File file = new File(getDataDir("TestOrderDetails.xml")); + // Create a new instance for the JAXBContext. + JAXBContext jaxbContext = JAXBContext.newInstance(TestOrderDetails.class); + // Reads the XML file. + Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + TestOrderDetails testOrders = (TestOrderDetails) jaxbUnmarshaller.unmarshal(file); + // Gets the list of test order details. + List list = testOrders.getTestOrderDetails(); + ListSupport testOrderList = new ListSupport(TestOrderDetail.class); + for (TestOrderDetail testOrder : list) { + if (testOrder.getOrderID().equals(Int32Support.toString(TestOrderId))) { + testOrderList.add(testOrder); } } - // Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection. - MailMergeDataTable dataTable = new MailMergeDataTable("Order", orders); - reader.close(); - fs.close(); + // Creates an instance of MailMergeDataTable by specifying mail merge group name and IEnumerable collection. + MailMergeDataTable dataTable = new MailMergeDataTable("Order", testOrderList); return dataTable; } @@ -168,313 +126,26 @@ private static MailMergeDataTable getTestOrderDetails(int TestOrderId) throws Ex * */ private static MailMergeDataTable getTestOrderTotals(int TestOrderId) throws Exception { - // Gets the test order total details as “IEnumerable” collection. - ListSupport orders = new ListSupport(TestOrderTotal.class); - FileStreamSupport fs = new FileStreamSupport(getDataDir("OrderTotals.xml"), FileMode.Open, - FileAccess.Read); - XmlReaderSupport reader = XmlReaderSupport.create(fs); - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName().equals("TestOrderTotals"))) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - while (!(reader.getLocalName().equals("TestOrderTotals"))) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "TestOrderTotal": - // Gets the test order total. - TestOrderTotal testOrder = getTestOrderTotal(reader); - if ((testOrder.getOrderID().equals(Int32Support.toString(TestOrderId)))) { - orders.add(testOrder); - break; - } - break; - } - reader.read(); - } else - - { - reader.read(); - if ((reader.getLocalName().equals("TestOrderTotals")) - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; + // Loads the XML file. + File file = new File(getDataDir("OrderTotals.xml")); + // Create a new instance for the JAXBContext. + JAXBContext jaxbContext = JAXBContext.newInstance(TestOrderTotals.class); + // Reads the XML file. + Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + TestOrderTotals testOrders = (TestOrderTotals) jaxbUnmarshaller.unmarshal(file); + // Gets the list of test order details. + List list = testOrders.getTestOrderTotals(); + ListSupport testOrderList = new ListSupport(TestOrderTotal.class); + for (TestOrderTotal testOrder : list) { + if (testOrder.getOrderID().equals(Int32Support.toString(TestOrderId))) { + testOrderList.add(testOrder); } } - // Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection. - MailMergeDataTable dataTable = new MailMergeDataTable("OrderTotals", orders); - reader.close(); - fs.close(); + // Creates an instance of MailMergeDataTable by specifying mail merge group name and IEnumerable collection. + MailMergeDataTable dataTable = new MailMergeDataTable("OrderTotals", testOrderList); return dataTable; } - /** - * - * Gets the test order. - * - * @param reader The reader. - */ - private static TestOrder getTestOrder(XmlReaderSupport reader) throws Exception { - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName().equals("TestOrder"))) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - TestOrder testOrder = new TestOrder(); - while (!(reader.getLocalName().equals("TestOrder"))) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "ShipName": - - testOrder.setShipName(reader.readContentAsString()); - break; - case "ShipAddress": - - testOrder.setShipAddress(reader.readContentAsString()); - break; - case "ShipCity": - - testOrder.setShipCity(reader.readContentAsString()); - break; - case "ShipPostalCode": - - testOrder.setShipPostalCode(reader.readContentAsString()); - break; - case "ShipCountry": - - testOrder.setShipCountry(reader.readContentAsString()); - break; - case "PostalCode": - - testOrder.setPostalCode(reader.readContentAsString()); - break; - case "CustomerID": - - testOrder.setCustomerID(reader.readContentAsString()); - break; - case "Customers.CompanyName": - - testOrder.setCustomers_CompanyName(reader.readContentAsString()); - break; - case "HomePage": - - testOrder.setSalesperson(reader.readContentAsString()); - break; - case "Address": - - testOrder.setAddress(reader.readContentAsString()); - break; - case "City": - - testOrder.setCity(reader.readContentAsString()); - break; - case "Country": - - testOrder.setCountry(reader.readContentAsString()); - break; - case "OrderID": - - testOrder.setOrderID(reader.readContentAsString()); - break; - case "OrderDate": - - testOrder.setOrderDate(reader.readContentAsString()); - break; - case "RequiredDate": - - testOrder.setRequiredDate(reader.readContentAsString()); - break; - case "ShippedDate": - - testOrder.setShippedDate(reader.readContentAsString()); - break; - case "Shippers.CompanyName": - - testOrder.setShippers_CompanyName(reader.readContentAsString()); - break; - default: - - reader.skip(); - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName().equals("TestOrders")) - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - return testOrder; - } - - /** - * Gets TestOrder ID - * - */ - @SuppressWarnings("unchecked") - private ArrayList getTestOrderID() throws Exception { - FileStreamSupport fs = new FileStreamSupport(getDataDir("TestOrder.xml"), FileMode.Open, FileAccess.Read); - XmlReaderSupport reader = XmlReaderSupport.create(fs); - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName().equals("TestOrders"))) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - ArrayList orderId = new ArrayList(); - while (!(reader.getLocalName().equals("TestOrders"))) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "OrderID": - - orderId.add(reader.readContentAsString()); - break; - default: - - break; - } - reader.read(); - } else - - { - reader.read(); - if ((reader.getLocalName().equals("TestOrders")) - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - return orderId; - } - - /** - * - * Gets the test order details. - * - * @param reader The reader. - */ - private static TestOrderDetail getTestOrderDetail(XmlReaderSupport reader) throws Exception { - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName().equals("TestOrderDetail"))) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - TestOrderDetail testOrderDetail = new TestOrderDetail(); - while (!(reader.getLocalName().equals("TestOrderDetail"))) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "OrderID": - - testOrderDetail.setOrderID(reader.readContentAsString()); - break; - case "ProductID": - - testOrderDetail.setProductID(reader.readContentAsString()); - break; - case "ProductName": - - testOrderDetail.setProductName(reader.readContentAsString()); - break; - case "UnitPrice": - - testOrderDetail.setUnitPrice(reader.readContentAsString()); - break; - case "Quantity": - - testOrderDetail.setQuantity(reader.readContentAsString()); - break; - case "Discount": - - testOrderDetail.setDiscount(reader.readContentAsString()); - break; - case "ExtendedPrice": - - testOrderDetail.setExtendedPrice(reader.readContentAsString()); - break; - default: - - reader.skip(); - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName().equals("TestOrderDetail")) - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - return testOrderDetail; - } - - /** - * - * Gets the test order total. - * - * @param reader The reader. - */ - private static TestOrderTotal getTestOrderTotal(XmlReaderSupport reader) throws Exception { - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName().equals("TestOrderTotal"))) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - TestOrderTotal testOrderTotal = new TestOrderTotal(); - while (!(reader.getLocalName().equals("TestOrderTotal"))) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "OrderID": - - testOrderTotal.setOrderID(reader.readContentAsString()); - break; - case "Subtotal": - - testOrderTotal.setSubtotal(reader.readContentAsString()); - break; - case "Freight": - - testOrderTotal.setFreight(reader.readContentAsString()); - break; - case "Total": - - testOrderTotal.setTotal(reader.readContentAsString()); - break; - default: - - reader.skip(); - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName().equals("TestOrderTotal")) - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - return testOrderTotal; - } /** * Get the file path * diff --git a/docio/salesinvoice/TestOrder.java b/docio/salesinvoice/TestOrder.java index f8b7157..92cdce4 100644 --- a/docio/salesinvoice/TestOrder.java +++ b/docio/salesinvoice/TestOrder.java @@ -1,7 +1,6 @@ package salesinvoice; -import java.text.SimpleDateFormat; -import java.util.Date; +import javax.xml.bind.annotation.XmlElement; public class TestOrder { private String m_orderID; @@ -22,162 +21,279 @@ public class TestOrder { private String m_shippedDate; private String m_shippersCompanyName; + /** + * Gets the ship name of order. + */ + @XmlElement(name = "ShipName") public String getShipName() throws Exception { return m_shipName; } + /** + * Sets the ship name of order. + */ public String setShipName(String value) throws Exception { m_shipName = value; return value; } + /** + * Gets the shipping address of order. + */ + @XmlElement(name = "ShipAddress") public String getShipAddress() throws Exception { return m_shipAddress; } + /** + * Sets the shipping address of order. + */ public String setShipAddress(String value) throws Exception { m_shipAddress = value; return value; } + /** + * Gets the shipping city of order. + */ + @XmlElement(name = "ShipCity") public String getShipCity() throws Exception { return m_shipCity; } + /** + * Sets the shipping city of order. + */ public String setShipCity(String value) throws Exception { m_shipCity = value; return value; } + /** + * Gets the shipping postal code of order. + */ + @XmlElement(name = "ShipPostalCode") public String getShipPostalCode() throws Exception { return m_shipPostalCode; } + /** + * Sets the shipping postal code of order. + */ public String setShipPostalCode(String value) throws Exception { m_shipPostalCode = value; return value; } + /** + * Gets the postal code of order. + */ + @XmlElement(name = "PostalCode") public String getPostalCode() throws Exception { return m_postalCode; } + /** + * Sets the postal code of order. + */ public String setPostalCode(String value) throws Exception { m_postalCode = value; return value; } + /** + * Gets the shipping country of order. + */ + @XmlElement(name = "ShipCountry") public String getShipCountry() throws Exception { return m_shipCountry; } + /** + * Sets the shipping country of order. + */ public String setShipCountry(String value) throws Exception { m_shipCountry = value; return value; } + /** + * Sets the ID of the customer. + */ + @XmlElement(name = "CustomerID") public String getCustomerID() throws Exception { return m_customerID; } + /** + * Sets the shipping country of order. + */ public String setCustomerID(String value) throws Exception { m_customerID = value; return value; } + /** + * Gets the company name of the customer. + */ + @XmlElement(name = "Customers.CompanyName") public String getCustomers_CompanyName() throws Exception { return m_customersCompanyName; } + /** + * Sets the company name of the customer. + */ public String setCustomers_CompanyName(String value) throws Exception { m_customersCompanyName = value; return value; } + /** + * Gets the address of the customer. + */ + @XmlElement(name = "Address") public String getAddress() throws Exception { return m_address; } + /** + * Sets the address of the customer. + */ public String setAddress(String value) throws Exception { m_address = value; return value; } + /** + * Gets the city of the customer. + */ + @XmlElement(name = "City") public String getCity() throws Exception { return m_city; } + /** + * Sets the city of the customer. + */ public String setCity(String value) throws Exception { m_city = value; return value; } + /** + * Gets the country of the customer. + */ + @XmlElement(name = "Country") public String getCountry() throws Exception { return m_country; } + /** + * Sets the country of the customer. + */ public String setCountry(String value) throws Exception { m_country = value; return value; } + /** + * Gets the sales person details. + */ + @XmlElement(name = "Salesperson") public String getSalesperson() throws Exception { return m_salesPerson; } + /** + * Sets the sales person details. + */ public String setSalesperson(String value) throws Exception { m_salesPerson = value; return value; } + /** + * Gets the Id of the order. + */ + @XmlElement(name = "OrderID") public String getOrderID() throws Exception { return m_orderID; } + /** + * Sets the Id of the order. + */ public String setOrderID(String value) throws Exception { m_orderID = value; return value; } + /** + * Gets the date of the order. + */ + @XmlElement(name = "OrderDate") public String getOrderDate() throws Exception { return m_orderDate; } - public String setOrderDate(String value) throws Exception { - int index = value.indexOf("T"); - m_orderDate = value.substring(0, index); + /** + * Sets the date of the order. + */ + public String setOrderDate(String value) throws Exception { + int index = value.indexOf("T"); + m_orderDate = value.substring(0, index); return value; } + /** + * Gets the required date of the order. + */ + @XmlElement(name = "RequiredDate") public String getRequiredDate() throws Exception { return m_requiredDate; } + /** + * Sets the required date of the order. + */ public String setRequiredDate(String value) throws Exception { - int index = value.indexOf("T"); - m_requiredDate = value.substring(0, index); + int index = value.indexOf("T"); + m_requiredDate = value.substring(0, index); return value; } + /** + * Gets the shipped date of the order. + */ + @XmlElement(name = "ShippedDate") public String getShippedDate() throws Exception { return m_shippedDate; } + /** + * Sets the shipped date of the order. + */ public String setShippedDate(String value) throws Exception { - int index = value.indexOf("T"); - m_shippedDate = value.substring(0, index); + int index = value.indexOf("T"); + m_shippedDate = value.substring(0, index); return value; } + /** + * Gets the company name of the shipper. + */ + @XmlElement(name = "Shippers.CompanyName") public String getShippers_CompanyName() throws Exception { return m_shippersCompanyName; } + /** + * Sets the company name of the shipper. + */ public String setShippers_CompanyName(String value) throws Exception { m_shippersCompanyName = value; return value; } - public TestOrder() throws Exception { - } } diff --git a/docio/salesinvoice/TestOrderDetail.java b/docio/salesinvoice/TestOrderDetail.java index 33e8596..7e9e7f7 100644 --- a/docio/salesinvoice/TestOrderDetail.java +++ b/docio/salesinvoice/TestOrderDetail.java @@ -1,5 +1,7 @@ package salesinvoice; +import javax.xml.bind.annotation.XmlElement; + public class TestOrderDetail { private String m_orderID; private String m_productID; @@ -9,69 +11,116 @@ public class TestOrderDetail { private String m_discount; private String m_extendedPrice; + /** + * Gets the ID of the order. + */ + @XmlElement(name = "OrderID") public String getOrderID() throws Exception { return m_orderID; } + /** + * Sets the ID of the order. + */ public String setOrderID(String value) throws Exception { m_orderID = value; return value; } + /** + * Gets the ID of the product. + */ + @XmlElement(name = "ProductID") public String getProductID() throws Exception { return m_productID; } + /** + * Sets the ID of the product. + */ public String setProductID(String value) throws Exception { m_productID = value; return value; } + /** + * Gets the name of the product. + */ + @XmlElement(name = "ProductName") public String getProductName() throws Exception { return m_productName; } + /** + * Sets the name of the product. + */ public String setProductName(String value) throws Exception { m_productName = value; return value; } + /** + * Gets the unit price of the product. + */ + @XmlElement(name = "UnitPrice") public String getUnitPrice() throws Exception { return m_unitPrice; } + /** + * Sets the unit price of the product. + */ public String setUnitPrice(String value) throws Exception { m_unitPrice = value; return value; } + /** + * Gets the quantity of the product. + */ + @XmlElement(name = "Quantity") public String getQuantity() throws Exception { return m_quantity; } + /** + * Sets the quantity of the product. + */ public String setQuantity(String value) throws Exception { m_quantity = value; return value; } + /** + * Gets the discount for the product. + */ + @XmlElement(name = "Discount") public String getDiscount() throws Exception { return m_discount; } + /** + * Sets the discount for the product. + */ public String setDiscount(String value) throws Exception { m_discount = value; return value; } + /** + * Gets the extended price of the product. + */ + @XmlElement(name = "ExtendedPrice") public String getExtendedPrice() throws Exception { return m_extendedPrice; } + /** + * Sets the extended price of the product. + */ public String setExtendedPrice(String value) throws Exception { m_extendedPrice = value; return value; } - public TestOrderDetail() throws Exception { - } } diff --git a/docio/salesinvoice/TestOrderDetails.java b/docio/salesinvoice/TestOrderDetails.java new file mode 100644 index 0000000..b875dd5 --- /dev/null +++ b/docio/salesinvoice/TestOrderDetails.java @@ -0,0 +1,24 @@ +package salesinvoice; + +import java.util.List; +import javax.xml.bind.annotation.*; + +@XmlRootElement(name = "TestOrderDetails") +public class TestOrderDetails { + private List TestOrderDetail; + + /** + * Gets the list of order details. + */ + @XmlElement(name = "TestOrderDetail") + public List getTestOrderDetails() { + return TestOrderDetail; + } + + /** + * Sets the list of order details. + */ + public void setTestOrderDetails(List testOrderDetail) { + this.TestOrderDetail = testOrderDetail; + } +} diff --git a/docio/salesinvoice/TestOrderTotal.java b/docio/salesinvoice/TestOrderTotal.java index a14110c..dc9fe93 100644 --- a/docio/salesinvoice/TestOrderTotal.java +++ b/docio/salesinvoice/TestOrderTotal.java @@ -1,47 +1,75 @@ package salesinvoice; +import javax.xml.bind.annotation.XmlElement; + public class TestOrderTotal { private String m_orderID; private String m_subTotal; private String m_freight; private String m_total; + /** + * Gets the ID of the order. + */ + @XmlElement(name = "OrderID") public String getOrderID() throws Exception { return m_orderID; } + /** + * Sets the ID of the order. + */ public String setOrderID(String value) throws Exception { m_orderID = value; return value; } + /** + * Gets the sub total of the order. + */ + @XmlElement(name = "Subtotal") public String getSubtotal() throws Exception { return m_subTotal; } + /** + * Sets the sub total of the order. + */ public String setSubtotal(String value) throws Exception { m_subTotal = value; return value; } + /** + * Gets the freight of the order. + */ + @XmlElement(name = "Freight") public String getFreight() throws Exception { return m_freight; } + /** + * Sets the freight of the order. + */ public String setFreight(String value) throws Exception { m_freight = value; return value; } + /** + * Gets the total of the order. + */ + @XmlElement(name = "Total") public String getTotal() throws Exception { return m_total; } + /** + * Sets the total of the order. + */ public String setTotal(String value) throws Exception { m_total = value; return value; } - public TestOrderTotal() throws Exception { - } } diff --git a/docio/salesinvoice/TestOrderTotals.java b/docio/salesinvoice/TestOrderTotals.java new file mode 100644 index 0000000..a5face6 --- /dev/null +++ b/docio/salesinvoice/TestOrderTotals.java @@ -0,0 +1,25 @@ +package salesinvoice; + +import java.util.List; + +import javax.xml.bind.annotation.*; + +@XmlRootElement(name = "TestOrderTotals") +public class TestOrderTotals { + private List TestOrderTotal; + + /** + * Gets the list of total of the order. + */ + @XmlElement(name = "TestOrderTotal") + public List getTestOrderTotals() { + return TestOrderTotal; + } + + /** + * Sets the list of total of the order. + */ + public void setTestOrderTotals(List testOrderTotal) { + this.TestOrderTotal = testOrderTotal; + } +} diff --git a/docio/salesinvoice/TestOrders.java b/docio/salesinvoice/TestOrders.java new file mode 100644 index 0000000..0eff2fa --- /dev/null +++ b/docio/salesinvoice/TestOrders.java @@ -0,0 +1,25 @@ +package salesinvoice; + +import java.util.List; +import javax.xml.bind.annotation.*; + +@XmlRootElement(name = "TestOrders") +public class TestOrders { + private List TestOrder; + + /** + * Gets the list of order. + */ + @XmlElement(name = "TestOrder") + public List getTestOrder() { + return TestOrder; + } + + /** + * Sets the list of order. + */ + public void setTestOrder(List testOrder) { + this.TestOrder = testOrder; + } + +} diff --git a/docio/tablestyles/Suppliers.java b/docio/tablestyles/Suppliers.java index 0758648..77e3547 100644 --- a/docio/tablestyles/Suppliers.java +++ b/docio/tablestyles/Suppliers.java @@ -1,5 +1,7 @@ package tablestyles; +import javax.xml.bind.annotation.XmlElement; + public class Suppliers { private String m_id; private String m_companyName; @@ -14,124 +16,195 @@ public class Suppliers { private String m_fax; private String m_homePage; + /** + * Gets the Id of the supplier. + */ + @XmlElement(name = "SupplierID") public String getSupplierID() throws Exception { return m_id; } + /** + * Sets the Id of the supplier. + */ public String setSupplierID(String value) throws Exception { m_id = value; return value; } + /** + * Gets the company name of the supplier. + */ + @XmlElement(name = "CompanyName") public String getCompanyName() throws Exception { return m_companyName; } + /** + * Sets the company name of the supplier. + */ public String setCompanyName(String value) throws Exception { m_companyName = value; return value; } + /** + * Gets the contact name of the supplier. + */ + @XmlElement(name = "ContactName") public String getContactName() throws Exception { return m_contactName; } + /** + * Sets the contact name of the supplier. + */ public String setContactName(String value) throws Exception { m_contactName = value; return value; } + /** + * Gets the contact title of the supplier. + */ + @XmlElement(name = "ContactTitle") public String getContactTitle() throws Exception { return m_contactTitle; } + /** + * Sets the contact title of the supplier. + */ public String setContactTitle(String value) throws Exception { m_contactTitle = value; return value; } + /** + * Gets the region. + */ + @XmlElement(name = "Region") public String getRegion() throws Exception { return m_region; } + /** + * Sets the region. + */ public String setRegion(String value) throws Exception { m_region = value; return value; } + /** + * Gets the postal code. + */ + @XmlElement(name = "PostalCode") public String getPostalCode() throws Exception { return m_postalCode; } + /** + * Sets the postal code. + */ public String setPostalCode(String value) throws Exception { m_postalCode = value; return value; } + /** + * Gets the contact number. + */ + @XmlElement(name = "Phone") public String getPhone() throws Exception { return m_phone; } + /** + * Sets the contact number. + */ public String setPhone(String value) throws Exception { m_phone = value; return value; } + /** + * Gets the fax details. + */ + @XmlElement(name = "Fax") public String getFax() throws Exception { return m_fax; } + /** + * Sets the fax details. + */ public String setFax(String value) throws Exception { m_fax = value; return value; } + /** + * Gets the home page. + */ + @XmlElement(name = "HomePage") public String getHomePage() throws Exception { return m_homePage; } + /** + * Sets the home page. + */ public String setHomePage(String value) throws Exception { m_homePage = value; return value; } + /** + * Gets the address. + */ + @XmlElement(name = "Address") public String getAddress() throws Exception { return m_address; } + /** + * Sets the address. + */ public String setAddress(String value) throws Exception { m_address = value; return value; } + /** + * Gets the city. + */ + @XmlElement(name = "City") public String getCity() throws Exception { return m_city; } + /** + * Sets the city. + */ public String setCity(String value) throws Exception { m_city = value; return value; } + /** + * Gets the country. + */ + @XmlElement(name = "Country") public String getCountry() throws Exception { return m_country; } + /** + * Sets the country. + */ public String setCountry(String value) throws Exception { m_country = value; return value; } - - public Suppliers(String id, String companyName, String contantName, String address, String city, String country) - throws Exception { - m_id = id; - m_companyName = companyName; - m_contactName = contantName; - m_address = address; - m_city = city; - m_country = country; - } - - public Suppliers() throws Exception { - } } diff --git a/docio/tablestyles/SuppliersList.java b/docio/tablestyles/SuppliersList.java new file mode 100644 index 0000000..09669cd --- /dev/null +++ b/docio/tablestyles/SuppliersList.java @@ -0,0 +1,24 @@ +package tablestyles; + +import java.util.List; +import javax.xml.bind.annotation.*; + +@XmlRootElement(name = "SuppliersList") +public class SuppliersList { + private List Suppliers; + + /** + * Gets the list of supplier details. + */ + @XmlElement(name = "Suppliers") + public List getSuppliers() { + return Suppliers; + } + + /** + * Sets the list of supplier details. + */ + public void setSuppliers(List supplier) { + this.Suppliers = supplier; + } +} diff --git a/docio/tablestyles/TableStyles.java b/docio/tablestyles/TableStyles.java index bf54e53..f3d1a8b 100644 --- a/docio/tablestyles/TableStyles.java +++ b/docio/tablestyles/TableStyles.java @@ -1,12 +1,14 @@ package tablestyles; import java.io.*; +import java.util.List; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; + import com.syncfusion.docio.*; -import com.syncfusion.javahelper.system.*; import com.syncfusion.javahelper.system.collections.generic.ListSupport; import com.syncfusion.javahelper.system.drawing.*; -import com.syncfusion.javahelper.system.io.*; -import com.syncfusion.javahelper.system.xml.*;; public class TableStyles { public static void main(String[] args) throws Exception { @@ -19,7 +21,7 @@ public static void main(String[] args) throws Exception { // Executes Mail Merge with groups. document.getMailMerge().executeGroup(mailMergeDataTable); // Creates table and apply table styles. - WTable table = createAndApplyTableStyles(document); + createAndApplyTableStyles(document); // Saves and closes the document. document.save("Table Styles.docx", FormatType.Docx); System.out.println("Word document generated successfully."); @@ -152,134 +154,25 @@ static WTable createAndApplyTableStyles(WordDocument document) throws Exception * @exception XmlException Unexpected xml tag + reader.LocalName */ private static MailMergeDataTable getMailMergeDataTable() throws Exception { - // Gets list of suppliers details. - ListSupport suppliers = new ListSupport(Suppliers.class); - FileStreamSupport fs = new FileStreamSupport(getDataDir("Suppliers.xml"), FileMode.Open, FileAccess.Read); - // Reads the xml document. - XmlReaderSupport reader = XmlReaderSupport.create(fs); - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "SuppliersList")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - // Iterates to add the suppliers details in list. - while (!(reader.getLocalName() == "SuppliersList")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "Suppliers": - - suppliers.add(getSupplier(reader)); - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName() == "SuppliersList") - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - //Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection. - MailMergeDataTable dataTable = new MailMergeDataTable("Suppliers", suppliers); - reader.close(); - fs.close(); + // Loads the XML file. + File file = new File(getDataDir("Suppliers.xml")); + // Create a new instance for the JAXBContext. + JAXBContext jaxbContext = JAXBContext.newInstance(SuppliersList.class); + // Reads the XML file. + Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + SuppliersList suppliers = (SuppliersList) jaxbUnmarshaller.unmarshal(file); + // Gets the list of suppliers details. + List list = suppliers.getSuppliers(); + ListSupport suppliersList = new ListSupport(Suppliers.class); + suppliersList.addRange(list); + // Creates an instance of MailMergeDataTable by specifying mail merge group name and IEnumerable collection. + MailMergeDataTable dataTable = new MailMergeDataTable("Suppliers", suppliersList); return dataTable; } - /** - * - * Gets the suppliers. - * - * @param reader The reader. - * @return - * @exception System.Exception reader - * @exception XmlException Unexpected xml tag + reader.LocalName - */ - private static Suppliers getSupplier(XmlReaderSupport reader) throws Exception { - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "Suppliers")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - Suppliers supplier = new Suppliers(); - while (!(reader.getLocalName() == "Suppliers")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "SupplierID": - - supplier.setSupplierID(reader.readContentAsString()); - break; - case "CompanyName": - - supplier.setCompanyName(reader.readContentAsString()); - break; - case "ContactName": - - supplier.setContactName(reader.readContentAsString()); - break; - case "ContactTitle": - - supplier.setContactTitle(reader.readContentAsString()); - break; - case "Region": - - supplier.setRegion(reader.readContentAsString()); - break; - case "PostalCode": - - supplier.setPostalCode(reader.readContentAsString()); - break; - case "Phone": - - supplier.setPhone(reader.readContentAsString()); - break; - case "Fax": - - supplier.setFax(reader.readContentAsString()); - break; - case "HomePage": - - supplier.setHomePage(reader.readContentAsString()); - break; - case "Address": - - supplier.setAddress(reader.readContentAsString()); - break; - case "City": - - supplier.setCity(reader.readContentAsString()); - break; - case "Country": - - supplier.setCountry(reader.readContentAsString()); - break; - default: - - reader.skip(); - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName() == "Suppliers") - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - return supplier; - } /** * Apply border properties to table. + * * @param borderStyles * @param styles * @param lineWidth diff --git a/docio/updatefields/StockDetails.java b/docio/updatefields/StockDetails.java index 8c03c54..d185aae 100644 --- a/docio/updatefields/StockDetails.java +++ b/docio/updatefields/StockDetails.java @@ -1,5 +1,7 @@ package updatefields; +import javax.xml.bind.annotation.XmlElement; + public class StockDetails { private String m_tradeNo; private String m_companyName; @@ -7,60 +9,84 @@ public class StockDetails { private String m_sharesCount; private String m_salesPrice; + /** + * Gets the trade number. + */ + @XmlElement(name = "TradeNo") public String getTradeNo() throws Exception { return m_tradeNo; } + /** + * Sets the trade number. + */ public String setTradeNo(String value) throws Exception { m_tradeNo = value; return value; } + /** + * Gets the name of the company. + */ + @XmlElement(name = "CompanyName") public String getCompanyName() throws Exception { return m_companyName; } + /** + * Sets the name of the company. + */ public String setCompanyName(String value) throws Exception { m_companyName = value; return value; } + /** + * Gets the cost price. + */ + @XmlElement(name = "CostPrice") public String getCostPrice() throws Exception { return m_costPrice; } + /** + * Sets the cost price. + */ public String setCostPrice(String value) throws Exception { m_costPrice = value; return value; } + /** + * Gets the total count of the share. + */ + @XmlElement(name = "SharesCount") public String getSharesCount() throws Exception { return m_sharesCount; } + /** + * Sets the total count of the share. + */ public String setSharesCount(String value) throws Exception { m_sharesCount = value; return value; } + /** + * Gets the sales price. + */ + @XmlElement(name = "SalesPrice") public String getSalesPrice() throws Exception { return m_salesPrice; } + /** + * Sets the sales price. + */ public String setSalesPrice(String value) throws Exception { m_salesPrice = value; return value; } - public StockDetails(String tradeNo, String companyName, String costPrice, String sharesCount, String salesPrice) - throws Exception { - m_tradeNo = tradeNo; - m_companyName = companyName; - m_costPrice = costPrice; - m_sharesCount = sharesCount; - m_salesPrice = salesPrice; - } - - public StockDetails() throws Exception { - } } diff --git a/docio/updatefields/StockMarket.java b/docio/updatefields/StockMarket.java new file mode 100644 index 0000000..c4440f2 --- /dev/null +++ b/docio/updatefields/StockMarket.java @@ -0,0 +1,24 @@ +package updatefields; + +import java.util.List; +import javax.xml.bind.annotation.*; + +@XmlRootElement(name = "StockMarket") +public class StockMarket { + private List StockDetails; + + /** + * Gets the list of stock details. + */ + @XmlElement(name = "StockDetails") + public List getStockDetails() { + return StockDetails; + } + + /** + * Sets the list of stock details. + */ + public void setStockDetails(List listStockDetails) { + this.StockDetails = listStockDetails; + } +} diff --git a/docio/updatefields/UpdateFields.java b/docio/updatefields/UpdateFields.java index 85e808a..bb5698d 100644 --- a/docio/updatefields/UpdateFields.java +++ b/docio/updatefields/UpdateFields.java @@ -2,12 +2,10 @@ import java.io.File; - +import java.util.List; +import javax.xml.bind.*; import com.syncfusion.docio.*; -import com.syncfusion.javahelper.system.*; import com.syncfusion.javahelper.system.collections.generic.ListSupport; -import com.syncfusion.javahelper.system.io.*; -import com.syncfusion.javahelper.system.xml.*; public class UpdateFields { public static void main(String[] args) throws Exception { @@ -128,107 +126,27 @@ private static void removeFieldCodesInTable(WTable table) throws Exception { * */ private static MailMergeDataTable getMailMergeDataTableStock() throws Exception { - // Gets list of stock details. + // Loads the XML file. + File file = new File(getDataDir("StockDetails.xml")); + // Create a new instance for the JAXBContext. + JAXBContext jaxbContext = JAXBContext.newInstance(StockMarket.class); + // Reads the XML file. + Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + StockMarket stockMarket = (StockMarket) jaxbUnmarshaller.unmarshal(file); + // Gets the list of stock details. + List list = stockMarket.getStockDetails(); ListSupport stockDetails = new ListSupport(StockDetails.class); - FileStreamSupport fs = new FileStreamSupport(getDataDir("StockDetails.xml"), - FileMode.Open, FileAccess.Read); - // Reads the xml document. - XmlReaderSupport reader = XmlReaderSupport.create(fs); - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "StockMarket")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - // Iterates to add the stock details in list. - while (!(reader.getLocalName() == "StockMarket")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "StockDetails": - - stockDetails.add(getStockDetails(reader)); - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName() == "StockMarket") - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - //Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection. + stockDetails.addRange(list); + // Creates an instance of MailMergeDataTable by specifying mail merge group name and IEnumerable collection. MailMergeDataTable dataTable = new MailMergeDataTable("StockDetails", stockDetails); - reader.close(); - fs.close(); return dataTable; } /** - * - * Gets the StockDetails. - * - * @param reader The reader. + * Get the file path + * + * @param path specifies the file path */ - private static StockDetails getStockDetails(XmlReaderSupport reader) throws Exception { - if (reader == null) - throw new Exception("reader"); - while (reader.getNodeType().getEnumValue() != XmlNodeType.Element.getEnumValue()) - reader.read(); - if (!(reader.getLocalName() == "StockDetails")) - throw new Exception("Unexpected xml tag " + reader.getLocalName()); - reader.read(); - while (reader.getNodeType().getEnumValue() == XmlNodeType.Whitespace.getEnumValue()) - reader.read(); - StockDetails stockDetails = new StockDetails(); - while (!(reader.getLocalName() == "StockDetails")) { - if (reader.getNodeType().getEnumValue() == XmlNodeType.Element.getEnumValue()) { - switch ((reader.getLocalName()) == null ? "string_null_value" : (reader.getLocalName())) { - case "TradeNo": - - stockDetails.setTradeNo(reader.readContentAsString()); - break; - case "CompanyName": - - stockDetails.setCompanyName(reader.readContentAsString()); - break; - case "CostPrice": - - stockDetails.setCostPrice(reader.readContentAsString()); - break; - case "SharesCount": - - stockDetails.setSharesCount(reader.readContentAsString()); - break; - case "SalesPrice": - - stockDetails.setSalesPrice(reader.readContentAsString()); - break; - default: - - reader.skip(); - break; - } - } else - - { - reader.read(); - if ((reader.getLocalName() == "StockDetails") - && reader.getNodeType().getEnumValue() == XmlNodeType.EndElement.getEnumValue()) - break; - } - } - return stockDetails; - } - /** - * Get the file path - * - * @param path specifies the file path - */ public static String getDataDir(String path) { File dir = new File(System.getProperty("user.dir")); if(!(dir.toString().endsWith("samples")))