Example usage for org.dom4j Document addElement

List of usage examples for org.dom4j Document addElement

Introduction

In this page you can find the example usage for org.dom4j Document addElement.

Prototype

Element addElement(String name);

Source Link

Document

Adds a new Element node with the given name to this branch and returns a reference to the new node.

Usage

From source file:com.sf.integration.warehouse.service.SFService.java

@SuppressWarnings("unchecked")
/**/*from w  ww  . j  a v  a  2s  .  co m*/
 * ?
 * @author sven
 * @param dctx
 * @param context
 * @return
 */
public static Map<String, Object> querySFOutboundListStatuc(DispatchContext dctx, Map<String, Object> context) {
    Map<String, Object> result = ServiceUtil.returnSuccess();
    Delegator delegator = dctx.getDelegator();
    Document doc = (Document) DocumentHelper.createDocument();
    //Request
    Element request = doc.addElement("Request");
    request.addAttribute("service", "SALE_ORDER_STATUS_QUERY_SERVICE");
    request.addAttribute("lang", "zh-CN");
    //Head
    Element head = request.addElement("Head");
    Element AccessCode = head.addElement("AccessCode");
    AccessCode.setText(ACCESS_CODE);//?
    Element Checkword = head.addElement("Checkword");
    Checkword.setText(CHECK_WORD);//??
    //Body
    Element Body = request.addElement("Body");
    Element SaleOrderRequest = Body.addElement("SaleOrderStatusRequest");
    Element CompanyCode = SaleOrderRequest.addElement("CompanyCode");
    CompanyCode.setText(COMPANY_CODE);//?
    Element SaleOrders = SaleOrderRequest.addElement("SaleOrders");
    Element SaleOrder = SaleOrders.addElement("SaleOrder");
    Element WarehouseCode = SaleOrder.addElement("WarehouseCode");
    WarehouseCode.setText(WAREHOUSE_CODE);//??
    Element ErpOrder = SaleOrder.addElement("ErpOrder");
    Element ShipmentId = SaleOrder.addElement("ShipmentId");
    ErpOrder.setText(context.get("erpOrder").toString());//???
    ShipmentId.setText(context.get("shipmentId").toString());//???
    String XMLStr = doc.getRootElement().asXML();
    try {
        String resultXML = sendSFRequest(XMLStr);
        SFAuditLogFilter.saveRequestContext(delegator, "SALE_ORDER_STATUS_QUERY_SERVICE", XMLStr, resultXML);
        Document resultDocument = (Document) DocumentHelper.parseText(resultXML);
        Element ResponseElement = resultDocument.getRootElement();
        Element HeadElement = ResponseElement.element("Head");
        if (HeadElement.getText().equals("ERR")) {
            return ServiceUtil.returnError(resultXML);
        } else {
            Element BodyElement = ResponseElement.element("Body");
            Element SaleOrderStatusResponseElement = BodyElement.element("SaleOrderStatusResponse");
            Element SaleOrderStatusElement = SaleOrderStatusResponseElement.element("SaleOrders");
            Element SaleOrderStatuElement = SaleOrderStatusElement.element("SaleOrder");
            Element ResultElement = SaleOrderStatuElement.element("Result");

            Element HeaderElement = SaleOrderStatuElement.element("Header");
            Element StepsElement = SaleOrderStatuElement.element("Steps");
            Element NoteElement = SaleOrderStatuElement.element("Note");

            result.put("resultCode", ResultElement.getText());
            if (ResultElement.getText().equals("1")) {
                Element StepElement = StepsElement.element("Step");
                Element StatusElement = StepElement.element("Status");
                Element WayBillNoElement = HeaderElement.element("WayBillNo");
                result.put("status", StatusElement.getText());
                if (UtilValidate.isNotEmpty(WayBillNoElement)) {
                    result.put("trackingNumberId", WayBillNoElement.getText());
                }

            } else {
                result.put("note", NoteElement.getText());
            }
            return result;
        }
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ??/*  w  ww.  j  av  a 2 s .  c o  m*/
 * ??????
 * @param dctx
 * @param context
 * @return
 */
@SuppressWarnings("unchecked")
public static Map<String, Object> cancelSFOutboundList(DispatchContext dctx, Map<String, Object> context) {
    Map<String, Object> result = ServiceUtil.returnSuccess();
    Delegator delegator = dctx.getDelegator();
    String message = verificationCancelSFOutboundList(context);
    if (!message.equals("success")) {
        return ServiceUtil.returnError(message);
    }
    Document doc = (Document) DocumentHelper.createDocument();
    //Request
    Element request = doc.addElement("Request");
    request.addAttribute("service", "CANCEL_SALE_ORDER_SERVICE");
    request.addAttribute("lang", "zh-CN");
    //Head
    Element head = request.addElement("Head");
    Element AccessCode = head.addElement("AccessCode");
    AccessCode.setText(ACCESS_CODE);//?
    Element Checkword = head.addElement("Checkword");
    Checkword.setText(CHECK_WORD);//??
    //Body
    Element Body = request.addElement("Body");
    Element SaleOrderRequest = Body.addElement("CancelSaleOrderRequest");
    Element CompanyCode = SaleOrderRequest.addElement("CompanyCode");
    CompanyCode.setText(COMPANY_CODE);//?
    Element SaleOrders = SaleOrderRequest.addElement("SaleOrders");

    Element SaleOrder = SaleOrders.addElement("SaleOrder");
    Element ErpOrder = SaleOrder.addElement("ErpOrder");
    ErpOrder.setText(context.get("erpOrder").toString());//???

    String XMLStr = doc.getRootElement().asXML();
    try {
        String resultXML = sendSFRequest(XMLStr);
        SFAuditLogFilter.saveRequestContext(delegator, "CANCEL_SALE_ORDER_SERVICE", XMLStr, resultXML);
        Document resultDocument = (Document) DocumentHelper.parseText(resultXML);
        Element ResponseElement = resultDocument.getRootElement();
        Element HeadElement = ResponseElement.element("Head");
        if (HeadElement.getText().equals("ERR")) {
            return ServiceUtil.returnError(resultXML);
        } else {
            Element BodyElement = ResponseElement.element("Body");
            Element PurchaseOrderResponseElement = BodyElement.element("CancelSaleOrderResponse");
            Element PurchaseOrdersElement = PurchaseOrderResponseElement.element("SaleOrders");
            Element PurchaseOrderElement = PurchaseOrdersElement.element("SaleOrder");
            Element ResultElement = PurchaseOrderElement.element("Result");
            result.put("resultCode", ResultElement.getText());
            result.put("note", PurchaseOrderElement.element("Note").getText());
            return result;
        }
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    }
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ????XML??//from  w w w.  j  a  v  a 2s  .c  o m
 * @param dctx
 * @param context
 * @return
 */
@SuppressWarnings("unchecked")
public static Map<String, Object> SFOutboundList(DispatchContext dctx, Map<String, Object> context) {
    String message = verificationOutboundListParameters(context);
    String localOrderTypeId = (String) context.get("localOrderTypeId");//??
    Map<String, Object> result = ServiceUtil.returnSuccess();
    Delegator delegator = dctx.getDelegator();
    if (!message.equals("success")) {
        return ServiceUtil.returnError(message);
    }
    Document doc = (Document) DocumentHelper.createDocument();
    //Request
    Element request = doc.addElement("Request");
    request.addAttribute("service", "SALE_ORDER_SERVICE");
    request.addAttribute("lang", "zh-CN");
    //Head
    Element head = request.addElement("Head");
    Element AccessCode = head.addElement("AccessCode");

    AccessCode.setText(ACCESS_CODE);//?
    Element Checkword = head.addElement("Checkword");
    Checkword.setText(CHECK_WORD);//??
    //Body
    Element Body = request.addElement("Body");
    Element SaleOrderRequest = Body.addElement("SaleOrderRequest");
    Element CompanyCode = SaleOrderRequest.addElement("CompanyCode");
    CompanyCode.setText(COMPANY_CODE);//?
    Element SaleOrders = SaleOrderRequest.addElement("SaleOrders");
    for (Map<String, Object> POrder : (List<Map<String, Object>>) context.get("saleOrders")) {
        Element SaleOrder = SaleOrders.addElement("SaleOrder");

        Element WarehouseCode = SaleOrder.addElement("WarehouseCode");
        WarehouseCode.setText(WAREHOUSE_CODE);//?

        Element ErpOrder = SaleOrder.addElement("ErpOrder");
        String ErpOrderStr = "";
        if (UtilValidate.isNotEmpty(POrder.get("erpOrder"))) {
            ErpOrderStr = POrder.get("erpOrder").toString();
        }
        ErpOrder.setText(ErpOrderStr);//???

        Element ErpOrderType = SaleOrder.addElement("ErpOrderType");
        String ErpOrderTypeStr = "";
        if (UtilValidate.isNotEmpty(POrder.get("ErpOrderType"))) {
            ErpOrderTypeStr = POrder.get("erpOrderType").toString();
        }
        ErpOrderType.setText(ErpOrderTypeStr);//?

        Element SFOrderType = SaleOrder.addElement("SFOrderType");
        String SFOrderTypeStr = "";
        if (UtilValidate.isNotEmpty(POrder.get("SFOrderType"))) {
            SFOrderTypeStr = OUT_WAREHOUSE_TYPE.get(POrder.get("SFOrderType").toString());
        }
        SFOrderType.setText(SFOrderTypeStr);//?

        Element OrderTotalAmount = SaleOrder.addElement("OrderTotalAmount");
        String OrderTotalAmountStr = "";
        if (UtilValidate.isNotEmpty(POrder.get("orderTotalAmount"))) {
            OrderTotalAmountStr = POrder.get("orderTotalAmount").toString();
        }
        OrderTotalAmount.setText(OrderTotalAmountStr);

        /*
        Map<String, Object> orderCarrier = new HashMap<String, Object>();
         orderCarrier.put("carrier", "CP");//?
         orderCarrier.put("carrierProduct", "1");
         orderCarrier.put("paymentOfCharge", "");
         orderCarrier.put("monthlyAccount", MONTHLY_ACCOUNT);
         **/

        Element orderCarrier = SaleOrder.addElement("OrderCarrier");
        orderCarrier.addElement("Carrier").addText("?");
        orderCarrier.addElement("CarrierProduct").addText("");
        orderCarrier.addElement("PaymentOfCharge").addText("");

        Map<String, Object> orderReceiverInfo = (Map<String, Object>) POrder.get("orderReceiverInfo");
        Element OrderReceiverInfo = SaleOrder.addElement("OrderReceiverInfo");

        Element ReceiverCompany = OrderReceiverInfo.addElement("ReceiverCompany");
        String ReceiverCompanyStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverCompany"))) {
            ReceiverCompanyStr = orderReceiverInfo.get("receiverCompany").toString();
        }
        ReceiverCompany.setText(ReceiverCompanyStr);
        Element ReceiverName = OrderReceiverInfo.addElement("ReceiverName");
        String ReceiverNameStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverName"))) {
            ReceiverNameStr = orderReceiverInfo.get("receiverName").toString();
        }
        ReceiverName.setText(ReceiverNameStr);
        Element ReceiverZipCode = OrderReceiverInfo.addElement("ReceiverZipCode");
        String ReceiverZipCodeStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverZipCode"))) {
            ReceiverZipCodeStr = orderReceiverInfo.get("receiverZipCode").toString();
        }
        ReceiverZipCode.setText(ReceiverZipCodeStr);
        Element ReceiverMobile = OrderReceiverInfo.addElement("ReceiverMobile");
        String ReceiverMobileStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverMobile"))) {
            ReceiverMobileStr = orderReceiverInfo.get("receiverMobile").toString();
        }
        ReceiverMobile.setText(ReceiverMobileStr);
        Element ReceiverPhone = OrderReceiverInfo.addElement("ReceiverPhone");
        String ReceiverPhoneStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverPhone"))) {
            ReceiverPhoneStr = orderReceiverInfo.get("receiverPhone").toString();
        }
        ReceiverPhone.setText(ReceiverPhoneStr);
        Element ReceiverCountry = OrderReceiverInfo.addElement("ReceiverCountry");
        String ReceiverCountryStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverCountry"))) {
            ReceiverCountryStr = orderReceiverInfo.get("receiverCountry").toString();
        }
        ReceiverCountry.setText(ReceiverCountryStr);

        Element ReceiverProvince = OrderReceiverInfo.addElement("ReceiverProvince");
        String ReceiverProvinceStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverProvince"))) {
            //??????hardcode
            ReceiverProvinceStr = getProvinceNameHardcode(orderReceiverInfo.get("receiverProvince").toString());
        }
        ReceiverProvince.setText(ReceiverProvinceStr);

        Element ReceiverCity = OrderReceiverInfo.addElement("ReceiverCity");
        String ReceiverCityStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverCity"))) {
            ReceiverCityStr = orderReceiverInfo.get("receiverCity").toString();
        }
        ReceiverCity.setText(ReceiverCityStr);

        Element ReceiverArea = OrderReceiverInfo.addElement("ReceiverArea");
        String ReceiverAreaStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverArea"))) {
            ReceiverAreaStr = orderReceiverInfo.get("receiverArea").toString();
        }
        ReceiverArea.setText(ReceiverAreaStr);

        Element ReceiverAddress = OrderReceiverInfo.addElement("ReceiverAddress");
        String ReceiverAddressStr = "";
        if (UtilValidate.isNotEmpty(orderReceiverInfo.get("receiverAddress"))) {
            ReceiverAddressStr = orderReceiverInfo.get("receiverAddress").toString();
        }
        ReceiverAddress.setText(ReceiverAddressStr);
        Element Items = SaleOrder.addElement("OrderItems");
        List<Map<String, Object>> orderItems = (List<Map<String, Object>>) POrder.get("orderItems");
        for (Map<String, Object> orderItem : orderItems) {
            Element Item = Items.addElement("OrderItem");
            Element ErpOrderLineNum = Item.addElement("ErpOrderLineNum");
            String ErpOrderLineNumStr = "";
            if (UtilValidate.isNotEmpty(orderItem.get("erpOrderLineNum"))) {
                ErpOrderLineNumStr = orderItem.get("erpOrderLineNum").toString();
            }
            ErpOrderLineNum.setText(ErpOrderLineNumStr);
            Element SkuNo = Item.addElement("SkuNo");//??
            String SkuNoStr = "";
            if (UtilValidate.isNotEmpty(orderItem.get("skuNo"))) {
                SkuNoStr = orderItem.get("skuNo").toString();
            }
            SkuNo.setText(SkuNoStr);
            Element ItemQuantity = Item.addElement("ItemQuantity");//??
            String ItemQuantityStr = "";
            if (UtilValidate.isNotEmpty(orderItem.get("itemQuantity"))) {
                ItemQuantityStr = orderItem.get("itemQuantity").toString();
            }
            ItemQuantity.setText(ItemQuantityStr);
        }
    }
    String XMLStr = doc.getRootElement().asXML();
    List<Map<String, Object>> resultList = FastList.newInstance();
    try {
        String resultStr = sendSFRequest(XMLStr);
        SFAuditLogFilter.saveRequestContext(delegator, "SALE_ORDER_SERVICE", XMLStr, resultStr);
        Document resultDocument = (Document) DocumentHelper.parseText(resultStr);
        Element ResponseElement = resultDocument.getRootElement();
        Element HeadElement = ResponseElement.element("Head");
        if (HeadElement.getText().equals("ERR")) {
            return ServiceUtil.returnError(resultStr);
        } else {
            Element BodyElement = ResponseElement.element("Body");
            Element PurchaseOrderResponseElement = BodyElement.element("SaleOrderResponse");
            Element PurchaseOrdersElement = PurchaseOrderResponseElement.element("SaleOrders");
            List<Element> PurchaseOrderElement = PurchaseOrdersElement.elements("SaleOrder");
            for (Element itemElement : PurchaseOrderElement) {
                Map<String, Object> resultMap = FastMap.newInstance();
                Element ResultElement = itemElement.element("Result");
                Element ShipmentIdElement = itemElement.element("ShipmentId");
                Element NoteElement = itemElement.element("Note");

                resultMap.put("erpOrder", itemElement.element("ErpOrder").getText());
                resultMap.put("resultCode", ResultElement.getText());
                if (UtilValidate.isNotEmpty(ShipmentIdElement)) {
                    resultMap.put("shipmentId", ShipmentIdElement.getText());
                }

                if (UtilValidate.isNotEmpty(NoteElement)) {
                    resultMap.put("note", NoteElement.getText());
                }
                resultList.add(resultMap);

            }
            result.put("shunfengResult", resultList);
            return result;
        }
    } catch (RemoteException e) {
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    } catch (DocumentException e) {
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    }
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ?/*from   w w  w  . j  a  v  a2s .c  om*/
 * @param request
 * @param response
 * @return
 */
public static Map<String, Object> QuerySFProductInventory(DispatchContext dctx, Map<String, Object> context) {
    Delegator delegator = dctx.getDelegator();
    Map<String, Object> result = ServiceUtil.returnSuccess();
    List<Map<String, String>> resultList = new ArrayList<Map<String, String>>();
    Map<String, Object> resultMap = new HashMap<String, Object>();

    Document doc = (Document) DocumentHelper.createDocument();
    //Request
    Element request = doc.addElement("Request");
    request.addAttribute("service", "RT_INVENTORY_QUERY_SERVICE");
    request.addAttribute("lang", "zh-CN");
    //Head
    Element head = request.addElement("Head");
    Element AccessCode = head.addElement("AccessCode");
    AccessCode.setText(ACCESS_CODE);//?
    Element Checkword = head.addElement("Checkword");
    Checkword.setText(CHECK_WORD);//??
    //Body
    Element Body = request.addElement("Body");
    Element RTInventoryQueryRequest = Body.addElement("RTInventoryQueryRequest");
    Element CompanyCode = RTInventoryQueryRequest.addElement("CompanyCode");
    CompanyCode.setText(COMPANY_CODE);//?

    Element WarehouseCode = RTInventoryQueryRequest.addElement("WarehouseCode");
    WarehouseCode.setText(WAREHOUSE_CODE);//?
    if (UtilValidate.isNotEmpty(context.get("inventoryStatus"))) {
        Element InventoryStatus = RTInventoryQueryRequest.addElement("InventoryStatus");
        InventoryStatus.setText((String) context.get("inventoryStatus"));
    }
    Element RTInventorys = RTInventoryQueryRequest.addElement("RTInventorys");
    Element RTInventory = RTInventorys.addElement("RTInventory");
    if (UtilValidate.isNotEmpty(context.get("productId"))) {
        Element SkuNo = RTInventory.addElement("SkuNo");
        SkuNo.setText((String) context.get("productId"));
    }

    //      Element PageIndex = RTInventoryQueryRequest.addElement("PageIndex");
    //      if (UtilValidate.isNotEmpty(context.get("inventoryStatus"))) {
    //         PageIndex.setText((String) context.get("pageIndex"));
    //      } else {
    //         PageIndex.setText("1");
    //      }
    String XMLStr = doc.getRootElement().asXML();
    String resultStr;

    try {
        resultStr = sendSFRequest(XMLStr);
        Document resultDocument = (Document) DocumentHelper.parseText(resultStr);
        Element ResponseElement = resultDocument.getRootElement();
        Element HeadElement = ResponseElement.element("Head");
        if (HeadElement.getText().equals("ERR")) {
            return ServiceUtil.returnError(resultStr);
        } else {
            //            Element BodyElement = ResponseElement.element("Body");
            //            Element WmsInventoryBalancePageQueryResponse = BodyElement.element("WmsInventoryBalancePageQueryResponse");
            //            Element Result = WmsInventoryBalancePageQueryResponse.element("Result");
            //            Element TotalSize = WmsInventoryBalancePageQueryResponse.element("TotalSize");
            //            Element TotalPage = WmsInventoryBalancePageQueryResponse.element("TotalPage");
            //            Element PageIndexElement = WmsInventoryBalancePageQueryResponse.element("PageIndex");
            //            resultMap.put("totalSize", TotalSize.getText());
            //            resultMap.put("totalPage", TotalPage.getText());
            //            resultMap.put("pageIndex", PageIndexElement.getText());
            //            if (Result.getText().equals("1")) {
            //               Element List = WmsInventoryBalancePageQueryResponse.element("List");
            //               if (UtilValidate.isNotEmpty(List)) {
            //                  @SuppressWarnings("unchecked")
            //                  List<Element> items = List.elements("Item");
            //                  for (Element item : items) {
            //                     Element SkuNo = item.element("SkuNo");
            //                     Element OnHandQty = item.element("OnHandQty");
            //                     Element InventoryStatus = item.element("InventoryStatus");
            //                     Map<String, String> itemMap = new HashMap<String, String>();
            //                     itemMap.put("productId", SkuNo.getText());
            //                     itemMap.put("quantityOnHandTotal", OnHandQty.getText());
            //                     itemMap.put("inventoryStatus", InventoryStatus.getText());
            //                     resultList.add((itemMap));
            //                  }         
            //               }   
            //            }   
            resultMap.put("resultList", resultList);
            result.put("resultMap", resultMap);
        }

        return result;

    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    }
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ????XML??//  w w w  .  j a  v  a2 s. co  m
 * @param dctx
 * @param context
 * @return
 */
@SuppressWarnings("unchecked")
public static Map<String, Object> SFGodownEntry(DispatchContext dctx, Map<String, Object> context) {
    try {
        String message = verificationGodownEntryParameters(context);
        Map<String, Object> result = ServiceUtil.returnSuccess();
        Delegator delegator = dctx.getDelegator();
        if (!message.equals("success")) {
            return ServiceUtil.returnError(message);
        }
        Document doc = (Document) DocumentHelper.createDocument();
        //Request
        Element request = doc.addElement("Request");
        request.addAttribute("service", "PURCHASE_ORDER_SERVICE");
        request.addAttribute("lang", "zh-CN");
        //Head
        Element head = request.addElement("Head");
        Element AccessCode = head.addElement("AccessCode");
        AccessCode.setText(ACCESS_CODE);//?
        Element Checkword = head.addElement("Checkword");
        Checkword.setText(CHECK_WORD);//??
        //Body
        Element Body = request.addElement("Body");

        Element PurchaseOrderRequest = Body.addElement("PurchaseOrderRequest");
        Element CompanyCode = PurchaseOrderRequest.addElement("CompanyCode");
        CompanyCode.setText(COMPANY_CODE);//?
        Element PurchaseOrders = PurchaseOrderRequest.addElement("PurchaseOrders");

        for (Map<String, Object> POrder : (List<Map<String, Object>>) context.get("purchaseOrders")) {
            List<Map<String, Object>> productItems = (List<Map<String, Object>>) POrder.get("items");

            Element PurchaseOrder = PurchaseOrders.addElement("PurchaseOrder");
            Element WarehouseCode = PurchaseOrder.addElement("WarehouseCode");
            WarehouseCode.setText(WAREHOUSE_CODE);//?

            Element ErpOrder = PurchaseOrder.addElement("ErpOrder");
            String ErpOrderStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("erpOrder"))) {
                ErpOrderStr = POrder.get("erpOrder").toString();
            }
            ErpOrder.setText(ErpOrderStr);//???

            Element ErpOrderType = PurchaseOrder.addElement("ErpOrderType");
            String ErpOrderTypeStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("erpOrderType"))) {
                ErpOrderTypeStr = POrder.get("erpOrderType").toString();
            }
            ErpOrderType.setText(ErpOrderTypeStr);//?

            Element SFOrderType = PurchaseOrder.addElement("SFOrderType");
            String SFOrderTypeStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("SFOrderType"))) {
                SFOrderTypeStr = IN_WAREHOUSE_TYPE.get(POrder.get("SFOrderType")).toString();
            }
            SFOrderType.setText(SFOrderTypeStr);//?

            Element OrderDate = PurchaseOrder.addElement("OrderDate");
            String OrderDateStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("orderDate"))) {
                OrderDateStr = POrder.get("orderDate").toString();
            }
            OrderDate.setText(OrderDateStr);//?

            Element Buyer = PurchaseOrder.addElement("Buyer");
            String buyStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("buyer"))) {
                buyStr = POrder.get("buyer").toString();
            }
            Buyer.setText(buyStr);//

            Element BuyerPhone = PurchaseOrder.addElement("BuyerPhone");
            String BuyerPhoneStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("buyerPhone"))) {
                BuyerPhoneStr = POrder.get("buyerPhone").toString();
            }
            BuyerPhone.setText(BuyerPhoneStr);//??

            Element ScheduledReceiptDate = PurchaseOrder.addElement("ScheduledReceiptDate");
            String ScheduledReceiptDateStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("scheduledReceiptDate"))) {
                ScheduledReceiptDateStr = POrder.get("scheduledReceiptDate").toString();
            }
            ScheduledReceiptDate.setText(ScheduledReceiptDateStr);//

            Element VendorCode = PurchaseOrder.addElement("VendorCode");
            String VendorCodeStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("vendorCode"))) {
                VendorCodeStr = POrder.get("vendorCode").toString();
            }
            VendorCode.setText(VendorCodeStr);//?   

            Element TransferWarehouseCode = PurchaseOrder.addElement("TransferWarehouseCode");
            String TransferWarehouseCodeStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("transferWarehouseCode"))) {
                TransferWarehouseCodeStr = POrder.get("transferWarehouseCode").toString();
            }
            TransferWarehouseCode.setText(TransferWarehouseCodeStr);//?

            Element OriginalOrderNo = PurchaseOrder.addElement("OriginalOrderNo");
            String OriginalOrderNoStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("originalOrderNo"))) {
                OriginalOrderNoStr = POrder.get("originalOrderNo").toString();
            }
            OriginalOrderNo.setText(OriginalOrderNoStr);//??

            Element Note = PurchaseOrder.addElement("Note");
            String NoteStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("note"))) {
                NoteStr = POrder.get("note").toString();
            }
            Note.setText(NoteStr);//?

            Element ReceiptMode = PurchaseOrder.addElement("ReceiptMode");
            String ReceiptModeStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("receiptMode"))) {
                ReceiptModeStr = POrder.get("receiptMode").toString();
            }
            ReceiptMode.setText(ReceiptModeStr);//??

            Element LicensePlateNumber = PurchaseOrder.addElement("LicensePlateNumber");
            String LicensePlateNumberStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("licensePlateNumber"))) {
                LicensePlateNumberStr = POrder.get("licensePlateNumber").toString();
            }
            LicensePlateNumber.setText(LicensePlateNumberStr);//?

            Element Driver = PurchaseOrder.addElement("Driver");
            String DriverStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("driver"))) {
                DriverStr = POrder.get("driver").toString();
            }
            Driver.setText(DriverStr);//?

            Element TradePlatform = PurchaseOrder.addElement("TradePlatform");
            String TradePlatformStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("tradePlatform"))) {
                TradePlatformStr = POrder.get("tradePlatform").toString();
            }
            TradePlatform.setText(TradePlatformStr);//?

            Element TradeOrder = PurchaseOrder.addElement("TradeOrder");
            String TradeOrderStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("tradeOrder"))) {
                TradeOrderStr = POrder.get("tradeOrder").toString();
            }
            TradeOrder.setText(TradeOrderStr);//??

            Element DriverCalls = PurchaseOrder.addElement("DriverCalls");
            String DriverCallsStr = "";
            if (UtilValidate.isNotEmpty(POrder.get("driverCalls"))) {
                DriverCallsStr = POrder.get("driverCalls").toString();
            }
            DriverCalls.setText(DriverCallsStr);//??
            for (int i = 1; i < 9; i++) {
                Element lot = PurchaseOrder.addElement("UserDef" + i);
                lot.setText("");
            }
            Element items = PurchaseOrder.addElement("Items");
            for (Map<String, Object> productItem : productItems) {
                Element item = items.addElement("Item");
                Element ErpOrderLineNum = item.addElement("ErpOrderLineNum");
                String ErpOrderLineNumStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("erpOrderLineNum"))) {
                    ErpOrderLineNumStr = productItem.get("erpOrderLineNum").toString();
                }
                ErpOrderLineNum.setText(ErpOrderLineNumStr);
                Element SkuNo = item.addElement("SkuNo");//??
                String SkuNoStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("skuNo"))) {
                    SkuNoStr = productItem.get("skuNo").toString();
                }
                SkuNo.setText(SkuNoStr);

                Element Qty = item.addElement("Qty");//?
                String QtyStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("qty"))) {
                    QtyStr = productItem.get("qty").toString();
                }
                Qty.setText(QtyStr);

                Element QtyUm = item.addElement("QtyUm");//???
                String QtyUmStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("qtyUm"))) {
                    QtyUmStr = productItem.get("qtyUm").toString();
                }
                QtyUm.setText(QtyUmStr);

                Element Lot = item.addElement("Lot");//?
                String lotStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("lot"))) {
                    lotStr = productItem.get("lot").toString();
                }
                Lot.setText(lotStr);

                Element itemNote = item.addElement("Note");//
                String itemNoteStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("note"))) {
                    itemNoteStr = productItem.get("note").toString();
                }
                itemNote.setText(itemNoteStr);

                Element Price = item.addElement("Price");//?
                String PriceStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("price"))) {
                    //PriceStr = productItem.get("price").toString();
                    PriceStr = "0.00";
                }
                Price.setText(PriceStr);

                Element InventoryStatus = item.addElement("InventoryStatus");
                String InventoryStatusStr = "";
                if (UtilValidate.isNotEmpty(productItem.get("inventoryStatus"))) {
                    InventoryStatusStr = productItem.get("inventoryStatus").toString();
                }
                InventoryStatus.setText(InventoryStatusStr);
                for (int i = 1; i < 7; i++) {
                    Element lot = item.addElement("LotAttr" + i);
                    lot.setText("");
                }
                for (int i = 1; i < 9; i++) {
                    Element lot = item.addElement("UserDef" + i);
                    lot.setText("");
                }
            }
        }
        String XMLStr = doc.getRootElement().asXML();
        String resultStr = sendSFRequest(XMLStr);
        SFAuditLogFilter.saveRequestContext(delegator, "PURCHASE_ORDER_SERVICE", XMLStr, resultStr);
        Document resultDocument = (Document) DocumentHelper.parseText(resultStr);
        Element ResponseElement = resultDocument.getRootElement();
        Element HeadElement = ResponseElement.element("Head");

        if (HeadElement.getText().equals("ERR")) {
            Element ErrorElement = ResponseElement.element("Error");
            String code = ErrorElement.attributeValue("code");
            String errorMessage = ErrorElement.getText();
            return ServiceUtil.returnError("ERROR : errorCode={" + code + "} message={" + errorMessage + "}");
        } else {
            Element BodyElement = ResponseElement.element("Body");
            Element PurchaseOrderResponseElement = BodyElement.element("PurchaseOrderResponse");
            Element PurchaseOrdersElement = PurchaseOrderResponseElement.element("PurchaseOrders");
            Element PurchaseOrderElement = PurchaseOrdersElement.element("PurchaseOrder");
            Element ResultElement = PurchaseOrderElement.element("Result");
            Element ReceiptIdElement = PurchaseOrderElement.element("ReceiptId");
            Element NoteElement = PurchaseOrderElement.element("Note");
            result.put("resultCode", ResultElement.getText());
            if (UtilValidate.isNotEmpty(ReceiptIdElement)) {
                result.put("receiptId", ReceiptIdElement.getText());
            }

            if (UtilValidate.isNotEmpty(NoteElement)) {
                result.put("note", NoteElement.getText());
            }
            return result;
        }
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ServiceUtil.returnError(e.getMessage());
    }
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ?/*ww w. ja  va 2  s .  c om*/
 * @author sven
 * @param request
 * @param response
 * @return
 */
public static String SFGodownEntryPush(HttpServletRequest request, HttpServletResponse response) {
    String logistics_interface = (String) request.getParameter("logistics_interface");
    Debug.log("logistics_interface : SFGodownEntryPush:?" + logistics_interface);
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    List<Map<String, Object>> shipmentList = FastList.newInstance();

    Document responseDoc = (Document) DocumentHelper.createDocument();
    Element responseElement = responseDoc.addElement("Response");
    responseElement.addAttribute("service", "PURCHASE_ORDER_INBOUND_SERVICE");
    responseElement.addAttribute("lang", "zh-CN");
    responseElement.addElement("Head").addText("OK");
    Element PurchaseOrderInboundResponse = responseElement.addElement("Body")
            .addElement("PurchaseOrderInboundResponse");
    try {
        GenericValue userLogin = delegator.findOne("UserLogin", true, UtilMisc.toMap("userLoginId", "system"));
        Document doc = (Document) DocumentHelper.parseText(logistics_interface);
        Element ResponseElement = doc.getRootElement();
        Element BodyElement = ResponseElement.element("Body");
        Element PurchaseOrderInboundRequest = BodyElement.element("PurchaseOrderInboundRequest");
        List<Element> PurchaseOrderList = PurchaseOrderInboundRequest.elements("PurchaseOrders");
        for (Element PurchaseOrder : PurchaseOrderList) {
            Element ErpOrder = PurchaseOrder.element("PurchaseOrder").element("ErpOrder");//???
            Element ReceiptId = PurchaseOrder.element("PurchaseOrder").element("ReceiptId");//??
            Element Status = PurchaseOrder.element("PurchaseOrder").element("Status");//?
            List<Element> items = PurchaseOrder.element("PurchaseOrder").element("Items").elements("Item");

            // ReceiptId ???
            GenericValue sfOrderAssoc = EntityUtil.getFirst(
                    delegator.findByAnd("SFOrderAssoc", UtilMisc.toMap("SFCallBackId", ReceiptId.getText())));
            if (UtilValidate.isEmpty(sfOrderAssoc)) {
                //?
                ApiUtil.messageEmailNotification(dispatcher, delegator, "SFRecepitPushError",
                        "receiptId " + ReceiptId.getText() + " not found", null);
                //return "error";
                continue;
            }
            if ("SHIPMENT_IN".equals(sfOrderAssoc.getString("localOrderTypeId"))) {
                //ofbizshipment?
                for (Element item : items) {
                    Map<String, Object> shipmentMap = UtilMisc.toMap("productId",
                            item.element("SkuNo").getText(), "quantity",
                            new BigDecimal(item.element("PlanQty").getText()), "actualQuantity",
                            new BigDecimal(item.element("ActualQty").getText()));
                    shipmentList.add(shipmentMap);
                }
                //  ??
                dispatcher.runSync("shunfengShipmentReceive", UtilMisc.toMap("shipmentItems", shipmentList,
                        "shipmentId", sfOrderAssoc.getString("shipmentId"), "userLogin", userLogin));
            } else if ("ORDER_IN".equals(sfOrderAssoc.getString("localOrderTypeId"))) {
                //?
                String returnId = sfOrderAssoc.getString("returnId");
                List<Map<String, Object>> reutnItems = FastList.newInstance();
                for (Element item : items) {
                    Map<String, Object> temp = UtilMisc.toMap("productId", item.element("SkuNo").getText(),
                            "quantity", new BigDecimal(item.element("PlanQty").getText()), "actualQuantity",
                            new BigDecimal(item.element("ActualQty").getText()));
                    reutnItems.add(temp);
                }
                Map<String, Object> returnMap = dispatcher.runSync("OMSReturnReceive",
                        UtilMisc.toMap("returnId", returnId, "itemList", reutnItems, "userLogin", userLogin));
                if (ServiceUtil.isError(returnMap)) {
                    ApiUtil.messageEmailNotification(dispatcher, delegator, "SFRecepitPushError",
                            ServiceUtil.getErrorMessage(returnMap), null);
                }
            }
        }
    } catch (DocumentException e) {
        ApiUtil.messageEmailNotification(dispatcher, delegator, "SFRecepitPushError", e.getMessage(), null);
        setResponseMsg(PurchaseOrderInboundResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
        e.printStackTrace();
    } catch (GenericEntityException e) {
        ApiUtil.messageEmailNotification(dispatcher, delegator, "SFRecepitPushError", e.getMessage(), null);
        setResponseMsg(PurchaseOrderInboundResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
        e.printStackTrace();
    } catch (GenericServiceException e) {
        ApiUtil.messageEmailNotification(dispatcher, delegator, "SFRecepitPushError", e.getMessage(), null);
        setResponseMsg(PurchaseOrderInboundResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
        e.printStackTrace();
    }
    setResponseMsg(PurchaseOrderInboundResponse, "1", "");
    responseToShunfeng(request, response, responseDoc.getRootElement().asXML());

    return "success";
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ?//from  w w w .  ja v a2  s  .  c om
 * @author sven
 * @param request
 * @param response
 * @return
 */
public static String SFInventoryPush(HttpServletRequest request, HttpServletResponse response) {
    String logistics_interface = (String) request.getParameter("logistics_interface");
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");

    Document responseDoc = (Document) DocumentHelper.createDocument();
    Element responseElement = responseDoc.addElement("Response");
    responseElement.addAttribute("service", "INVENTORY_BALANCE_SERVICE");
    responseElement.addAttribute("lang", "zh-CN");
    responseElement.addElement("Head").addText("OK");
    Element InventoryBalanceResponse = responseElement.addElement("Body")
            .addElement("InventoryBalanceResponse");

    try {
        Document doc = (Document) DocumentHelper.parseText(logistics_interface);
        Element ResponseElement = doc.getRootElement();
        Element BodyElement = ResponseElement.element("Body");
        Element InventoryBalanceRequest = BodyElement.element("InventoryBalanceRequest");
        Element InventoryBalances = InventoryBalanceRequest.element("InventoryBalances");
        Element Status = InventoryBalanceRequest.element("Status");
        // ?1?
        if (UtilValidate.isEmpty(InventoryBalances) || "1".equals(Status.getText())) {
            setResponseMsg(InventoryBalanceResponse, "1", "");
            responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
            return "success";
        }
        List<Element> inventoryBalanceList = InventoryBalances.elements("InventoryBalance");
        for (Element inventoryBalance : inventoryBalanceList) {
            Element SkuNo = inventoryBalance.element("SkuNo");
            Element Qty = inventoryBalance.element("Qty");
            Element InventoryStatus = inventoryBalance.element("InventoryStatus");

            GenericValue invTemp = delegator.makeValue("ShunfengInventoryTemp");
            invTemp.put("baseId", delegator.getNextSeqId("ShunfengInventoryTemp"));
            invTemp.put("productId", SkuNo.getText());
            invTemp.put("availableToPromiseTotal", new BigDecimal(Qty.getText()));
            invTemp.put("quantityOnHandTotal", new BigDecimal(Qty.getText()));
            invTemp.put("inventoryStatus", InventoryStatus.getText());
            invTemp.put("pushDateTime", UtilDateTime.nowTimestamp());
            invTemp.create();
        }
        setResponseMsg(InventoryBalanceResponse, "1", "");
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
    } catch (DocumentException e) {
        setResponseMsg(InventoryBalanceResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
        e.printStackTrace();
    } catch (GenericEntityException e) {
        setResponseMsg(InventoryBalanceResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
        e.printStackTrace();
    }
    return "success";
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ??//from w  w  w . j  av  a2s .com
 * @author sven
 * @param request
 * @param response
 * @return
 */
public static String SFOutboundListPush(HttpServletRequest request, HttpServletResponse response) {
    String logistics_interface = (String) request.getParameter("logistics_interface");

    Debug.log("====== logistics_interface SFOutboundListPush ? :" + logistics_interface);
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    StringBuffer errorOrderBody = new StringBuffer();
    List<Map<String, Object>> orderList = FastList.newInstance();
    List<Map<String, Object>> shipmentList = FastList.newInstance();

    Document responseDoc = (Document) DocumentHelper.createDocument();
    Element responseElement = responseDoc.addElement("Response");
    responseElement.addAttribute("service", "SALE_ORDER_OUTBOUND_DETAIL_SERVICE");
    responseElement.addAttribute("lang", "zh-CN");
    responseElement.addElement("Head").addText("OK");
    Element PurchaseOrderInboundResponse = responseElement.addElement("Body")
            .addElement("SaleOrderOutboundDetailResponse");

    try {
        GenericValue userLogin = delegator.findOne("UserLogin", true, UtilMisc.toMap("userLoginId", "system"));
        Document doc = (Document) DocumentHelper.parseText(logistics_interface);
        Element ResponseElement = doc.getRootElement();
        Element BodyElement = ResponseElement.element("Body");
        Element PurchaseOrderInboundRequest = BodyElement.element("SaleOrderOutboundDetailRequest");
        List<Element> salesOrders = PurchaseOrderInboundRequest.elements("SaleOrders");
        for (Element salesOrder : salesOrders) {
            String sfShipmentId = salesOrder.element("SaleOrder").element("ShipmentId").getText();
            String trackingIdNumber = salesOrder.element("SaleOrder").element("WayBillNo").getText();
            String status = salesOrder.element("SaleOrder").element("DataStatus").getText();
            if (!"2900".equals(status) && !"3900".equals(status)) {
                errorOrderBody.append("SFOutboundListPush:ErpOrder[" + sfShipmentId + "],status[" + status
                        + "] ???<br/>");
                continue;
            }
            // ReceiptId ???
            GenericValue sfOrderAssoc = EntityUtil.getFirst(
                    delegator.findByAnd("SFOrderAssoc", UtilMisc.toMap("SFCallBackId", sfShipmentId)));
            if (UtilValidate.isEmpty(sfOrderAssoc)) {
                errorOrderBody.append("SFOutboundListPush:sfShipmentId not found<br/>");
                continue;
            }
            if ("SHIPMENT_OUT".equals(sfOrderAssoc.getString("localOrderTypeId"))) {
                //ofbizshipment?
                Map<String, Object> shipmentMap = UtilMisc.toMap("shipmentId",
                        sfOrderAssoc.getString("shipmentId"), "trackingIdNumber", trackingIdNumber);
                shipmentList.add(shipmentMap);
            } else if ("ORDER_OUT".equals(sfOrderAssoc.getString("localOrderTypeId"))) {
                Map<String, Object> orderMap = UtilMisc.toMap("orderId", sfOrderAssoc.getString("orderId"),
                        "orderItemShipGroupId", sfOrderAssoc.getString("shipGroupSeqId"), "trackingIdNumber",
                        trackingIdNumber);
                orderList.add(orderMap);
            }
        }

        if (UtilValidate.isNotEmpty(errorOrderBody)) {
            //?
            ApiUtil.messageEmailNotification(dispatcher, delegator, "SFShipmentPushError",
                    errorOrderBody.toString(), null);
            //return "error";
        }
        if (UtilValidate.isNotEmpty(orderList)) {
            //???
            dispatcher.runSync("OMSOrderShipComplete",
                    UtilMisc.toMap("orderList", orderList, "userLogin", userLogin));
        }

        if (UtilValidate.isNotEmpty(shipmentList)) {
            //shipment??
            dispatcher.runSync("sendShipmentFromShunfeng",
                    UtilMisc.toMap("shipmentList", shipmentList, "userLogin", userLogin));
        }

        setResponseMsg(PurchaseOrderInboundResponse, "1", "");
        responseToShunfeng(request, response, responseDoc.asXML());
    } catch (DocumentException e) {
        ApiUtil.messageEmailNotification(dispatcher, delegator, "SFShipmentPushError", e.getMessage(), null);
        setResponseMsg(PurchaseOrderInboundResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.asXML());
        e.printStackTrace();
    } catch (GenericEntityException e) {
        ApiUtil.messageEmailNotification(dispatcher, delegator, "SFShipmentPushError", e.getMessage(), null);
        setResponseMsg(PurchaseOrderInboundResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.asXML());
        e.printStackTrace();
    } catch (GenericServiceException e) {
        ApiUtil.messageEmailNotification(dispatcher, delegator, "SFShipmentPushError", e.getMessage(), null);
        setResponseMsg(PurchaseOrderInboundResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.asXML());
        e.printStackTrace();
    }
    return "success";
}

From source file:com.synesoft.fisp.app.common.utils.XmlFileUtil.java

License:Open Source License

/**
 * add root element// www .j  av  a  2  s . c  o  m
 * 
 * @param elName
 *            child node name
 * @param doc
 *            document
 * @return
 */
public static Element appendChile(String elName, Document doc) {
    Element root = doc.addElement(elName);
    return root;
}

From source file:com.taobao.datax.engine.tools.JobConfGenDriver.java

License:Open Source License

private static int genXmlFile(String filename, ClassNode reader, ClassNode writer) throws IOException {

    Document document = DocumentHelper.createDocument();
    Element jobsElement = document.addElement("jobs");
    Element jobElement = jobsElement.addElement("job");
    String id = reader.getName() + "_to_" + writer.getName() + "_job";
    jobElement.addAttribute("id", id);

    /**// w ww .  j a v a 2  s .co m
     * ?readerxml
     */
    Element readerElement = jobElement.addElement("reader");
    Element plugin_Element = readerElement.addElement("plugin");
    plugin_Element.setText(reader.getName());

    ClassNode readerNode = reader;
    Element tempElement = null;

    List<ClassMember> members = readerNode.getAllMembers();
    for (ClassMember member : members) {
        StringBuilder command = new StringBuilder("\n");

        Set<String> set = member.getAllKeys();
        String value = "";
        for (String key : set) {
            value = member.getAttr("default");
            command.append(key).append(":").append(member.getAttr(key)).append("\n");
        }
        readerElement.addComment(command.toString());

        String keyName = member.getName();
        keyName = keyName.substring(1, keyName.length() - 1);
        tempElement = readerElement.addElement("param");
        tempElement.addAttribute("key", keyName);

        if (value == null || "".equals(value)) {
            value = "?";
        }
        tempElement.addAttribute("value", value);
    }

    /**
     * ?writerxml
     */
    Element writerElement = jobElement.addElement("writer");
    plugin_Element = writerElement.addElement("plugin");
    plugin_Element.setText(writer.getName());

    members = writer.getAllMembers();
    for (ClassMember member : members) {
        StringBuilder command = new StringBuilder("\n");
        Set<String> set = member.getAllKeys();

        String value = "";
        for (String key : set) {
            value = member.getAttr("default");
            command.append(key).append(":").append(member.getAttr(key)).append("\n");
        }
        writerElement.addComment(command.toString());

        String keyName = member.getName();
        keyName = keyName.substring(1, keyName.length() - 1);
        tempElement = writerElement.addElement("param");
        tempElement.addAttribute("key", keyName);

        if (value == null || "".equals(value)) {
            value = "?";
        }
        tempElement.addAttribute("value", value);
    }

    try {
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setEncoding("UTF-8");
        XMLWriter writerOfXML = new XMLWriter(new FileWriter(new File(filename)), format);
        writerOfXML.write(document);
        writerOfXML.close();
    } catch (Exception ex) {
        throw new IOException(ex.getCause());
    }

    return 0;
}